Explorar o código

前端调试完成 缺少年数据

ANG YU %!s(int64=5) %!d(string=hai) anos
pai
achega
b33e7931cc

+ 19 - 8
app/Http/Controllers/ControlPanelController.php

@@ -38,10 +38,9 @@ class ControlPanelController extends Controller
         $warehousesOrders = $realtimePendingOrdersService->warehousesOrders();
         $orderCountingRecordService = app(NewOrderCountingRecordService::class);
         //默认查询一个月的数据
-        $start = (new Carbon())->subMonth()->addDay()->toDateString();
+        $start = (new Carbon())->subMonth()->toDateString();
         $end = (new Carbon())->toDateString();
         $ownerIds = $this->getCountingOwnerIds(null);
-
         $unit = '日';
         $orderCountingRecords = $orderCountingRecordService->orderCountingRecords($start, $end, $unit, $ownerIds);
         $logisticsCountingRecords = $orderCountingRecordService->logisticsCountingRecords($start, $end, $ownerIds);
@@ -55,28 +54,40 @@ class ControlPanelController extends Controller
 
     public function orderCountingRecordsApi(Request $request)
     {
-        $orderCountingRecordService = app(OrderCountingRecordService::class);
+        /**
+         * @var $orderCountingRecordService  NewOrderCountingRecordService
+         */
+        $orderCountingRecordService = app(NewOrderCountingRecordService::class);
         $start = Carbon::parse($request->start)->gt(Carbon::now()) ? Carbon::now()->toDateString() : $request->start;
         $end = Carbon::parse($request->end)->gt(Carbon::now()) ? Carbon::now()->toDateString() : $request->end;
-        $orderCountingRecords = $orderCountingRecordService->orderCountingRecords($start, $end, null, $request->unit, null);
+        $ownerIds = $this->getCountingOwnerIds(null);
+        $orderCountingRecords = $orderCountingRecordService->orderCountingRecords($start, $end, $request->unit, $ownerIds);
         return compact('orderCountingRecords');
     }
 
     public function logisticsCountingRecordsApi(Request $request)
     {
-        $orderCountingRecordService = app(OrderCountingRecordService::class);
+        /**
+         * @var $orderCountingRecordService  NewOrderCountingRecordService
+         */
+        $orderCountingRecordService = app(NewOrderCountingRecordService::class);
         $start = Carbon::parse($request->start)->gt(Carbon::now()) ? Carbon::now()->toDateString() : $request->start;
         $end = Carbon::parse($request->end)->gt(Carbon::now()) ? Carbon::now()->toDateString() : $request->end;
-        $logisticsCountingRecords = $orderCountingRecordService->logisticsCountingRecords($start, $end);
+        $ownerIds = $this->getCountingOwnerIds(null);
+        $logisticsCountingRecords = $orderCountingRecordService->logisticsCountingRecords($start, $end, $ownerIds);
         return compact('logisticsCountingRecords');
     }
 
     public function warehouseCountingRecordsApi(Request $request)
     {
-        $orderCountingRecordService = app(OrderCountingRecordService::class);
+        /**
+         * @var $orderCountingRecordService  NewOrderCountingRecordService
+         */
+        $orderCountingRecordService = app(NewOrderCountingRecordService::class);
         $start = Carbon::parse($request->start)->gt(Carbon::now()) ? Carbon::now()->toDateString() : $request->start;
         $end = Carbon::parse($request->end)->gt(Carbon::now()) ? Carbon::now()->toDateString() : $request->end;
-        $warehouseCountingRecords = $orderCountingRecordService->warehouseCountingRecords($start, $end);
+        $ownerIds = $this->getCountingOwnerIds(null);
+        $warehouseCountingRecords = $orderCountingRecordService->warehouseCountingRecords($start, $end, $ownerIds);
         return compact('warehouseCountingRecords');
     }
 

+ 26 - 19
app/Services/NewOrderCountingRecordService.php

@@ -15,22 +15,19 @@ class NewOrderCountingRecordService
 {
     public function orderCountingRecords($start, $end, $unit, $ownerIds)
     {
-        $key = 'orderCountingRecords_' . $start . '_' . $end . '_' . $unit . '_' . json_encode($ownerIds);
-        return Cache::remember($key, 60, function () use ($start, $end, $unit, $ownerIds) {
-            $orders = $this->get($start, $end, $unit, $ownerIds);
-            $dataList = collect();
-            $orders->groupBy('date_target')->each(function ($items) use (&$dataList, $unit) {
-                $counter = $items->reduce(function ($sum, $item) {
-                    return $sum + $item->amount;
-                }, 0);
-                $date_target = $items[0]->date_target;
-                $dataList->push([
-                    'counter' => $counter,
-                    'date_target' => $date_target,
-                ]);
-            });
-            return $dataList->sortBy("date_target");
+        $orders = $this->get($start, $end, $unit, $ownerIds);
+        $dataList = collect();
+        $orders->groupBy('date_target')->each(function ($items) use (&$dataList, $unit) {
+            $counter = $items->reduce(function ($sum, $item) {
+                return $sum + $item->amount;
+            }, 0);
+            $date_target = $items[0]->date_target;
+            $dataList->push([
+                'counter' => $counter,
+                'date_target' => $date_target,
+            ]);
         });
+        return $dataList->sortBy("date_target");
     }
 
     public function logisticsCountingRecords($start, $end, $ownerIds)
@@ -172,10 +169,20 @@ class NewOrderCountingRecordService
         if (!empty($lackingCondition)) {
             $orderCountingRecords_FromOrder = $this->dataFromOrder($lackingCondition);
         }
-        return $orderCountingRecords_FromOrder ?? collect()
-                ->concat($orderCountingRecords_fromCache)
-                ->concat($orderCountingRecords_fromSelfTable)
-                ->concat($orderCountingRecords_combinedByLower ?? collect());
+        $result = collect();
+        if (isset($orderCountingRecords_FromOrder)  && !$orderCountingRecords_FromOrder->isEmpty()) {
+            $result =  $result->concat($orderCountingRecords_FromOrder);
+        }
+        if (!$orderCountingRecords_fromCache->isEmpty()) {
+            $result =  $result->concat($orderCountingRecords_fromCache);
+        }
+        if (!$orderCountingRecords_fromSelfTable->isEmpty()) {
+            $result = $result->concat($orderCountingRecords_fromSelfTable);
+        }
+        if (count($orderCountingRecords_combinedByLower) != 0) {
+            $result = $result->concat($orderCountingRecords_combinedByLower);
+        }
+        return $result;
     }
 
 

+ 1 - 1
package-lock.json

@@ -6254,7 +6254,7 @@
         },
         "minimist": {
             "version": "1.2.0",
-            "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
+            "resolved": "https://registry.npm.taobao.org/minimist/download/minimist-1.2.0.tgz",
             "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
             "dev": true
         },

+ 4 - 11
resources/views/control/panel.blade.php

@@ -71,9 +71,6 @@
                             <el-button type="primary" value="日" @click="orderCountingRecordApi('日')"
                                        v-model="orderCountingRecordsUnit">日
                             </el-button>
-                            <el-button type="primary" value="周" @click="orderCountingRecordApi('周')"
-                                       v-model="orderCountingRecordsUnit">周
-                            </el-button>
                             <el-button type="primary" value="月" @click="orderCountingRecordApi('月')"
                                        v-model="orderCountingRecordsUnit">月
                             </el-button>
@@ -168,9 +165,6 @@
                                 <el-button type="primary" value="日" @click="laborReportsCountingRecordApi('日')"
                                            v-model="laborReportsCountingRecordUnit">日
                                 </el-button>
-                                <el-button type="primary" value="周" @click="laborReportsCountingRecordApi('周')"
-                                           v-model="laborReportsCountingRecordUnit">周
-                                </el-button>
                                 <el-button type="primary" value="月" @click="laborReportsCountingRecordApi('月')"
                                            v-model="laborReportsCountingRecordUnit">月
                                 </el-button>
@@ -330,11 +324,10 @@
                     return this.warehouses[code];
                 },
                 initOrderCountingRecords() {
-                    let _this = this;
-                    this.orderCountingRecords.forEach(function (item) {
-                        _this.orderCountingRecordsDateTarget.push(item.date_target);
-                        _this.orderCountingRecordsData.push(item.counter);
-                    });
+                    for (let key in this.orderCountingRecords) {
+                        this.orderCountingRecordsDateTarget.push(this.orderCountingRecords[key].date_target);
+                        this.orderCountingRecordsData.push(this.orderCountingRecords[key].counter);
+                    }
                 },
                 initOrderCountingRecordsChart() {
                     this.orderCountingRecordsChart.setOption({