| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- namespace addons\Store\client\controllers;
- use addons\Store\common\models\Store;
- use addons\Store\common\models\StoreCensus;
- use addons\Store\common\models\StoreGoods;
- use addons\Store\common\models\StoreGoodsRanking;
- use addons\Store\common\models\StoreOrder;
- use addons\Store\common\models\StoreUser;
- use common\enums\RefundStatusEnum;
- use common\models\order\OrderRefund;
- use common\models\user\User;
- use Yii;
- use common\enums\StatusEnum;
- class IndexController extends BaseController
- {
- /**
- * 门店首页(概况)
- * @Author bing
- * @DateTime 2022-04-26 18:06:27
- * @return void
- * @copyright: Copyright (c) 2022 广东七件事集团
- */
- public function actionIndex()
- {
- if (Yii::$app->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'));
- }
- }
|