belongsTo(Server::class, 'id', 'server_id'); } /** * 获取器:订单状态文字描述 * @param $value * @param $data * @return string */ public function getOrderStatusTextAttr($value, $data): string { // 订单状态 $result = ServerEnum::data(); if (!empty($result[$data['order_status']]['name'])) { return $result[$data['order_status']]['name']; } return '未知'; } /** * 图片 * @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); } }