request->isAjax) { $goods_ranking_list = StoreGoodsRanking::lists([ 'where' => [ ['store_id' => $this->store_id], ], 'order' => 'sales_money desc', 'select' => 'id,goods_id,sales_money', 'limit' => 5 ]); $goods_ids = array_column($goods_ranking_list, 'goods_id'); $store_goods_list = StoreGoods::lists(['where' => [['id' => $goods_ids]], 'index' => 'id', 'select' => 'id,goods_name,cover_pic']); foreach ($goods_ranking_list as &$item) { $item['goods_name'] = $item['cover_pic'] = ''; if (isset($store_goods_list[$item['goods_id']])) { $item['goods_name'] = $store_goods_list[$item['goods_id']]['goods_name']; $item['cover_pic'] = $store_goods_list[$item['goods_id']]['cover_pic']; } } $user_ranking_list = StoreUser::lists([ 'where' => [ ['store_id' => $this->store_id], ], 'order' => 'pay_money desc', 'select' => 'id,user_id,pay_money', 'limit' => 5 ]); $user_ids = array_column($user_ranking_list, 'user_id'); $user_list = User::lists(['where' => [['id' => $user_ids]], 'index' => 'id', 'select' => 'id,nickname,avatar_url']); foreach ($user_ranking_list as &$item) { $item['nickname'] = $item['avatar_url'] = ''; if (isset($user_list[$item['user_id']])) { $item['nickname'] = $user_list[$item['user_id']]['nickname']; $item['avatar_url'] = $user_list[$item['user_id']]['avatar_url']; } } $time = time(); $today = date('Y-m-d', $time); $yesterday = date("Y-m-d", strtotime("-1 day")); $date_time_arr = [$today, $yesterday]; for ($i = 2; $i <= 4; $i++) { $date_time_arr[] = date("Y-m-d", strtotime("-{$i} day")); } $today_data = $yesterday_data = [ 'add_user_nums'=>'--', 'order_nums'=>'--', 'settlement_commission'=>'--', 'sales_money'=>'--', 'cashier_sales_money'=>'--', ]; $store_census_list = StoreCensus::lists(['where' => [['store_id' => $this->store_id], ['date_time' => $date_time_arr]], 'order' => 'created_at asc']); $table_list = []; if ($store_census_list) { foreach ($store_census_list as $val) { $table_list[] = [ 'created_at' => $val['date_time'], 'sales_money' => $val['sales_money'] ?? 0, 'cashier_sales_money' => $val['cashier_sales_money'] ?? 0, ]; switch ($val['date_time']) { case $today: $today_data = $val; break; case $yesterday: $yesterday_data = $val; break; } } } $store = Store::getOne([['id' => $this->store_id]], true, [], false, 'id,shop_owner,store_name,logo_img,expire_time,business_time_start,business_time_end'); $store['business_status'] = '营业中'; if ($time < $store['business_time_start'] || $time > $store['business_time_end']) { $store['business_status'] = '休息中'; } $no_pay_counts = StoreOrder::find()->where(['store_id' => $this->store_id, 'order_status' => 0])->count();//待付款 $no_delivery_counts = StoreOrder::find()->where(['store_id' => $this->store_id, 'order_status' => 1])->andWhere(['!=','order_source','Reserve'])->count();//待发货,除了服务订单 $no_delivery_reserve_counts = StoreOrder::find()->where(['store_id' => $this->store_id, 'order_status' => 2])->andWhere(['=','order_source','Reserve'])->count();//待服务,服务订单额外统计 $after_sale_counts = OrderRefund::find()->where(['store_id' => $this->store_id])->andWhere(['in', 'refund_status', [RefundStatusEnum::APPLY, RefundStatusEnum::HANDEL, RefundStatusEnum::RETURN_GOODS, RefundStatusEnum::EXCHANGE_GOODS]])->count();//售后 $sell_out_counts = StoreGoods::find()->where(['store_id' => $this->store_id, 'stock' => 0, 'status' => StatusEnum::ENABLED])->count();//售罄 $store['no_pay_counts'] = $no_pay_counts ?? 0; $store['no_delivery_counts'] = $no_delivery_counts + $no_delivery_reserve_counts ?? 0; $store['after_sale_counts'] = $after_sale_counts ?? 0; $store['sell_out_counts'] = $sell_out_counts ?? 0; $store['is_alert'] = false; if ($store['expire_time'] > 0) { if ($store['expire_time'] - (7 * 86400) < time()) { $store['is_alert'] = true; } } return $this->success('操作成功', compact('goods_ranking_list', 'user_ranking_list', 'today_data', 'yesterday_data', 'table_list', 'store')); } return $this->render($this->action->id); } //不用验证权限 public function actionToPay() { if (Yii::$app->request->isAjax) { $params = Yii::$app->request->post(); $limit = 1; switch ($params['activeDay']) { case "one": $limit = 1; break; case "seven": $limit = 6; break; case "thirty": $limit = 29; break; } $time = time(); $today = date('Y-m-d', $time); $date_time_arr = [$today]; for ($i = 1; $i <= $limit; $i++) { $date_time_arr[] = date("Y-m-d", strtotime("-{$i} day")); } $today_data = ['add_user_nums' => 0, 'order_nums' => 0, 'settlement_commission' => 0, 'sales_money' => 0, 'cashier_sales_money' => 0]; $store_census_list = StoreCensus::lists(['where' => [['store_id' => $this->store_id], ['date_time' => $date_time_arr]], 'order' => 'created_at asc']); if ($store_census_list) { foreach ($store_census_list as $val) { $today_data['add_user_nums'] += $val['add_user_nums']; $today_data['order_nums'] += $val['order_nums']; $today_data['settlement_commission'] += $val['settlement_commission']; $today_data['sales_money'] += $val['sales_money']; $today_data['cashier_sales_money'] += $val['cashier_sales_money']; } } return $this->success('操作成功', compact('today_data')); } return $this->render($this->action->id); } public function actionHeader() { $admin = Yii::$app->store_user->identity; $user = array( 'id' => $admin->id, 'store_id' => $admin->store_id, 'username' => $admin->username, 'admin_type' => $admin->admin_type, ); $mall = array( 'id' => $this->mall['id'], 'name' => $this->mall['name'], ); $services = Yii::$app->services->setting->platform->get('system'); $update_password_status = Yii::$app->services->setting->mall->get('basic.update_password_status'); $navs = []; return $this->success('操作成功', compact('user', 'mall', 'services', 'update_password_status', 'navs')); } }