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/server/Order.php

109 lines
2.7 KiB

10 months ago
<?php
declare (strict_types=1);
namespace app\common\model\server;
use app\common\enum\ServerEnum;
use app\common\model\UploadFile;
use cores\BaseModel;
use think\model\relation\BelongsTo;
use think\model\relation\HasOne;
use think\Paginator;
class Order extends BaseModel
{
// 定义表名
protected $name = 'server_order';
// 定义主键
protected $pk = 'order_id';
/**
* 追加字段
* @var array
*/
protected $append = [
'order_status_text', // 订单状态文字描述
];
public function serve(): BelongsTo
{
return $this->belongsTo(Server::class, 'id', 'server_id');
}
/**
* 获取器:订单状态文字描述
10 months ago
* @param $value
* @param $data
10 months ago
* @return string
*/
public function getOrderStatusTextAttr($value, $data): string
{
// 订单状态
10 months ago
$result = ServerEnum::data();
if (!empty($result[$data['order_status']]['name'])) {
return $result[$data['order_status']]['name'];
}
return '未知';
10 months ago
}
/**
* 图片
* @return HasOne
*/
public function image(): HasOne
{
return $this->hasOne(UploadFile::class, 'file_id', 'server_image_id')
->bind(['server_image' => 'preview_url']);
}
/**
* 关联用户表
* @return BelongsTo
*/
public function user(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\$module\\model\\User")
->bind(['user_name' => 'nick_name', 'user_mobile' => 'mobile']);
}
public function dealer(): BelongsTo
{
$module = self::getCalledModule();
return $this->belongsTo("app\\$module\\model\\User", 'dealer_id', 'user_id')
->bind(['dealer_name' => 'nick_name', 'dealer_mobile' => 'mobile']);
}
/**
* @notes:服务订单列表
* @param array $where
* @param int $listRows
* @return Paginator
* @author: wanghousheng
*/
public function getList(array $where, int $listRows = 15): Paginator
{
$where = $this->setQueryDefaultValue($where);
return $this->with(['image', 'dealer'])
->alias('a')
->join('user b', 'b.user_id = a.user_id')
->where($where)
->order(['create_time'])
->field('a.*,b.mobile as user_mobile,b.nick_name as user_nick_name')
->paginate($listRows);
}
/**
* @notes:订单详情
* @param $where
* @param array $with
* @return Order|array|null
* @author: wanghousheng
*/
public static function detail($where, array $with = [])
{
return static::get($where, $with);
}
}