Browse Source

商户中心 首页

master
Lemon 5 years ago
parent
commit
ed1568e765
  1. 7
      app/Constants/v3/SsdbKeys.php
  2. 8
      app/Controller/v3/BalanceStatementController.php
  3. 74
      app/Controller/v3/HomeController.php
  4. 4
      app/Service/v3/Implementations/OrderListService.php
  5. 11
      app/Service/v3/Implementations/OrderOnlineService.php
  6. 39
      app/Service/v3/Implementations/OrderStatisticsService.php
  7. 14
      app/Service/v3/Implementations/RevenueListService.php
  8. 2
      app/Service/v3/Implementations/WithdrawalListService.php
  9. 7
      app/Service/v3/Interfaces/OrderOnlineServiceInterface.php
  10. 13
      app/Service/v3/Interfaces/OrderStatisticsServiceInterface.php
  11. 2
      app/Service/v3/Interfaces/RevenueListServiceInterface.php
  12. 1
      config/autoload/dependencies.php

7
app/Constants/v3/SsdbKeys.php

@ -29,7 +29,12 @@ class SsdbKeys extends AbstractConstants
* @Message("用户新订单统计") * @Message("用户新订单统计")
*/ */
const USER_ORDER_BADGE = 'user_order_badge_'; const USER_ORDER_BADGE = 'user_order_badge_';
/**
* @Message("店铺新订单统计")
*/
const STORE_ORDER_BADGE = 'store_order_badge_';
/** /**
* @Message("收藏店铺") * @Message("收藏店铺")
*/ */

8
app/Controller/v3/BalanceStatementController.php

@ -27,6 +27,10 @@ class BalanceStatementController extends BaseController
$pagesize = $this->request->input('pagesize',0); $pagesize = $this->request->input('pagesize',0);
$startTime = $this->request->input('start_time',''); $startTime = $this->request->input('start_time','');
$endTime = $this->request->input('end_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)); 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); $pagesize = $this->request->input('pagesize',0);
$startTime = $this->request->input('start_time',''); $startTime = $this->request->input('start_time','');
$endTime = $this->request->input('end_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); $res = $this->withdrawalListService->getListByStore($storeId,$page,$pagesize,$startTime,$endTime);
return $this->success($res); return $this->success($res);
} }

74
app/Controller/v3/HomeController.php

@ -4,9 +4,12 @@ namespace App\Controller\v3;
use App\Constants\v3\ActivityType; use App\Constants\v3\ActivityType;
use App\Constants\v3\Banner; use App\Constants\v3\Banner;
use App\Constants\v3\OrderState;
use App\Constants\v3\OrderType;
use App\Constants\v3\SsdbKeys; use App\Constants\v3\SsdbKeys;
use App\Constants\v3\Tabs; use App\Constants\v3\Tabs;
use App\Controller\BaseController; use App\Controller\BaseController;
use App\Model\v3\FinancialRecord;
use App\Request\v3\StoreIndexRequest; use App\Request\v3\StoreIndexRequest;
use App\Request\v3\UserIndexRequest; use App\Request\v3\UserIndexRequest;
use App\Service\v3\Interfaces\ActivityServiceInterface; 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\CategoryServiceInterface;
use App\Service\v3\Interfaces\CollectStoreServiceInterface; use App\Service\v3\Interfaces\CollectStoreServiceInterface;
use App\Service\v3\Interfaces\CouponServiceInterface; 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\StoreServiceInterface;
use App\Service\v3\Interfaces\TabsServiceInterface; use App\Service\v3\Interfaces\TabsServiceInterface;
use App\Service\v3\Interfaces\UserCenterBlockServiceInterface; use App\Service\v3\Interfaces\UserCenterBlockServiceInterface;
@ -85,6 +91,17 @@ class HomeController extends BaseController
*/ */
protected $tabsService; protected $tabsService;
/**
* @Inject
* @var OrderStatisticsServiceInterface
*/
protected $orderStatisticsService;
/**
* @Inject
* @var RevenueListServiceInterface
*/
protected $revenueListService;
/** /**
* 小程序首页,根据market_id * 小程序首页,根据market_id
* 1.banner数据 * 1.banner数据
@ -178,21 +195,56 @@ class HomeController extends BaseController
public function storeIndex(StoreIndexRequest $request) public function storeIndex(StoreIndexRequest $request)
{ {
$params = $request->validated(); $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['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'] = [ $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'] = [ $data['badge'] = [
'unpaid' => 0, 'unpaid' => 0,
'receiving' => 0, 'receiving' => 0,

4
app/Service/v3/Implementations/OrderListService.php

@ -68,7 +68,7 @@ class OrderListService implements OrderListServiceInterface
public function onlineByStore($storeId, $tab, $page=1, $pagesize=10) 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( ->select(
'lanzu_order.*', 'lanzu_order.*',
'lanzu_order_main.state', 'lanzu_order_main.state',
@ -141,7 +141,7 @@ class OrderListService implements OrderListServiceInterface
public function offlineByStore($storeId, $page=1, $pagesize=10 ,$start_time = '',$end_time = '') 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('store_id', $storeId)
->where('lanzu_order_main.type',4) ->where('lanzu_order_main.type',4)
->with('user'); ->with('user');

11
app/Service/v3/Implementations/OrderOnlineService.php

@ -478,6 +478,12 @@ class OrderOnlineService implements OrderOnlineServiceInterface
// 记录用户中心的badge // 记录用户中心的badge
$ssdb->exec('hincr', SsdbKeys::USER_ORDER_BADGE.$orderMain->user_id, 'receiving', 1); $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; return true;
} catch (Exception $e) { } catch (Exception $e) {
@ -563,9 +569,4 @@ class OrderOnlineService implements OrderOnlineServiceInterface
return $this->paymentService->undo($orderMain->global_order_id, $userId); return $this->paymentService->undo($orderMain->global_order_id, $userId);
} }
} }
public function countByStore($storeId)
{
$res['count'] = Order::query()->find();
}
} }

39
app/Service/v3/Implementations/OrderStatisticsService.php

@ -0,0 +1,39 @@
<?php
namespace App\Service\v3\Implementations;
use App\Constants\v3\OrderState;
use App\Model\v3\Order;
use \App\Service\v3\Interfaces\OrderStatisticsServiceInterface;
class OrderStatisticsService implements OrderStatisticsServiceInterface
{
public function do()
{
// TODO: Implement do() method.
}
public function check()
{
// TODO: Implement check() method.
}
public function undo()
{
// TODO: Implement undo() method.
}
public function countOrder($storeId,$type,$startTime = '',$endTime = '')
{
$builder = Order::join('lanzu_order_main','lanzu_order_main.global_order_id','lanzu_order.order_main_id')
->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;
}
}

14
app/Service/v3/Implementations/RevenueListService.php

@ -36,4 +36,18 @@ class RevenueListService implements RevenueListServiceInterface
$revenues = $paginate->toArray(); $revenues = $paginate->toArray();
return ['has_more_pages' => $paginate->hasMorePages(), 'revenue_list' => $revenues['data']]; 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;
}
} }

2
app/Service/v3/Implementations/WithdrawalListService.php

@ -25,7 +25,7 @@ class WithdrawalListService implements WithdrawalListServiceInterface
{ {
$builder = StoreWithdrawal::query()->where('store_id',$storeId); $builder = StoreWithdrawal::query()->where('store_id',$storeId);
if(!empty($startTime) && !empty($endTime)){ 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); $paginate = $builder->paginate($pagesize);
$orders = $paginate->toArray(); $orders = $paginate->toArray();

7
app/Service/v3/Interfaces/OrderOnlineServiceInterface.php

@ -70,11 +70,4 @@ interface OrderOnlineServiceInterface
* @return mixed * @return mixed
*/ */
public function doRefund($globalOrderId, $userId); public function doRefund($globalOrderId, $userId);
/**
* 统计商户线上订单
* @param $storeId
* @return mixed
*/
public function countByStore($storeId);
} }

13
app/Service/v3/Interfaces/OrderStatisticsServiceInterface.php

@ -0,0 +1,13 @@
<?php
namespace App\Service\v3\Interfaces;
interface OrderStatisticsServiceInterface
{
public function do();
public function check();
public function undo();
public function countOrder($storeId,$type,$startTime = '',$endTime = '');
}

2
app/Service/v3/Interfaces/RevenueListServiceInterface.php

@ -13,4 +13,6 @@ interface RevenueListServiceInterface
public function undo(); public function undo();
public function getListByUser($userId, $page=1, $pagesize=10 ,$startTime = '',$endTime = ''); public function getListByUser($userId, $page=1, $pagesize=10 ,$startTime = '',$endTime = '');
public function getRevenueByUser($userId,$type = [],$startTime = '',$endTime = '');
} }

1
config/autoload/dependencies.php

@ -80,4 +80,5 @@ return [
\App\Service\v3\Interfaces\SmsServiceInterface::class => \App\Service\v3\Implementations\SmsAliService::class, \App\Service\v3\Interfaces\SmsServiceInterface::class => \App\Service\v3\Implementations\SmsAliService::class,
\App\Service\v3\Interfaces\AttachmentServiceInterface::class => \App\Service\v3\Implementations\AttachmentService::class, \App\Service\v3\Interfaces\AttachmentServiceInterface::class => \App\Service\v3\Implementations\AttachmentService::class,
\App\JsonRpc\PrintServiceInterface::class => \App\JsonRpc\FeieService::class, \App\JsonRpc\PrintServiceInterface::class => \App\JsonRpc\FeieService::class,
\App\Service\v3\Interfaces\OrderStatisticsServiceInterface::class => \App\Service\v3\Implementations\OrderStatisticsService::class,
]; ];
Loading…
Cancel
Save