Quellcode durchsuchen

临时工报表增加年处理

ANG YU vor 5 Jahren
Ursprung
Commit
91cb7990fd

+ 11 - 19
app/Services/LaborReportsCountingRecordService.php

@@ -18,7 +18,7 @@ class LaborReportsCountingRecordService
     {
         $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')
+                ->with('userWorkgroup', 'laborReportStatus')
                 ->whereDate('created_at', '>=', $start)
                 ->whereDate('created_at', '<', $end)
                 ->groupBy('user_workgroup_id')->get();
@@ -88,11 +88,6 @@ class LaborReportsCountingRecordService
                     $dataArray[] = $item->toDateString();
                 }
                 break;
-            case '周';
-                foreach (Carbon::parse($start)->startOfWeek(1)->weeksUntil($end, 1)->toArray() as $item) {
-                    $dataArray[] = $item->year . '-' . $item->week . '';
-                }
-                break;
             case '月';
                 foreach (Carbon::parse($start)->monthsUntil($end, 1)->toArray() as $item) {
                     $dataArray[] = $item->year . '-' . $item->format('m') . '';
@@ -100,7 +95,7 @@ class LaborReportsCountingRecordService
                 break;
             case '年';
                 foreach (Carbon::parse($start)->yearsUntil($end, 1)->toArray() as $item) {
-                    $dataArray[] = $item->year . '-' . $item->month . '';
+                    $dataArray[] = $item->year.'';
                 }
                 break;
             default:
@@ -127,31 +122,28 @@ class LaborReportsCountingRecordService
                     Cache::put($key, $item);
                 });
                 break;
-            case '':
-                $query = LaborReport::query()->selectRaw("DATE_FORMAT(created_at,'%x-%v') as date_target, count(DISTINCT user_id) as counter");
+            case '':
+                $query = LaborReport::query()->selectRaw("DATE_FORMAT(created_at,'%Y-%m') as date_target, count(DISTINCT user_id) as counter");
                 foreach ($dateList as $date) {
                     $query->orWhere(function ($query) use ($date) {
                         $year = Str::of($date)->explode('-')[0];
-                        $week = Str::of($date)->explode('-')[1];
-                        $startOfWeek = Carbon::now()->setISODate($year, $week)->startOfWeek()->toDateString();
-                        $endOfWeek = Carbon::parse($startOfWeek)->endOfWeek()->toDateString();
-                        $query->whereDate('created_at', '>=', $startOfWeek)->whereDate('created_at', '<=', $endOfWeek);
+                        $month = Str::of($date)->explode('-')[1];
+                        $query->whereYear('created_at', $year)->whereMonth('created_at', $month);
                     });
                 }
                 $dataList = $query->groupBy('date_target')->get();
                 $dataList->each(function ($item) use ($unit) {
                     $date = $item->date_target;
-                    $item->date_target = Carbon::now()->setISODate(Str::of($date)->explode('-')[0], Str::of($date)->explode('-')[1])->startOfWeek()->toDateString();
-                    Cache::put('laborReportsCountingRecords_' . $date . '_' . $unit, $item);
+                    $key = 'laborReportsCountingRecords_' . $date . '_' . $unit;
+                    Cache::put($key, $item);
                 });
                 break;
-            case '':
-                $query = LaborReport::query()->selectRaw("DATE_FORMAT(created_at,'%Y-%m') as date_target, count(DISTINCT user_id) as counter");
+            case '':
+                $query = LaborReport::query()->selectRaw("DATE_FORMAT(created_at,'%Y') as date_target, count(DISTINCT user_id) as counter");
                 foreach ($dateList as $date) {
                     $query->orWhere(function ($query) use ($date) {
                         $year = Str::of($date)->explode('-')[0];
-                        $month = Str::of($date)->explode('-')[1];
-                        $query->whereYear('created_at', $year)->whereMonth('created_at', $month);
+                        $query->whereYear('created_at', $year)->whereYear('created_at', $year);
                     });
                 }
                 $dataList = $query->groupBy('date_target')->get();

+ 103 - 14
resources/views/control/panel.blade.php

@@ -209,23 +209,89 @@
                         <div class="card">
                             <div class="card-header">
                                 <span class="demonstration"></span>
-                                <el-date-picker @blur="laborReportsCountingRecordApi('')"
-                                                v-model="laborReportsCountingRecordsDate"
-                                                type="daterange"
-                                                align="right"
-                                                unlink-panels
-                                                range-separator="-"
-                                                start-placeholder="开始日期"
-                                                end-placeholder="结束日期"
-                                                value-format="yyyy-MM-dd"
-                                                :picker-options="pickerOptions">
-                                </el-date-picker>
+{{--                                <el-date-picker @blur="laborReportsCountingRecordApi('')"--}}
+{{--                                                v-model="laborReportsCountingRecordsDate"--}}
+{{--                                                type="daterange"--}}
+{{--                                                align="right"--}}
+{{--                                                unlink-panels--}}
+{{--                                                range-separator="-"--}}
+{{--                                                start-placeholder="开始日期"--}}
+{{--                                                end-placeholder="结束日期"--}}
+{{--                                                value-format="yyyy-MM-dd"--}}
+{{--                                                :picker-options="pickerOptions">--}}
+{{--                                </el-date-picker>--}}
+
+                                <div class="block">
+                                    <span v-show="laborReportsCountingRecordsDayShow" class="demonstration">起始日期</span>
+                                    <el-date-picker
+                                        @blur="laborReportsCountingRecordApi('')"
+                                        v-show="laborReportsCountingRecordsDayShow"
+                                        v-model="laborReportsCountingRecordsStart"
+                                        type="date"
+                                        value-format="yyyy-MM-dd"
+                                        placeholder="选起始日期">
+                                    </el-date-picker>
+
+                                    <span v-show="laborReportsCountingRecordsDayShow" class="demonstration">结束日期</span>
+                                    <el-date-picker
+                                        @blur="laborReportsCountingRecordApi('')"
+                                        v-show="laborReportsCountingRecordsDayShow"
+                                        v-model="laborReportsCountingRecordsEnd"
+                                        type="date"
+                                        value-format="yyyy-MM-dd"
+                                        placeholder="选择结束日期">
+                                    </el-date-picker>
+
+                                    <span v-show="laborReportsCountingRecordsMonthShow" class="demonstration">起始月</span>
+                                    <el-date-picker
+                                        @blur="laborReportsCountingRecordApi('')"
+                                        v-show="laborReportsCountingRecordsMonthShow"
+                                        v-model="laborReportsCountingRecordsStart"
+                                        type="month"
+                                        value-format="yyyy-MM-dd"
+                                        placeholder="选择起始月">
+                                    </el-date-picker>
+
+                                    <span v-show="laborReportsCountingRecordsMonthShow" class="demonstration">结束月</span>
+                                    <el-date-picker
+                                        @blur="laborReportsCountingRecordApi('')"
+                                        v-show="laborReportsCountingRecordsMonthShow"
+                                        v-model="laborReportsCountingRecordsEnd"
+                                        type="month"
+                                        value-format="yyyy-MM-dd"
+                                        placeholder="选择结束月">
+                                    </el-date-picker>
+
+                                    <span v-show="laborReportsCountingRecordsYearShow" class="demonstration">起始年</span>
+                                    <el-date-picker
+                                        @blur="laborReportsCountingRecordApi('')"
+                                        v-show="laborReportsCountingRecordsYearShow"
+                                        v-model="laborReportsCountingRecordsStart"
+                                        type="year"
+                                        value-format="yyyy-MM-dd"
+                                        placeholder="选择年">
+                                    </el-date-picker>
+
+                                    <span v-show="laborReportsCountingRecordsYearShow" class="demonstration">结束年</span>
+                                    <el-date-picker
+                                        @blur="laborReportsCountingRecordApi('')"
+                                        v-show="laborReportsCountingRecordsYearShow"
+                                        v-model="laborReportsCountingRecordsEnd"
+                                        type="year"
+                                        value-format="yyyy-MM-dd"
+                                        placeholder="选择年">
+                                    </el-date-picker>
+                                </div>
+
                                 <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>
                             </div>
                             <div class="card-body row">
                                 <div v-show="laborReportsCountingRecordsShow" id="laborReportsCountingRecords"
@@ -346,7 +412,12 @@
                 orderCountingRecordsMonthShow: false,
                 orderCountingRecordsYearShow: false,
                 orderCountingRecordsStart: moment().subtract('1', 'month').format('yyyy-MM-DD'),
-                orderCountingRecordsEnd: moment(new Date()).format('yyyy-MM-DD')
+                orderCountingRecordsEnd: moment(new Date()).format('yyyy-MM-DD'),
+                laborReportsCountingRecordsDayShow: true,
+                laborReportsCountingRecordsMonthShow: false,
+                laborReportsCountingRecordsYearShow:false ,
+                laborReportsCountingRecordsStart: moment().subtract('1', 'month').format('yyyy-MM-DD'),
+                laborReportsCountingRecordsEnd: moment(new Date()).format('yyyy-MM-DD'),
             },
             mounted: function () {
                 $('#list').removeClass('d-none');
@@ -594,9 +665,27 @@
                         laborReportsCountingRecordUnit = this.laborReportsCountingRecordUnit;
                     }
                     this.laborReportsCountingRecordUnit = laborReportsCountingRecordUnit;
+                    switch (laborReportsCountingRecordUnit) {
+                        case '日':
+                            this.laborReportsCountingRecordsDayShow = true;
+                            this.laborReportsCountingRecordsMonthShow = false;
+                            this.laborReportsCountingRecordsYearShow = false;
+                            break;
+                        case '月':
+                            this.laborReportsCountingRecordsDayShow = false;
+                            this.laborReportsCountingRecordsMonthShow = true;
+                            this.laborReportsCountingRecordsYearShow = false;
+                            break;
+                        case '年':
+                            this.laborReportsCountingRecordsDayShow = false;
+                            this.laborReportsCountingRecordsMonthShow = false;
+                            this.laborReportsCountingRecordsYearShow = true;
+                            break;
+                    }
+
                     let formData = new FormData();
-                    formData.append('start', this.laborReportsCountingRecordsDate[0]);
-                    formData.append('end', this.laborReportsCountingRecordsDate[1]);
+                    formData.append('start', this.laborReportsCountingRecordsStart);
+                    formData.append('end', this.laborReportsCountingRecordsEnd);
                     formData.append('unit', laborReportsCountingRecordUnit);
                     let _this = this;
                     axios.post('{{url('apiLocal/control/panel/menu/laborReportsCountingRecordApi')}}', formData).then(function (res) {