|
@@ -6,7 +6,8 @@ import {
|
|
|
PaymentQueryParams,
|
|
PaymentQueryParams,
|
|
|
PaymentQueryResponse,
|
|
PaymentQueryResponse,
|
|
|
CreatePaymentOrderParams,
|
|
CreatePaymentOrderParams,
|
|
|
- CreatePaymentOrderResponse
|
|
|
|
|
|
|
+ CreatePaymentOrderResponse,
|
|
|
|
|
+ UserQueryOrderResponse
|
|
|
} from '../dto/payment.dto'
|
|
} from '../dto/payment.dto'
|
|
|
import axios from 'axios'
|
|
import axios from 'axios'
|
|
|
import crypto from 'crypto'
|
|
import crypto from 'crypto'
|
|
@@ -174,7 +175,7 @@ export class PaymentService {
|
|
|
type: 'alipay',
|
|
type: 'alipay',
|
|
|
out_trade_no,
|
|
out_trade_no,
|
|
|
notify_url: `https://9g15.vip/api/payment/notify`,
|
|
notify_url: `https://9g15.vip/api/payment/notify`,
|
|
|
- return_url: `https://yz1df.cc/account`,
|
|
|
|
|
|
|
+ return_url: `https://yz1df.cc/account?pay=true`,
|
|
|
name: `${params.type} 订单`,
|
|
name: `${params.type} 订单`,
|
|
|
money: price,
|
|
money: price,
|
|
|
client_ip: params.ip
|
|
client_ip: params.ip
|
|
@@ -274,6 +275,73 @@ export class PaymentService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ async userQueryOrder(userId: number, orderNo?: string): Promise<UserQueryOrderResponse> {
|
|
|
|
|
+ const responseData: UserQueryOrderResponse = {
|
|
|
|
|
+ orderNo: orderNo || '',
|
|
|
|
|
+ msg: '',
|
|
|
|
|
+ status: 0
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ let targetOrderNo = orderNo
|
|
|
|
|
+ let incomeRecord
|
|
|
|
|
+
|
|
|
|
|
+ if (!orderNo) {
|
|
|
|
|
+ // 查询用户最近12小时内的订单
|
|
|
|
|
+ const twelveHoursAgo = new Date(Date.now() - 12 * 60 * 60 * 1000)
|
|
|
|
|
+ const recentRecord = await this.incomeRecordsService.findRecentByUserId(userId, twelveHoursAgo)
|
|
|
|
|
+
|
|
|
|
|
+ if (!recentRecord) {
|
|
|
|
|
+ responseData.msg = '没有找到最近的订单'
|
|
|
|
|
+ return responseData
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ targetOrderNo = recentRecord.orderNo
|
|
|
|
|
+ incomeRecord = recentRecord
|
|
|
|
|
+ responseData.orderNo = targetOrderNo
|
|
|
|
|
+ } else {
|
|
|
|
|
+ incomeRecord = await this.incomeRecordsService.findByOrderNo(orderNo, userId)
|
|
|
|
|
+ if (!incomeRecord) {
|
|
|
|
|
+ responseData.msg = '没有找到订单'
|
|
|
|
|
+ return responseData
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!targetOrderNo) {
|
|
|
|
|
+ responseData.msg = '订单号无效'
|
|
|
|
|
+ return responseData
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const result = await this.queryOrder({ out_trade_no: targetOrderNo })
|
|
|
|
|
+ if (result.code !== 1) {
|
|
|
|
|
+ responseData.msg = '没有找到支付订单'
|
|
|
|
|
+ return responseData
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (result.status !== 1) {
|
|
|
|
|
+ responseData.msg = '订单未支付'
|
|
|
|
|
+ return responseData
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (incomeRecord.status === false) {
|
|
|
|
|
+ await this.incomeRecordsService.update({
|
|
|
|
|
+ id: incomeRecord.id,
|
|
|
|
|
+ status: true
|
|
|
|
|
+ })
|
|
|
|
|
+ responseData.msg = '订单支付成功'
|
|
|
|
|
+ responseData.status = 1
|
|
|
|
|
+ } else {
|
|
|
|
|
+ responseData.msg = '订单已支付'
|
|
|
|
|
+ responseData.status = 1
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ this.app.log.error('Failed to query user order:', error)
|
|
|
|
|
+ responseData.msg = '查询订单失败'
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return responseData
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private getVipLevelByOrderType(orderType: OrderType): VipLevel {
|
|
private getVipLevelByOrderType(orderType: OrderType): VipLevel {
|
|
|
return PaymentService.ORDER_TYPE_TO_VIP_LEVEL_MAP[orderType] ?? VipLevel.FREE
|
|
return PaymentService.ORDER_TYPE_TO_VIP_LEVEL_MAP[orderType] ?? VipLevel.FREE
|
|
|
}
|
|
}
|