1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace App\Repositories\Models\Base;
- use App\Repositories\Enums\TaskMakeStatusEnum;
- use App\Repositories\Models\Model;
- class Task extends Model
- {
- /**
- * @var string
- */
- protected $table = 'base_tasks';
- protected $guarded = [];
- protected $casts = ['result' => 'json'];
- /**
- * The attributes excluded from the model's JSON form.
- *
- * @var array
- */
- protected $hidden = [];
- public function admin()
- {
- return $this->belongsTo(Admin::class)->select(['id', 'username', 'name']);
- }
- /**
- * 创建导入任务
- * @param $resource
- * @param $type
- * @param $admin_id
- * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model
- */
- public static function importTask($resource, $type, $admin_id)
- {
- return self::query()->updateOrCreate([
- 'resource_id' => $resource['id'],
- 'type' => $type,
- 'admin_id' => $admin_id,
- ], [
- 'name' => $resource['original_name'],
- 'type_id' => 0,
- 'make_status' => TaskMakeStatusEnum::WAIT,
- ]);
- }
- }
|