| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace App\Http\Controllers\Api\v1;
- use App\Http\Controllers\Api\webApp;
- use App\Http\Validator\GoodsValidator;
- use App\Services\Api\GoodsService;
- use App\Services\Api\GoodsCategoryService;
- use App\Services\RedisService;
- /**
- * 商品服务管理
- * @package App\Http\Controllers\Api
- */
- class GoodsController extends webApp
- {
- /**
- * 列表
- * @return array
- */
- public function index()
- {
- try {
- $params = request()->post();
- $pageSize = request()->post('pageSize', 0);
- $datas = GoodsService::make()->getDataList($params, $pageSize,'', $this->userId);
- return message(1010, true, $datas);
- } catch (\Exception $exception){
- RedisService::set("caches:request:error_goods_index", ['trace'=>$exception->getTrace()], 7200);
- return message(1018, false, ['error'=>env('APP_DEBUG')? $exception->getMessage() : '']);
- }
- }
- /**
- * 列表
- * @return array
- */
- public function list()
- {
- try {
- $params = request()->post();
- $pageSize = request()->post('pageSize', 0);
- $datas = GoodsService::make()->getDataList($params, $pageSize,'lev_a.*,lev_c.name as merch_name', $this->userId);
- return message(1010, true, $datas);
- } catch (\Exception $exception){
- RedisService::set("caches:request:error_goods_index", ['trace'=>$exception->getTrace()], 7200);
- return message(1018, false, ['error'=>env('APP_DEBUG')? $exception->getTrace() : '']);
- }
- }
- /**
- * 分类
- * @return array
- */
- public function category()
- {
- $params = request()->post();
- $pageSize = request()->post('pageSize', 99);
- $datas = GoodsCategoryService::make()->getDataList($params, $pageSize);
- return message(1010, true, $datas);
- }
- /**
- * 详情
- * @return array
- */
- public function info()
- {
- $id = request()->post('id', 0);
- $info = GoodsService::make()->getInfo($id, $this->userId);
- return message(1010, true, $info);
- }
- /**
- * 推荐
- * @return array
- */
- public function recommend()
- {
- try {
- $params = request()->post();
- $pageSize = request()->post('pageSize', 0);
- $lng = isset($params['lng'])? $params['lng'] : '';
- $lat = isset($params['lat'])? $params['lat'] : '';
- $params = [
- 'lat'=> $lat? $lat : (isset($this->userInfo['lat'])? $this->userInfo['lat'] : ''),
- 'lng'=> $lng? $lng : (isset($this->userInfo['lng'])? $this->userInfo['lng'] : ''),
- 'sort_type'=> 1,
- 'is_recommend'=> 1,
- 'type'=> isset($params['type'])? intval($params['type']) : 2,
- 'status'=> 2,
- ];
- $datas = GoodsService::make()->getDataList($params, $pageSize);
- return message(1010, true, $datas);
- } catch (\Exception $exception){
- RedisService::set("caches:request:error_goods_recommend", ['trace'=>$exception->getTrace()], 7200);
- return message(1018, false, ['error'=>env('APP_DEBUG')? $exception->getMessage() : '']);
- }
- }
- /**
- * 发布
- * @param GoodsValidator $validator
- * @return array
- */
- public function submit(GoodsValidator $validator)
- {
- $params = request()->all();
- $params = $validator->check($params, 'submit');
- if (!is_array($params)) {
- return message($params, false);
- }
- if(!$result = GoodsService::make()->submit($this->userId, $params)){
- return message(GoodsService::make()->getError(), false);
- }else{
- return message(GoodsService::make()->getError(), true, $result);
- }
- }
- /**
- * 状态/上下架
- * @return array|mixed
- */
- public function status()
- {
- if(!$result = GoodsService::make()->status()){
- return message(GoodsService::make()->getError(), false);
- }else{
- return message(GoodsService::make()->getError(), true, $result);
- }
- }
- /**
- * 删除
- * @return array|mixed
- */
- public function delete()
- {
- return GoodsService::make()->delete();
- }
- }
|