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

135 lines
3.3 KiB

10 months ago
<?php
declare (strict_types=1);
namespace app\common\model\server;
9 months ago
use app\common\enum\payment\Method;
10 months ago
use app\common\enum\ServerEnum;
use app\common\model\UploadFile;
use cores\BaseModel;
8 months ago
use think\model\concern\SoftDelete;
10 months ago
use think\model\relation\BelongsTo;
use think\model\relation\HasOne;
use think\Paginator;
class Order extends BaseModel
{
8 months ago
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
10 months ago
// 定义表名
protected $name = 'server_order';
// 定义主键
protected $pk = 'order_id';
/**
* 追加字段
* @var array
*/
protected $append = [
'order_status_text', // 订单状态文字描述
9 months ago
'pay_method_text', //支付方式
10 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 '未知';
10 months ago
}
/**
* 获取器:订单状态文字描述
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);
}
8 months ago
public function remove($orderId): bool
{
if (static::destroy($orderId)) {
return true;
}
return false;
}
10 months ago
}