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

订单量趋势 优化查询按钮

ANG YU 5 лет назад
Родитель
Сommit
3e0282f32e

+ 4 - 2
app/Http/Controllers/ControlPanelController.php

@@ -24,7 +24,7 @@ class ControlPanelController extends Controller
         $warehousesOrders = $realtimePendingOrdersService->warehousesOrders();
         $orderCountingRecordService = app(OrderCountingRecordService::class);
         //默认查询一个月的数据
-        $start = (new Carbon())->subMonth()->toDateString();
+        $start = (new Carbon())->subMonth()->addDay()->toDateString();
         $end = (new Carbon())->toDateString();
         $orderCountingRecords = $orderCountingRecordService->orderCountingRecords($start, $end);
         $logisticsCountingRecords = $orderCountingRecordService->logisticsCountingRecords($start, $end);
@@ -38,7 +38,9 @@ class ControlPanelController extends Controller
         $start = $request->start;
         $end = $request->end;
         $unit = $request->unit;
-        $orderCountingRecords = $orderCountingRecordService->orderCountingRecords($start, $end, $unit);
+//        var_dump($start,$end,$unit);
+        $orderCountingRecords = $orderCountingRecordService->orderCountingRecords($start, $end, null, $unit, null);
+//        var_dump($orderCountingRecords);
         return compact('orderCountingRecords');
     }
 

+ 5 - 1
app/Services/OrderCountingRecordService.php

@@ -188,7 +188,11 @@ class OrderCountingRecordService
         $resultOrders->groupBy(['date_target', 'owner_id'])->each(function ($item, $dateStr) use ($unit) {
             $item->each(function ($item, $owner_id) use ($dateStr, $unit) {
                 $key = "order_counting_records_{$dateStr}_{$owner_id}_{$unit}";
-                Cache::put($key, $item, 600);
+                $ttl = 3600 * 24;
+                if ($dateStr==Carbon::now()->toDateString()) {
+                    $ttl = 60;
+                }
+                Cache::put($key, $item, $ttl);
             });
         });
         $map = [];

+ 13 - 18
resources/views/control/panel.blade.php

@@ -53,8 +53,8 @@
                 <div class="card">
                     <div class="card-header">
                         <div class="col-5 row">
-                            <span class="demonstration"></span>
-                            <el-date-picker
+                            <span class="demonstration" ></span>
+                            <el-date-picker @blur="orderCountingRecordApi('')"
                                 v-model="orderCountingRecordsDate"
                                 type="daterange"
                                 align="right"
@@ -66,10 +66,9 @@
                                 :picker-options="pickerOptions">
                             </el-date-picker>
                             <div class="row">
-                                <el-button type="primary" value="日" @click="unit= '日'" v-model="unit">日</el-button>
-                                <el-button type="primary" value="周" @click="unit= '周'" v-model="unit">周</el-button>
-                                <el-button type="primary" value="月" @click="unit= '月'" v-model="unit">月</el-button>
-                                <el-button type="primary" icon="el-icon-search" @click="orderCountingRecordApi()">搜索
+                                <el-button type="primary" value="日" @click="orderCountingRecordApi('日')" v-model="unit">日</el-button>
+                                <el-button type="primary" value="周" @click="orderCountingRecordApi('周')" v-model="unit">周</el-button>
+                                <el-button type="primary" value="月" @click="orderCountingRecordApi('月')" v-model="unit">月</el-button>
                                 </el-button>
                             </div>
                         </div>
@@ -87,7 +86,7 @@
                                 <div class="col-5 row">
                                     <div class="block">
                                         <span class="demonstration"></span>
-                                        <el-date-picker
+                                        <el-date-picker @blur="logisticsCountingRecordsApi()"
                                             v-model="logisticsCountingRecordsData"
                                             type="daterange"
                                             align="right"
@@ -98,9 +97,6 @@
                                             value-format="yyyy-MM-dd"
                                             :picker-options="pickerOptions">
                                         </el-date-picker>
-                                        <el-button type="primary" icon="el-icon-search"
-                                                   @click="logisticsCountingRecordsApi()">搜索
-                                        </el-button>
                                     </div>
                                 </div>
                             </div>
@@ -116,7 +112,7 @@
                                 <div class="col-5 row">
                                     <div class="block">
                                         <span class="demonstration"></span>
-                                        <el-date-picker
+                                        <el-date-picker @blur="warehouseCountingRecordsApi()"
                                             v-model="warehouseCountingRecordsData"
                                             type="daterange"
                                             align="right"
@@ -127,9 +123,6 @@
                                             value-format="yyyy-MM-dd"
                                             :picker-options="pickerOptions">
                                         </el-date-picker>
-                                        <el-button type="primary" icon="el-icon-search"
-                                                   @click="warehouseCountingRecordsApi()">搜索
-                                        </el-button>
                                     </div>
                                 </div>
                             </div>
@@ -316,12 +309,13 @@
                         ]
                     });
                 },
-                orderCountingRecordApi() {
+                orderCountingRecordApi(unit) {
+                    this.unit = unit;
                     let formData = new FormData();
                     formData.append('start', this.orderCountingRecordsDate[0]);
                     formData.append('end', this.orderCountingRecordsDate[1]);
-                    formData.append('unit', this.unit);
-                    console.log(this.unit);
+                    formData.append('unit', unit);
+                    console.log(formData.get('unit'));
                     let _this = this;
                     axios.post('{{url('apiLocal/control/panel/menu/orderCountingRecordApi')}}', formData).then(function (res) {
                         if (res.status === 200) {
@@ -357,7 +351,8 @@
                             _this.initWarehouseCountingRecordsChart();
                         }
                     });
-                }
+                },
+
             }
         });
     </script>

+ 2 - 2
tests/Services/OrderCountingRecordService/DateTestTest.php

@@ -13,7 +13,7 @@ class DateTestTest extends TestCase
 {
     public function test01()
     {
-        dd((new Carbon())->subMonth() ->toDateString());
-
+        $dateStr = '2020-11-13';
+        dd($dateStr == Carbon::now()->toDateString());
     }
 }