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.
yanzong/app/common/model/RecoveryOrder.php

85 lines
2.0 KiB

<?php
declare (strict_types=1);
namespace app\common\model;
use app\api\model\Server\ServerRecovery;
use app\api\model\store\Shop;
use app\common\enum\RecoveryStatusEnum;
use app\common\enum\RecoveryTypeEnum;
use cores\BaseModel;
use think\model\relation\HasMany;
use think\model\relation\HasOne;
class RecoveryOrder extends BaseModel
{
// 定义表名
protected $name = 'server_recovery_order';
// 定义主键
protected $pk = 'order_id';
/**
* 追加字段
* @var array
*/
protected $append = [
'order_status_text', //状态
'recovery_type_text', //回收方式
];
/**
* 关联图片表
* @return HasMany
*/
public function images(): HasMany
{
return $this->hasMany(RecoveryImage::class, 'order_id')->order(['id']);
}
public function getOrderStatusTextAttr($value, $data)
{
$result = RecoveryStatusEnum::data();
if (!empty($result[$data['order_status']]['name'])) {
return $result[$data['order_status']]['name'];
}
return '未知';
}
public function getRecoveryTypeTextAttr($value, $data)
{
$result = RecoveryTypeEnum::data();
if (!empty($result[$data['recovery_type']]['name'])) {
return $result[$data['recovery_type']]['name'];
}
return '未知';
}
/**
* @notes:详情
* @param $where
* @param array $with
* @return RecoveryOrder|array|null
* @author: wanghousheng
*/
public static function detail($where, array $with = [])
{
return static::get($where, $with);
}
public function user(): HasOne
{
return $this->hasOne(User::class, 'user_id', 'user_id');
}
public function shop(): HasOne
{
return $this->hasOne(Shop::class, 'shop_id', 'shop_id');
}
public function recovery(): HasOne
{
return $this->hasOne(ServerRecovery::class, 'recovery_id', 'recovery_id');
}
}