whereDay('create_time')->count(); $orderPayNum = StoreOrder::where('store_id', $store_id)->where('paid', 1)->whereDay('create_time')->group('uid')->count(); $monthOrderNum = StoreOrder::where('store_id', $store_id)->whereMonth('create_time')->count(); $monthOrderPayNum = StoreOrder::where('store_id', $store_id)->where('paid', 1)->whereMonth('create_time')->group('uid')->count(); $data = [ "orderNum" => $orderNum, "monthOrderNum" => $monthOrderNum, "monthOrderNumRate" => 0, "orderNumRate" => 0, "orderPayNum" => $orderPayNum, "monthOrderPayNum" => $monthOrderPayNum, "monthOrderPayRate" => 0, "orderOrderPayRate" => 0 ]; return $data; } public static function Currday($store_id) { $date = date("Y-m-d"); $startTime = strtotime($date . ' 00:00:00'); // 当天的开始时间戳 $endTime = strtotime($date . ' 23:59:59'); // 当天的结束时间戳 $interval = 4 * 60 * 60; // 4小时的秒数 $data = []; for ($time = $startTime; $time < $endTime; $time += $interval) { $endTimeSegment = $time + $interval; $startTimeSegment = date('Y-m-d H:i:s', $time); $yesterendTimeSegment = date('Y-m-d H:i:s', $endTimeSegment - 86400); $endTimeSegment = date('Y-m-d H:i:s', $endTimeSegment); $yesterstartTimeSegment = date('Y-m-d H:i:s', $time - 86400); // 统计当前时间段的订单 $todayAmount = StoreOrder::where('store_id', $store_id) ->where('paid', 1) ->whereBetween('create_time', [strtotime($startTimeSegment), strtotime($endTimeSegment)]) ->sum('pay_price'); $yesterdayAmount = StoreOrder::where('store_id', $store_id) ->where('paid', 1) ->whereBetween('create_time', [strtotime($yesterstartTimeSegment), strtotime($yesterendTimeSegment)]) ->sum('pay_price'); $data[] = [ 'todayAmount' => $todayAmount, 'yesterdayAmount' => $yesterdayAmount, ]; } return $data; } public static function dayPayPrice($store_id) { $todayAmount = UserRecharge::where('store_id', $store_id) ->where('paid', 1) ->whereDay('create_time') ->sum('price'); return $todayAmount; } }