DeliveryAppointment.php 2.0 KB

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