diff --git a/app/Controller/v3/BalanceStatementController.php b/app/Controller/v3/BalanceStatementController.php index 799205c..9e19de9 100644 --- a/app/Controller/v3/BalanceStatementController.php +++ b/app/Controller/v3/BalanceStatementController.php @@ -22,13 +22,22 @@ class BalanceStatementController extends BaseController protected $withdrawalListService; public function getRevenueListByUser() { - $params = $this->request->all(); - return $this->success($this->revenueListService->getListByUser(46)); + $userId = $this->request->input('user_id',0); + $page = $this->request->input('page',0); + $pagesize = $this->request->input('pagesize',0); + $startTime = $this->request->input('start_time',''); + $endTime = $this->request->input('end_time',''); + return $this->success($this->revenueListService->getListByUser($userId, $page, $pagesize ,$startTime,$endTime)); } public function getWithdrawalListByStore() { - $params = $this->request->all(); - return $this->success($this->withdrawalListService->getListByStore(7)); + $storeId = $this->request->input('store_id',0); + $page = $this->request->input('page',0); + $pagesize = $this->request->input('pagesize',0); + $startTime = $this->request->input('start_time',''); + $endTime = $this->request->input('end_time',''); + $res = $this->withdrawalListService->getListByStore($storeId,$page,$pagesize,$startTime,$endTime); + return $this->success($res); } } \ No newline at end of file diff --git a/app/Controller/v3/CategoryController.php b/app/Controller/v3/CategoryController.php index 42ef214..0330c4f 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,34 @@ 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']) > 2){ + $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]; + $item['banners']=$type_banners; + + } + + return $this->success(['category' => $category]); } } \ No newline at end of file diff --git a/app/Controller/v3/CollectStoreController.php b/app/Controller/v3/CollectStoreController.php index 8f13dca..8dffdd9 100644 --- a/app/Controller/v3/CollectStoreController.php +++ b/app/Controller/v3/CollectStoreController.php @@ -22,11 +22,12 @@ 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']); } - return $this->success($res); + $res = (bool) $this->collectStoreService->check($params['user_id'],$params['store_id']); + return $this->success(['is_collect' => $res]); } public function getListByUser() 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/OrderListController.php b/app/Controller/v3/OrderListController.php index 4f1e58f..5aceb5b 100644 --- a/app/Controller/v3/OrderListController.php +++ b/app/Controller/v3/OrderListController.php @@ -48,7 +48,7 @@ class OrderListController extends BaseController public function offlineForStore() { $params = $this->request->all(); - $list = $this->orderListService->offlineByStore($params['store_id'], $params['tab'], $params['page'], $params['pagesize']); + $list = $this->orderListService->offlineByStore($params['store_id'], $params['tab'], $params['page'], $params['pagesize'],$params['start_time'],$params['end_time']); return $this->success($list); } } \ No newline at end of file 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/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); } 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 d8aec92..7bc5b17 100644 --- a/app/Service/v3/Implementations/OrderListService.php +++ b/app/Service/v3/Implementations/OrderListService.php @@ -82,16 +82,16 @@ class OrderListService implements OrderListServiceInterface case 'all': break; case 'completed': - $builder->whereIn('state', OrderState::FINISH); + $builder->whereIn('lanzu_order_main.state', OrderState::FINISH); break; case 'unpaid': - $builder->where(['state' => OrderState::UNPAID]); + $builder->where(['lanzu_order_main.state' => OrderState::UNPAID]); break; case 'receiving': - $builder->whereIn('state', OrderState::RECEIVING); + $builder->whereIn('lanzu_order_main.state', OrderState::RECEIVING); break; case 'refund': - $builder->whereIn('state', OrderState::REFUND); + $builder->whereIn('lanzu_order_main.state', OrderState::REFUND); break; } @@ -111,37 +111,34 @@ class OrderListService implements OrderListServiceInterface return $res; } - public function offlineByStore($storeId, $tab, $page=1, $pagesize=10) + public function offlineByStore($storeId, $tab, $page=1, $pagesize=10 ,$start_time = '',$end_time = '') { $builder = Order::Join('lanzu_order_main','lanzu_order.order_main_id','lanzu_order_main.id') ->where('store_id', $storeId) ->where('lanzu_order_main.type',4) ->with('user'); - $sw = [ - 'all'=>'', - 'completed'=> OrderState::FINISH, - 'unpaid'=> OrderState::UNPAID, - 'receiving' => OrderState::RECEIVING, - 'refund' => OrderState::REFUND - ]; switch ($tab) { case 'all': break; case 'completed': - $builder->whereIn('state', OrderState::FINISH); + $builder->whereIn('lanzu_order_main.state', OrderState::FINISH); break; case 'unpaid': - $builder->where(['state' => OrderState::UNPAID]); + $builder->where(['lanzu_order_main.state' => OrderState::UNPAID]); break; case 'receiving': - $builder->whereIn('state', OrderState::RECEIVING); + $builder->whereIn('lanzu_order_main.state', OrderState::RECEIVING); break; case 'refund': - $builder->whereIn('state', OrderState::REFUND); + $builder->whereIn('lanzu_order_main.state', OrderState::REFUND); break; } + 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')]); + } + $paginate = $builder->paginate($pagesize); $orders = $paginate->toArray(); return ['has_more_pages' => $paginate->hasMorePages(), 'orders' => $orders['data']]; diff --git a/app/Service/v3/Implementations/RevenueListService.php b/app/Service/v3/Implementations/RevenueListService.php index 563f8dc..6154e1f 100644 --- a/app/Service/v3/Implementations/RevenueListService.php +++ b/app/Service/v3/Implementations/RevenueListService.php @@ -23,11 +23,17 @@ class RevenueListService implements RevenueListServiceInterface // TODO: Implement undo() method. } - public function getListByUser($userId) + public function getListByUser($userId, $page=1, $pagesize=10 ,$startTime = '',$endTime = '') { $financialRecord = new FinancialRecord(); $mod = bcmod((string)$userId, '5', 0); $financialRecord->suffix($mod); - return $financialRecord::query()->get(); + $builder = $financialRecord->where('user_id',$userId); + if(!empty($startTime) && !empty($endTime)){ + $builder->whereBetween('created_at',[strtotime($startTime.' 23:59:59'),strtotime($endTime.' 23:59:59')]); + } + $paginate = $builder->paginate($pagesize); + $revenues = $paginate->toArray(); + return ['has_more_pages' => $paginate->hasMorePages(), 'revenue_list' => $revenues['data']]; } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/WithdrawalListService.php b/app/Service/v3/Implementations/WithdrawalListService.php index 5dd2d1a..1170a36 100644 --- a/app/Service/v3/Implementations/WithdrawalListService.php +++ b/app/Service/v3/Implementations/WithdrawalListService.php @@ -21,9 +21,14 @@ class WithdrawalListService implements WithdrawalListServiceInterface // TODO: Implement undo() method. } - public function getListByStore($storeId) + public function getListByStore($storeId, $page=1, $pagesize=10 ,$startTime = '',$endTime = '') { - $res = StoreWithdrawal::query()->where('store_id',$storeId)->get(); - return $res; + $builder = StoreWithdrawal::query()->where('store_id',$storeId); + if(!empty($startTime) && !empty($endTime)){ + $builder->whereBetween('created_at',[strtotime($startTime.' 23:59:59'),strtotime($endTime.' 23:59:59')]); + } + $paginate = $builder->paginate($pagesize); + $orders = $paginate->toArray(); + return ['has_more_pages' => $paginate->hasMorePages(), 'orders' => $orders['data']]; } } \ No newline at end of file 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/app/Service/v3/Interfaces/OrderListServiceInterface.php b/app/Service/v3/Interfaces/OrderListServiceInterface.php index 8404aa8..3a7f204 100644 --- a/app/Service/v3/Interfaces/OrderListServiceInterface.php +++ b/app/Service/v3/Interfaces/OrderListServiceInterface.php @@ -9,5 +9,5 @@ interface OrderListServiceInterface public function undo(); public function onlineByUser($userId, $tab, $page=1, $pagesize=10); public function onlineByStore($userId, $tab, $page, $pagesize); - public function offlineByStore($userId, $tab, $page, $pagesize); + public function offlineByStore($userId, $tab, $page, $pagesize,$start_time = '',$end_time = ''); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/RevenueListServiceInterface.php b/app/Service/v3/Interfaces/RevenueListServiceInterface.php index e3b3132..3b42557 100644 --- a/app/Service/v3/Interfaces/RevenueListServiceInterface.php +++ b/app/Service/v3/Interfaces/RevenueListServiceInterface.php @@ -12,5 +12,5 @@ interface RevenueListServiceInterface public function undo(); - public function getListByUser($userId); + public function getListByUser($userId, $page=1, $pagesize=10 ,$startTime = '',$endTime = ''); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/WithdrawalListServiceInterface.php b/app/Service/v3/Interfaces/WithdrawalListServiceInterface.php index 9b68af4..1dfc852 100644 --- a/app/Service/v3/Interfaces/WithdrawalListServiceInterface.php +++ b/app/Service/v3/Interfaces/WithdrawalListServiceInterface.php @@ -9,5 +9,5 @@ interface WithdrawalListServiceInterface public function do(); public function check(); public function undo(); - public function getListByStore($storeId); + public function getListByStore($storeId, $page=1, $pagesize=10 ,$startTime = '',$endTime = ''); } \ 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