Files
code-bang/backend/application/common/model/Orders.php
T
2026-10-14 14:44:01 +08:00

103 lines
2.9 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',
'commission_status_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 getCommissionStatusList()
{
return ['0' => __('Commission_status 0'), '1' => __('Commission_status 1'), '2' => __('Commission_status 2')];
}
public function getCommissionStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['commission_status']) ? $data['commission_status'] : '');
$list = $this->getCommissionStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
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');
}
}