with(['image', 'user']) ->where($where) ->where('dealer_id', '=', $userId) ->where('is_delete', '=', 0) ->order(['create_time' => 'desc']) ->paginate($listRows); } elseif (UserService::isStore()) { // 店主 return $this->with(['image', 'user', 'dealer']) ->where($where) ->where('is_delete', '=', 0) ->order(['create_time' => 'desc']) ->paginate($listRows); } else { return $this->with(['image', 'dealer']) ->where($where) ->where('user_id', '=', $userId) ->where('is_delete', '=', 0) ->order(['create_time' => 'desc']) ->paginate($listRows); } } /** * 获取用户订单详情(仅订单记录) * @param int $orderId * @param array $with * @param bool $onlyCurrentUser 只查询当前登录用户的记录 * @return array|Order|null * @throws BaseException */ public static function getDetail(int $orderId, array $with = [], bool $onlyCurrentUser = true) { // 查询条件 $where = ['order_id' => $orderId]; $onlyCurrentUser && $where['user_id'] = UserService::getCurrentLoginUserId(); // 查询订单记录 $order = static::detail($where, $with); empty($order) && throwError('订单不存在'); return $order; } /** * 待支付订单详情 * @param string $orderNo 订单号 * @return null|static */ public static function getPayDetail(string $orderNo): ?Order { $where = ['order_no' => $orderNo, 'is_delete' => 0]; return self::detail($where, ['user']); } /** * @notes:获取未支付的订单详情(用于订单支付) * @param int $orderId 订单ID * @return array * @throws BaseException * @throws DataNotFoundException * @throws DbException * @throws ModelNotFoundException * @author: wanghousheng */ public static function getUnpaidOrderDetail(int $orderId): array { // 获取订单详情 $orderInfo = static::getDetail($orderId); // 验证订单状态 if ($orderInfo['order_status'] != ServerEnum::APPLYPAY || $orderInfo['pay_status'] == PayStatus::SUCCESS) { throwError('当前订单状态不允许支付'); } // 未支付订单的过期时间 $orderCloseTime = SettingModel::getOrderCloseTime() * 60 * 60; // 订单超时截止时间 $expirationTime = strtotime($orderInfo['create_time']) + $orderCloseTime; if ($orderCloseTime > 0 && $expirationTime <= time()) { throwError('当前订单支付已超时,请重新下单'); } // 仅返回需要的数据 return [ 'orderId' => $orderInfo['order_id'], 'order_no' => $orderInfo['order_no'], 'pay_price' => $orderInfo['pay_price'], 'pay_status' => $orderInfo['pay_status'], 'order_status' => $orderInfo['order_status'], 'create_time' => $orderInfo['create_time'], 'showExpiration' => $orderCloseTime > 0, 'expirationTime' => format_time($expirationTime), ]; } }