| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 | <?phpnamespace App\Console\Commands;use App\Http\Models\ScheduledTasks;use App\Http\Models\WeekTaskHistory;use App\Http\Models\WeekTaskInfo;use Illuminate\Console\Command;use Illuminate\Support\Facades\DB;class PlanWeek extends Command{    /**     * The name and signature of the console command.     *     * @var string     */    protected $signature = 'plan:week';    /**     * The console command description.     *     * @var string     */    protected $description = 'Command description';    /**     * Create a new command instance.     *     * @return void     */    public function __construct()    {        parent::__construct();    }    /**     * Execute the console command.     * 任务计划     * @return mixed     */    public function handle()    {        $condMap = DB::table('week_task_cond')->pluck('name', 'id')->toArray();        $itemsMap = DB::table('week_task_items')->pluck('name', 'id')->toArray();        $weekInfoList = WeekTaskInfo::query()            ->whereNotIn('user_type', ['wfp-web', 'wfp-design', 'wfp-exam', 'wfp-site-exam', 'wfp-site', 'wfp-seo'])            ->where(['type' => 'now'])->get()->toArray();        $result = [];        foreach ($weekInfoList as $item) {            $result[] = [                'day' => $item['day'],                'user_type' => $item['user_type'],                'describe' => $item['describe'],                'duty_id' => $item['duty_id'],                'design_id' => $item['design_id'],                'web_id' => $item['web_id'],                'cond_name' => $condMap[$item['cond_id']] ?? '',                'cond_id' => $item['cond_id'],                'cond_item_id' => $item['cond_item_id'],                'cond_item_name' => $itemsMap[$item['cond_item_id']] ?? '',                'remark' => $item['remark'],                'status' => $item['status'],                'insert_date' => date('Y-m-d'),                'slices_number' => $item['slices_number'] ?? 0,                'check_score' => $item['check_score'] ?? 0,                'created_at' => $item['created_at'] ?? null,                'updated_at' => $item['updated_at'] ?? null,                'deadline' => $item['deadline'] ?? null,                'complete' => $item['complete'] ?? null,            ];        }        WeekTaskHistory::query()->insert($result);        //获取近期的日期 排除周末        $dayList = $this->getDay();        //创建延迟任务        $taskList = ScheduledTasks::query()->get();        if (!empty($taskList->toArray())) {            foreach ($taskList as $key => $value) {                $diff = strtotime(date('Y-m-d')) - strtotime(substr($value->created_at, 0, 10));                $day = 86400 * 3;                if ($diff >= $day) {                    $update = [                        'type' => $value->type,                        'day' => $value->day,                        'user_type' => $value->user_type,                        'describe' => $value->describe,                        'duty_id' => $value->duty_id,                        'design_id' => $value->design_id,                        'web_id' => $value->web_id,                        'feedback' => $value->feedback,                        'remark' => $value->remark,                        'status' => $value->status,                        'cond_id' => $value->cond_id,                        'created_at' => date('Y-m-d H:i:s'),                        'deadline' => $dayList[2],                    ];                    WeekTaskInfo::query()->insert($update);                    ScheduledTasks::query()->where('id', $value->id)->delete();                }            }        }    }    public function getDay()    {        $days = 12;        $dayList = [];        for ($i = 1; $i <= $days; $i++) {            $day = date('Y-m-d', strtotime(date('Y-m-d')) + 86400 * $i);            $result = $this->isWeekend($day);            if (!$result) {                $dayList[] = $day;            }        }        return $dayList;    }    public function isWeekend($date)    {        if ((date('w', strtotime($date)) == 6) || (date('w', strtotime($date)) == 0)) {            return true;        } else {            return false;        }    }}
 |