DeliveryAppointment.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App;
  3. use App\Traits\ModelTimeFormat;
  4. use Carbon\Carbon;
  5. use Illuminate\Database\Eloquent\Model;
  6. use App\Traits\ModelLogChanging;
  7. class DeliveryAppointment extends Model
  8. {
  9. use ModelLogChanging;
  10. use ModelTimeFormat;
  11. protected $fillable=[
  12. "user_id",
  13. "owner_id",
  14. "procurement_number",
  15. "asn_number",
  16. "warehouse_id",
  17. "tonne",
  18. "cubic_meter",
  19. "box_amount",
  20. "capacity",
  21. "appointment_date",
  22. "date_period",
  23. "status",
  24. "logistic_id",
  25. "logistic_number",
  26. "type_mark",
  27. "remark",
  28. ];
  29. //时段 映射date_period字段 必须有序 否则展示数据错乱
  30. const PERIOD=[
  31. 0 => "09-11",
  32. 1 => "12-14",
  33. 2 => "14-18",
  34. ];
  35. //时长 映射PERIOD常量
  36. const HOUR=[
  37. 0 => 3,
  38. 1 => 3,
  39. 2 => 5,
  40. ];
  41. //状态
  42. const STATUS=[
  43. 0 => "待收",
  44. 1 => "取消",
  45. 2 => "完成",
  46. 3 => "已逾期",
  47. 4 => "逾期收货",
  48. ];
  49. //类型标记
  50. const TYPE = [
  51. 0 => "质检",
  52. ];
  53. protected $appends=[
  54. "period"
  55. ];
  56. public function cars()
  57. { //车辆
  58. return $this->hasMany(DeliveryAppointmentCar::class,"delivery_appointment_id","id");
  59. }
  60. public function car()
  61. { //单车辆
  62. return $this->belongsTo(DeliveryAppointmentCar::class,"id","delivery_appointment_id");
  63. }
  64. public function details()
  65. { //明细
  66. return $this->hasMany(DeliveryAppointmentDetail::class);
  67. }
  68. public function user()
  69. { //用户
  70. return $this->belongsTo(User::class);
  71. }
  72. public function owner()
  73. { //货主
  74. return $this->belongsTo(Owner::class);
  75. }
  76. public function warehouse()
  77. { //仓库
  78. return $this->belongsTo(Warehouse::class);
  79. }
  80. public function logistic()
  81. { //快递
  82. return $this->belongsTo(Logistic::class);
  83. }
  84. /**
  85. * 2021-08-05 在此之前所有 period为1的时间都为13-17
  86. *
  87. * @return string
  88. */
  89. public function getPeriodAttribute(){
  90. /** @var Carbon $create */
  91. $create = $this["created_at"];
  92. if ($create->lt(Carbon::parse("2021-08-05")) && $this["date_period"]==1)return '13-17';
  93. return self::PERIOD[$this["date_period"]];
  94. }
  95. }