123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace app\common\model;
- use think\Model;
- use traits\model\SoftDelete;
- use app\common\Enum\OrderEnum;
- /**
- * 父订单模型
- * 仅用于数据存储,不包含业务逻辑
- */
- class ParentOrder extends Model
- {
- use SoftDelete;
- // 表名
- protected $name = 'shop_parent_order';
-
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
-
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = 'deletetime';
- // 追加属性
- protected $append = [
- 'order_status_text',
- 'pay_status_text'
- ];
- /**
- * 获取订单状态文本
- */
- public function getOrderStatusTextAttr($value, $data)
- {
- return OrderEnum::getOrderStatusText($data['order_status']);
- }
- /**
- * 获取支付状态文本
- */
- public function getPayStatusTextAttr($value, $data)
- {
- $statusMap = [
- 0 => '未支付',
- 1 => '已支付'
- ];
- return $statusMap[$data['pay_status']] ?? '未知';
- }
- /**
- * 关联用户
- */
- public function user()
- {
- return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- /**
- * 关联子订单
- */
- public function childOrders()
- {
- return $this->hasMany('Order', 'parent_order_id', 'id');
- }
- }
|