|
@@ -8,11 +8,19 @@ use support\Request;
|
|
|
|
|
|
class StatisticsController
|
|
|
{
|
|
|
+ /**
|
|
|
+ * @Desc 标准订单
|
|
|
+ * @Author Gorden
|
|
|
+ * @Date 2024/10/28 9:57
|
|
|
+ *
|
|
|
+ * @param Request $request
|
|
|
+ * @return \support\Response
|
|
|
+ */
|
|
|
public function order(Request $request)
|
|
|
{
|
|
|
$orderCategory = $request->get('order_category');
|
|
|
$searchTime = $request->get('order_addtimes');
|
|
|
- if (!empty($searchTime)){
|
|
|
+ if (!empty($searchTime)) {
|
|
|
$searchTime[0] = strtotime($searchTime[0]);
|
|
|
$searchTime[1] = strtotime($searchTime[1]);
|
|
|
}
|
|
@@ -22,10 +30,17 @@ class StatisticsController
|
|
|
}
|
|
|
if ($orderCategory == 'SERVICE') {
|
|
|
$orderCategory = ['SERVICE', 'CHNMED', 'CHNNCD'];
|
|
|
+ } else if ($orderCategory == 'ALL') {
|
|
|
+ $orderCategory = ['SERVICE', 'CHNMED', 'CHNNCD', 'GOODS', 'PACKAGE', 'MEALS', 'RECHARGE', 'COMBINE', 'PARTNER', 'REFERRER', 'VIP'];
|
|
|
} else {
|
|
|
$orderCategory = [$orderCategory];
|
|
|
}
|
|
|
|
|
|
+ $where = '';
|
|
|
+ if (in_array('RECHARGE', $orderCategory)) {
|
|
|
+ $where = " and join_pay_order_id not in ('COMBINE','PARTNER','REFERRER')";
|
|
|
+ }
|
|
|
+
|
|
|
$orderCategoryStr = "'" . implode("','", $orderCategory) . "'";
|
|
|
|
|
|
$todayTimeUnix = strtotime(date('Y-m-d'));
|
|
@@ -37,35 +52,44 @@ class StatisticsController
|
|
|
$statistics['todayRevenue'] = PayDetail::whereRaw('CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) >= ? ', [$todayTimeUnix])
|
|
|
->where('pay_status', 'SUCCESS')
|
|
|
->whereIn('pay_category', $orderCategory)
|
|
|
+ ->when(in_array('RECHARGE', $orderCategory), function ($query) {
|
|
|
+ $query->whereNotIn('join_pay_order_id', ['COMBINE', 'PARTNER', 'REFERRER']);
|
|
|
+ })
|
|
|
->sum('pay_amount');
|
|
|
- $todayRevenueOrderNbrModel = Db::select("select count(1) as total from (select join_pay_order_id,JSON_EXTRACT(join_pay_object_json,'$.order_id') as order_id from app_pay_detail where
|
|
|
+ $todayRevenueOrderNbrModel = Db::select("select count(1) as total from (select JSON_EXTRACT(join_pay_object_json,'$.order_id') as order_id from app_pay_detail where
|
|
|
CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) >= {$todayTimeUnix}
|
|
|
and pay_status = 'SUCCESS'
|
|
|
- and pay_category in ({$orderCategoryStr})
|
|
|
- group by join_pay_order_id,order_id) count");
|
|
|
+ and pay_category in ({$orderCategoryStr}) {$where}
|
|
|
+ group by order_id) count");
|
|
|
$statistics['todayRevenueOrderNbr'] = $todayRevenueOrderNbrModel[0]->total;
|
|
|
// 昨日收入
|
|
|
$statistics['yesterdayRevenue'] = PayDetail::whereRaw('CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) >= ? and CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) <= ?', [$yesterdayStart, $yesterdayEnd])
|
|
|
->where('pay_status', 'SUCCESS')
|
|
|
->whereIn('pay_category', $orderCategory)
|
|
|
+ ->when(in_array('RECHARGE', $orderCategory), function ($query) {
|
|
|
+ $query->whereNotIn('join_pay_order_id', ['COMBINE', 'PARTNER', 'REFERRER']);
|
|
|
+ })
|
|
|
->sum('pay_amount');
|
|
|
- $yesterdayRevenueOrderNbrModel = Db::select("select count(1) as total from (select join_pay_order_id,JSON_EXTRACT(join_pay_object_json,'$.order_id') as order_id from app_pay_detail where
|
|
|
+ $yesterdayRevenueOrderNbrModel = Db::select("select count(1) as total from (select JSON_EXTRACT(join_pay_object_json,'$.order_id') as order_id from app_pay_detail where
|
|
|
CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) >= {$yesterdayStart} and CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) <= {$yesterdayEnd}
|
|
|
and pay_status = 'SUCCESS'
|
|
|
- and pay_category in ({$orderCategoryStr})
|
|
|
- group by join_pay_order_id,order_id) count");
|
|
|
+ and pay_category in ({$orderCategoryStr}) {$where}
|
|
|
+ group by order_id) count");
|
|
|
$statistics['yesterdayRevenueOrderNbr'] = $yesterdayRevenueOrderNbrModel[0]->total;
|
|
|
|
|
|
// 本月收入
|
|
|
$statistics['monthRevenue'] = PayDetail::whereRaw('CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) >= ? and CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) <= ?', [$monthStart, $monthEnd])
|
|
|
->where('pay_status', 'SUCCESS')
|
|
|
->whereIn('pay_category', $orderCategory)
|
|
|
+ ->when(in_array('RECHARGE', $orderCategory), function ($query) {
|
|
|
+ $query->whereNotIn('join_pay_order_id', ['COMBINE', 'PARTNER', 'REFERRER']);
|
|
|
+ })
|
|
|
->sum('pay_amount');
|
|
|
- $monthRevenueOrderNbrModel = Db::select("select count(1) as total from (select join_pay_order_id,JSON_EXTRACT(join_pay_object_json,'$.order_id') as order_id from app_pay_detail where
|
|
|
+ $monthRevenueOrderNbrModel = Db::select("select count(1) as total from (select JSON_EXTRACT(join_pay_object_json,'$.order_id') as order_id from app_pay_detail where
|
|
|
CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) >= {$monthStart} and CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) <= {$monthEnd}
|
|
|
and pay_status = 'SUCCESS'
|
|
|
- and pay_category in ({$orderCategoryStr})
|
|
|
- group by join_pay_order_id,order_id) count");
|
|
|
+ and pay_category in ({$orderCategoryStr}) {$where}
|
|
|
+ group by order_id) count");
|
|
|
$statistics['monthRevenueOrderNbr'] = $monthRevenueOrderNbrModel[0]->total;
|
|
|
// 累计收入
|
|
|
// $statistics['totalRevenue'] = PayDetail::where('pay_status', 'SUCCESS')
|
|
@@ -88,10 +112,10 @@ class StatisticsController
|
|
|
$statistics['totalRefund'] = $totalRefundItem[0]->amount;
|
|
|
$statistics['totalRefundNbr'] = $totalRefundItem[0]->total;
|
|
|
|
|
|
- if (in_array('MEALS',$orderCategory)){
|
|
|
+ if (in_array('MEALS', $orderCategory)) {
|
|
|
// 挂账
|
|
|
$sql = "select SUM(order_amount_pay) as amount, count(1) as total from app_order where order_status_payment = 'AWAITING'";
|
|
|
- if (!empty($searchTime)){
|
|
|
+ if (!empty($searchTime)) {
|
|
|
$sql .= " and order_addtimes > {$searchTime[0]} and order_addtimes < $searchTime[1]";
|
|
|
}
|
|
|
$awaitingModel = Db::select($sql);
|