Просмотр исходного кода

已退款、出工人数为零报错

dong025 5 дней назад
Родитель
Сommit
85c0b33222
2 измененных файлов с 85 добавлено и 77 удалено
  1. 1 0
      app/api/controller/GroupUser.php
  2. 84 77
      app/api/controller/Worker.php

+ 1 - 0
app/api/controller/GroupUser.php

@@ -277,6 +277,7 @@ class GroupUser extends Base
                 $item['avatar']= $this->startsWithHttp($item['avatar'])?$item['avatar']:request()->domain().'/' . $item['avatar'];
                 return $item;
             });
+            if(empty($this->today_worker_out_num)||$this->today_worker_out_num==null||$this->today_worker_out_num==0) return $this->success('出工人员列表',[]);
             $labor_cost_money_avg=round(bcdiv(strval($labor_cost_money_avg['labor_cost_money_sum']),strval($this->today_worker_out_num),2),2);
             foreach ($list as $item) {
                 if($item['selected']){

+ 84 - 77
app/api/controller/Worker.php

@@ -32,9 +32,9 @@ class Worker extends Base
     protected $labor_cost_money_avg = 0;
     protected $worker_num = 0;
     protected $worker_list = [];
-    protected $time =null;
+    protected $time = null;
+
 
-    
 
     /**
      * 判断权限
@@ -50,7 +50,7 @@ class Worker extends Base
         }
     }
     //首页
-    public function index(StockConfig $stockConfig,ScanLog $scanLog)
+    public function index(StockConfig $stockConfig, ScanLog $scanLog)
     {
         $data = [];
         $data['today'] = ScanLog::where('user_id', $this->userinfo['id'])->whereTime('createtime', 'today')->count();
@@ -61,30 +61,30 @@ class Worker extends Base
         $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 = $startTime . ',' . $endTime;
 
         $arr = explode(',', $time);
-            $where[] = ['sl.createtime', '>=', strtotime($arr[0])];
-            $where[] = ['sl.createtime', '<=', strtotime($arr[1])];
+        $where[] = ['sl.createtime', '>=', strtotime($arr[0])];
+        $where[] = ['sl.createtime', '<=', strtotime($arr[1])];
 
         $pid = $this->userinfo['id'];
         $where[] = ['sl.user_id', '=', $pid];
 
-        
+
         $list = $scanLog->alias('sl')
             ->join("shop_delivery sd", "sl.code = sd.waybill_no", "INNER")
             ->where('sl.order_status', 1)
-            ->where('sl.spec_id','<>', null)
+            ->where('sl.spec_id', '<>', null)
             ->where($where)
             ->field("sl.code,sl.spec_id,SUM(COALESCE(sd.num,0) * 1) as pack_count,SUM(COALESCE(sd.num,0) * COALESCE(sd.labor_cost_money,0)) as pack_money")
             ->group('sl.spec_id')
             ->select()->each(function ($item, $key) {
                 $spec_name = $this->get_order_info($item['code']);
-                $item['pack_name']=$spec_name;
+                $item['pack_name'] = $spec_name;
                 unset($item['code']);
             });
 
-        $data['pack_specs']=$list;
+        $data['pack_specs'] = $list;
         // $data['pack_specs'] = [
         //     [
         //         'pack_name' => '三斤',
@@ -128,46 +128,53 @@ class Worker extends Base
             ];
             $sql_data = $this->shopDeliveryModel->where('waybill_no', $data['code'])->find();
             if (!empty($sql_data)) {
-                if (!empty($sql_data['user_id']) && $sql_data['user_id'] != 0) {
-                    $insert_data['order_status'] = 2;
-                    $insert_data['remark'] = '请勿重复录入';
-                } else {
-                    $result = $sql_data->save([
-                        'user_id'    =>   $this->userinfo['id'],
-                        'entry_time'    =>    $time,
-                        'updatetime' =>    $time
-                    ]);
-                    if ($result) {
-                        $insert_data['order_status'] = 1;
-                        $insert_data['remark'] = '录入成功';
-                        $insert_data['spec_id'] = $sql_data['spec_id'];
-                    } else {
-                        $insert_data['remark'] = '录入失败';
-                    }
-                }
-
-
-
-                $entry_time = $sql_data['entry_time'];
-                if (!empty($sql_data['entry_time'])) {
-                    $entry_time = date('Y-m-d H:i:s', $sql_data['entry_time']);
-                }
-                switch ($sql_data['incubator']) {
-                    case 1:
-                        $sql_data['incubator_title'] = '单层保温';
-                        break;
-                    case 2:
-                        $sql_data['incubator_title'] = '双层保温';
+                switch ($sql_data['order_status']) {
+                    case 'TRADE_CLOSED':
+                        $insert_data['order_status']=3;
+                        $insert_data['remark'] = '已退款';
                         break;
+
                     default:
-                        $sql_data['incubator_title'] = '不是保温箱';
+                        if (!empty($sql_data['user_id']) && $sql_data['user_id'] != 0) {
+                            $insert_data['order_status'] = 2;
+                            $insert_data['remark'] = '请勿重复录入';
+                        } else {
+                            $result = $sql_data->save([
+                                'user_id'    =>   $this->userinfo['id'],
+                                'entry_time'    =>    $time,
+                                'updatetime' =>    $time
+                            ]);
+                            if ($result) {
+                                $insert_data['order_status'] = 1;
+                                $insert_data['remark'] = '录入成功';
+                                $insert_data['spec_id'] = $sql_data['spec_id'];
+                            } else {
+                                $insert_data['remark'] = '录入失败';
+                            }
+                        }
+
+                        $entry_time = $sql_data['entry_time'];
+                        if (!empty($sql_data['entry_time'])) {
+                            $entry_time = date('Y-m-d H:i:s', $sql_data['entry_time']);
+                        }
+                        switch ($sql_data['incubator']) {
+                            case 1:
+                                $sql_data['incubator_title'] = '单层保温';
+                                break;
+                            case 2:
+                                $sql_data['incubator_title'] = '双层保温';
+                                break;
+                            default:
+                                $sql_data['incubator_title'] = '不是保温箱';
+                                break;
+                        }
+                        $sql_data['entry_time'] = $entry_time;
+                        $insert_data['order_data'] = $sql_data;
                         break;
                 }
-                $sql_data['entry_time'] = $entry_time;
-                $insert_data['order_data'] = $sql_data;
             }
             $result = $scanLog->save($insert_data);
-            
+
 
             Db::commit();
         } catch (ValidateException $e) {
@@ -199,7 +206,7 @@ class Worker extends Base
 
         $list = $scanLog->alias('sl')
             ->where('user_id', $this->userinfo['id'])
-            ->whereIn('order_status', [0,1,2])
+            ->whereIn('order_status', [0, 1, 2])
             ->where($where)
             ->order('createtime desc')
             ->paginate($limit)
@@ -234,10 +241,10 @@ class Worker extends Base
         $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 = $startTime . ',' . $endTime;
 
-        $time = $this->request->post('create_time/s',$time); //日期
-        $this->time=$time;
+        $time = $this->request->post('create_time/s', $time); //日期
+        $this->time = $time;
         if (!empty($time)) {
             $arr = explode(',', $time);
             $where[] = ['sl.createtime', '>=', strtotime($arr[0])];
@@ -247,58 +254,59 @@ class Worker extends Base
         $pid = $this->userinfo['id'];
         $where[] = ['sl.user_id', '=', $pid];
 
-        
+
         $list = $scanLog->alias('sl')
             ->join("shop_delivery sd", "sl.code = sd.waybill_no", "INNER")
             ->where('sl.order_status', 1)
-            ->where('sl.spec_id','<>', null)
+            ->where('sl.spec_id', '<>', null)
             ->where($where)
             ->field("sl.code,sl.spec_id,SUM(COALESCE(sd.num,0) * 1) as spec_quantity_sum,SUM(COALESCE(sd.num,0) * COALESCE(sd.labor_cost_money,0)) as spec_labor_cost_money_sum")
             ->group('sl.spec_id')
             ->paginate($limit)->each(function ($item, $key) {
                 $spec_name = $this->get_order_info($item['code']);
-                $item['spec_name']=$spec_name;
+                $item['spec_name'] = $spec_name;
                 unset($item['code']);
             });
         $list_sum = $scanLog->alias('sl')
             ->join("shop_delivery sd", "sl.code = sd.waybill_no", "INNER")
             ->where('sl.order_status', 1)
-            ->where('sl.spec_id','<>', null)
+            ->where('sl.spec_id', '<>', null)
             ->where($where)
             ->field("sl.code,sl.spec_id,SUM(COALESCE(sd.num,0) * 1) as spec_quantity_sum,SUM(COALESCE(sd.num,0) * COALESCE(sd.labor_cost_money,0)) as spec_labor_cost_money_sum")
             ->group('sl.spec_id')
             ->select();
-        $quantity_sum=0;
-        $labor_cost_money_sum=0;
+        $quantity_sum = 0;
+        $labor_cost_money_sum = 0;
         foreach ($list_sum as $item) {
-            $spec_quantity_sum=$item['spec_quantity_sum'];
-            $spec_labor_cost_money_sum=$item['spec_labor_cost_money_sum'];
-            $quantity_sum=bcadd(strval($quantity_sum), strval($spec_quantity_sum),0);
-            $labor_cost_money_sum=bcadd(strval($labor_cost_money_sum), strval($spec_labor_cost_money_sum),4);
+            $spec_quantity_sum = $item['spec_quantity_sum'];
+            $spec_labor_cost_money_sum = $item['spec_labor_cost_money_sum'];
+            $quantity_sum = bcadd(strval($quantity_sum), strval($spec_quantity_sum), 0);
+            $labor_cost_money_sum = bcadd(strval($labor_cost_money_sum), strval($spec_labor_cost_money_sum), 4);
             $labor_cost_money_sum = round((float)$labor_cost_money_sum, 2);
         }
 
         $data = [
             'quantity_sum' => $quantity_sum,
             'labor_cost_money_sum' => $labor_cost_money_sum,
-            'list' => empty($list) ? [] :$list
-            
+            'list' => empty($list) ? [] : $list
+
 
         ];
         $this->success('ok', $data);
     }
     //获取数量、总价
-    public function quantity_labor_cost_money(ScanLog $scanLog){
-         $where = [];
+    public function quantity_labor_cost_money(ScanLog $scanLog)
+    {
+        $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 = $startTime . ',' . $endTime;
 
-        $time = $this->request->post('create_time/s',$time); //日期
-        $this->time=$time;
+        $time = $this->request->post('create_time/s', $time); //日期
+        $this->time = $time;
         if (!empty($time)) {
             $arr = explode(',', $time);
             $where[] = ['sl.createtime', '>=', strtotime($arr[0])];
@@ -311,18 +319,18 @@ class Worker extends Base
         $list_sum = $scanLog->alias('sl')
             ->join("shop_delivery sd", "sl.code = sd.waybill_no", "INNER")
             ->where('sl.order_status', 1)
-            ->where('sl.spec_id','<>', null)
+            ->where('sl.spec_id', '<>', null)
             ->where($where)
             ->field("sl.code,sl.spec_id,SUM(COALESCE(sd.num,0) * 1) as spec_quantity_sum,SUM(COALESCE(sd.num,0) * COALESCE(sd.labor_cost_money,0)) as spec_labor_cost_money_sum")
             ->group('sl.spec_id')
             ->select();
-        $quantity_sum=0;
-        $labor_cost_money_sum=0;
+        $quantity_sum = 0;
+        $labor_cost_money_sum = 0;
         foreach ($list_sum as $item) {
-            $spec_quantity_sum=$item['spec_quantity_sum'];
-            $spec_labor_cost_money_sum=$item['spec_labor_cost_money_sum'];
-            $quantity_sum=bcadd(strval($quantity_sum), strval($spec_quantity_sum),0);
-            $labor_cost_money_sum=bcadd(strval($labor_cost_money_sum), strval($spec_labor_cost_money_sum),4);
+            $spec_quantity_sum = $item['spec_quantity_sum'];
+            $spec_labor_cost_money_sum = $item['spec_labor_cost_money_sum'];
+            $quantity_sum = bcadd(strval($quantity_sum), strval($spec_quantity_sum), 0);
+            $labor_cost_money_sum = bcadd(strval($labor_cost_money_sum), strval($spec_labor_cost_money_sum), 4);
             $labor_cost_money_sum = round((float)$labor_cost_money_sum, 2);
         }
 
@@ -333,7 +341,7 @@ class Worker extends Base
         return $data;
     }
     //获取今天出工人员状态,0=未出个,1=出工
-    public function get_worker_out_state($id, $pid,$time)
+    public function get_worker_out_state($id, $pid, $time)
     {
         $groupUserModel = new GroupUserModel();
         $count = $groupUserModel->where('id', $id)->where('pid', $pid)->count();
@@ -352,9 +360,8 @@ class Worker extends Base
         }
         return $workerOutModel->where($where)->count();
     }
-    public function get_order_info($waybill_no){
-        return $this->shopDeliveryModel->where('waybill_no',$waybill_no)->value('spec_name');
-        
+    public function get_order_info($waybill_no)
+    {
+        return $this->shopDeliveryModel->where('waybill_no', $waybill_no)->value('spec_name');
     }
-    
 }