Przeglądaj źródła

小组临时工分布

ANG YU 5 lat temu
rodzic
commit
891632108c

+ 11 - 1
app/Http/Controllers/ControlPanelController.php

@@ -34,7 +34,8 @@ class ControlPanelController extends Controller
 
         $laborReportsCountingRecordService = app(LaborReportsCountingRecordService::class);
         $laborReportsCountingRecords = $laborReportsCountingRecordService->get($start, $end, '日');
-        return view('control.panel', compact('menus', 'warehousesOrders', 'orderCountingRecords', 'logisticsCountingRecords', 'warehouseCountingRecords', 'laborReportsCountingRecords'));
+        $laborReportsUserGroupsCount = $laborReportsCountingRecordService->userGroupsCount($start, $end);
+        return view('control.panel', compact('menus', 'warehousesOrders', 'orderCountingRecords', 'logisticsCountingRecords', 'warehouseCountingRecords', 'laborReportsCountingRecords','laborReportsUserGroupsCount'));
     }
 
     public function orderCountingRecordsApi(Request $request)
@@ -74,4 +75,13 @@ class ControlPanelController extends Controller
         $laborReportsCountingRecords = $laborReportsCountingRecordService->get($start, $end, $unit);
         return compact('laborReportsCountingRecords');
     }
+
+    public function laborReportsUserGroupsCountApi(Request $request)
+    {
+        $laborReportsCountingRecordService = app(LaborReportsCountingRecordService::class);
+        $start = $request->start;
+        $end = $request->end;
+        $laborReportsUserGroupsCount = $laborReportsCountingRecordService->userGroupsCount($start, $end);
+        return compact('laborReportsUserGroupsCount');
+    }
 }

+ 31 - 3
app/Services/LaborReportsCountingRecordService.php

@@ -14,6 +14,33 @@ use Ramsey\Uuid\Type\Integer;
 
 class LaborReportsCountingRecordService
 {
+    public function userGroupsCount($start, $end)
+    {
+        $resultByCache = Cache::remember('userGroupsCount_' . $start . '_' . $end, 600, function () use ($start, $end) {
+            return LaborReport::query()->selectRaw('user_workgroup_id,count(user_workgroup_id) amount')
+                ->with('userWorkgroup','laborReportStatus')
+                ->whereDate('created_at', '>=', $start)
+                ->whereDate('created_at', '<', $end)
+                ->groupBy('user_workgroup_id')->get();
+        });
+
+        $resultByCache = $resultByCache->filter(function ($item) {
+            return $item->amount != 0;
+        });
+
+        $result = collect();
+        $resultByCache->each(function ($item) use (&$result) {
+            $result->push(
+                [
+                    'value' => $item->amount,
+                    'name' => $item->userWorkgroup->name,
+                    'id' => $item->userWorkgroup->id,
+                ]
+            );
+        });
+        return $result->sortBy('id');
+    }
+
     public function get($start, $end, $unit = '日')
     {
         $resultByCache = $this->getByCache($start, $end, $unit);
@@ -86,7 +113,8 @@ class LaborReportsCountingRecordService
     {
         switch ($unit) {
             case '日':
-                $query = LaborReport::query()->selectRaw("DATE_FORMAT(created_at,'%Y-%m-%d') as date_target, count(1) as counter");
+                $query = LaborReport::query()
+                    ->selectRaw("DATE_FORMAT(created_at,'%Y-%m-%d') as date_target, count(1) as counter");
                 foreach ($dateList as $startOfWeek) {
                     $query->orWhere(function ($query) use ($startOfWeek) {
                         $query->whereDate('created_at', $startOfWeek);
@@ -113,8 +141,8 @@ class LaborReportsCountingRecordService
                 $dataList = $query->groupBy('date_target')->get();
                 $dataList->each(function ($item) use ($unit) {
                     $date = $item->date_target;
-                    $key = 'laborReportsCountingRecords_' . $date . '_' . $unit;
-                    Cache::put($key, $item);
+                    $item->date_target = Carbon::now()->setISODate(Str::of($date)->explode('-')[0], Str::of($date)->explode('-')[1])->startOfWeek()->toDateString();
+                    Cache::put('laborReportsCountingRecords_' . $date . '_' . $unit, $item);
                 });
                 break;
             case '月':

+ 68 - 1
resources/views/control/panel.blade.php

@@ -153,6 +153,27 @@
                     </div>
                 </div>
             </div>
+            <div class="col-7">
+                <div class="card">
+                    <div class="card-header">
+                        <span class="demonstration" ></span>
+                        <el-date-picker @blur="laborReportsUserGroupsCountApi('')"
+                                        v-model="laborReportsUserGroupsCountDate"
+                                        type="daterange"
+                                        align="right"
+                                        unlink-panels
+                                        range-separator="-"
+                                        start-placeholder="开始日期"
+                                        end-placeholder="结束日期"
+                                        value-format="yyyy-MM-dd"
+                                        :picker-options="pickerOptions">
+                        </el-date-picker>
+                    </div>
+                    <div class="card-body row">
+                        <div id="laborReportsUserGroupsCount" class="col" style="width:600px;height:600px;"></div>
+                    </div>
+                </div>
+            </div>
         </div>
     </div>
 @endsection
@@ -173,6 +194,7 @@
                 logisticsCountingRecords:{!! $logisticsCountingRecords !!},
                 warehouseCountingRecords:{!! $warehouseCountingRecords !!},
                 laborReportsCountingRecords:{!! $laborReportsCountingRecords !!},
+                laborReportsUserGroupsCount:{!! $laborReportsUserGroupsCount !!},
                 warehouses: {},
                 totalOrders: {
                     total: null,
@@ -221,6 +243,8 @@
                     moment(new Date()).format('yyyy-MM-DD')],
                 laborReportsCountingRecordsDate: [moment(new Date(new Date().getTime() - 3600 * 1000 * 24 * 30)).format('yyyy-MM-DD'),
                     moment(new Date()).format('yyyy-MM-DD')],
+                laborReportsUserGroupsCountDate: [moment(new Date(new Date().getTime() - 3600 * 1000 * 24 * 30)).format('yyyy-MM-DD'),
+                    moment(new Date()).format('yyyy-MM-DD')],
                 orderCountingRecordsUnit: '日',
                 laborReportsCountingRecordUnit: '日'
             },
@@ -253,6 +277,9 @@
                 this.laborReportsCountingRecordsChart = echarts.init(document.getElementById('laborReportsCountingRecords'));
                 this.initLaborReportsCountingRecordsChart();
 
+                this.laborReportsUserGroupsCountChart = echarts.init(document.getElementById('laborReportsUserGroupsCount'));
+                this.initLaborReportsUserGroupsCountChart();
+
             },
             methods: {
                 getWareHouse: function (code) {
@@ -267,7 +294,7 @@
                 },
                 initOrderCountingRecordsChart() {
                     this.orderCountingRecordsChart.setOption({
-                        title: {text: '实时待处理订单'},
+                        title: {text: '订单量趋势'},
                         tooltip: {},
                         legend: {data: ['订单数']},
                         xAxis: {
@@ -355,6 +382,34 @@
                         ]
                     });
                 },
+                initLaborReportsUserGroupsCountChart() {
+                    this.laborReportsUserGroupsCountChart.setOption({
+                        title: {
+                            text: '小组临时工分布',
+                            left: 'left'
+                        },
+                        tooltip: {
+                            trigger: 'item',
+                            formatter: '{a} <br/>{b} : {c} ({d}%)'
+                        },
+                        series: [
+                            {
+                                name: '访问来源',
+                                type: 'pie',
+                                radius: '55%',
+                                center: ['50%', '60%'],
+                                data: this.laborReportsUserGroupsCount,
+                                emphasis: {
+                                    itemStyle: {
+                                        shadowBlur: 10,
+                                        shadowOffsetX: 0,
+                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
+                                    }
+                                }
+                            }
+                        ]
+                    });
+                },
                 initLaborReportsCountingRecords() {
                     let _this = this;
                     this.laborReportsCountingRecords.forEach(function (item) {
@@ -429,6 +484,18 @@
                         }
                     });
                 },
+                laborReportsUserGroupsCountApi() {
+                    let formData = new FormData();
+                    formData.append('start', this.laborReportsUserGroupsCountDate[0]);
+                    formData.append('end', this.laborReportsUserGroupsCountDate[1]);
+                    let _this = this;
+                    axios.post('{{url('apiLocal/control/panel/menu/laborReportsUserGroupsCountApi')}}', formData).then(function (res) {
+                        if (res.status === 200) {
+                            _this.laborReportsUserGroupsCount = res.data.laborReportsUserGroupsCount;
+                            _this.initLaborReportsUserGroupsCountChart();
+                        }
+                    });
+                },
             }
         });
     </script>

+ 1 - 0
routes/apiLocal.php

@@ -91,4 +91,5 @@ Route::group(['prefix'=>'control'],function () {
     Route::post('panel/menu/logisticsCountingRecordsApi','ControlPanelController@logisticsCountingRecordsApi');
     Route::post('panel/menu/warehouseCountingRecordsApi','ControlPanelController@warehouseCountingRecordsApi');
     Route::post('panel/menu/laborReportsCountingRecordApi','ControlPanelController@laborReportsCountingRecordApi');
+    Route::post('panel/menu/laborReportsUserGroupsCountApi','ControlPanelController@laborReportsUserGroupsCountApi');
 });

+ 27 - 0
tests/Services/LaborReportsCountingRecordService/UserGroupsCountTest.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace LaborReportsCountingRecordService;
+
+use App\Services\CacheService;
+use App\Services\LaborReportsCountingRecordService;
+use App\Services\OrderCountingRecordService;
+use Illuminate\Support\Facades\Cache;
+use Tests\TestCase;
+
+class UserGroupsCountTest extends TestCase
+{
+    /** @var LaborReportsCountingRecordService $laborReportsCountingRecordService */
+    public $laborReportsCountingRecordService;
+
+    public function setUp(): void
+    {
+        parent::setUp();
+        $this->laborReportsCountingRecordService = new LaborReportsCountingRecordService();
+    }
+
+    public function testUserGroupsCount()
+    {
+        $result =  $this->laborReportsCountingRecordService->userGroupsCount('2020-10-17','2020-11-16')->toArray();
+        dd($result);
+    }
+}