| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace App;
- use App\Traits\ModelTimeFormat;
- use Carbon\Carbon;
- use Illuminate\Database\Eloquent\Model;
- use App\Traits\ModelLogChanging;
- class DeliveryAppointment extends Model
- {
- use ModelLogChanging;
- use ModelTimeFormat;
- protected $fillable=[
- "user_id",
- "owner_id",
- "procurement_number",
- "asn_number",
- "warehouse_id",
- "tonne",
- "cubic_meter",
- "box_amount",
- "capacity",
- "appointment_date",
- "date_period",
- "status",
- "logistic_id",
- "logistic_number",
- "type_mark",
- "remark",
- ];
- //时段 映射date_period字段 必须有序 否则展示数据错乱
- const PERIOD=[
- 0 => "09-12",
- 1 => "13-15",
- 2 => "15-17",
- ];
- //时长 映射PERIOD常量
- const HOUR=[
- 0 => 3,
- 1 => 2,
- 2 => 2,
- ];
- //状态
- const STATUS=[
- 0 => "待收",
- 1 => "取消",
- 2 => "完成",
- 3 => "已逾期",
- 4 => "逾期收货",
- ];
- //类型标记
- const TYPE = [
- 0 => "质检",
- ];
- //禁止送货日期列表 REDIS key
- const BAN = "DELIVERY_BAN_ON_DATE";
- protected $appends=[
- "period"
- ];
- public function cars()
- { //车辆
- return $this->hasMany(DeliveryAppointmentCar::class,"delivery_appointment_id","id");
- }
- public function car()
- { //单车辆
- return $this->belongsTo(DeliveryAppointmentCar::class,"id","delivery_appointment_id");
- }
- public function details()
- { //明细
- return $this->hasMany(DeliveryAppointmentDetail::class);
- }
- public function user()
- { //用户
- return $this->belongsTo(User::class);
- }
- public function owner()
- { //货主
- return $this->belongsTo(Owner::class);
- }
- public function warehouse()
- { //仓库
- return $this->belongsTo(Warehouse::class);
- }
- public function logistic()
- { //快递
- return $this->belongsTo(Logistic::class);
- }
- /**
- * 2021-08-05 在此之前所有 period为1的时间都为13-17
- *
- * @return string
- */
- public function getPeriodAttribute(){
- /** @var Carbon $create */
- $create = $this["created_at"];
- if ($create->lt(Carbon::parse("2021-08-05")) && $this["date_period"]==1)return '13-17';
- return self::PERIOD[$this["date_period"]];
- }
- }
|