diff --git a/app/api/controller/CronController.php b/app/api/controller/CronController.php index f03ae6d10..90a08d4db 100644 --- a/app/api/controller/CronController.php +++ b/app/api/controller/CronController.php @@ -3,6 +3,8 @@ namespace app\api\controller; use app\common\model\task_scheduling_plan\TaskSchedulingPlan; use app\job\TaskInformationJob; +use app\job\TownTaskAdd; +use app\job\TownTaskSettlementJob; use think\facade\Log; use app\common\model\Company; use app\common\model\task_template\TaskTemplate; @@ -20,7 +22,7 @@ class CronController extends BaseApiController public array $notNeedLogin = ['settlement','task_add']; /** - * 结算 + * 小组服务公司任务结算 */ public function settlement(){ // $all=TaskSchedulingPlan::where('is_pay',0)->with(['template_info','scheduling'])->select()->toArray(); @@ -34,11 +36,14 @@ class CronController extends BaseApiController foreach($all as $k=>$v){ queue(TaskInformationJob::class,$v); } - Log::info('定时任务结算执行成功'.date('Y-m-d H:i:s')); - return $this->success('定时任务结算执行成功'); + Log::info('小组服务公司定时任务结算执行成功'.date('Y-m-d H:i:s')); + return $this->success('小组服务公司定时任务结算执行成功'); } + /** + * 小组服务公司任务下发 + */ public function task_add(){ //任务下发 // $time=strtotime(date('Y-m-d',strtotime('-1 day'))); @@ -66,7 +71,59 @@ class CronController extends BaseApiController } Company::where('id', 'in', $company_id)->inc('day_count')->update(); TaskScheduling::where('id', 'in', $plan_ids)->update(['cron_time' => time()]); - Log::info('定时任务下发执行成功' . date('Y-m-d H:i:s')); + Log::info('小组服务公司定时任务下发执行成功' . date('Y-m-d H:i:s')); return $this->success('定时任务下发执行成功'); } + + /** + * 镇管理公司任务结算 + */ + public function town_task_settlement() + { + Log::info('镇管理公司定时任务结算执行-开始'.date('Y-m-d H:i:s')); + //yesterday 昨日未结算的任务计划 + $taskSchedulingPlanList = TaskSchedulingPlan::whereDay('end_time','yesterday') + ->withJoin(['scheduling'], 'left') + ->where('scheduling.company_type', 41) + ->where('is_pay',0) + ->with(['template_info']) + ->select() + ->toArray(); + foreach($taskSchedulingPlanList as $taskSchedulingPlan){ + queue(TownTaskSettlementJob::class, $taskSchedulingPlan); + } + Log::info('镇管理公司定时任务结算执行-结束'.date('Y-m-d H:i:s')); + return $this->success('镇管理公司定时任务结算执行成功'); + } + + /** + * 镇管理公司任务下发 + */ + public function town_task_add() + { + //任务下发 + $time = strtotime(date('Y-m-d')); + // 查询系统 所有镇管理公司 未下发 的 任务安排 + $taskSchedulingList = TaskScheduling::where('cron_time', '<', $time)->where('status', 1)->where('company_type', 41)->with('company_info')->select()->toArray(); + + $taskSchedulingIds = []; + $companyIds = []; + foreach ($taskSchedulingList as $k => $taskScheduling) { + $templateList = TaskTemplate::where('status', 1)->where('task_scheduling', $taskScheduling['id'])->limit(30)->select()->toArray(); + $taskSchedulingIds[] = $taskScheduling['id']; + $companyIds[] = $taskScheduling['company_id']; + foreach ($templateList as $template) { + queue(TownTaskAdd::class, $template); +// TaskLogic::TownCronAdd($template); // 手动下发用 + } + + if (empty($templateList)) { + unset($taskSchedulingList[$k]); + } + } + Company::where('id', 'in', $companyIds)->inc('day_count')->update(); + TaskScheduling::where('id', 'in', $taskSchedulingIds)->update(['cron_time' => time()]); + Log::info('镇管理公司定时任务下发执行成功' . date('Y-m-d H:i:s')); + return $this->success('镇管理公司定时任务下发执行成功'); + } } \ No newline at end of file