|
|
@@ -77,9 +77,12 @@ class LaborApplyService
|
|
|
{
|
|
|
//当前时间小于 1.00 禁止生成数据
|
|
|
if (now()->lte(now()->startOfDay()->addHours(1))) return ['success' => false, 'error_message' => '当前时间禁止生成临时工派遣数据'];
|
|
|
-
|
|
|
- $lately_allocation_at = Cache::get(self::LATELY_LABOR_COMPANY_DISPATCH_CREATED_AT);
|
|
|
-
|
|
|
+ //上次分配时间 默认为前一天的18:00
|
|
|
+ $lately_allocation_at = now()->subDay()->startOfDay()->addHours(self::TIME_OUT_HOUR);
|
|
|
+ //缓存中有上次的同步时间
|
|
|
+ if (Cache::has(self::LATELY_LABOR_COMPANY_DISPATCH_CREATED_AT)) {
|
|
|
+ $lately_allocation_at = Cache::get(self::LATELY_LABOR_COMPANY_DISPATCH_CREATED_AT);
|
|
|
+ }
|
|
|
//派遣日期 为报表生成日期的后一天
|
|
|
$dispatch_date = now()->addDay()->startOfDay()->toDateTimeString();
|
|
|
|
|
|
@@ -92,10 +95,11 @@ class LaborApplyService
|
|
|
->selectRaw("sum(man_num) as man_num ,sum(woman_num) as woman_num")
|
|
|
->whereBetween('created_at', [now()->startOfDay(), now()->endOfDay()])
|
|
|
->where('warehouse_id', $warehouse->id);
|
|
|
+ //如果是追加模式
|
|
|
if ($isAppend) {
|
|
|
+ //只查询最后一次分配后的申请
|
|
|
$builder->where('created_at', '>=', $lately_allocation_at);
|
|
|
}
|
|
|
-
|
|
|
$apply_man_nums = $builder
|
|
|
->groupBy('warehouse_id')
|
|
|
->first();
|
|
|
@@ -118,7 +122,7 @@ class LaborApplyService
|
|
|
'status' => 2,//指派成功
|
|
|
]);
|
|
|
}
|
|
|
- //保存上一次计算的时间
|
|
|
+ //保存分配时间为当前时间
|
|
|
Cache::put(self::LATELY_LABOR_COMPANY_DISPATCH_CREATED_AT, now());
|
|
|
return ['success' => true, 'message' => '生成临时工派遣数据成功'];
|
|
|
}
|
|
|
@@ -240,7 +244,7 @@ class LaborApplyService
|
|
|
LaborCompanyDispatch::query()
|
|
|
->whereDate('dispatch_date', $check_in_at)
|
|
|
->update([
|
|
|
- 'status' => 3//任务完结
|
|
|
+ 'status' => 4//任务完结
|
|
|
]);
|
|
|
}
|
|
|
}
|