get('order_category'); if (!$orderCategory) { return json_fail('参数异常'); } if ($orderCategory == 'SERVICE') { $orderCategory = ['SERVICE', 'CHNMED', 'CHNNCD']; } else { $orderCategory = [$orderCategory]; } $todayTimeUnix = strtotime(date('Y-m-d')); $yesterdayStart = strtotime(date('Y-m-d', strtotime("-1 days"))); $yesterdayEnd = strtotime(date('Y-m-d 23:59:59', strtotime("-1 days"))); $monthStart = strtotime(date('Y-m-01')); $monthEnd = strtotime(date('Y-m-t 23:59:59')); // 今日收入 $statistics['todayRevenue'] = PayDetail::whereRaw('CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) >= ? ', [$todayTimeUnix]) ->where('pay_status', 'SUCCESS') ->whereIn('pay_category', $orderCategory) ->sum('pay_amount'); // 昨日收入 $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) ->sum('pay_amount'); // 本月收入 $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) ->sum('pay_amount'); // 累计收入 $statistics['totalRevenue'] = PayDetail::where('pay_status', 'SUCCESS') ->whereIn('pay_category', $orderCategory) ->sum('pay_amount'); // 今日退款 $todayRefundItem = Db::select("select SUM(d2.pay_amount) as amount from app_pay_detail d1 inner join app_pay_detail d2 ON d1.join_pay_order_id=d2.join_pay_order_id and d2.pay_category='REFUND' where CAST(UNIX_TIMESTAMP(d2.pay_paytimes) as SIGNED) >= ? AND d1.pay_category in ('".implode("','",$orderCategory)."') ", [$todayTimeUnix]); $statistics['todayRefund'] = 0; if (!empty($todayRefundItem) && !empty($todayRefundItem[0])){ $statistics['todayRefund'] = $todayRefundItem[0]->amount; } // 累计退款 $totalRefundItem = Db::select("select SUM(d2.pay_amount) as amount, d1.pay_category as d1_pay_category,d2.pay_category as d2_pay_category from app_pay_detail d1 inner join app_pay_detail d2 ON d1.join_pay_order_id=d2.join_pay_order_id and d2.pay_category='REFUND' where d1.pay_category in ('".implode("','",$orderCategory)."') "); dump($totalRefundItem); } }