Browse Source

商户中心统计

master
weigang 5 years ago
parent
commit
f4459464a2
  1. 37
      app/Controller/v3/HomeController.php
  2. 4
      app/JsonRpc/OrdersService.php
  3. 30
      app/Service/v3/Implementations/FinancialRecordService.php
  4. 12
      app/Service/v3/Implementations/OrderStatisticsService.php
  5. 17
      app/Service/v3/Interfaces/FinancialRecordServiceInterface.php

37
app/Controller/v3/HomeController.php

@ -8,6 +8,7 @@ use App\Constants\v3\OrderState;
use App\Constants\v3\OrderType; 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\Constants\v3\UserType;
use App\Controller\BaseController; use App\Controller\BaseController;
use App\Model\v3\FinancialRecord; use App\Model\v3\FinancialRecord;
use App\Model\v3\Market; use App\Model\v3\Market;
@ -20,6 +21,7 @@ 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\CouponRecServiceInterface; use App\Service\v3\Interfaces\CouponRecServiceInterface;
use App\Service\v3\Interfaces\FinancialRecordServiceInterface;
use App\Service\v3\Interfaces\OrderOnlineServiceInterface; use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
use App\Service\v3\Interfaces\OrderStatisticsServiceInterface; use App\Service\v3\Interfaces\OrderStatisticsServiceInterface;
use App\Service\v3\Interfaces\RevenueListServiceInterface; use App\Service\v3\Interfaces\RevenueListServiceInterface;
@ -113,6 +115,12 @@ class HomeController extends BaseController
*/ */
protected $badgeService; protected $badgeService;
/**
* @Inject
* @var FinancialRecordServiceInterface
*/
protected $financialRecordService;
/** /**
* 小程序首页,根据market_id * 小程序首页,根据market_id
* 1.banner数据 * 1.banner数据
@ -211,20 +219,23 @@ class HomeController extends BaseController
//统计订单金额 //统计订单金额
$type = [ $type = [
FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP, FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP,
FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP
FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP,
FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_DIRECT_REFUND,
]; ];
$data['order_online']['total'] = 0;
$data['order_offline']['total'] = 0;
$revenueByOrder = $this->revenueListService->getRevenueByUser($userId,$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_offline']['total'],$order['money'],2);
}
}
$sumAmounts = $this->financialRecordService->sumAmountGroup($userId, UserType::STORE, $type, $dayStartTime, $dayEndTime);
$data['order_online']['total'] = bcsub($sumAmounts[FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP],$sumAmounts[FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_DIRECT_REFUND], 2);
$data['order_offline']['total'] = $sumAmounts[FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP];
// $revenueByOrder = $this->revenueListService->getRevenueByUser($userId,$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_offline']['total'],$order['money'],2);
// }
// }
//统计新增用户 无法筛选时间 所以和订单分开查询 //统计新增用户 无法筛选时间 所以和订单分开查询
$revenueByNewUsers = $this->revenueListService->getRevenueByUser($userId,[FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER]); $revenueByNewUsers = $this->revenueListService->getRevenueByUser($userId,[FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER]);
$data['new_user'] = [ $data['new_user'] = [

4
app/JsonRpc/OrdersService.php

@ -182,7 +182,9 @@ class OrdersService implements OrdersServiceInterface
throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL); throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL);
} }
$orderGoods = OrderGoods::query()->where(['order_id' => $orderChild->id, 'id' => $order_goods_id])->first();
$orderGoods = OrderGoods::query()
->where(['order_id' => $orderChild->id, 'id' => $order_goods_id, 'status' => 1])
->first();
if (is_null($orderGoods)) { if (is_null($orderGoods)) {
$this->log->event(LogLabel::ORDER_REFUND_LOG, [ $this->log->event(LogLabel::ORDER_REFUND_LOG, [

30
app/Service/v3/Implementations/FinancialRecordService.php

@ -317,6 +317,36 @@ class FinancialRecordService implements FinancialRecordServiceInterface
return bcadd($sumAmount, '0', 2); return bcadd($sumAmount, '0', 2);
} }
/**
* @inheritDoc
*/
public function sumAmountGroup($user_id, $user_type, $money_type = [], $startTime = 0, $endTime = 0)
{
$financialRecord = new FinancialRecord();
if ($user_id != FinancialRecord::ACCOUNT_LEDGER) {
$mod = bcmod((string)$user_id, '5', 0);
$financialRecord->suffix($mod);
}
$builder = $financialRecord->selectRaw('SUM(money) AS total, money_type')
->where([
'user_id' => $user_id,
'user_type' => $user_type
])
->whereIn('money_type', $money_type);
if ($startTime) {
$builder = $builder->where('created_at', '>=', $startTime);
}
if ($endTime) {
$builder = $builder->where('created_at', '<', $endTime);
}
return $builder->groupBy('money_type')->pluck('total', 'money_type');
}
/** /**
* @inheritDoc * @inheritDoc
*/ */

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

@ -3,6 +3,7 @@
namespace App\Service\v3\Implementations; namespace App\Service\v3\Implementations;
use App\Constants\v3\OrderState; use App\Constants\v3\OrderState;
use App\Constants\v3\OrderType;
use App\Model\v3\Order; use App\Model\v3\Order;
use App\Model\v3\OrderGoods; use App\Model\v3\OrderGoods;
use App\Model\v3\OrderMain; use App\Model\v3\OrderMain;
@ -35,10 +36,13 @@ class OrderStatisticsService implements OrderStatisticsServiceInterface
$builder = OrderMain::query() $builder = OrderMain::query()
->join($childTable, ''.$childTable.'.order_main_id', '=', ''.$mainTable.'.global_order_id') ->join($childTable, ''.$childTable.'.order_main_id', '=', ''.$mainTable.'.global_order_id')
->join($goodsTable, ''.$goodsTable.'.order_id', '=', ''.$childTable.'.id')
->where([''.$childTable.'.store_id' => $storeId, ''.$mainTable.'.type' => $type]) ->where([''.$childTable.'.store_id' => $storeId, ''.$mainTable.'.type' => $type])
->whereIn(''.$mainTable.'.state', array_merge(OrderState::FINISH, [OrderState::REFUNDED,OrderState::REFUND_REFUSE]))
->whereIn(''.$goodsTable.'.status', [1,2]);
->whereIn(''.$mainTable.'.state', array_merge(OrderState::FINISH, [OrderState::REFUNDED,OrderState::REFUND_REFUSE]));
if ($type == OrderType::ONLINE) {
$builder = $builder->join($goodsTable, ''.$goodsTable.'.order_id', '=', ''.$childTable.'.id')
->whereIn(''.$goodsTable.'.status', [1,2]);
}
if ($startTime) { if ($startTime) {
$builder = $builder->where(''.$mainTable.'.created_at', '>=', $startTime); $builder = $builder->where(''.$mainTable.'.created_at', '>=', $startTime);
@ -48,7 +52,7 @@ class OrderStatisticsService implements OrderStatisticsServiceInterface
$builder = $builder->where(''.$mainTable.'.created_at', '<=', $endTime); $builder = $builder->where(''.$mainTable.'.created_at', '<=', $endTime);
} }
return $builder->groupBy(''.$mainTable.'.id')->count();
return $builder->count();
// $builder = Order::join('lanzu_order_main','lanzu_order_main.global_order_id','lanzu_order.order_main_id') // $builder = Order::join('lanzu_order_main','lanzu_order_main.global_order_id','lanzu_order.order_main_id')
// ->where('lanzu_order.store_id',$storeId); // ->where('lanzu_order.store_id',$storeId);

17
app/Service/v3/Interfaces/FinancialRecordServiceInterface.php

@ -266,6 +266,23 @@ interface FinancialRecordServiceInterface
$money_type = [] $money_type = []
); );
/**
* 统计用户金额,按money_type分组
* @param $user_id
* @param $user_type
* @param array $money_type
* @param int $startTime
* @param int $endTime
* @return mixed
*/
public function sumAmountGroup(
$user_id,
$user_type,
$money_type = [],
$startTime = 0,
$endTime = 0
);
/** /**
* 商户微信提现流水 * 商户微信提现流水
* @param $user_id * @param $user_id

Loading…
Cancel
Save