DeliveryAppointment.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. ];
  24. //时段 映射date_period字段 必须有序 否则展示数据错乱
  25. const PERIOD=[
  26. 0 => "09-11",
  27. 1 => "13-17",
  28. ];
  29. //时长 映射PERIOD常量
  30. const HOUR=[
  31. 0 => 3,
  32. 1 => 5
  33. ];
  34. //状态
  35. const STATUS=[
  36. 0 => "待收",
  37. 1 => "取消",
  38. 2 => "完成",
  39. 3 => "已逾期",
  40. ];
  41. protected $appends=[
  42. "period"
  43. ];
  44. public function cars()
  45. { //车辆
  46. return $this->hasMany(DeliveryAppointmentCar::class,"delivery_appointment_id","id");
  47. }
  48. public function details()
  49. { //明细
  50. return $this->hasMany(DeliveryAppointmentDetail::class);
  51. }
  52. public function user()
  53. { //用户
  54. return $this->belongsTo(User::class);
  55. }
  56. public function owner()
  57. { //货主
  58. return $this->belongsTo(Owner::class);
  59. }
  60. public function warehouse()
  61. { //仓库
  62. return $this->belongsTo(Warehouse::class);
  63. }
  64. public function getPeriodAttribute(){
  65. return self::PERIOD[$this["date_period"]];
  66. }
  67. }