dong025 6 дней назад
Родитель
Сommit
4a1b1b3bce
2 измененных файлов с 121 добавлено и 6 удалено
  1. 116 6
      app/api/controller/Worker.php
  2. 5 0
      app/api/route/route.php

+ 116 - 6
app/api/controller/Worker.php

@@ -13,7 +13,10 @@ use app\api\validate\Worker as WorkerValidate;
 use think\facade\Cache;
 use think\facade\Db;
 use think\Response;
+use app\common\model\GroupUser as GroupUserModel;
+use app\api\controller\GroupUser as GroupUserController;
 use app\common\model\ShopDelivery as ShopDeliveryModel;
+use app\common\model\WorkerOut as WorkerOutModel;
 
 /**
  * 打包工人相关接口
@@ -21,6 +24,16 @@ use app\common\model\ShopDelivery as ShopDeliveryModel;
 class Worker extends Base
 {
     protected $shopDeliveryModel = null;
+    protected $groupUserController = null;
+    protected $quantity_sum = 0;
+    protected $labor_cost_money_sum = 0;
+    protected $quantity_avg = 0;
+    protected $labor_cost_money_avg = 0;
+    protected $worker_num = 0;
+    protected $worker_list = [];
+    protected $time =null;
+
+    
 
     /**
      * 判断权限
@@ -30,6 +43,7 @@ class Worker extends Base
     {
         parent::_initialize();
         $this->shopDeliveryModel = new ShopDeliveryModel();
+        $this->groupUserController = new GroupUserController();
         if (!str_contains($this->userinfo['role'], "1")) {
             $this->error(__('没有权限' . $this->userinfo['role']));
         }
@@ -132,13 +146,14 @@ class Worker extends Base
             $where[] = ['sl.createtime', '<=', strtotime($arr[1])];
         }
 
-        $list = $scanLog
+        $list = $scanLog->alias('sl')
             ->where('user_id', $this->userinfo['id'])
+            ->where('order_status', 1)
             ->where($where)
             ->order('createtime desc')
             ->paginate($limit)
             ->each(function ($item, $key) {
-                $order_data=$this->shopDeliveryModel->where('waybill_no', $item['code'])->find();
+                $order_data = $this->shopDeliveryModel->where('waybill_no', $item['code'])->find();
                 $item['order_data'] = [];
                 if (!empty($order_data['waybill_no'])) {
                     $incubator_title = '不是保温箱';
@@ -150,13 +165,108 @@ class Worker extends Base
                             $incubator_title = '双层保温';
                             break;
                     }
-                    $item['order_data']=$order_data;
-                    $item['order_data']['incubator_title']=$incubator_title;
-                    
-                
+                    $item['order_data'] = $order_data;
+                    $item['order_data']['incubator_title'] = $incubator_title;
                 }
                 return $item;
             });
         $this->success('ok', $list);
     }
+
+    //数据统计,今日昨日,本周
+    public function pack_data_statistics(ScanLog $scanLog, GroupUserModel $groupUserModel)
+    {
+        $where = [];
+        $group_where = [];
+        $todayTime = date("Y-m-d");
+        $startTime = strtotime($todayTime . ' 00:00:00');
+        $startTime = date('Y-m-d H:i:s', $startTime);
+        $endTime = strtotime($todayTime . ' 23:59:59');
+        $endTime = date('Y-m-d H:i:s', $endTime);
+        $time=$startTime.','.$endTime;
+
+        $time = $this->request->post('create_time/s',$time); //日期
+        $this->time=$time;
+        if (!empty($time)) {
+            $arr = explode(',', $time);
+            $where[] = ['sl.createtime', '>=', strtotime($arr[0])];
+            $where[] = ['sl.createtime', '<=', strtotime($arr[1])];
+        }
+
+        $pid = $this->userinfo['id'];
+        $where[] = ['sl.user_id', '=', $pid];
+
+        $sql = $scanLog->alias('sl')
+            ->join("shop_delivery sd", "sl.code = sd.waybill_no", "INNER")
+            ->where('order_status', 1)
+            ->where($where);
+        // 总件数
+        $this->quantity_sum = $sql->sum('num');
+        // 总工价
+        $this->labor_cost_money_sum = $scanLog->alias('sl')
+            ->join("shop_delivery sd", "sl.code = sd.waybill_no", "INNER")
+            ->where('sl.order_status', 1)
+            ->where($where)
+            ->value("SUM(COALESCE(sd.num,0) * COALESCE(sd.labor_cost_money,0)) as total_labor_cost");
+        
+        
+
+        
+
+        
+        $list = $groupUserModel
+            ->where('pid', '=', $pid)
+            ->field('id,pid,nickname')
+            ->select()->each(function ($item, $key) {
+                $state = $this->get_worker_out_state($item['id'], $this->userinfo['id'],$this->time);
+                $state = $state == 0 ? false : true;
+                
+                // $item['selected']=$state;
+                if ($state) {
+                    $this->worker_num++;
+                    $this->worker_list[]=$item;
+                }
+                
+            });
+        // 工价平均值
+        $quantity_sum = strval($this->labor_cost_money_sum);
+        $num = strval($this->worker_num);
+        $labor_cost_money_avg = bcdiv($quantity_sum, $num, 2); 
+
+        // 件数平均值
+        $quantity_avg = strval($this->quantity_sum);
+        $this->worker_num = strval($this->worker_num);
+        $quantity_avg = bcdiv($quantity_avg, $this->worker_num, 2);
+
+        $data = [
+            'quantity_sum' => $this->quantity_sum,
+            'labor_cost_money_sum' => $this->labor_cost_money_sum,
+            'quantity_avg' => $quantity_avg,
+            'labor_cost_money_avg' => $labor_cost_money_avg,
+            'worker_list' => empty($this->worker_list) ? [] : $this->worker_list
+            
+
+        ];
+        $this->success('ok', $data);
+    }
+    //获取今天出工人员状态,0=未出个,1=出工
+    public function get_worker_out_state($id, $pid,$time)
+    {
+        $groupUserModel = new GroupUserModel();
+        $count = $groupUserModel->where('id', $id)->where('pid', $pid)->count();
+        if ($count == 0) return 1;
+
+        $workerOutModel = new WorkerOutModel();
+        $todayTime = strtotime('today');
+        $where = [];
+        $where[] = ['user_id', '=', $id];
+        $where[] = ['pid', '=', $pid];
+        $where[] = ['state', '=', 1];
+        if (!empty($time)) {
+            $arr = explode(',', $time);
+            $where[] = ['createtime', '>=', strtotime($arr[0])];
+            $where[] = ['createtime', '<=', strtotime($arr[1])];
+        }
+        return $workerOutModel->where($where)->count();
+    }
 }

+ 5 - 0
app/api/route/route.php

@@ -77,6 +77,8 @@ Route::group('user', function () {
     Route::rule('set_worker_out','GroupUser/set_worker_out','POST');
     //清除今日出工人员
     Route::rule('clear_worker_out','GroupUser/clear_worker_out','POST');
+    //打包汇总
+    Route::rule('worker_pack_sum','GroupUser/worker_pack_sum','POST');
     
     
   })->middleware(AllowCrossDomain::class);
@@ -87,6 +89,9 @@ Route::group('worker', function () {
     //扫码
     Route::rule('scan','worker/scan','POST');
     Route::rule('scanlog','worker/scanlog','POST');
+    //数据统计,今日昨日,本周
+    Route::rule('pack_data_statistics','worker/pack_data_statistics','POST');
+    
 })->middleware(AllowCrossDomain::class);
 Route::rule('ceshi','index/getArr','GET|POST');