优化查询代码
This commit is contained in:
parent
9250ef6f65
commit
ac26713f86
@ -1170,6 +1170,9 @@ class ProjectController extends AbstractController
|
||||
$name = Request::input('name');
|
||||
//
|
||||
$task = ProjectTask::userTask($task_id, true, true);
|
||||
if ($task->complete_at) {
|
||||
return Base::retError('主任务已完成无法添加子任务');
|
||||
}
|
||||
//
|
||||
$task = ProjectTask::addTask([
|
||||
'name' => $name,
|
||||
@ -1761,6 +1764,9 @@ class ProjectController extends AbstractController
|
||||
$list = $builder->orderByDesc('created_at')->paginate(Base::getPaginate(100, 20));
|
||||
$list->transform(function (ProjectLog $log) use ($task_id) {
|
||||
$timestamp = Carbon::parse($log->created_at)->timestamp;
|
||||
if ($task_id === 0) {
|
||||
$log->projectTask?->cancelAppend();
|
||||
}
|
||||
$log->time = [
|
||||
'ymd' => date(date("Y", $timestamp) == date("Y", Base::time()) ? "m-d" : "Y-m-d", $timestamp),
|
||||
'hi' => date("h:i", $timestamp) ,
|
||||
|
@ -17,6 +17,7 @@ use Illuminate\Support\Facades\DB;
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel saveOrIgnore()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|AbstractModel getKeyValue()
|
||||
* @method static \Illuminate\Database\Eloquent\Model|object|static|null cancelAppend()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|static with($relations)
|
||||
* @method static \Illuminate\Database\Query\Builder|static select($columns = [])
|
||||
* @method static \Illuminate\Database\Query\Builder|static whereNotIn($column, $values, $boolean = 'and')
|
||||
@ -62,6 +63,15 @@ class AbstractModel extends Model
|
||||
return $this->$key;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消附加值
|
||||
* @return static
|
||||
*/
|
||||
protected function scopeCancelAppend()
|
||||
{
|
||||
return $this->setAppends([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 为数组 / JSON 序列化准备日期。
|
||||
* @param DateTimeInterface $date
|
||||
|
@ -112,7 +112,7 @@ class ProjectTask extends AbstractModel
|
||||
public function getFileNumAttribute()
|
||||
{
|
||||
if (!isset($this->appendattrs['file_num'])) {
|
||||
$this->appendattrs['file_num'] = ProjectTaskFile::whereTaskId($this->id)->count();
|
||||
$this->appendattrs['file_num'] = $this->parent_id > 0 ? 0 : ProjectTaskFile::whereTaskId($this->id)->count();
|
||||
}
|
||||
return $this->appendattrs['file_num'];
|
||||
}
|
||||
@ -494,6 +494,8 @@ class ProjectTask extends AbstractModel
|
||||
if (version_compare(Base::getClientVersion(), '0.6.0', '<')) {
|
||||
throw new ApiException('当前版本过低');
|
||||
}
|
||||
// 主任务
|
||||
$mainTask = $this->parent_id > 0 ? self::find($this->parent_id) : null;
|
||||
// 工作流
|
||||
if (Arr::exists($data, 'flow_item_id')) {
|
||||
if ($this->flow_item_id == $data['flow_item_id']) {
|
||||
@ -564,6 +566,10 @@ class ProjectTask extends AbstractModel
|
||||
}
|
||||
// 状态
|
||||
if (Arr::exists($data, 'complete_at')) {
|
||||
// 子任务:主任务已完成时无法修改
|
||||
if ($mainTask?->complete_at) {
|
||||
throw new ApiException('主任务已完成,无法修改子任务状态');
|
||||
}
|
||||
if (Base::isDate($data['complete_at'])) {
|
||||
// 标记已完成
|
||||
if ($this->complete_at) {
|
||||
@ -646,7 +652,6 @@ class ProjectTask extends AbstractModel
|
||||
$end_at = Carbon::parse($end);
|
||||
if ($this->parent_id > 0) {
|
||||
// 判断同步主任务时间(子任务时间 超出 主任务)
|
||||
$mainTask = self::find($this->parent_id);
|
||||
if ($mainTask) {
|
||||
$isUp = false;
|
||||
if ($start_at->lt(Carbon::parse($mainTask->start_at))) {
|
||||
@ -669,7 +674,6 @@ class ProjectTask extends AbstractModel
|
||||
} else {
|
||||
if ($this->parent_id > 0) {
|
||||
// 清空子任务时间(子任务时间等于主任务时间)
|
||||
$mainTask = self::find($this->parent_id);
|
||||
$this->start_at = $mainTask->start_at;
|
||||
$this->end_at = $mainTask->end_at;
|
||||
}
|
||||
@ -798,9 +802,7 @@ class ProjectTask extends AbstractModel
|
||||
{
|
||||
if ($this->parent_id > 0) {
|
||||
$task = self::find($this->parent_id);
|
||||
if ($task) {
|
||||
$task->syncDialogUser();
|
||||
}
|
||||
$task?->syncDialogUser();
|
||||
return;
|
||||
}
|
||||
if (empty($this->dialog_id)) {
|
||||
@ -872,24 +874,6 @@ class ProjectTask extends AbstractModel
|
||||
return $this->appendattrs['has_owner'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否负责人
|
||||
* @param bool $isParent 是父级任务的负责人也算
|
||||
* @return bool
|
||||
*/
|
||||
public function isOwner($isParent = true) {
|
||||
if ($this->owner) {
|
||||
return true;
|
||||
}
|
||||
if ($isParent && $this->parent_id > 0) {
|
||||
$parentTask = self::find($this->parent_id);
|
||||
if ($parentTask?->owner) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记已完成、未完成
|
||||
* @param Carbon|null $complete_at 完成时间
|
||||
|
Loading…
x
Reference in New Issue
Block a user