DeliveryAppointment.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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-12",
  32. 1 => "13-15",
  33. 2 => "15-17",
  34. ];
  35. //时长 映射PERIOD常量
  36. const HOUR=[
  37. 0 => 3,
  38. 1 => 2,
  39. 2 => 2,
  40. ];
  41. //状态
  42. const STATUS=[
  43. 0 => "待收",
  44. 1 => "取消",
  45. 2 => "完成",
  46. 3 => "已逾期",
  47. 4 => "逾期收货",
  48. ];
  49. //类型标记
  50. const TYPE = [
  51. 0 => "质检",
  52. ];
  53. //禁止送货日期列表 REDIS key
  54. const BAN = "DELIVERY_BAN_ON_DATE";
  55. protected $appends=[
  56. "period"
  57. ];
  58. public function cars()
  59. { //车辆
  60. return $this->hasMany(DeliveryAppointmentCar::class,"delivery_appointment_id","id");
  61. }
  62. public function car()
  63. { //单车辆
  64. return $this->belongsTo(DeliveryAppointmentCar::class,"id","delivery_appointment_id");
  65. }
  66. public function details()
  67. { //明细
  68. return $this->hasMany(DeliveryAppointmentDetail::class);
  69. }
  70. public function user()
  71. { //用户
  72. return $this->belongsTo(User::class);
  73. }
  74. public function owner()
  75. { //货主
  76. return $this->belongsTo(Owner::class);
  77. }
  78. public function warehouse()
  79. { //仓库
  80. return $this->belongsTo(Warehouse::class);
  81. }
  82. public function logistic()
  83. { //快递
  84. return $this->belongsTo(Logistic::class);
  85. }
  86. /**
  87. * 2021-08-05 在此之前所有 period为1的时间都为13-17
  88. *
  89. * @return string
  90. */
  91. public function getPeriodAttribute(){
  92. /** @var Carbon $create */
  93. $create = $this["created_at"];
  94. if ($create->lt(Carbon::parse("2021-08-05")) && $this["date_period"]==1)return '13-17';
  95. return self::PERIOD[$this["date_period"]];
  96. }
  97. }