You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

69 lines
1.6 KiB

<?php
namespace App\Model\v3;
use App\Constants\v3\OrderState;
use App\Constants\v3\Payment;
use App\Constants\v3\Shipping;
use App\Model\Model;
class OrderMain extends Model
{
protected $table = 'lanzu_order_main';
protected $appends = [
'created_at_text',
'state_text',
'pay_time_text',
'pay_type_text',
'shipping_type_text',
];
public function getCreatedAtTextAttribute()
{
return date('Y-m-d H:i:s', $this->attributes['created_at']);
}
public function getPayTimeTextAttribute()
{
return date('Y-m-d H:i:s', $this->attributes['time_pay']);
}
public function getStateTextAttribute()
{
return OrderState::getMessage($this->attributes['state']);
}
public function getPayTypeTextAttribute()
{
return Payment::getMessage($this->attributes['pay_type']);
}
public function getShippingTypeTextAttribute()
{
return Shipping::getMessage($this->attributes['shipping_type']);
}
public function market()
{
return $this->belongsTo(Market::class, 'market_id', 'id');
}
public function orders()
{
return $this->hasMany(Order::class, 'order_main_id', 'id');
}
public function orderGoods()
{
// firstKey是中间表联当前表的列,secondKey是远程表对应中间表的列,localKey是当前表关联中间表的列,secondLocalKey是中间表关联远程表的列
return $this->hasManyThrough(
OrderGoods::class,
Order::class,
'order_main_id',
'order_id',
'id',
'id'
);
}
}