ConfigService::get('shop', 'name'), 'today' => $today, 'pending' => $pending, 'business5' => $business5, 'visitor5' => $visitor5, ]; } /** * @notes 待办事项 * @return array * @author Tab * @date 2021/9/10 17:57 */ public static function pending() { // 待发货订单数 $waitShipped = Order::where('order_status', OrderEnum::STATUS_WAIT_DELIVERY)->count(); // 待审核售后申请 $waitAudit = AfterSale::where('sub_status', AfterSaleEnum::SUB_STATUS_WAIT_SELLER_AGREE)->count(); // 待审核评价 $waitProcess = GoodsComment::where(['status'=>YesNoEnum::NO])->count(); // 售罄商品 $noStockGoods = Goods::where('total_stock', 0)->count(); return [ 'wait_shipped' => $waitShipped, 'wait_audit' => $waitAudit, 'wait_process' => $waitProcess, 'no_stock_goods' => $noStockGoods ]; } /** * @notes 今日数据 * @return array * @author Tab * @date 2021/9/10 17:41 */ public static function today() { // 营业额 $todayOrderAmount = Order::where('pay_status', YesNoEnum::YES) ->whereDay('create_time') ->sum('order_amount'); // 成交订单数 $todayOrderNum = Order::where('pay_status', YesNoEnum::YES) ->whereDay('create_time') ->count(); // 访客数 $visitor = IndexVisit::whereDay('create_time')->column('ip'); $todayVisitor = count(array_unique($visitor)); // 新增用户 $todayNewUser = User::whereDay('create_time')->count(); return [ 'today_order_amount' => $todayOrderAmount, 'today_order_num' => $todayOrderNum, 'today_visitor' => $todayVisitor, 'today_new_user' => $todayNewUser, ]; } /** * @notes 近15天营业额 * @return array * @author Tab * @date 2021/9/10 18:06 */ public static function business7() { $today = new \DateTime(); $todayStr = $today->format('Y-m-d') . ' 23:59:59'; $todayDec15 = $today->add(\DateInterval::createFromDateString('-4day')); $todayDec15Str = $todayDec15->format('Y-m-d'); $field = [ "FROM_UNIXTIME(create_time,'%Y%m%d') as date", "sum(order_amount) as today_amount" ]; $lists = Order::field($field) ->whereTime('create_time', 'between', [$todayDec15Str,$todayStr]) ->where('pay_status', YesNoEnum::YES) ->group('date') ->select() ->toArray(); $lists = array_column($lists, 'today_amount', 'date'); $amountData = []; $date = []; for($i = 6; $i >= 0; $i --) { $today = new \DateTime(); $targetDay = $today->add(\DateInterval::createFromDateString('-'. $i . 'day')); $targetDayTime = $targetDay->format('Ymd'); $targetDays = $targetDay->format('d'); $date[] = $targetDays; $amountData[] = $lists[$targetDayTime] ?? 0; } return [ 'date' => $date, 'list' => [ ['name' => '营业额', 'data' => $amountData] ] ]; } /** * @notes 近15天访客数 * @return mixed * @author Tab * @date 2021/9/10 18:51 */ public static function visitor7() { $today = new \DateTime(); $todayStr = $today->format('Y-m-d') . ' 23:59:59'; $todayDec15 = $today->add(\DateInterval::createFromDateString('-5day')); $todayDec15Str = $todayDec15->format('Y-m-d'); $field = [ "FROM_UNIXTIME(create_time,'%Y%m%d') as date", "ip" ]; $lists = IndexVisit::field($field) ->distinct(true) ->whereTime('create_time', 'between', [$todayDec15Str,$todayStr]) ->select() ->toArray(); // 集合一天的IP $temp1 = []; foreach ($lists as $item) { $temp1[$item['date']][] = $item['ip']; } // 统计数量 $temp2 = []; foreach ($temp1 as $k => $v) { $temp2[$k] = count($v); } $userData = []; $date = []; for($i = 6; $i >= 0; $i --) { $today = new \DateTime(); $targetDay = $today->add(\DateInterval::createFromDateString('-'. $i . 'day')); $targetDayTime = $targetDay->format('Ymd'); $targetDays = $targetDay->format('d'); $date[] = $targetDays; $userData[] = $temp2[$targetDayTime] ?? 0; } return [ 'date' => $date, 'list' => [ ['name' => '访客数', 'data' => $userData] ] ]; } }