From dabe8fbe7a56785f73b6cd65f470bde3649ae281 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Sun, 6 Sep 2020 10:02:34 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=94=B6=E8=97=8F=E5=BA=97=E9=93=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/CollectStoreController.php | 5 +++-- app/Controller/v3/UserAddressController.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Controller/v3/CollectStoreController.php b/app/Controller/v3/CollectStoreController.php index 8f13dca..036266b 100644 --- a/app/Controller/v3/CollectStoreController.php +++ b/app/Controller/v3/CollectStoreController.php @@ -22,10 +22,11 @@ class CollectStoreController extends BaseController $exists = $this->collectStoreService->check($params['user_id'],$params['store_id']); //如果已收藏则删除 if($exists){ - $res = $this->collectStoreService->undo($params['user_id'],$params['store_id']); + $this->collectStoreService->undo($params['user_id'],$params['store_id']); }else{ - $res = $this->collectStoreService->do($params['user_id'],$params['store_id']); + $this->collectStoreService->do($params['user_id'],$params['store_id']); } + $res = $this->collectStoreService->check($params['user_id'],$params['store_id']); return $this->success($res); } diff --git a/app/Controller/v3/UserAddressController.php b/app/Controller/v3/UserAddressController.php index 7d2f2ca..961b051 100644 --- a/app/Controller/v3/UserAddressController.php +++ b/app/Controller/v3/UserAddressController.php @@ -32,7 +32,7 @@ class UserAddressController extends BaseController public function get() { - $userAddressId = $this->request->input('$user_address_id'); + $userAddressId = $this->request->input('user_address_id'); $res = $this->userAddressService->get($userAddressId); return $this->success($res); } From 3fcb13f5c34f6c12cfcd9d838765e98db03ff914 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Sun, 6 Sep 2020 10:12:48 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/CollectStoreController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Controller/v3/CollectStoreController.php b/app/Controller/v3/CollectStoreController.php index 036266b..8dffdd9 100644 --- a/app/Controller/v3/CollectStoreController.php +++ b/app/Controller/v3/CollectStoreController.php @@ -26,8 +26,8 @@ class CollectStoreController extends BaseController }else{ $this->collectStoreService->do($params['user_id'],$params['store_id']); } - $res = $this->collectStoreService->check($params['user_id'],$params['store_id']); - return $this->success($res); + $res = (bool) $this->collectStoreService->check($params['user_id'],$params['store_id']); + return $this->success(['is_collect' => $res]); } public function getListByUser() From bc143cb1632d755ffe6fe8b05ee478444cac78fa Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 6 Sep 2020 12:58:44 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E=E6=95=B0=E6=8D=AE=EF=BC=8C?= =?UTF-8?q?=E5=8C=85=E5=90=ABhot=20types,banners?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/CategoryController.php | 37 +++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/app/Controller/v3/CategoryController.php b/app/Controller/v3/CategoryController.php index 42ef214..96e8ed3 100644 --- a/app/Controller/v3/CategoryController.php +++ b/app/Controller/v3/CategoryController.php @@ -4,6 +4,8 @@ namespace App\Controller\v3; use App\Controller\BaseController; use App\Service\v3\Interfaces\CategoryServiceInterface; +use App\Service\v3\Interfaces\BannerServiceInterface; +use App\Constants\v3\Banner; use Hyperf\Di\Annotation\Inject; class CategoryController extends BaseController @@ -14,6 +16,12 @@ class CategoryController extends BaseController */ protected $categoryService; + /** + * @Inject + * @var BannerServiceInterface + */ + protected $bannerService; + /** * 获取分类页所有分类 * 1、无参数 @@ -22,6 +30,33 @@ class CategoryController extends BaseController */ public function all() { - return $this->success(['category' => $this->categoryService->all()]); + + $category = $this->categoryService->all(); + + //mock datas + $gmarket_id = $this->request->input('gmarket_id', 0); + if($gmarket_id == -1 ) $gmarket_id = 0; + + $banners = $this->bannerService->all(Banner::TYPE_APPLET_INDEX, $gmarket_id); + foreach ($category as $key => &$item) { + $hot_types = []; + if(count($item['goods_types']) > 4){ + $hot_types = array_slice($item['goods_types'],0,2); + } + + $hot_titles = ['当季热销','为你推荐','热卖品类']; + $rand_index = rand(0,2); + $type_banners = []; + if(count($banners)>0){ + $r = rand(0,count($banners)-1); + + $type_banners = [$banners[$r]]; + } + + $item['hot_category'] = ['title'=>$hot_titles[$rand_index],'goods_types'=>$hot_types,'banners'=>$type_banners]; + + } + + return $this->success(['category' => $category]); } } \ No newline at end of file From d1e2d60317c86cdf07754558b1f72b74ae6c01b0 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 6 Sep 2020 13:06:23 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/CategoryController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Controller/v3/CategoryController.php b/app/Controller/v3/CategoryController.php index 96e8ed3..9947218 100644 --- a/app/Controller/v3/CategoryController.php +++ b/app/Controller/v3/CategoryController.php @@ -53,7 +53,8 @@ class CategoryController extends BaseController $type_banners = [$banners[$r]]; } - $item['hot_category'] = ['title'=>$hot_titles[$rand_index],'goods_types'=>$hot_types,'banners'=>$type_banners]; + $item['hot_category'] = ['title'=>$hot_titles[$rand_index],'goods_types'=>$hot_types]; + $item['banners']=$type_banners; } From 5d9abdeb838ca39b67ba0616ed40d07e26dc67a1 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Sun, 6 Sep 2020 14:55:00 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=20=E4=BC=98?= =?UTF-8?q?=E6=83=A0=E5=88=B8=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/CouponController.php | 85 +++++++++++++++++++ app/Controller/v3/ShopCartController.php | 9 +- app/Model/v3/Coupon.php | 18 ++++ app/Model/v3/CouponRec.php | 9 ++ .../v3/Implementations/CouponRecService.php | 83 ++++++++++++++++++ .../v3/Implementations/OrderListService.php | 2 +- .../Interfaces/CouponRecServiceInterface.php | 3 + config/routes.php | 2 + 8 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 app/Controller/v3/CouponController.php diff --git a/app/Controller/v3/CouponController.php b/app/Controller/v3/CouponController.php new file mode 100644 index 0000000..5b6ad2e --- /dev/null +++ b/app/Controller/v3/CouponController.php @@ -0,0 +1,85 @@ +request->input('user_id'); + $page = $this->request->input('page'); + $pagesize = $this->request->input('pagesize'); + $type = $this->request->input('type','1'); + /** + * $type unused 未使用 used 已使用 expired已失效 + */ + switch ($type){ + case 'unused': + $res = $this->couponRecService->getUnusedListByUser($userId,$page,$pagesize); + break; + case 'used': + $res = $this->couponRecService->getUsedListByUser($userId,$page,$pagesize); + break; + case 'expired': + $res = $this->couponRecService->getExpiredListByUser($userId,$page,$pagesize); + break; + } + + return $this->success($res); + } + +} diff --git a/app/Controller/v3/ShopCartController.php b/app/Controller/v3/ShopCartController.php index 9a6da33..e8d4e64 100644 --- a/app/Controller/v3/ShopCartController.php +++ b/app/Controller/v3/ShopCartController.php @@ -20,7 +20,14 @@ class ShopCartController extends BaseController //获取购物车失效商品信息 $res['store_lists_invalid'] = $this->shopCartService->undo(); //计算购物车价格 - $res['total'] = '820.00'; + $res['total'] = $this->shopCartService->getTotal(); + return $this->success($res); + } + + public function info() + { + $res['shopcart']['count'] = $this->shopCartService->countGoods(); + $res['shopcart']['total'] = $this->shopCartService->getTotal(); return $this->success($res); } } \ No newline at end of file diff --git a/app/Model/v3/Coupon.php b/app/Model/v3/Coupon.php index d798c0d..4d77051 100644 --- a/app/Model/v3/Coupon.php +++ b/app/Model/v3/Coupon.php @@ -11,4 +11,22 @@ class Coupon extends Model protected $table = 'lanzu_coupon'; + protected $appends = [ + 'full_amount_text', + 'discounts_text' + ]; + + public function getFullAmountTextAttribute() + { + return '满'.$this->attributes['full_amount'].'可用'; + } + + public function getDiscountsTextAttribute() + { + if($this->attributes['discount_type'] == 1){ + return '¥'.$this->attributes['discounts']; + }elseif($this->attributes['discount_type'] == 2){ + return floatval($this->attributes['discounts'])."折"; + } + } } diff --git a/app/Model/v3/CouponRec.php b/app/Model/v3/CouponRec.php index a1db5fb..d0679ee 100644 --- a/app/Model/v3/CouponRec.php +++ b/app/Model/v3/CouponRec.php @@ -9,6 +9,15 @@ class CouponRec extends Model protected $table = 'lanzu_coupon_receive'; + protected $appends = [ + 'used_num' + ]; + + public function getUsedNumAttribute() + { + return ($this->attributes['number'] - $this->attributes['number_remain']); + } + public function coupon() { return $this->hasOne(Coupon::class,'id','coupon_id'); diff --git a/app/Service/v3/Implementations/CouponRecService.php b/app/Service/v3/Implementations/CouponRecService.php index 8953662..6f4c2d9 100644 --- a/app/Service/v3/Implementations/CouponRecService.php +++ b/app/Service/v3/Implementations/CouponRecService.php @@ -76,4 +76,87 @@ class CouponRecService implements CouponRecServiceInterface ->get() ->toArray(); } + + /** + * 用户未使用优惠券列表 + */ + public function getUnusedListByUser($userId,$page = 1,$pagesize = 5) + { + //查询可用优惠券 + $builder = CouponRec::query()->join('lanzu_coupon', 'lanzu_coupon.id', '=', 'lanzu_coupon_receive.coupon_id') + ->where([ + ['lanzu_coupon_receive.user_id' ,'=', $userId], + ['lanzu_coupon.usable_end_time' ,'>', time()], + ['lanzu_coupon_receive.number_remain' ,'>', 0] + ]); + $builder = $builder->whereIn('lanzu_coupon_receive.status',[0,1]) + ->select( + 'lanzu_coupon.title', + 'lanzu_coupon.discounts', + 'lanzu_coupon.full_amount', + 'lanzu_coupon.discount_type', + 'lanzu_coupon.introduce', + 'lanzu_coupon.usable_end_time', + 'lanzu_coupon_receive.number', + 'lanzu_coupon_receive.number_remain' + ) + ->orderBy('lanzu_coupon.weigh','desc'); + $paginate = $builder->paginate($pagesize); + $couponList = $paginate->toArray(); + foreach ($couponList['data'] as $key => &$coupon) { + //拼接满减文字提示 + $coupon['full_amount_text'] = '满' . $coupon['full_amount'] . "可用"; + //判断是折扣优惠券还是满减优惠券 + if($coupon['discount_type'] == 1){ + $coupon['discounts_text'] = '¥'.$coupon['discounts']; + }elseif($coupon['discount_type'] == 2){ + $coupon['discounts_text'] = floatval($coupon['discounts'])."折"; + } + } + return ['has_more_pages' => $paginate->hasMorePages(), 'coupon_list' => $couponList['data']]; + } + + /** + * 用户已使用 + */ + public function getUsedListByUser($userId,$page = 1,$pagesize = 5) + { + //查询可用优惠券 + $builder = CouponRec::query()->join('lanzu_coupon', 'lanzu_coupon.id', '=', 'lanzu_coupon_receive.coupon_id') + ->where('lanzu_coupon_receive.user_id' ,$userId) + ->whereIn('lanzu_coupon_receive.status',[1,2]) + ->select( + 'lanzu_coupon.title', + 'lanzu_coupon.discounts', + 'lanzu_coupon.full_amount', + 'lanzu_coupon.discount_type', + 'lanzu_coupon.introduce', + 'lanzu_coupon.usable_end_time', + 'lanzu_coupon_receive.number', + 'lanzu_coupon_receive.number_remain' + ) + ->orderBy('lanzu_coupon_receive.updated_at','desc'); + $paginate = $builder->paginate($pagesize); + $couponList = $paginate->toArray(); + foreach ($couponList['data'] as $key => &$coupon) { + //拼接满减文字提示 + $coupon['full_amount_text'] = '满' . $coupon['full_amount'] . "可用"; + //判断是折扣优惠券还是满减优惠券 + if($coupon['discount_type'] == 1){ + $coupon['discounts_text'] = '¥'.$coupon['discounts']; + }elseif($coupon['discount_type'] == 2){ + $coupon['discounts_text'] = floatval($coupon['discounts'])."折"; + } + } + return ['has_more_pages' => $paginate->hasMorePages(), 'coupon_list' => $couponList['data']]; + } + + /** + * 用户已失效 + */ + public function getExpiredListByUser($userId,$page = 1,$pagesize = 5) + { + + } + } \ No newline at end of file diff --git a/app/Service/v3/Implementations/OrderListService.php b/app/Service/v3/Implementations/OrderListService.php index 16713a3..7bc5b17 100644 --- a/app/Service/v3/Implementations/OrderListService.php +++ b/app/Service/v3/Implementations/OrderListService.php @@ -135,7 +135,7 @@ class OrderListService implements OrderListServiceInterface break; } - if(!is_null($start_time) && !is_null($end_time)){ + if(!empty($start_time) && !empty($end_time)){ $builder->whereBetween('lanzu_order_main.created_at',[strtotime($start_time.' 23:59:59'),strtotime($end_time.' 23:59:59')]); } diff --git a/app/Service/v3/Interfaces/CouponRecServiceInterface.php b/app/Service/v3/Interfaces/CouponRecServiceInterface.php index 1931874..c0e5743 100644 --- a/app/Service/v3/Interfaces/CouponRecServiceInterface.php +++ b/app/Service/v3/Interfaces/CouponRecServiceInterface.php @@ -8,4 +8,7 @@ interface CouponRecServiceInterface public function check(); public function undo(); public function allForOrderOlAvailable($totalAmount,$userId,$marketId,$type,$storeTypeId); + public function getUnusedListByUser($userId,$page = 1,$pagesize = 5); + public function getUsedListByUser($userId,$page = 1,$pagesize = 5); + public function getExpiredListByUser($userId,$page = 1,$pagesize = 5); } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 89dca29..89bb6c1 100644 --- a/config/routes.php +++ b/config/routes.php @@ -128,4 +128,6 @@ Router::addGroup('/v3/', function () { Router::post('userAddress/setDefault', 'App\Controller\v3\UserAddressController@setDefault'); Router::post('userAddress/get', 'App\Controller\v3\UserAddressController@get'); Router::post('userAddress/delete', 'App\Controller\v3\UserAddressController@delete'); + Router::post('coupon/getListByUser', 'App\Controller\v3\CouponController@getListByUser'); + Router::post('shopCart/info', 'App\Controller\v3\ShopCartController@info'); },['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]); \ No newline at end of file From be3853ec3451a1954adf1b2697df055a428e7855 Mon Sep 17 00:00:00 2001 From: Mike Date: Sun, 6 Sep 2020 15:23:38 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E7=83=AD=E9=94=80=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/CategoryController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Controller/v3/CategoryController.php b/app/Controller/v3/CategoryController.php index 9947218..0330c4f 100644 --- a/app/Controller/v3/CategoryController.php +++ b/app/Controller/v3/CategoryController.php @@ -40,7 +40,7 @@ class CategoryController extends BaseController $banners = $this->bannerService->all(Banner::TYPE_APPLET_INDEX, $gmarket_id); foreach ($category as $key => &$item) { $hot_types = []; - if(count($item['goods_types']) > 4){ + if(count($item['goods_types']) > 2){ $hot_types = array_slice($item['goods_types'],0,2); }