ReqOrder.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. /**
  5. * ReqOrder
  6. */
  7. class ReqOrder extends Model
  8. {
  9. // 表名
  10. protected $name = 'req_order';
  11. // 自动写入时间戳字段
  12. protected $autoWriteTimestamp = true;
  13. // 追加属性
  14. protected $append = [
  15. 'city_text',
  16. ];
  17. public function getCityAttr($value): array
  18. {
  19. if ($value === '' || $value === null) return [];
  20. if (!is_array($value)) {
  21. return explode(',', $value);
  22. }
  23. return $value;
  24. }
  25. public function setCityAttr($value): string
  26. {
  27. return is_array($value) ? implode(',', $value) : $value;
  28. }
  29. public function getCityTextAttr($value, $row): string
  30. {
  31. if ($row['city'] === '' || $row['city'] === null) return '';
  32. $cityNames = \think\facade\Db::name('area')->whereIn('id', $row['city'])->column('name');
  33. return $cityNames ? implode(',', $cityNames) : '';
  34. }
  35. public function getRequireItemAttr($value): array
  36. {
  37. if ($value === '' || $value === null) return [];
  38. if (!is_array($value)) {
  39. return explode(',', $value);
  40. }
  41. return $value;
  42. }
  43. public function setRequireItemAttr($value): string
  44. {
  45. return is_array($value) ? implode(',', $value) : $value;
  46. }
  47. public function getPrepayAmountAttr($value): float
  48. {
  49. return (float)$value;
  50. }
  51. public function getPrepayImageAttr($value): array
  52. {
  53. if ($value === '' || $value === null) return [];
  54. if (!is_array($value)) {
  55. return explode(',', $value);
  56. }
  57. return $value;
  58. }
  59. public function setPrepayImageAttr($value): string
  60. {
  61. return is_array($value) ? implode(',', $value) : $value;
  62. }
  63. public function getSettleAmountAttr($value): float
  64. {
  65. return (float)$value;
  66. }
  67. public function department()
  68. {
  69. return $this->belongsTo(\app\admin\model\department\Department::class, 'req_corp', 'id');
  70. }
  71. public function admin()
  72. {
  73. return $this->belongsTo(\app\admin\model\Admin::class, 'req_user_id', 'id');
  74. }
  75. public function supplier()
  76. {
  77. return $this->belongsTo(\app\admin\model\Supplier::class, 'supplier_id', 'id');
  78. }
  79. }