ItemNode.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Model;
  3. use App\Traits\HasCustomFields;
  4. class ItemNode extends DataScopeBaseModel
  5. {
  6. protected $table = "item_node"; //指定表
  7. const CREATED_AT = 'crt_time';
  8. const UPDATED_AT = 'upd_time';
  9. protected $dateFormat = 'U';
  10. const employee_column = "crt_id";
  11. const table_column = "item_node_employee";
  12. const table_id_column = "item_node_id";
  13. const detail_table_column = 'item_node_details';
  14. const Order_type = "item_node";
  15. public static $field = ['*'];
  16. const TYPE_MINUS_ONE = -1;
  17. const TYPE_MINUS_TWO = -2;
  18. const TYPE_ONE = 1;
  19. const TYPE_TWO = 2;
  20. const TYPE_THREE = 3;
  21. const State_Type = [
  22. self::TYPE_MINUS_ONE => '审核中',
  23. self::TYPE_MINUS_TWO => '已超期',
  24. self::TYPE_ONE => '待开始',
  25. self::TYPE_TWO => '进行中',
  26. self::TYPE_THREE => '已完成',
  27. ];
  28. const delivery_zero = 0;
  29. const delivery_one = 1;
  30. const Delivery_Attribute = [
  31. self::delivery_zero => '否',
  32. self::delivery_one => '是',
  33. ];
  34. const entrust_zero = 0;
  35. const entrust_one = 1;
  36. const entrust_two = 2;
  37. const Entrust_Attribute = [
  38. self::entrust_zero => '无',
  39. self::entrust_one => '境内委托',
  40. self::entrust_two => '境外委托',
  41. ];
  42. const review_zero = 0;
  43. const review_one = 1;
  44. const Review_Attribute = [
  45. self::review_zero => '否',
  46. self::review_one => '是',
  47. ];
  48. // 引入自定义字段预加载关系
  49. use HasCustomFields;
  50. // 作用域 里面关联了客户自定义的表头数据 列表页需要 :: withCustomData($user) 这个是预加载
  51. public function scopeWithCustomData($query, $user)
  52. {
  53. $top_depart_id = $user['top_depart_id'];
  54. return $query->with(['customFields' => function ($subQuery) use ($top_depart_id) {
  55. $subQuery->where('top_depart_id', $top_depart_id)
  56. ->where('table_name', $this->table)
  57. ->where('del_time', 0);
  58. }]);
  59. }
  60. }