hasOne(Project::class, 'id', 'project_id'); } /** * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function projectTask(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(projectTask::class, 'column_id', 'id')->whereNull('archived_at')->orderBy('sort')->orderBy('id'); } /** * 删除列表 * @param bool $pushMsg 是否推送 * @return bool */ public function deleteColumn($pushMsg = true) { $result = AbstractModel::transaction(function () use ($pushMsg) { $tasks = ProjectTask::whereColumnId($this->id)->get(); foreach ($tasks as $task) { $task->deleteTask($pushMsg); } if ($pushMsg) { $this->pushMsg("delete", $this->toArray()); } $this->delete(); $this->addLog("删除列表:" . $this->name); return Base::retSuccess('删除成功', $this->toArray()); }); return Base::isSuccess($result); } /** * 添加项目日志 * @param string $detail * @param int $userid * @return ProjectLog */ public function addLog($detail, $userid = 0) { $log = ProjectLog::createInstance([ 'project_id' => $this->project_id, 'column_id' => $this->id, 'task_id' => 0, 'userid' => $userid ?: User::token2userid(), 'detail' => $detail, ]); $log->save(); return $log; } /** * 推送消息 * @param string $action * @param array $data */ public function pushMsg($action, $data) { if (!$this->project) { return; } $lists = [ 'userid' => $this->project->relationUserids(), 'msg' => [ 'type' => 'projectColumn', 'action' => $action, 'data' => $data, ] ]; $task = new PushTask($lists, false); Task::deliver($task); } }