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

121 lines
3.0 KiB

11 months ago
<?php
declare (strict_types=1);
namespace app\common\model\server;
9 months ago
use app\common\enum\payment\Method;
11 months ago
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', // 订单状态文字描述
9 months ago
'pay_method_text', //支付方式
11 months ago
];
public function serve(): BelongsTo
{
9 months ago
return $this->belongsTo(Server::class, 'server_id', 'server_id');
}
public function getPayMethodTextAttr($value, $data): string
{
// 订单状态
$result = Method::data();
if (!empty($result[$data['pay_method']]['name'])) {
return $result[$data['pay_method']]['name'];
}
return '未知';
11 months ago
}
/**
* 获取器:订单状态文字描述
11 months ago
* @param $value
* @param $data
11 months ago
* @return string
*/
public function getOrderStatusTextAttr($value, $data): string
{
// 订单状态
11 months ago
$result = ServerEnum::data();
if (!empty($result[$data['order_status']]['name'])) {
return $result[$data['order_status']]['name'];
}
return '未知';
11 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);
}
}