dong025 5 дней назад
Родитель
Сommit
cf5f01aee5
1 измененных файлов с 52 добавлено и 18 удалено
  1. 52 18
      app/api/controller/Worker.php

+ 52 - 18
app/api/controller/Worker.php

@@ -49,29 +49,63 @@ class Worker extends Base
         }
     }
     //首页
-    public function index(StockConfig $stockConfig)
+    public function index(StockConfig $stockConfig,ScanLog $scanLog)
     {
         $data = [];
         $data['today'] = ScanLog::where('user_id', $this->userinfo['id'])->whereTime('createtime', 'today')->count();
         $data['yesterday'] = ScanLog::where('user_id', $this->userinfo['id'])->whereTime('createtime', 'yesterday')->count();
-        $data['pack_specs'] = [
-            [
-                'pack_name' => '三斤',
-                'pack_count' => '120',
-                'pack_money' => '100'
-            ],
-            [
-                'pack_name' => '五斤',
-                'pack_count' => '120',
-                'pack_money' => '100'
-            ],
-            [
-                'pack_name' => '五斤保温',
-                'pack_count' => '120',
-                'pack_money' => '100'
-            ],
 
-        ];
+        $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];
+
+        
+        $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($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;
+                unset($item['code']);
+            });
+
+        $data['pack_specs']=$list;
+        // $data['pack_specs'] = [
+        //     [
+        //         'pack_name' => '三斤',
+        //         'pack_count' => '120',
+        //         'pack_money' => '100'
+        //     ],
+        //     [
+        //         'pack_name' => '五斤',
+        //         'pack_count' => '120',
+        //         'pack_money' => '100'
+        //     ],
+        //     [
+        //         'pack_name' => '五斤保温',
+        //         'pack_count' => '120',
+        //         'pack_money' => '100'
+        //     ],
+
+        // ];
         $this->success('ok', $data);
     }