| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace App\Http\Controllers\Api\v1;
- use App\Http\Controllers\Api\webApp;
- use App\Services\Api\GoodsService;
- use App\Services\Common\AdService;
- use App\Services\RedisService;
- /**
- * 商品管理
- * @package App\Http\Controllers\Api
- */
- class GoodsController extends webApp
- {
- /**
- * 列表
- * @return array
- */
- public function index()
- {
- $params =request()->post();
- $pageSize = request()->post('pageSize', 12);
- $datas = GoodsService::make()->getDataList($params, $pageSize);
- return message(1010, true, $datas);
- }
- /**
- * 购买商品列表
- * @return array
- */
- public function buyGoods()
- {
- $params =request()->post();
- $goods = isset($params['goods']) && $params['goods'] ? $params['goods'] : [];
- $ids = $goods ? array_column($goods, 'id') : [];
- if($datas = GoodsService::make()->getOrderGoods($ids, $goods, $this->userId)){
- return message(1010, true, $datas);
- }else{
- $error = GoodsService::make()->getError();
- return message($error, false,'',$error==1042? 403 : -1);
- }
- }
- /**
- * 分类
- * @return array
- */
- public function categorys()
- {
- $datas = GoodsService::make()->getCategoryList();
- return message(1010, true, $datas);
- }
- /**
- * 详情
- */
- public function info()
- {
- $params = request()->all();
- $id = isset($params['id'])? intval($params['id']) : 0;
- if(empty($id)){
- return message(1036, false);
- }
- if($info = GoodsService::make()->getInfo($id, $this->userId)){
- return message(1010, true, $info);
- }else{
- return message('商品已下架', false);
- }
- }
- /**
- * 创业大礼包
- * @return array
- */
- public function data()
- {
- $areaId = $this->areaId;
- $buyType = $this->buyType;
- if($areaId<=0){
- $cacheInfo = RedisService::get("caches:index:area_".get_client_ip());
- $areaId = isset($cacheInfo['area_id'])?$cacheInfo['area_id'] : 1;
- $buyType = isset($cacheInfo['buy_type'])?$cacheInfo['buy_type'] : 1;
- }
- try {
- $data = [
- // 轮播
- 'banners' => AdService::make()->getListByPosition(1),
- 'goods' => GoodsService::make()->getListByType(2, $buyType, $this->userId),
- 'areaId'=> $areaId,
- 'buyType'=> $buyType,
- ];
- return showJson(1010, true, $data);
- } catch (\Exception $exception) {
- $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
- return showJson(1046, false, $error);
- }
- }
- /**
- * 收藏
- */
- public function collect()
- {
- $params = request()->all();
- $id = isset($params['id']) ? intval($params['id']) : 0;
- if (empty($id)) {
- return message(1036, false);
- }
- try {
- if ($result = GoodsService::make()->collect($this->userId, $id)) {
- return message(GoodsService::make()->getError(), true, $result);
- } else {
- return message(GoodsService::make()->getError(), false);
- }
- } catch (\Exception $exception) {
- $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
- return showJson(1046, false, $error);
- }
- }
- }
|