Merge branch 'main' of https://gitea.lihaink.cn/mkm/multi-store
This commit is contained in:
commit
d26d9c97d4
@ -201,6 +201,18 @@ class StoreOrderLogic extends BaseLogic
|
|||||||
return StoreOrder::where($where)->sum('pay_price');
|
return StoreOrder::where($where)->sum('pay_price');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单统计
|
||||||
|
* @param $storeId
|
||||||
|
* @param $start
|
||||||
|
* @param $end
|
||||||
|
* @param $extra
|
||||||
|
* @return float|\think\db\Query
|
||||||
|
*/
|
||||||
|
public function storeOrderSumByDate($storeId, $start, $end, $extra = [])
|
||||||
|
{
|
||||||
|
return StoreOrder::where('store_id', $storeId)->where('paid', 1)->where($extra)->whereBetweenTime('create_time', $start, $end)->sum('pay_price');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 退款
|
* 退款
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
namespace app\store\logic;
|
namespace app\store\logic;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\enum\PayEnum;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use app\common\logic\store_order\StoreOrderLogic;
|
use app\common\logic\store_order\StoreOrderLogic;
|
||||||
use app\common\model\store_order\StoreOrder;
|
use app\common\model\store_order\StoreOrder;
|
||||||
@ -39,42 +40,47 @@ class WorkbenchLogic extends BaseLogic
|
|||||||
public static function index($params)
|
public static function index($params)
|
||||||
{
|
{
|
||||||
$data = [];
|
$data = [];
|
||||||
$orderLogic = new StoreOrderLogic();
|
|
||||||
$data['order_amount'] = $orderLogic->storeOrderSumByWhere([
|
|
||||||
'store_id' => $params['store_id'],
|
|
||||||
'paid' => 1,
|
|
||||||
]);
|
|
||||||
$data['cashier_amount'] = $orderLogic->storeOrderSumByWhere([
|
|
||||||
'store_id' => $params['store_id'],
|
|
||||||
'paid' => 1,
|
|
||||||
'shipping_type' => 3,
|
|
||||||
]);
|
|
||||||
$data['delivery_amount'] = $orderLogic->storeOrderSumByWhere([
|
|
||||||
'store_id' => $params['store_id'],
|
|
||||||
'paid' => 1,
|
|
||||||
'shipping_type' => 1,
|
|
||||||
]);
|
|
||||||
$data['verify_amount'] = $orderLogic->storeOrderSumByWhere([
|
|
||||||
'store_id' => $params['store_id'],
|
|
||||||
'paid' => 1,
|
|
||||||
'shipping_type' => 2,
|
|
||||||
]);
|
|
||||||
$startTime = $params['start_time'];
|
$startTime = $params['start_time'];
|
||||||
$endTime = $params['end_time'];
|
$endTime = $params['end_time'];
|
||||||
$days = (new \DateTime($endTime))->diff(new \DateTime($startTime))->days;
|
$endTime = date('Y-m-d', strtotime($endTime) + 86400);
|
||||||
$days += 1;
|
$dateDiff = (new \DateTime($endTime))->diff(new \DateTime($startTime));
|
||||||
if ($days == 1) {
|
if ($dateDiff->days > 366) {
|
||||||
|
throw new \Exception('时间范围不能超过一年');
|
||||||
|
}
|
||||||
|
$orderLogic = new StoreOrderLogic();
|
||||||
|
$data['order_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime);
|
||||||
|
$data['balance_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, ['pay_type' => PayEnum::BALANCE_PAY]);
|
||||||
|
$data['cashier_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, ['shipping_type' => 3]);
|
||||||
|
$data['delivery_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, ['shipping_type' => 1]);
|
||||||
|
$data['verify_amount'] = $orderLogic->storeOrderSumByDate($params['store_id'], $startTime, $endTime, ['shipping_type' => 2]);
|
||||||
|
$data['user_number'] = StoreOrder::where('store_id', $params['store_id'])
|
||||||
|
->where('paid', 1)
|
||||||
|
->whereBetweenTime('create_time', $startTime, $endTime)
|
||||||
|
->group('uid')
|
||||||
|
->count();
|
||||||
|
if ($dateDiff->days == 1) {
|
||||||
$group = 'HOUR(pay_time)';
|
$group = 'HOUR(pay_time)';
|
||||||
$timeRange = [0, 23];
|
$i = 0;
|
||||||
$endTime = date('Y-m-d H:i:s', strtotime($endTime) + 86400);
|
while ($i < 24) {
|
||||||
|
$timeRange[] = date('H', strtotime("+$i hours", strtotime($startTime)));
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
$field = 'from_unixtime(pay_time,"%H") as pay_time,sum(pay_price) as pay_price';
|
$field = 'from_unixtime(pay_time,"%H") as pay_time,sum(pay_price) as pay_price';
|
||||||
} elseif ($days <= 31) {
|
} elseif ($dateDiff->days <= 31) {
|
||||||
$group = 'DAY(pay_time)';
|
$group = 'DAY(pay_time)';
|
||||||
$timeRange = [1, $days];
|
$i = 0;
|
||||||
|
while ($i < $dateDiff->days) {
|
||||||
|
$timeRange[] = date('m-d', strtotime("+$i days", strtotime($startTime)));
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
$field = 'from_unixtime(pay_time,"%m-%d") as pay_time,sum(pay_price) as pay_price';
|
$field = 'from_unixtime(pay_time,"%m-%d") as pay_time,sum(pay_price) as pay_price';
|
||||||
} else {
|
} else {
|
||||||
$group = 'MONTH(pay_time)';
|
$group = 'MONTH(pay_time)';
|
||||||
$timeRange = [1, (int)date('n')];
|
$i = 0;
|
||||||
|
while ($i <= $dateDiff->m) {
|
||||||
|
$timeRange[] = date('Y-m', strtotime("+$i months", strtotime($startTime)));
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
$field = 'from_unixtime(pay_time,"%Y-%m") as pay_time,sum(pay_price) as pay_price';
|
$field = 'from_unixtime(pay_time,"%Y-%m") as pay_time,sum(pay_price) as pay_price';
|
||||||
}
|
}
|
||||||
$orderList = StoreOrder::field($field)
|
$orderList = StoreOrder::field($field)
|
||||||
@ -96,17 +102,17 @@ class WorkbenchLogic extends BaseLogic
|
|||||||
$orderListTmp = [];
|
$orderListTmp = [];
|
||||||
$userListTmp = [];
|
$userListTmp = [];
|
||||||
$range = [];
|
$range = [];
|
||||||
for ($i = $timeRange[0]; $i <= $timeRange[1]; $i++) {
|
foreach ($timeRange as $item) {
|
||||||
$range[] = $i;
|
$range[] = $item;
|
||||||
if (!isset($orderList[$i])) {
|
if (!isset($orderList[$item])) {
|
||||||
$orderListTmp[$i] = 0;
|
$orderListTmp[$item] = 0;
|
||||||
} else {
|
} else {
|
||||||
$orderListTmp[$i] = $orderList[$i]['pay_price'];
|
$orderListTmp[$item] = $orderList[$item]['pay_price'];
|
||||||
}
|
}
|
||||||
if (!isset($userList[$i])) {
|
if (!isset($userList[$item])) {
|
||||||
$userListTmp[$i] = 0;
|
$userListTmp[$item] = 0;
|
||||||
} else {
|
} else {
|
||||||
$userListTmp[$i] = $userList[$i]['user_num'];
|
$userListTmp[$item] = $userList[$item]['user_num'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$data['statistics'] = [
|
$data['statistics'] = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user