Browse Source

门店统计 库存查看

moonsflyer 8 months ago
parent
commit
a2297e2647
2 changed files with 23 additions and 3 deletions
  1. 20 2
      addon/store/shop/controller/Stat.php
  2. 3 1
      app/model/store/Stat.php

+ 20 - 2
addon/store/shop/controller/Stat.php

@@ -15,7 +15,9 @@ namespace addon\store\shop\controller;
 use app\model\store\Stat as StatModel;
 use app\model\store\Store as StoreModel;
 use app\shop\controller\BaseShop;
+use app\model\system\UserGroup;
 use Carbon\Carbon;
+use think\validate\ValidateRule;
 
 
 class Stat extends BaseShop
@@ -25,7 +27,16 @@ class Stat extends BaseShop
      */
     public function store()
     {
-        $store_list = ( new StoreModel() )->getStoreList([ [ 'site_id', '=', $this->site_id ] ], 'store_id,store_name');
+        $user_info = $this->user_info;
+        $user_id = $user_info['uid'];
+        $uwhere['uid'] = $user_id;
+        $UgObj = new UserGroup();
+
+        $user_store_list =$UgObj->getUserList($uwhere,'uid,store_id');
+
+        $store_id_arr = array_column($user_store_list['data'],'store_id');
+
+        $store_list = ( new StoreModel() )->getStoreList([ [ 'site_id', '=', $this->site_id ],['store_id','in',$store_id_arr] ], 'store_id,store_name');
         $this->assign('store_list', $store_list[ 'data' ]);
         $this->assign('today', Carbon::today()->toDateString());
         $this->assign('yesterday', Carbon::yesterday()->toDateString());
@@ -46,10 +57,17 @@ class Stat extends BaseShop
                 $start_time = input('end_time');
                 $end_time = input('start_time');
             }
+            $user_info = $this->user_info;
+            $user_id = $user_info['uid'];
+            $uwhere['uid'] = $user_id;
+            $UgObj = new UserGroup();
+
+            $user_store_list =$UgObj->getUserList($uwhere,'uid,store_id');
 
+            $store_id_arr = array_column($user_store_list['data'],'store_id');
             $stat_model = new StatModel();
 
-            $data = $stat_model->getShopStatSum($this->site_id, $start_time, $end_time, $store_id);
+            $data = $stat_model->getShopStatSum($this->site_id, $start_time, $end_time, $store_id,$store_id_arr);
             return $data;
         }
     }

+ 3 - 1
app/model/store/Stat.php

@@ -202,7 +202,7 @@ class Stat extends BaseModel
      * @param int $store_id
      * @return array
      */
-    public function getShopStatSum($site_id, $start_time, $end_time, $store_id = 0)
+    public function getShopStatSum($site_id, $start_time, $end_time, $store_id = 0,$store_id_arr=[])
     {
         $condition = [
             [ 'site_id', '=', $site_id ],
@@ -211,6 +211,8 @@ class Stat extends BaseModel
         ];
         if (!empty($store_id)) {
             $condition[] = [ 'store_id', '=', $store_id ];
+        }else{
+            $condition[] = [ 'store_id', 'in', $store_id_arr ];
         }
         $field = array_map(function($field) {
             return "ifnull(sum($field), 0) as $field";