From 4e9c7e62c8a930cfcd2b1933b8967870a708dab1 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Thu, 1 Sep 2022 21:41:40 +0800 Subject: [PATCH] Delete app/Models/Workorder directory --- app/Models/Workorder/Reply.php | 77 ----------------- app/Models/Workorder/Workorder.php | 133 ----------------------------- 2 files changed, 210 deletions(-) delete mode 100644 app/Models/Workorder/Reply.php delete mode 100644 app/Models/Workorder/Workorder.php diff --git a/app/Models/Workorder/Reply.php b/app/Models/Workorder/Reply.php deleted file mode 100644 index 22d591d..0000000 --- a/app/Models/Workorder/Reply.php +++ /dev/null @@ -1,77 +0,0 @@ -belongsTo(WorkOrder::class); - } - - public function user() - { - return $this->belongsTo(User::class); - } - - public function scopeWorkOrderId($query, $work_order_id) - { - return $query->where('work_order_id', $work_order_id); - } - - - // before create - protected static function boot() - { - parent::boot(); - static::creating(function ($model) { - - $model->is_pending = 1; - - - // load work order - $model->load(['workOrder']); - - throw_if($model->workOrder->status == 'pending' || $model->workOrder->status == 'error', CommonException::class, '工单状态不正确'); - - // change work order status - if (auth('sanctum')->check()) { - $model->user_id = auth()->id(); - $model->workOrder->status = 'user_replied'; - } - - if (auth('remote')->check()) { - $model->user_id = null; - $model->workOrder->status = 'replied'; - } - - $model->workOrder->save(); - }); - - static::created(function ($model) { - if (auth('remote')->check()) { - $model->workOrder->status = 'replied'; - $model->workOrder->save(); - } - // dispatch - dispatch(new \App\Jobs\Remote\WorkOrder\Reply($model)); - dispatch(new \App\Jobs\Remote\WorkOrder\WorkOrder($model->workOrder, 'put')); - }); - } -} diff --git a/app/Models/Workorder/Workorder.php b/app/Models/Workorder/Workorder.php deleted file mode 100644 index 1625407..0000000 --- a/app/Models/Workorder/Workorder.php +++ /dev/null @@ -1,133 +0,0 @@ -belongsTo(User::class); - } - - // replies - public function replies() - { - return $this->hasMany(Reply::class); - } - - // host - public function host() - { - return $this->belongsTo(Host::class); - } - - public function module() - { - return $this->belongsTo(Module::class); - } - - // scope - public function scopeThisModule($query) - { - return $query->where('module_id', auth('remote')->id()); - } - - public function scopeThisUser($query) - { - return $query->where('user_id', auth()->id()); - } - - - // on create - protected static function boot() - { - parent::boot(); - - static::creating(function ($model) { - - if ($model->host_id) { - $model->load(['host']); - $model->module_id = $model->host->module_id; - } - - // if logged - if (auth('sanctum')->check()) { - $model->user_id = auth('sanctum')->id(); - - if ($model->host_id) { - if (!$model->user_id === $model->host->user_id) { - throw new CommonException('user_id not match host user_id'); - } - } - } else { - throw new CommonException('user_id is required'); - } - - - if ($model->host_id) { - $model->host->load('module'); - $module = $model->host->module; - - - if ($module === null) { - $model->status = 'open'; - } else { - $model->status = 'pending'; - } - } - }); - - // 更新时获取差异部分 - static::updating(function ($model) { - // $original = $model->getOriginal(); - // // dd($original); - // $diff = array_diff_assoc($model->attributes, $original); - - // // 如果更新了host_id,则抛出异常 - // if (isset($diff['host_id'])) { - // throw new CommonException('host_id cannot be updated'); - // } - - }); - - // updated - static::updated(function ($model) { - dispatch(new \App\Jobs\Remote\WorkOrder\WorkOrder($model, 'put')); - - // $original = $model->getOriginal(); - // $diff = array_diff_assoc($model->attributes, $original); - // // dd($diff); - // if (isset($diff['status'])) { - // $model->load(['host']); - // $model->host->load('module'); - // $module = $model->host->module; - // if ($module === null) { - // $model->status = 'open'; - // } else { - // $model->status = 'pending'; - // } - // $model->save(); - // } - }); - } -}