LaborApply.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App;
  3. use App\Traits\ModelTimeFormat;
  4. use Illuminate\Database\Eloquent\Model;
  5. use App\Traits\ModelLogChanging;
  6. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  7. class LaborApply extends Model
  8. {
  9. const CAN_CREATE_STATUS_OPEN = 1;
  10. const CAN_CREATE_STATUS_FORBID = 2;
  11. const CAN_CREATE_STATUS_TEMPORARY_OPEN = 3;
  12. use ModelLogChanging;
  13. use ModelTimeFormat;
  14. public $fillable = [
  15. 'status',//状态
  16. 'warehouse_id',//仓库
  17. 'user_workgroup_id',//仓库小组
  18. 'apply_user_id',//申请人
  19. 'man_num',//男工数量
  20. 'woman_num',//女工数量
  21. 'actual_num',//到岗人数
  22. 'remark',//用工要求
  23. ];
  24. static public $enums = [
  25. 'status' => [
  26. '' => 0,
  27. '创建' => 1,
  28. '指派成功' => 2,
  29. '劳务接单' => 3,
  30. '任务完结' => 4,
  31. ],
  32. ];
  33. function __construct(array $attributes = [])
  34. {
  35. foreach (self::$enums as &$enum) {
  36. $enum = $enum + array_flip($enum);
  37. }
  38. parent::__construct($attributes);
  39. }
  40. public function getStatusAttribute($value)
  41. {
  42. if (!$value) return '';
  43. return self::$enums['status'][$value];
  44. }
  45. public function setStatusAttribute($value)
  46. {
  47. if (!$value) return 0;
  48. $this->attributes['status'] = self::$enums['status'][$value];
  49. }
  50. public function warehouse(): BelongsTo
  51. {
  52. return $this->belongsTo(Warehouse::class);
  53. }
  54. public function userWorkGroup(): BelongsTo
  55. {
  56. return $this->belongsTo(UserWorkgroup::class, 'user_workgroup_id', 'id');
  57. }
  58. public function applyUser(): BelongsTo
  59. {
  60. return $this->belongsTo(User::class, 'apply_user_id', 'id');
  61. }
  62. public function scopeFilter($query, $filters)
  63. {
  64. return $filters->apply($query);
  65. }
  66. }