From 952ca9d420dc222e2232dabd6090ee61a71ebf31 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 10 Sep 2020 16:54:32 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E9=85=8D=E9=80=81=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/v3/Implementations/DistributionPriceService.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Service/v3/Implementations/DistributionPriceService.php b/app/Service/v3/Implementations/DistributionPriceService.php index 0e4fffe..5075b57 100644 --- a/app/Service/v3/Implementations/DistributionPriceService.php +++ b/app/Service/v3/Implementations/DistributionPriceService.php @@ -3,6 +3,8 @@ namespace App\Service\v3\Implementations; +use App\Constants\v3\ErrorCode; +use App\Exception\ErrorCodeException; use Hyperf\Di\Annotation\Inject; use App\Service\v3\Interfaces\DistributionPriceServiceInterface; @@ -22,8 +24,7 @@ class DistributionPriceService implements DistributionPriceServiceInterface $distributionRrice = bcmul(1.50,($km-3),2); break; case ($km >= 10) : - $distributionRrice = bcmul(1.50,($km-3),2); - // throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE); + throw new ErrorCodeException(ErrorCode::LOCATION_LONG_DISTANCE); break; default: $distributionRrice = 0; From e60edd18684d60582df68e57a0e5d2b2682fc2fc Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Thu, 10 Sep 2020 17:09:21 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E8=AE=A2=E5=8D=95=20?= =?UTF-8?q?=E5=A4=84=E7=90=86=E7=94=A8=E6=88=B7=E6=B2=A1=E6=9C=89=E6=94=B6?= =?UTF-8?q?=E8=B4=A7=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/OrderOnlineController.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/Controller/v3/OrderOnlineController.php b/app/Controller/v3/OrderOnlineController.php index 7f90422..4924fad 100644 --- a/app/Controller/v3/OrderOnlineController.php +++ b/app/Controller/v3/OrderOnlineController.php @@ -87,10 +87,9 @@ class OrderOnlineController extends BaseController throw new ErrorCodeException(ErrorCode::NOT_BIND_TEL_ERROR); } //获取用户收货地址 - $address = UserAddress::query()->where([ - ['user_id','=',$userId], - ['is_default','=',1], - ]) + $address = UserAddress::query()->where('user_id',$userId) + ->orderByDesc('is_default') + ->orderByDesc('updated_at') ->first(); $res['location'] = [ 'address' => $address, From ed1568e76542784558442a7fb9509dc9a55280b7 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 11 Sep 2020 14:10:08 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=95=86=E6=88=B7=E4=B8=AD=E5=BF=83=20?= =?UTF-8?q?=E9=A6=96=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/v3/SsdbKeys.php | 7 +- .../v3/BalanceStatementController.php | 8 ++ app/Controller/v3/HomeController.php | 74 ++++++++++++++++--- .../v3/Implementations/OrderListService.php | 4 +- .../v3/Implementations/OrderOnlineService.php | 11 +-- .../OrderStatisticsService.php | 39 ++++++++++ .../v3/Implementations/RevenueListService.php | 14 ++++ .../Implementations/WithdrawalListService.php | 2 +- .../OrderOnlineServiceInterface.php | 7 -- .../OrderStatisticsServiceInterface.php | 13 ++++ .../RevenueListServiceInterface.php | 2 + config/autoload/dependencies.php | 1 + 12 files changed, 155 insertions(+), 27 deletions(-) create mode 100644 app/Service/v3/Implementations/OrderStatisticsService.php create mode 100644 app/Service/v3/Interfaces/OrderStatisticsServiceInterface.php diff --git a/app/Constants/v3/SsdbKeys.php b/app/Constants/v3/SsdbKeys.php index c2b85bd..e6f6eca 100644 --- a/app/Constants/v3/SsdbKeys.php +++ b/app/Constants/v3/SsdbKeys.php @@ -29,7 +29,12 @@ class SsdbKeys extends AbstractConstants * @Message("用户新订单统计") */ const USER_ORDER_BADGE = 'user_order_badge_'; - + + /** + * @Message("店铺新订单统计") + */ + const STORE_ORDER_BADGE = 'store_order_badge_'; + /** * @Message("收藏店铺") */ diff --git a/app/Controller/v3/BalanceStatementController.php b/app/Controller/v3/BalanceStatementController.php index 9e19de9..b8c0829 100644 --- a/app/Controller/v3/BalanceStatementController.php +++ b/app/Controller/v3/BalanceStatementController.php @@ -27,6 +27,10 @@ class BalanceStatementController extends BaseController $pagesize = $this->request->input('pagesize',0); $startTime = $this->request->input('start_time',''); $endTime = $this->request->input('end_time',''); + if(!empty($startTime) && !empty($endTime)){ + $startTime = strtotime(date($startTime.' 00:00:00')); + $endTime = strtotime(date($endTime.' 23:59:59')); + } return $this->success($this->revenueListService->getListByUser($userId, $page, $pagesize ,$startTime,$endTime)); } @@ -37,6 +41,10 @@ class BalanceStatementController extends BaseController $pagesize = $this->request->input('pagesize',0); $startTime = $this->request->input('start_time',''); $endTime = $this->request->input('end_time',''); + if(!empty($startTime) && !empty($endTime)){ + $startTime = strtotime(date($startTime.' 00:00:00')); + $endTime = strtotime(date($endTime.' 23:59:59')); + } $res = $this->withdrawalListService->getListByStore($storeId,$page,$pagesize,$startTime,$endTime); return $this->success($res); } diff --git a/app/Controller/v3/HomeController.php b/app/Controller/v3/HomeController.php index 80ce4de..ce46208 100644 --- a/app/Controller/v3/HomeController.php +++ b/app/Controller/v3/HomeController.php @@ -4,9 +4,12 @@ namespace App\Controller\v3; use App\Constants\v3\ActivityType; use App\Constants\v3\Banner; +use App\Constants\v3\OrderState; +use App\Constants\v3\OrderType; use App\Constants\v3\SsdbKeys; use App\Constants\v3\Tabs; use App\Controller\BaseController; +use App\Model\v3\FinancialRecord; use App\Request\v3\StoreIndexRequest; use App\Request\v3\UserIndexRequest; use App\Service\v3\Interfaces\ActivityServiceInterface; @@ -14,6 +17,9 @@ use App\Service\v3\Interfaces\BannerServiceInterface; use App\Service\v3\Interfaces\CategoryServiceInterface; use App\Service\v3\Interfaces\CollectStoreServiceInterface; use App\Service\v3\Interfaces\CouponServiceInterface; +use App\Service\v3\Interfaces\OrderOnlineServiceInterface; +use App\Service\v3\Interfaces\OrderStatisticsServiceInterface; +use App\Service\v3\Interfaces\RevenueListServiceInterface; use App\Service\v3\Interfaces\StoreServiceInterface; use App\Service\v3\Interfaces\TabsServiceInterface; use App\Service\v3\Interfaces\UserCenterBlockServiceInterface; @@ -85,6 +91,17 @@ class HomeController extends BaseController */ protected $tabsService; + /** + * @Inject + * @var OrderStatisticsServiceInterface + */ + protected $orderStatisticsService; + + /** + * @Inject + * @var RevenueListServiceInterface + */ + protected $revenueListService; /** * 小程序首页,根据market_id * 1.banner数据 @@ -178,21 +195,56 @@ class HomeController extends BaseController public function storeIndex(StoreIndexRequest $request) { $params = $request->validated(); + //每日 每周 每月 开始结束时间 + $dayStartTime = strtotime(date('Y-m-d'.' 00:00:00')); + $dayEndTime = strtotime(date('Y-m-d'.' 23:59:59')); + $weekStartTime = mktime(0,0,0,date('m'),date('d')-date('N')+1,date('y')); + //$weekEndTime = mktime(23,59,59,date('m'),date('d')-date('N')+7,date('Y')); + $monthStartTime = mktime(0,0,0,date('m'),1,date('Y')); + //$monthEndTime = mktime(23,59,59,date('m'),date('t'),date('Y')); $data['detail'] = $this->storeService->detail($params['store_id']); - $data['order_online'] = [ - 'count' => 6549, - 'total' => 12654.12 - ]; - $data['order_offline'] = [ - 'count' => 3639, - 'total' => 89563.12 + //当面付 and 线上订单个数统计 + $data['order_online']['count'] = $this->orderStatisticsService->countOrder($params['store_id'],OrderType::ONLINE,$dayStartTime,$dayEndTime); + $data['order_offline']['count'] = $this->orderStatisticsService->countOrder($params['store_id'],OrderType::OFFLINE,$dayStartTime,$dayEndTime); + //统计订单金额 + $type = [ + FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP, + FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP ]; + $data['order_online']['total'] = 0; + $data['order_offline']['total'] = 0; + $revenueByOrder = $this->revenueListService->getRevenueByUser($params['user_id'],$type,$dayStartTime,$dayEndTime); + foreach ($revenueByOrder as $order){ + if($order['money_type'] == FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP){ + //线上订单 + $data['order_online']['total'] = bcadd($data['order_online']['total'],$order['money'],2); + }else if($order->money_type == FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP){ + //线下订单 + $data['order_offline']['total'] = bcadd($data['order_online']['total'],$order['money'],2); + } + } + //统计新增用户 无法筛选时间 所以和订单分开查询 + $revenueByNewUsers = $this->revenueListService->getRevenueByUser($params['user_id'],[FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER]); $data['new_user'] = [ - 'day' => 10, - 'week' => 15, - 'month' => 25, - 'all' => 50 + 'day' => 0, + 'week' => 0, + 'month' => 0, + 'all' => 0 ]; + foreach ($revenueByNewUsers as $newUser) + { + if($newUser['created_at'] > $dayStartTime){ + $data['new_user']['day']++; + } + if($newUser['created_at'] > $weekStartTime){ + $data['new_user']['week']++; + } + if($newUser['created_at'] > $monthStartTime){ + $data['new_user']['month']++; + } + $data['new_user']['all']++; + } + $data['badge'] = [ 'unpaid' => 0, 'receiving' => 0, diff --git a/app/Service/v3/Implementations/OrderListService.php b/app/Service/v3/Implementations/OrderListService.php index 7f60c5a..db7f6c7 100644 --- a/app/Service/v3/Implementations/OrderListService.php +++ b/app/Service/v3/Implementations/OrderListService.php @@ -68,7 +68,7 @@ class OrderListService implements OrderListServiceInterface public function onlineByStore($storeId, $tab, $page=1, $pagesize=10) { - $builder = Order::join('lanzu_order_main','lanzu_order.order_main_id','lanzu_order_main.id') + $builder = Order::join('lanzu_order_main','lanzu_order.order_main_id','lanzu_order_main.global_order_id') ->select( 'lanzu_order.*', 'lanzu_order_main.state', @@ -141,7 +141,7 @@ class OrderListService implements OrderListServiceInterface public function offlineByStore($storeId, $page=1, $pagesize=10 ,$start_time = '',$end_time = '') { - $builder = Order::join('lanzu_order_main','lanzu_order.order_main_id','lanzu_order_main.id') + $builder = Order::join('lanzu_order_main','lanzu_order.order_main_id','lanzu_order_main.global_order_id') ->where('store_id', $storeId) ->where('lanzu_order_main.type',4) ->with('user'); diff --git a/app/Service/v3/Implementations/OrderOnlineService.php b/app/Service/v3/Implementations/OrderOnlineService.php index b4f0e42..dffbe17 100644 --- a/app/Service/v3/Implementations/OrderOnlineService.php +++ b/app/Service/v3/Implementations/OrderOnlineService.php @@ -478,6 +478,12 @@ class OrderOnlineService implements OrderOnlineServiceInterface // 记录用户中心的badge $ssdb->exec('hincr', SsdbKeys::USER_ORDER_BADGE.$orderMain->user_id, 'receiving', 1); + //记录商家中心的badge + $storeIds = array_values(array_column($orders, 'store_id')); + foreach ($storeIds as $storeId){ + $ssdb->exec('hincr', SsdbKeys::STORE_ORDER_BADGE . $storeId, 'paid', 1); + } + return true; } catch (Exception $e) { @@ -563,9 +569,4 @@ class OrderOnlineService implements OrderOnlineServiceInterface return $this->paymentService->undo($orderMain->global_order_id, $userId); } } - - public function countByStore($storeId) - { - $res['count'] = Order::query()->find(); - } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/OrderStatisticsService.php b/app/Service/v3/Implementations/OrderStatisticsService.php new file mode 100644 index 0000000..99b14bb --- /dev/null +++ b/app/Service/v3/Implementations/OrderStatisticsService.php @@ -0,0 +1,39 @@ +where('lanzu_order.store_id',$storeId); + if(!empty($startTime) && !empty($endTime)){ + $builder->whereBetween('lanzu_order_main.created_at',[$startTime,$endTime]); + } + $count = $builder->whereIn('lanzu_order_main.state', OrderState::FINISH) + ->where('type',$type) + ->count(); + return $count; + } +} \ No newline at end of file diff --git a/app/Service/v3/Implementations/RevenueListService.php b/app/Service/v3/Implementations/RevenueListService.php index 6154e1f..d427b5f 100644 --- a/app/Service/v3/Implementations/RevenueListService.php +++ b/app/Service/v3/Implementations/RevenueListService.php @@ -36,4 +36,18 @@ class RevenueListService implements RevenueListServiceInterface $revenues = $paginate->toArray(); return ['has_more_pages' => $paginate->hasMorePages(), 'revenue_list' => $revenues['data']]; } + + public function getRevenueByUser($userId,$type = [],$startTime = '',$endTime = '') + { + $financialRecord = new FinancialRecord(); + $mod = bcmod((string)$userId, '5', 0); + $financialRecord->suffix($mod); + $builder = $financialRecord->where('user_id',$userId) + ->whereIn('money_type',$type); + if(!empty($startTime) && !empty($endTime)){ + $builder->whereBetween('created_at',[$startTime,$endTime]); + } + $revenue = $builder->select('money','money_type','created_at')->get()->toArray(); + return $revenue; + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/WithdrawalListService.php b/app/Service/v3/Implementations/WithdrawalListService.php index 1170a36..7ed2c9d 100644 --- a/app/Service/v3/Implementations/WithdrawalListService.php +++ b/app/Service/v3/Implementations/WithdrawalListService.php @@ -25,7 +25,7 @@ class WithdrawalListService implements WithdrawalListServiceInterface { $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')]); + $builder->whereBetween('created_at',[$startTime,$endTime]); } $paginate = $builder->paginate($pagesize); $orders = $paginate->toArray(); diff --git a/app/Service/v3/Interfaces/OrderOnlineServiceInterface.php b/app/Service/v3/Interfaces/OrderOnlineServiceInterface.php index dfecb21..d396b1a 100644 --- a/app/Service/v3/Interfaces/OrderOnlineServiceInterface.php +++ b/app/Service/v3/Interfaces/OrderOnlineServiceInterface.php @@ -70,11 +70,4 @@ interface OrderOnlineServiceInterface * @return mixed */ public function doRefund($globalOrderId, $userId); - - /** - * 统计商户线上订单 - * @param $storeId - * @return mixed - */ - public function countByStore($storeId); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/OrderStatisticsServiceInterface.php b/app/Service/v3/Interfaces/OrderStatisticsServiceInterface.php new file mode 100644 index 0000000..b7a2227 --- /dev/null +++ b/app/Service/v3/Interfaces/OrderStatisticsServiceInterface.php @@ -0,0 +1,13 @@ + \App\Service\v3\Implementations\SmsAliService::class, \App\Service\v3\Interfaces\AttachmentServiceInterface::class => \App\Service\v3\Implementations\AttachmentService::class, \App\JsonRpc\PrintServiceInterface::class => \App\JsonRpc\FeieService::class, + \App\Service\v3\Interfaces\OrderStatisticsServiceInterface::class => \App\Service\v3\Implementations\OrderStatisticsService::class, ]; From 1c411c3a8ee59d6d7899884be9e8b76a899ad02d Mon Sep 17 00:00:00 2001 From: lanzu_qinsheng <334039090@qq.com> Date: Fri, 11 Sep 2020 14:28:26 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=80=80=E6=AC=BE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/JsonRpc/OrderService.php | 37 +++++++------------ .../v3/Implementations/PaymentService.php | 8 ++++ 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/app/JsonRpc/OrderService.php b/app/JsonRpc/OrderService.php index 1f49932..530d09e 100644 --- a/app/JsonRpc/OrderService.php +++ b/app/JsonRpc/OrderService.php @@ -78,32 +78,21 @@ class OrderService implements OrderServiceInterface */ public function onlineRefund($global_order_id, $user_id) { - - Db::beginTransaction(); try { - $result = $this->orderOnlineService->doRefund($global_order_id, $user_id); - - Db::commit(); - if ($result['return_code'] == 'SUCCESS' && isset($result['result_code']) && $result['result_code'] == "SUCCESS") { - return [ - "status" => 200, - "code" => 0, - "result" => [], - "message" => '处理成功' - ]; - } else { - return [ - "status" => 200, - "code" => -1, - "result" => [], - "message" => $result['err_code_des'] - ]; - } + $this->orderOnlineService->doRefund($global_order_id, $user_id); + return [ + "status" => 200, + "code" => 0, + "result" => [], + "message" => '处理成功' + ]; } catch (\Exception $e) { - - Db::rollBack(); - $this->log->event(LogLabel::ORDER_REFUND_LOG, ['jsonrpc_order_service_exception_onlineRefund' => $e->getMessage(), 'params' => json([$global_order_id, $user_id])]); - throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL); + return [ + "status" => 200, + "code" => $e->getCode(), + "result" => [], + "message" => $e->getMessage() + ]; } } diff --git a/app/Service/v3/Implementations/PaymentService.php b/app/Service/v3/Implementations/PaymentService.php index e979635..58b25b5 100644 --- a/app/Service/v3/Implementations/PaymentService.php +++ b/app/Service/v3/Implementations/PaymentService.php @@ -127,6 +127,14 @@ class PaymentService implements PaymentServiceInterface 'notify_url' => config('wechat.notify_url.refund'), ] ); + if ($result['return_code'] == 'SUCCESS' && isset($result['result_code']) && $result['result_code'] == "SUCCESS") { + return true; + } else { + throw new ErrorCodeException(ErrorCode::PAYMENT_FAIL); + } + + + return $result; } catch (\Exception $e) { $this->log->event(LogLabel::ORDER_PAYMENT_LOG, ['payment_do_exception_msg' => $e->getMessage()]);