| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <?php
- namespace addons\Happiness\client\controllers;
- use addons\Happiness\common\models\HappinessGoodsRanking;
- use addons\Happiness\common\models\HappinessOrder;
- use addons\Happiness\common\models\HappinessStore;
- use addons\Happiness\common\models\HappinessStoreCensus;
- use addons\Happiness\common\models\HappinessStoreGoods;
- use addons\Happiness\common\models\HappinessStoreUser;
- use common\enums\OrderStatusEnum;
- use common\models\goods\Goods;
- use common\models\order\Order;
- use common\models\order\OrderRefund;
- use common\models\user\User;
- use Yii;
- 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 = HappinessGoodsRanking::lists([
- 'where' => [
- ['store_id' => $this->store_id],
- ['mall_id' => $this->mall_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 = HappinessStoreGoods::lists([
- 'alias' => 'yg',
- 'where' => [['yg.goods_id' => $goods_ids], ['yg.mall_id' => $this->mall_id]],
- 'index' => 'goods_id',
- 'join' => [['LEFT JOIN', Goods::tableName(). ' as g', "g.id = yg.goods_id"]],
- 'select' => 'yg.id,g.goods_name,g.cover_pic,yg.goods_id'
- ]);
- 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 = HappinessStoreUser::lists([
- 'where' => [
- ['store_id' => $this->store_id],
- ['mall_id' => $this->mall_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 = HappinessStoreCensus::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,
- ];
- switch ($val['date_time']) {
- case $today:
- $today_data = $val;
- break;
- case $yesterday:
- $yesterday_data = $val;
- break;
- }
- }
- }
- $store = HappinessStore::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 = HappinessOrder::listCount([
- 'alias' => 'yo',
- 'where' => [
- ['yo.store_id' => $this->store_id],
- ['o.order_status' => 0],
- ],
- 'join' => [['LEFT JOIN', Order::tableName(). ' as o', "o.id = yo.order_id"]],
- ]);
- // $no_pay_counts = HappinessOrder::find()->where([, ])->count();//待付款
- $no_delivery_counts = HappinessOrder::listCount([
- 'alias' => 'yo',
- 'where' => [
- ['yo.store_id' => $this->store_id],
- ['o.order_status' => 1],
- ],
- 'join' => [['LEFT JOIN', Order::tableName(). ' as o', "o.id = yo.order_id"]],
- ]);
- //待自提订单
- $no_take_counts = HappinessOrder::listCount([
- 'alias' => 'yo',
- 'where' => [
- ['yo.store_id' => $this->store_id],
- ['o.order_status' => OrderStatusEnum::TAKE],
- ],
- 'join' => [['LEFT JOIN', Order::tableName(). ' as o', "o.id = yo.order_id"]],
- ]);
- // $no_delivery_counts = HappinessOrder::find()->where(['store_id' => $this->store_id, 'order_status' => 1])->count();//待发货
- $after_sale_counts = OrderRefund::find()->where(['store_id' => $this->store_id, 'order_source' => 'happiness'])->andWhere(['!=','refund_status',1])->count();//售后
- $sell_out_counts = HappinessStoreGoods::find()->where(['store_id' => $this->store_id, 'stock' => 0])->count();//售罄
- $store['no_pay_counts'] = $no_pay_counts ?? 0;
- $store['no_delivery_counts'] = $no_delivery_counts ?? 0;
- $store['no_take_counts'] = $no_take_counts ?? 0;
- $store['after_sale_counts'] = $after_sale_counts ?? 0;
- $store['sell_out_counts'] = $sell_out_counts ?? 0;
- 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 = HappinessStoreCensus::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'));
- }
- }
|