90 lines
2.4 KiB
PHP
90 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace app\common\model;
|
|
|
|
use think\Model;
|
|
|
|
|
|
class Orders extends Model
|
|
{
|
|
|
|
|
|
// 表名
|
|
protected $name = 'orders';
|
|
|
|
// 自动写入时间戳字段
|
|
protected $autoWriteTimestamp = 'integer';
|
|
|
|
// 定义时间戳字段名
|
|
protected $createTime = 'createtime';
|
|
protected $updateTime = 'updatetime';
|
|
protected $deleteTime = false;
|
|
|
|
// 追加属性
|
|
protected $append = [
|
|
'order_type_text',
|
|
'order_status_text',
|
|
'auto_cancel_time_text'
|
|
];
|
|
|
|
|
|
public function getOrderTypeList()
|
|
{
|
|
return ['0' => __('Order_type 0'), '1' => __('Order_type 1')];
|
|
}
|
|
|
|
public function getOrderStatusList()
|
|
{
|
|
return ['0' => __('Order_status 0'), '10' => __('Order_status 10'), '20' => __('Order_status 20'), '30' => __('Order_status 30'), '40' => __('Order_status 40'), '50' => __('Order_status 50')];
|
|
}
|
|
|
|
|
|
public function getOrderTypeTextAttr($value, $data)
|
|
{
|
|
$value = $value ? $value : (isset($data['order_type']) ? $data['order_type'] : '');
|
|
$list = $this->getOrderTypeList();
|
|
return isset($list[$value]) ? $list[$value] : '';
|
|
}
|
|
|
|
|
|
public function getOrderStatusTextAttr($value, $data)
|
|
{
|
|
$value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
|
|
$list = $this->getOrderStatusList();
|
|
return isset($list[$value]) ? $list[$value] : '';
|
|
}
|
|
|
|
|
|
public function getAutoCancelTimeTextAttr($value, $data)
|
|
{
|
|
$value = $value ? $value : (isset($data['auto_cancel_time']) ? $data['auto_cancel_time'] : '');
|
|
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
|
|
}
|
|
|
|
protected function setAutoCancelTimeAttr($value)
|
|
{
|
|
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
|
|
}
|
|
|
|
public function orderGoods(): \think\model\relation\HasMany
|
|
{
|
|
return $this->hasMany('app\common\model\order\Goods', 'order_no', 'order_no');
|
|
}
|
|
|
|
public function orderPayment(): \think\model\relation\HasMany
|
|
{
|
|
return $this->hasMany('app\common\model\order\Payment', 'order_no', 'order_no');
|
|
}
|
|
|
|
public function Demand()
|
|
{
|
|
return $this->belongsTo('Demands', 'parent_order_no', 'parent_order_no');
|
|
}
|
|
|
|
public function orderShip(): \think\model\relation\HasOne
|
|
{
|
|
return $this->hasOne('app\common\model\order\Ships', 'order_no', 'order_no');
|
|
}
|
|
|
|
}
|