From 2585b8d6565a8aafe1187ffed500da1bafb7fcbd Mon Sep 17 00:00:00 2001 From: weigang Date: Sun, 13 Sep 2020 14:13:44 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=EF=BC=8C=E6=8F=90=E7=8E=B0=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/GoodsRecommendController.php | 1 - app/Service/v3/Implementations/ActivityService.php | 10 +++++----- .../v3/Implementations/WithdrawalListService.php | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/Controller/v3/GoodsRecommendController.php b/app/Controller/v3/GoodsRecommendController.php index e96b29f..2763cbc 100644 --- a/app/Controller/v3/GoodsRecommendController.php +++ b/app/Controller/v3/GoodsRecommendController.php @@ -47,7 +47,6 @@ class GoodsRecommendController extends BaseController break; case Tabs::APPLET_INDEX_OFFICE: $categoryIds = [97,98]; - var_dump('ids', $categoryIds); // 查询出三级分类 $goodsCategoryIds = GoodsCategory::query()->whereIn('category_id', $categoryIds)->pluck('id'); $builder = $builder->where(function ($query) use ($categoryIds, $goodsCategoryIds) { diff --git a/app/Service/v3/Implementations/ActivityService.php b/app/Service/v3/Implementations/ActivityService.php index 3f3cfc4..3eea246 100644 --- a/app/Service/v3/Implementations/ActivityService.php +++ b/app/Service/v3/Implementations/ActivityService.php @@ -28,11 +28,11 @@ class ActivityService implements ActivityServiceInterface { $builder = GoodsActivity::query() ->with(['store']) - ->where(['type' => $type]); - - if ($marketId != -1) { - $builder = $builder->where('market_id', $marketId); - } + ->where(['type' => $type]) + ->where(function ($query) use ($marketId) { + $query->whereJsonContains("market_ids", [(string)$marketId]) + ->orWhereJsonLength("market_ids", '=', 0); + }); return $builder->get()->toArray(); } diff --git a/app/Service/v3/Implementations/WithdrawalListService.php b/app/Service/v3/Implementations/WithdrawalListService.php index 7ed2c9d..36c2d8c 100644 --- a/app/Service/v3/Implementations/WithdrawalListService.php +++ b/app/Service/v3/Implementations/WithdrawalListService.php @@ -27,7 +27,7 @@ class WithdrawalListService implements WithdrawalListServiceInterface if(!empty($startTime) && !empty($endTime)){ $builder->whereBetween('created_at',[$startTime,$endTime]); } - $paginate = $builder->paginate($pagesize); + $paginate = $builder->orderBy('created_at', 'desc')->paginate($pagesize); $orders = $paginate->toArray(); return ['has_more_pages' => $paginate->hasMorePages(), 'orders' => $orders['data']]; } From d4c9eacdf13f82dfd5797dc3ca7141e895945174 Mon Sep 17 00:00:00 2001 From: weigang Date: Sun, 13 Sep 2020 14:41:53 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=95=86=E6=88=B7=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=E7=9A=84=E5=88=86=E7=B1=BB=E4=BF=A1=E6=81=AF=E3=80=81?= =?UTF-8?q?=E5=95=86=E5=93=81=E6=90=9C=E7=B4=A2=E5=8A=A0=E5=85=A5store=5Fi?= =?UTF-8?q?d=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/Implementations/CategoryService.php | 18 ++++++++++++++---- .../v3/Implementations/SearchService.php | 4 ++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/Service/v3/Implementations/CategoryService.php b/app/Service/v3/Implementations/CategoryService.php index 039e532..9ca52f7 100644 --- a/app/Service/v3/Implementations/CategoryService.php +++ b/app/Service/v3/Implementations/CategoryService.php @@ -50,16 +50,26 @@ class CategoryService implements CategoryServiceInterface public function allForStore($storeId) { - $goodsTypeIds = Goods::query()->select('id','category_id') + $goodsTypeIds = Goods::query() ->where(['store_id' => $storeId]) ->groupBy('category_id', 'id') - ->get()->toArray(); + ->pluck('category_id'); - return Category::query() - ->whereIn('id', array_values(array_column($goodsTypeIds, 'category_id'))) + $categories = Category::query() + ->with(['goodsCategory']) + ->whereIn('id', $goodsTypeIds) ->orderBy('sort', 'DESC') ->orderBy('id', 'DESC') ->get()->toArray(); + + foreach ($categories as $key => &$item) { + $item['goods_category_ids'] = ''; + if (isset($item['goods_category']) && $item['goods_category']) { + $item['goods_category_ids'] = implode(',', array_values(array_column($item['goods_category'], 'id'))); + } + } + + return $categories; } public function allForAppletIndex() diff --git a/app/Service/v3/Implementations/SearchService.php b/app/Service/v3/Implementations/SearchService.php index 6088023..86addd7 100644 --- a/app/Service/v3/Implementations/SearchService.php +++ b/app/Service/v3/Implementations/SearchService.php @@ -26,6 +26,10 @@ class SearchService implements SearchServiceInterface $query->where('inventory', '>', 0)->orWhere('is_infinite', '=', 1); });; + if (isset($params['store_id']) && $params['store_id']) { + $builder->where(['store_id' => $params['store_id']]); + } + if (isset($params['type_id']) && $params['type_id']) { $typeIds = explode(',', $params['type_id']); $builder->whereIn('category_id', $typeIds); From 407df2b57a16b257a3ed86674a538cc04a301ffa Mon Sep 17 00:00:00 2001 From: weigang Date: Sun, 13 Sep 2020 15:10:05 +0800 Subject: [PATCH 3/8] no message --- app/Model/v3/ShoppingCart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Model/v3/ShoppingCart.php b/app/Model/v3/ShoppingCart.php index e1d246c..5784036 100644 --- a/app/Model/v3/ShoppingCart.php +++ b/app/Model/v3/ShoppingCart.php @@ -3,11 +3,11 @@ namespace App\Model\v3; use App\Model\Model; -use Hyperf\Database\Model\SoftDeletes; +// use Hyperf\Database\Model\SoftDeletes; class ShoppingCart extends Model { - use SoftDeletes; + // use SoftDeletes; protected $table = 'lanzu_shopping_cart'; protected $fillable = [ From 275a1085f5c5f1c7e51a8e35571564c51d0021ee Mon Sep 17 00:00:00 2001 From: weigang Date: Sun, 13 Sep 2020 15:55:10 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v3/Implementations/UserAddressService.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Service/v3/Implementations/UserAddressService.php b/app/Service/v3/Implementations/UserAddressService.php index e41f7c7..c615f17 100644 --- a/app/Service/v3/Implementations/UserAddressService.php +++ b/app/Service/v3/Implementations/UserAddressService.php @@ -65,7 +65,10 @@ class UserAddressService implements UserAddressServiceInterface public function get($userAddressId) { - return UserAddress::query()->find($userAddressId); + $address['address'] = UserAddress::query()->find($userAddressId); + $address['tags'] = $this->getTags(); + + return $address; } public function getList($userId) @@ -89,5 +92,15 @@ class UserAddressService implements UserAddressServiceInterface return $res; } + public function getTags() + { + return [ + ['id' => 1, 'name' => '家'], + ['id' => 2, 'name' => '父母家'], + ['id' => 3, 'name' => '岳父母家'], + ['id' => 4, 'name' => '公司'], + ['id' => 5, 'name' => '朋友家'], + ]; + } } \ No newline at end of file From ede12992c83faa8d8fb3391747269f883c26bc52 Mon Sep 17 00:00:00 2001 From: weigang Date: Sun, 13 Sep 2020 16:26:53 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E5=95=86=E5=93=81=E8=B4=AD=E7=89=A9?= =?UTF-8?q?=E8=BD=A6=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/Goods.php | 3 ++- app/Model/v3/GoodsActivity.php | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Model/v3/Goods.php b/app/Model/v3/Goods.php index c1f971c..b43d946 100644 --- a/app/Model/v3/Goods.php +++ b/app/Model/v3/Goods.php @@ -100,7 +100,8 @@ class Goods extends Model public function getCartNumAttribute() { - return 0; + $userId = $this->request->user->id ?? 0; + return $userId ? (integer)$this->shopCartService->check($userId, $this->id,1) : 0; } public function getIsEffectiveAttribute() diff --git a/app/Model/v3/GoodsActivity.php b/app/Model/v3/GoodsActivity.php index bb78d70..a9bb3b2 100644 --- a/app/Model/v3/GoodsActivity.php +++ b/app/Model/v3/GoodsActivity.php @@ -68,7 +68,8 @@ class GoodsActivity extends Model public function getCartNumAttribute() { - return 0; + $userId = $this->request->user->id ?? 0; + return $userId ? (integer)$this->shopCartService->check($userId, $this->id,1) : 0; } public function getIsEffectiveAttribute() From 6020642d0eff58fa59fb256958ba449c2dca1e0c Mon Sep 17 00:00:00 2001 From: weigang Date: Sun, 13 Sep 2020 17:13:58 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E9=94=81?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/ShopCartUpdateService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Service/v3/Implementations/ShopCartUpdateService.php b/app/Service/v3/Implementations/ShopCartUpdateService.php index 0c05168..7b69881 100644 --- a/app/Service/v3/Implementations/ShopCartUpdateService.php +++ b/app/Service/v3/Implementations/ShopCartUpdateService.php @@ -50,7 +50,7 @@ class ShopCartUpdateService implements ShopCartUpdateServiceInterface throw new ErrorCodeException($goodsCheck); } - return ShoppingCart::query()->updateOrCreate( + return ShoppingCart::query()->lockForUpdate()->updateOrCreate( [ 'user_id' => $userId, 'goods_id' => $goodsId, From 5f7f8bd558d351baaf282321c9b1a4eb7c353981 Mon Sep 17 00:00:00 2001 From: weigang Date: Sun, 13 Sep 2020 17:31:07 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E5=9C=B0=E5=9D=80tags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/UserAddress.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Model/v3/UserAddress.php b/app/Model/v3/UserAddress.php index abf86e0..cdfa395 100644 --- a/app/Model/v3/UserAddress.php +++ b/app/Model/v3/UserAddress.php @@ -27,4 +27,9 @@ class UserAddress extends Model protected $casts = [ 'tags' => 'array' ]; + + public function setTagsAttribute($value) + { + return json_encode(json_decode($value, true)); + } } \ No newline at end of file From da3bc94532b821323b4964b8a2946e9bbf9957e5 Mon Sep 17 00:00:00 2001 From: weigang Date: Sun, 13 Sep 2020 17:46:36 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/v3/UserAddress.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Model/v3/UserAddress.php b/app/Model/v3/UserAddress.php index cdfa395..355758f 100644 --- a/app/Model/v3/UserAddress.php +++ b/app/Model/v3/UserAddress.php @@ -30,6 +30,6 @@ class UserAddress extends Model public function setTagsAttribute($value) { - return json_encode(json_decode($value, true)); + $this->attributes['tags'] = json_encode(json_decode($value, true)); } } \ No newline at end of file