From ccb01b3308b92518471ca428d83b772d295cf9c3 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 25 Sep 2020 14:18:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/GoodsController.php | 13 ++++++++- app/Model/v3/Goods.php | 10 +++++++ .../v3/Implementations/GoodsService.php | 27 +++++++++++++++++-- config/routes.php | 1 + 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index c4fdb99..c46b361 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -112,7 +112,18 @@ class GoodsController extends BaseController 'goods' => $goods, 'first' => $first, 'secend' => $secend, - 'third' => $third + 'third' => $third, + 'tags' => [ + '新品', + '热销', + '新鲜' + ] ]); } + + public function create(GoodsEditorRequest $request) + { + $res = $this->goodsService->create($this->request->all()); + return $this->success($res); + } } \ No newline at end of file diff --git a/app/Model/v3/Goods.php b/app/Model/v3/Goods.php index 9ff23d0..74558a1 100644 --- a/app/Model/v3/Goods.php +++ b/app/Model/v3/Goods.php @@ -162,4 +162,14 @@ class Goods extends Model { return $this->morphMany(ShoppingCart::class, 'goods'); } + + public function setTagsAttribute($value) + { + $this->attributes['tags'] = json_encode(json_decode($value, true)); + } + + public function setSpecAttribute($value) + { + $this->attributes['spec'] = json_encode(json_decode($value, true)); + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index ff7804b..6509a1e 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -76,6 +76,29 @@ class GoodsService implements GoodsServiceInterface return Goods::query()->withoutGlobalScope('normal')->where(['store_id' => $storeId,'category_id' => $typeId])->orderByDesc('on_sale')->orderByDesc('created_at')->get()->toArray(); } + public function create($params) + { + $data = + [ + 'market_id' => $params['market_id'], + 'store_id' => $params['store_id'], + 'name' => $params['name'], + 'category_id' => $params['market_id'], + 'goods_unit' => $params['goods_unit'], + 'price' => $params['price'], + 'original_price' => $params['original_price'], + 'inventory' => $params['inventory'], + 'restrict_num' => $params['restrict_num'], + 'start_num' => $params['start_num'], + 'spec' => $params['spec'], + 'tags' => $params['tags'], + 'remark' => $params['remark'], + 'on_sale' => $params['on_sale'], + 'is_infinite' => $params['is_infinite'] + ]; + return Goods::create($data); + } + public function update($params) { $goods = Goods::query()->where( @@ -94,8 +117,8 @@ class GoodsService implements GoodsServiceInterface 'inventory' => $params['inventory'], 'restrict_num' => $params['restrict_num'], 'start_num' => $params['start_num'], - //'spec' => $params['spec'], - //'tags' => $params['tags'], + 'spec' => $params['spec'], + 'tags' => $params['tags'], 'remark' => $params['remark'], 'on_sale' => $params['on_sale'], 'is_infinite' => $params['is_infinite'], diff --git a/config/routes.php b/config/routes.php index 015a49a..b2c28d4 100644 --- a/config/routes.php +++ b/config/routes.php @@ -160,6 +160,7 @@ Router::addGroup('/v3/', function () { Router::post('category/first', 'App\Controller\v3\CategoryController@first'); Router::post('category/secend', 'App\Controller\v3\CategoryController@secend'); Router::post('category/third', 'App\Controller\v3\CategoryController@third'); + Router::post('goods/create', 'App\Controller\v3\GoodsController@create'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]); // 微信支付回调