diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index 7846c01..29a37d3 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -77,4 +77,10 @@ class GoodsController extends BaseController } return $this->success($res); } + + public function update() + { + $res = $this->goodsService->update($this->request->all()); + return $this->success($res); + } } \ No newline at end of file diff --git a/app/Controller/v3/StoreController.php b/app/Controller/v3/StoreController.php index 2afc46e..164dd98 100644 --- a/app/Controller/v3/StoreController.php +++ b/app/Controller/v3/StoreController.php @@ -6,6 +6,7 @@ use App\Controller\BaseController; use App\Request\v3\StoreIndexRequest; use App\Service\v3\Interfaces\CategoryServiceInterface; use App\Service\v3\Interfaces\CollectStoreServiceInterface; +use App\Service\v3\Interfaces\GoodsServiceInterface; use App\Service\v3\Interfaces\StoreServiceInterface; use Hyperf\Di\Annotation\Inject; use Psr\Http\Message\ResponseInterface; @@ -38,6 +39,12 @@ class StoreController extends BaseController */ protected $businessHoursService; + /** + * @Inject + * @var GoodsServiceInterface + */ + protected $goodsService; + /** * 商户详情页 * 1、商户id用来查询的,还要有user_id @@ -82,4 +89,14 @@ class StoreController extends BaseController $res = $this->businessHoursService->do($storeId,$isRest,$time1,$time2,$time3,$time4); return $this->success($res); } + + public function getGoodsByType() + { + $storeId = $this->request->input('store_id'); + $typeId = $this->request->input('type_id',''); + $page = $this->request->input('page',1); + $pagesize = $this->request->input('pagesize',10); + $goods = $this->goodsService->getByType($storeId,$typeId,$page,$pagesize); + return $this->success($goods); + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index 6740d92..4933d21 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -70,4 +70,25 @@ class GoodsService implements GoodsServiceInterface $res = Goods::query()->with('store')->where('id',$goodsId)->first(); return $res; } + + public function getByType($storeId,$typeId, $page=1, $pagesize=10) + { + $builder = Goods::query()->where(['store_id' => $storeId,'category_id' => $typeId]); + + $paginate = $builder->orderByDesc('on_sale')->orderByDesc('created_at')->paginate($pagesize); + $goods = $paginate->toArray(); + return ['has_more_pages' => $paginate->hasMorePages(), 'goods' => $goods['data']]; + } + + public function update($params) + { + $goods = Goods::find($params['id']); + if (empty($goods)) { + return ErrorCode::GOODS_NOT_EXISTS; + } + foreach ($params as $k => $v){ + $goods->$k = $v; + } + return $goods->save(); + } } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/GoodsServiceInterface.php b/app/Service/v3/Interfaces/GoodsServiceInterface.php index 53c4b43..32c0251 100644 --- a/app/Service/v3/Interfaces/GoodsServiceInterface.php +++ b/app/Service/v3/Interfaces/GoodsServiceInterface.php @@ -10,4 +10,6 @@ interface GoodsServiceInterface public function check(Goods $goods,$num = 1); public function undo(); public function getBanner($goodsId); + public function getByType($storeId,$typeId, $page=1, $pagesize=10); + public function update($params); } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index fa8aa28..c029b54 100644 --- a/config/routes.php +++ b/config/routes.php @@ -150,6 +150,8 @@ Router::addGroup('/v3/', function () { Router::post('device/list', 'App\Controller\v3\DeviceController@list'); Router::post('device/unbind', 'App\Controller\v3\DeviceController@unbind'); Router::post('orderOffline/completePage', 'App\Controller\v3\OrderOfflineController@completePage'); + Router::post('store/getGoodsByType', 'App\Controller\v3\StoreController@getGoodsByType'); + Router::post('goods/update', 'App\Controller\v3\GoodsController@update'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]); // 微信支付回调