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

98 lines
2.2 KiB

10 months ago
<?php
declare (strict_types=1);
namespace app\common\model;
10 months ago
use app\api\model\Server\ServerRecovery;
10 months ago
use app\api\model\store\Shop;
10 months ago
use app\common\enum\RecoveryStatusEnum;
use app\common\enum\RecoveryTypeEnum;
use cores\BaseModel;
8 months ago
use think\model\concern\SoftDelete;
10 months ago
use think\model\relation\HasMany;
10 months ago
use think\model\relation\HasOne;
10 months ago
class RecoveryOrder extends BaseModel
{
8 months ago
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
10 months ago
// 定义表名
10 months ago
protected $name = 'server_recovery_order';
10 months ago
// 定义主键
10 months ago
protected $pk = 'order_id';
10 months ago
/**
* 追加字段
* @var array
*/
protected $append = [
'order_status_text', //状态
'recovery_type_text', //回收方式
];
/**
* 关联图片表
* @return HasMany
*/
public function images(): HasMany
{
8 months ago
return $this->hasMany(RecoveryImage::class, 'order_id')->order(['id']);
10 months ago
}
10 months ago
10 months ago
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);
}
8 months ago
public function user(): HasOne
{
return $this->hasOne(User::class, 'user_id', 'user_id');
}
10 months ago
public function shop(): HasOne
{
return $this->hasOne(Shop::class, 'shop_id', 'shop_id');
}
8 months ago
public function recovery(): HasOne
{
return $this->hasOne(ServerRecovery::class, 'recovery_id', 'recovery_id');
}
8 months ago
public function remove($orderId): bool
{
if (static::destroy($orderId)) {
return true;
}
return false;
}
10 months ago
}