|
|
@@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
use App\Traits\ModelLogChanging;
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
+use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
@@ -111,27 +112,58 @@ class WorkOrder extends Model
|
|
|
// 关联货主
|
|
|
public function owner(): BelongsTo
|
|
|
{
|
|
|
- return $this->belongsTo(Owner::class,'owner_id');
|
|
|
+ return $this->belongsTo(Owner::class, 'owner_id');
|
|
|
}
|
|
|
|
|
|
// 工单类型
|
|
|
public function type(): BelongsTo
|
|
|
{
|
|
|
- return $this->BelongsTo(WorkOrderType::class,'work_order_type_id');
|
|
|
+ return $this->BelongsTo(WorkOrderType::class, 'work_order_type_id');
|
|
|
}
|
|
|
|
|
|
// 生成问题件类型
|
|
|
- public function issueType():BelongsTo
|
|
|
+ public function issueType(): BelongsTo
|
|
|
{
|
|
|
- return $this->belongsTo(OrderIssueType::class,'order_issue_type_id');
|
|
|
+ return $this->belongsTo(OrderIssueType::class, 'order_issue_type_id');
|
|
|
}
|
|
|
|
|
|
/** 对应问题件 */
|
|
|
public function orderIssue(): BelongsTo
|
|
|
{
|
|
|
- return $this->belongsTo(OrderIssue::class,'order_id','order_id');
|
|
|
+ return $this->belongsTo(OrderIssue::class, 'order_id', 'order_id');
|
|
|
}
|
|
|
|
|
|
+ // 图片
|
|
|
+ public function image(): HasMany
|
|
|
+ {
|
|
|
+ return $this->hasMany(WorkOrderImage::class);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 外包装图片
|
|
|
+ public function packageImages(): HasMany
|
|
|
+ {
|
|
|
+ return $this->hasMany(WorkOrderImage::class)->where('type', 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 内物破损图片
|
|
|
+ public function commodityImage(): HasMany
|
|
|
+ {
|
|
|
+ return $this->hasMany(WorkOrderImage::class)->where('type', 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 交易图片
|
|
|
+ public function dealImages(): HasMany
|
|
|
+ {
|
|
|
+ return $this->hasMany(WorkOrderImage::class)->where('type', 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 退款图片
|
|
|
+ public function refundImages(): HasMany
|
|
|
+ {
|
|
|
+ return $this->hasMany(WorkOrderImage::class)->where('type', 3);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public function scopeFilter($query, $filters)
|
|
|
{
|
|
|
return $filters->apply($query);
|
|
|
@@ -141,16 +173,16 @@ class WorkOrder extends Model
|
|
|
/** 默认 with 参数 */
|
|
|
public function scopeDefaultWith($query)
|
|
|
{
|
|
|
- $query->with(['type','owner','issueType','creator','reviewer','order'=>function($query){
|
|
|
+ $query->with(['type', 'owner', 'issueType', 'creator', 'reviewer', 'order' => function ($query) {
|
|
|
/** @var $query Builder */
|
|
|
- $query->with('packages','logistic','owner');
|
|
|
- },'orderIssue'=>function($query){
|
|
|
+ $query->with('packages', 'logistic', 'owner');
|
|
|
+ }, 'orderIssue' => function ($query) {
|
|
|
/** @var $query Builder */
|
|
|
- $query->with(['issueType','logs'=>function($query){
|
|
|
- if (Gate::denies('订单管理-问题件-客户不可见')){
|
|
|
+ $query->with(['issueType', 'logs' => function ($query) {
|
|
|
+ if (Gate::denies('订单管理-问题件-客户不可见')) {
|
|
|
$query->with('user')->orderByDesc('created_at');
|
|
|
- } else{
|
|
|
- $query->with('user')->where('tag','=',0)->orderByDesc('created_at');
|
|
|
+ } else {
|
|
|
+ $query->with('user')->where('tag', '=', 0)->orderByDesc('created_at');
|
|
|
}
|
|
|
}]);
|
|
|
}]);
|
|
|
@@ -159,11 +191,56 @@ class WorkOrder extends Model
|
|
|
public function notification()
|
|
|
{
|
|
|
$user = Auth::user();
|
|
|
- $this->loadMissing('owner','order');
|
|
|
+ $this->loadMissing('owner', 'order');
|
|
|
$remark = $this->remark;
|
|
|
$ownerName = $this->owner->name ?? '';
|
|
|
$clientCode = $this->order->client_code ?? '';
|
|
|
- $msg = $user["name"]."建立了新工单<br/>".$ownerName.":".$clientCode."<br/>".$remark;
|
|
|
- NotificationService::SingleRegister($msg,$clientCode,"订单管理-问题件");
|
|
|
+ $msg = $user["name"] . "建立了新工单<br/>" . $ownerName . ":" . $clientCode . "<br/>" . $remark;
|
|
|
+ NotificationService::SingleRegister($msg, $clientCode, "订单管理-问题件");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function addPackageImages($images)
|
|
|
+ {
|
|
|
+ foreach ($images as $image) {
|
|
|
+ $count = $this->packageImages()->count();
|
|
|
+ /** @var WorkOrderImage $workOrderImage */
|
|
|
+ $workOrderImage = WorkOrderImage::query()->create(['type' => 0, 'amount' => ++$count]);
|
|
|
+ $workOrderImage->saveFile($image);
|
|
|
+ $this->packageImages()->save($workOrderImage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addCommodityImage($images)
|
|
|
+ {
|
|
|
+ foreach ($images as $image) {
|
|
|
+ $count = $this->commodityImage()->count();
|
|
|
+ /** @var WorkOrderImage $workOrderImage */
|
|
|
+ $workOrderImage = WorkOrderImage::query()->create(['type' => 1, 'amount' => ++$count]);
|
|
|
+ $workOrderImage->saveFile($image);
|
|
|
+ $this->commodityImage()->save($workOrderImage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addDealImages($images)
|
|
|
+ {
|
|
|
+ foreach ($images as $image) {
|
|
|
+ $count = $this->dealImages()->count();
|
|
|
+ /** @var WorkOrderImage $workOrderImage */
|
|
|
+ $workOrderImage = WorkOrderImage::query()->create(['type' => 2, 'amount' => ++$count]);
|
|
|
+ $workOrderImage->saveFile($image);
|
|
|
+ $this->dealImages()->save($workOrderImage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addRefundImage($images)
|
|
|
+ {
|
|
|
+ foreach ($images as $image) {
|
|
|
+ $count = $this->refundImages()->count();
|
|
|
+ /** @var WorkOrderImage $workOrderImage */
|
|
|
+ $workOrderImage = WorkOrderImage::query()->create(['type' => 3, 'amount' => ++$count]);
|
|
|
+ $workOrderImage->saveFile($image);
|
|
|
+ $this->refundImages()->save($workOrderImage);
|
|
|
+ }
|
|
|
}
|
|
|
}
|