Task.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Repositories\Models\Base;
  3. use App\Repositories\Enums\TaskMakeStatusEnum;
  4. use App\Repositories\Models\Model;
  5. class Task extends Model
  6. {
  7. /**
  8. * @var string
  9. */
  10. protected $table = 'base_tasks';
  11. protected $guarded = [];
  12. protected $casts = ['result' => 'json'];
  13. /**
  14. * The attributes excluded from the model's JSON form.
  15. *
  16. * @var array
  17. */
  18. protected $hidden = [];
  19. public function admin()
  20. {
  21. return $this->belongsTo(Admin::class)->select(['id', 'username', 'name']);
  22. }
  23. /**
  24. * 创建导入任务
  25. * @param $resource
  26. * @param $type
  27. * @param $admin_id
  28. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model
  29. */
  30. public static function importTask($resource, $type, $admin_id)
  31. {
  32. return self::query()->updateOrCreate([
  33. 'resource_id' => $resource['id'],
  34. 'type' => $type,
  35. 'admin_id' => $admin_id,
  36. ], [
  37. 'name' => $resource['original_name'],
  38. 'type_id' => 0,
  39. 'make_status' => TaskMakeStatusEnum::WAIT,
  40. ]);
  41. }
  42. }