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.
140 lines
3.5 KiB
140 lines
3.5 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;
|
|
use Hyperf\Database\Model\SoftDeletes;
|
|
|
|
class OrderMain extends Model
|
|
{
|
|
use SoftDeletes;
|
|
protected $table = 'lanzu_order_main';
|
|
|
|
protected $guarded = [];
|
|
|
|
// protected $fillable = [
|
|
// 'market_id',
|
|
// 'order_num',
|
|
// 'global_order_id',
|
|
// 'user_id',
|
|
// 'pay_type',
|
|
// 'type',
|
|
// 'order_type',
|
|
// 'shipping_type',
|
|
// 'money',
|
|
// 'total_money',
|
|
// 'services_money',
|
|
// 'coupon_money',
|
|
// 'delivery_money',
|
|
// 'state',
|
|
// 'pay_time',
|
|
// 'receive_time',
|
|
// 'delivery_time',
|
|
// 'complete_time',
|
|
// 'cancel_time',
|
|
// 'refund_time',
|
|
// 'tel',
|
|
// 'address',
|
|
// 'area',
|
|
// 'lat',
|
|
// 'lng',
|
|
// 'name',
|
|
// 'print_num',
|
|
// 'plat',
|
|
// 'refuse_refund_note',
|
|
// 'delivery_time_note',
|
|
// 'total_refund_note',
|
|
// 'note',
|
|
// 'delivery_distance'
|
|
// ];
|
|
|
|
protected $appends = [
|
|
'created_at_text',
|
|
'state_text',
|
|
'pay_time_text',
|
|
'pay_type_text',
|
|
'shipping_type_text',
|
|
];
|
|
|
|
protected $casts = [
|
|
'global_order_id' => 'string'
|
|
];
|
|
|
|
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['pay_time']);
|
|
}
|
|
|
|
public function getStateTextAttribute()
|
|
{
|
|
if ($this->attributes['state'] == OrderState::DELIVERY) {
|
|
if($this->attributes['shipping_type'] == 3) {
|
|
return '待自提';
|
|
}elseif ($this->attributes['shipping_type'] == 1 && !$this->attributes['horseman_id']){
|
|
return '已接单';
|
|
}
|
|
}
|
|
|
|
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 getNoteAttribute($value)
|
|
{
|
|
if ($this->attributes['refuse_refund_note'] || $this->attributes['total_refund_note']) {
|
|
return $this->attributes['refuse_refund_note'] ?: $this->attributes['total_refund_note'];
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
|
|
public function market()
|
|
{
|
|
return $this->belongsTo(Market::class, 'market_id', 'id');
|
|
}
|
|
|
|
public function orders()
|
|
{
|
|
return $this->hasMany(Order::class, 'order_main_id', 'global_order_id');
|
|
}
|
|
|
|
public function orderGoods()
|
|
{
|
|
// firstKey是中间表联当前表的列,secondKey是远程表对应中间表的列,localKey是当前表关联中间表的列,secondLocalKey是中间表关联远程表的列
|
|
return $this->hasManyThrough(
|
|
OrderGoods::class,
|
|
Order::class,
|
|
'order_main_id',
|
|
'order_id',
|
|
'global_order_id',
|
|
'id'
|
|
);
|
|
}
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id', 'id');
|
|
}
|
|
|
|
public function employees()
|
|
{
|
|
return $this->belongsTo(Employees::class, 'horseman_id', 'id');
|
|
}
|
|
}
|