$params['title'], 'template_id' => $params['template_id'], 'company_id' => $params['company_id'], // 'admin_id' => $params['admin_id'], 'start_time' => strtotime($params['start_time']), 'end_time' => strtotime($params['end_time']), 'director_uid' => $params['director_uid'], 'type' => $params['type'], 'status' => $params['status'], 'content' => $params['content'], 'extend' => json_encode($params['extend']) ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * 定时添加任务 */ public static function CronAdd(array $v): bool { if ($v['template_info'] != null) { try { $arr = [ 'template_id' => $v['template_id'], 'scheduling_plan_id' => $v['id'], 'company_id' => $v['scheduling']['company_id'], 'title' => $v['template_info']['title'], 'money' => $v['template_info']['money'], 'type' => $v['template_info']['type'], 'content' => $v['template_info']['content'], 'start_time' => strtotime($v['start_time']), 'end_time' => strtotime($v['end_time']), 'create_time' => time(), 'update_time' => time(), ]; $data = $arr; $data['money'] = self::task_money($v); if($v['template_info']['type'] == 31){ $data["extend"]=json_encode(['informationg'=>['count'=>5,'update'=>0]]); TaskTemplate::where('id',$v['template_id'])->inc('information_day_count',5)->update(); }else{ $data["extend"]=json_encode([]); } if ($v['template_info']['type'] == 32) { $data['director_uid'] = $v['company']['user_id']; } $task_id = (new Task())->insertGetId($data); TaskSchedulingPlan::where('id', $v['id'])->update(['task_id' => $task_id, 'is_execute' => 1]); return true; } catch (\Exception $e) { Log::error('定时任务添加失败', [$e->getMessage()]); return false; } } } //任务金额 private static function task_money($v) { if ($v['template_info']['types'] == 1 || $v['template_info']['types'] == 3) { if ($v['company'] && $v['company']['day_count'] <= $v['template_info']['stage_day_one']) { return $v['template_info']['money']; } else { return $v['template_info']['money_two']; } } elseif ($v['template_info']['types'] == 2) { if ($v['company'] && $v['company']['day_count'] <= $v['template_info']['stage_day_one']) { return $v['template_info']['money']; } elseif ($v['company'] && $v['company']['day_count'] <= $v['template_info']['stage_day_two']) { return $v['template_info']['money_two']; } else { return $v['template_info']['money_three']; } } else { if ($v['company'] && $v['company']['day_count'] <= $v['template_info']['stage_day_one']) { $a = $v['template_info']['money']; } else { $a = $v['template_info']['money_two']; } if($v['company'] && $v['company']['day_count']>=$v['template_info']['stage_day_two']){ TaskTemplate::where('id',$v['template_id'])->update(['status'=>0]); } return $a; } } /** * @notes 随机生成信息更新任务 */ private static function random_informationg($company_id) { $res = UserInformationg::where('company_id', $company_id)->where('status', 1)->order('update_time', 'desc')->limit(5)->field('id,create_user_id')->select(); return $res; } /** * @notes 更新任务状态 * @param array $params * @return bool * @author likeadmin * @date 2023/08/05 13:39 */ public static function edit(array $params): bool { Db::startTrans(); try { Task::where('id', $params['id'])->update(['status' => 3, 'update_time' => time()]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 删除任务 * @param array $params * @return bool * @author likeadmin * @date 2023/08/05 13:39 */ public static function delete(array $params): bool { return Task::destroy($params['id']); } /** * @notes 获取任务详情 * @param $params * @return array * @author likeadmin * @date 2023/08/05 13:39 */ public static function detail($params): array { $task = Task::findOrEmpty($params['id'])->toArray(); if ($task) { if (isset($task['extend']['informationg'])) { $task['extend']['informationg'] = UserInformationg::where('id', $task['extend']['informationg'])->field('name,phone,sex,age,update_time') ->find()->toArray(); } } return $task; } }