feat: 重构了订单相关的统计逻辑和代码结构
This commit is contained in:
parent
140fe814c2
commit
67532a536a
@ -72,197 +72,6 @@ class WorkbenchController extends BaseAdminController
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
//首页订单
|
||||
public function order()
|
||||
{
|
||||
$data = [
|
||||
"yAxis" => [
|
||||
"maxnum" => 35,
|
||||
"maxprice" => "111374.41"
|
||||
],
|
||||
"legend" => [
|
||||
"订单金额",
|
||||
"订单数"
|
||||
],
|
||||
"xAxis" => [
|
||||
"2024-05-06",
|
||||
"2024-05-07",
|
||||
"2024-05-08",
|
||||
"2024-05-09",
|
||||
"2024-05-10",
|
||||
"2024-05-11",
|
||||
"2024-05-12",
|
||||
"2024-05-13",
|
||||
"2024-05-14",
|
||||
"2024-05-15",
|
||||
"2024-05-16",
|
||||
"2024-05-17",
|
||||
"2024-05-18",
|
||||
"2024-05-19",
|
||||
"2024-05-20",
|
||||
"2024-05-21",
|
||||
"2024-05-22",
|
||||
"2024-05-23",
|
||||
"2024-05-24",
|
||||
"2024-05-25",
|
||||
"2024-05-26",
|
||||
"2024-05-27",
|
||||
"2024-05-28",
|
||||
"2024-05-29",
|
||||
"2024-05-30",
|
||||
"2024-05-31",
|
||||
"2024-06-01",
|
||||
"2024-06-02",
|
||||
"2024-06-03",
|
||||
"2024-06-04"
|
||||
],
|
||||
"series" => [
|
||||
[
|
||||
"name" => "订单金额",
|
||||
"type" => "bar",
|
||||
"itemStyle" => [
|
||||
"normal" => [
|
||||
"color" => [
|
||||
"x" => 0,
|
||||
"y" => 0,
|
||||
"x2" => 0,
|
||||
"y2" => 1,
|
||||
"colorStops" => [
|
||||
[
|
||||
"offset" => 0,
|
||||
"color" => "#69cdff"
|
||||
],
|
||||
[
|
||||
"offset" => 0.5,
|
||||
"color" => "#3eb3f7"
|
||||
],
|
||||
[
|
||||
"offset" => 1,
|
||||
"color" => "#1495eb"
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
"data" => [
|
||||
171.29,
|
||||
167.46,
|
||||
1455.65,
|
||||
45.47,
|
||||
542.69,
|
||||
216.58,
|
||||
228.82,
|
||||
34.24,
|
||||
8249.85,
|
||||
664.23,
|
||||
8586.24,
|
||||
10.19,
|
||||
90.19,
|
||||
105.4,
|
||||
62.59,
|
||||
1051.34,
|
||||
160.84,
|
||||
2437.68,
|
||||
111374.41,
|
||||
12161.05,
|
||||
189,
|
||||
4831.65,
|
||||
1276.31,
|
||||
582.4,
|
||||
906.02,
|
||||
597,
|
||||
0.08,
|
||||
771.16,
|
||||
10262.64,
|
||||
278.67
|
||||
]
|
||||
],
|
||||
[
|
||||
"name" => "订单数",
|
||||
"type" => "line",
|
||||
"itemStyle" => [
|
||||
"normal" => [
|
||||
"color" => [
|
||||
"x" => 0,
|
||||
"y" => 0,
|
||||
"x2" => 0,
|
||||
"y2" => 1,
|
||||
"colorStops" => [
|
||||
[
|
||||
"offset" => 0,
|
||||
"color" => "#6fdeab"
|
||||
],
|
||||
[
|
||||
"offset" => 0.5,
|
||||
"color" => "#44d693"
|
||||
],
|
||||
[
|
||||
"offset" => 1,
|
||||
"color" => "#2cc981"
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
"data" => [
|
||||
5,
|
||||
8,
|
||||
15,
|
||||
6,
|
||||
13,
|
||||
5,
|
||||
3,
|
||||
4,
|
||||
7,
|
||||
14,
|
||||
12,
|
||||
6,
|
||||
2,
|
||||
2,
|
||||
6,
|
||||
8,
|
||||
19,
|
||||
18,
|
||||
13,
|
||||
30,
|
||||
2,
|
||||
35,
|
||||
12,
|
||||
5,
|
||||
20,
|
||||
2,
|
||||
2,
|
||||
7,
|
||||
13,
|
||||
6
|
||||
],
|
||||
"yAxisIndex" => 1
|
||||
]
|
||||
],
|
||||
"pre_cycle" => [
|
||||
"count" => [
|
||||
"data" => 170
|
||||
],
|
||||
"price" => [
|
||||
"data" => "1333354.63"
|
||||
]
|
||||
],
|
||||
"cycle" => [
|
||||
"count" => [
|
||||
"data" => 268,
|
||||
"percent" => 57.65,
|
||||
"is_plus" => 1
|
||||
],
|
||||
"price" => [
|
||||
"data" => "157451.54",
|
||||
"percent" => 88.19,
|
||||
"is_plus" => -1
|
||||
]
|
||||
]
|
||||
];
|
||||
return $this->data($data);
|
||||
}
|
||||
//-------------------------------商品统计---------------------------------------//
|
||||
|
||||
/**
|
||||
|
@ -24,7 +24,7 @@ class TradeStatisticLogic extends BaseLogic
|
||||
//总交易额
|
||||
$selectType = "sum";
|
||||
$tradeTotalMoney = $this->tradeTotalMoney($where, $selectType);
|
||||
|
||||
|
||||
//交易曲线
|
||||
$selectType = "group";
|
||||
$hourTotalMoney = $this->tradeGroupMoney($where, $selectType);
|
||||
@ -46,26 +46,7 @@ class TradeStatisticLogic extends BaseLogic
|
||||
];
|
||||
|
||||
//今日订单数曲线
|
||||
$todayHourOrderCount = $storeOrder->where($orderCountWhere)
|
||||
->when(isset($where['timeKey']), function ($query) use ($where) {
|
||||
$query->whereBetweenTime('create_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
|
||||
if ($where['timeKey']['days'] == 1) {
|
||||
$timeUinx = "%H";
|
||||
} elseif ($where['timeKey']['days'] == 30) {
|
||||
$timeUinx = "%Y-%m-%d";
|
||||
} elseif ($where['timeKey']['days'] == 365) {
|
||||
$timeUinx = "%Y-%m";
|
||||
} elseif ($where['timeKey']['days'] > 1 && $where['timeKey']['days'] < 30) {
|
||||
$timeUinx = "%Y-%m-%d";
|
||||
} elseif ($where['timeKey']['days'] > 30 && $where['timeKey']['days'] < 365) {
|
||||
$timeUinx = "%Y-%m";
|
||||
} else {
|
||||
$timeUinx = "%Y-%m";
|
||||
}
|
||||
$query->field("count(*) as number,FROM_UNIXTIME(create_time, '$timeUinx') as time");
|
||||
$query->group("FROM_UNIXTIME(create_time, '$timeUinx')");
|
||||
})
|
||||
->order('create_time ASC')->select()->toArray();
|
||||
$todayHourOrderCount = $storeOrder->getCurveData($orderCountWhere, $where, 'count(*)');
|
||||
$todayHourOrderCount = $this->trendYdata((array)$todayHourOrderCount, $timeKey);
|
||||
|
||||
//昨日订单数
|
||||
@ -87,29 +68,10 @@ class TradeStatisticLogic extends BaseLogic
|
||||
/** day支付人数 */
|
||||
//今日支付人数
|
||||
$todayPayOrderPeople = $storeOrder->where($orderCountWhere)->whereDay('create_time')->group('uid')->count();
|
||||
|
||||
|
||||
//今日支付人数曲线
|
||||
$todayHourOrderPeople = $storeOrder->where($orderCountWhere)
|
||||
->when(isset($where['timeKey']), function ($query) use ($where) {
|
||||
$query->whereBetweenTime('create_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
|
||||
if ($where['timeKey']['days'] == 1) {
|
||||
$timeUinx = "%H";
|
||||
} elseif ($where['timeKey']['days'] == 30) {
|
||||
$timeUinx = "%Y-%m-%d";
|
||||
} elseif ($where['timeKey']['days'] == 365) {
|
||||
$timeUinx = "%Y-%m";
|
||||
} elseif ($where['timeKey']['days'] > 1 && $where['timeKey']['days'] < 30) {
|
||||
$timeUinx = "%Y-%m-%d";
|
||||
} elseif ($where['timeKey']['days'] > 30 && $where['timeKey']['days'] < 365) {
|
||||
$timeUinx = "%Y-%m";
|
||||
} else {
|
||||
$timeUinx = "%Y-%m";
|
||||
}
|
||||
$query->field("count(distinct uid) as number,FROM_UNIXTIME(create_time, '$timeUinx') as time");
|
||||
$query->group("FROM_UNIXTIME(create_time, '$timeUinx')");
|
||||
})
|
||||
->order('create_time ASC')->select()->toArray();
|
||||
|
||||
$todayHourOrderPeople = $storeOrder->getCurveData($orderCountWhere, $where, 'count(distinct uid)');
|
||||
|
||||
$todayHourOrderPeople = $this->trendYdata((array)$todayHourOrderPeople, $where['timeKey']);
|
||||
//昨日支付人数
|
||||
$yestodayPayOrderPeople = $storeOrder->where($orderCountWhere)->whereDay('create_time', 'yesterday')->group('uid')->count();
|
||||
@ -151,26 +113,8 @@ class TradeStatisticLogic extends BaseLogic
|
||||
];
|
||||
$monthOrderCount = $storeOrder->where($monthOrderCountWhere)->whereBetweenTime('create_time', $where['timeKey']['start_time'], $where['timeKey']['end_time'])->count();
|
||||
//本月订单数曲线
|
||||
$monthCurveOrderCount = $storeOrder->where($monthOrderCountWhere)
|
||||
->when(isset($where['timeKey']), function ($query) use ($where) {
|
||||
$query->whereBetweenTime('create_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
|
||||
if ($where['timeKey']['days'] == 1) {
|
||||
$timeUinx = "%H";
|
||||
} elseif ($where['timeKey']['days'] == 30) {
|
||||
$timeUinx = "%Y-%m-%d";
|
||||
} elseif ($where['timeKey']['days'] == 365) {
|
||||
$timeUinx = "%Y-%m";
|
||||
} elseif ($where['timeKey']['days'] > 1 && $where['timeKey']['days'] < 30) {
|
||||
$timeUinx = "%Y-%m-%d";
|
||||
} elseif ($where['timeKey']['days'] > 30 && $where['timeKey']['days'] < 365) {
|
||||
$timeUinx = "%Y-%m";
|
||||
} else {
|
||||
$timeUinx = "%Y-%m";
|
||||
}
|
||||
$query->field("count(*) as number,FROM_UNIXTIME(create_time, '$timeUinx') as time");
|
||||
$query->group("FROM_UNIXTIME(create_time, '$timeUinx')");
|
||||
})
|
||||
->order('create_time ASC')->select()->toArray();
|
||||
$monthCurveOrderCount = $storeOrder->getCurveData($monthOrderCountWhere, $where, 'count(*)');
|
||||
|
||||
$monthCurveOrderCount = $this->trendYdata((array)$monthCurveOrderCount, $timeKey);
|
||||
//上月订单数
|
||||
$lastOrderCountWhere['timeKey'] = $this->TimeConvert("last_month");
|
||||
@ -206,26 +150,7 @@ class TradeStatisticLogic extends BaseLogic
|
||||
$monthPayOrderPeople = $storeOrder->where($monthOrderPeopleWhere)->whereMonth('create_time')->group('uid')->count();
|
||||
|
||||
//本月支付人数曲线
|
||||
$monthCurveOrderPeople = $storeOrder->where($monthOrderPeopleWhere)
|
||||
->when(isset($where['timeKey']), function ($query) use ($where) {
|
||||
$query->whereBetweenTime('create_time', $where['timeKey']['start_time'], $where['timeKey']['end_time']);
|
||||
if ($where['timeKey']['days'] == 1) {
|
||||
$timeUinx = "%H";
|
||||
} elseif ($where['timeKey']['days'] == 30) {
|
||||
$timeUinx = "%Y-%m-%d";
|
||||
} elseif ($where['timeKey']['days'] == 365) {
|
||||
$timeUinx = "%Y-%m";
|
||||
} elseif ($where['timeKey']['days'] > 1 && $where['timeKey']['days'] < 30) {
|
||||
$timeUinx = "%Y-%m-%d";
|
||||
} elseif ($where['timeKey']['days'] > 30 && $where['timeKey']['days'] < 365) {
|
||||
$timeUinx = "%Y-%m";
|
||||
} else {
|
||||
$timeUinx = "%Y-%m";
|
||||
}
|
||||
$query->field("count(distinct uid) as number,FROM_UNIXTIME(create_time, '$timeUinx') as time");
|
||||
$query->group("FROM_UNIXTIME(create_time, '$timeUinx')");
|
||||
})
|
||||
->order('create_time ASC')->select()->toArray();
|
||||
$monthCurveOrderPeople = $storeOrder->getCurveData($monthOrderPeopleWhere, $where, 'count(distinct uid)');
|
||||
|
||||
$monthCurveOrderPeople = $this->trendYdata((array)$monthCurveOrderPeople, $timeKey);
|
||||
//上月支付人数
|
||||
@ -496,7 +421,7 @@ class TradeStatisticLogic extends BaseLogic
|
||||
/** 收入营业额 */
|
||||
//商品订单收入
|
||||
$inOrderMoney = $this->getOrderTotalMoney($where, $selectType, "", $isNum);
|
||||
|
||||
|
||||
//用户充值收入
|
||||
$inRechargeMoneyHome = $this->getRechargeTotalMoney($where, $selectType, "", $isNum);
|
||||
|
||||
|
@ -85,4 +85,34 @@ class StoreOrder extends BaseModel
|
||||
})->field("FROM_UNIXTIME(create_time,'$timeType') as days,$str as num")
|
||||
->group('days')->select()->toArray();
|
||||
}
|
||||
/**
|
||||
* 曲线统计
|
||||
* @param $time
|
||||
* @param $type
|
||||
* @param $timeType
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCurveData($where,$time,$str)
|
||||
{
|
||||
return $this->where($where)
|
||||
->when(isset($where['timeKey']), function ($query) use ($time,$str) {
|
||||
$query->whereBetweenTime('create_time', $time['timeKey']['start_time'], $time['timeKey']['end_time']);
|
||||
if ($time['timeKey']['days'] == 1) {
|
||||
$timeUinx = "%H";
|
||||
} elseif ($time['timeKey']['days'] == 30) {
|
||||
$timeUinx = "%Y-%m-%d";
|
||||
} elseif ($time['timeKey']['days'] == 365) {
|
||||
$timeUinx = "%Y-%m";
|
||||
} elseif ($time['timeKey']['days'] > 1 && $time['timeKey']['days'] < 30) {
|
||||
$timeUinx = "%Y-%m-%d";
|
||||
} elseif ($time['timeKey']['days'] > 30 && $time['timeKey']['days'] < 365) {
|
||||
$timeUinx = "%Y-%m";
|
||||
} else {
|
||||
$timeUinx = "%Y-%m";
|
||||
}
|
||||
$query->field("$str as number,FROM_UNIXTIME(create_time, '$timeUinx') as time");
|
||||
$query->group("FROM_UNIXTIME(create_time, '$timeUinx')");
|
||||
})
|
||||
->order('create_time ASC')->select()->toArray();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user