|
@@ -70,7 +70,7 @@ export class OrderService extends BaseService {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
getMerchantId(params) {
|
|
|
let merchantId;
|
|
@@ -130,7 +130,7 @@ export class OrderService extends BaseService {
|
|
|
// 检查对应钱包余额
|
|
|
const wallet = await this.walletEntity.findOne({
|
|
|
where: {
|
|
|
- merchantId: merchant.id.toString(),
|
|
|
+ merchantId: merchant.mchId,
|
|
|
channel: channel,
|
|
|
currency: currency,
|
|
|
},
|
|
@@ -148,7 +148,7 @@ export class OrderService extends BaseService {
|
|
|
// 查询对应客户
|
|
|
const customer = await this.customerEntity.findOne({
|
|
|
where: {
|
|
|
- merchantId: merchant.id.toString(),
|
|
|
+ merchantId: merchant.mchId,
|
|
|
},
|
|
|
});
|
|
|
if (!customer) {
|
|
@@ -157,7 +157,7 @@ export class OrderService extends BaseService {
|
|
|
const payeeAddress = await this.payeeAddressEntity.findOne({
|
|
|
where: {
|
|
|
id: payee_address_id,
|
|
|
- merchantId: merchant.id.toString(),
|
|
|
+ merchantId: merchant.mchId,
|
|
|
},
|
|
|
});
|
|
|
if (!payeeAddress) {
|
|
@@ -193,7 +193,7 @@ export class OrderService extends BaseService {
|
|
|
orderData = await this.generateOrderDataBySunpay(type, {
|
|
|
...params,
|
|
|
amount: amount,
|
|
|
- merchantId: merchant.id.toString(),
|
|
|
+ merchantId: merchant.mchId,
|
|
|
customerId: customer.customer_id,
|
|
|
beneficiary_address_id: payeeAddress.beneficiary_address_id,
|
|
|
cryptoAddress: payeeAddress.address,
|
|
@@ -209,7 +209,7 @@ export class OrderService extends BaseService {
|
|
|
await this.walletEntity.save(wallet);
|
|
|
// 1. 创建订单
|
|
|
const order = await this.orderEntity.save({
|
|
|
- merchantId: merchant.id.toString(),
|
|
|
+ merchantId: merchant.mchId,
|
|
|
channel: channel,
|
|
|
customer_id: customer?.id.toString(),
|
|
|
order_type: 'WITHDRAW',
|
|
@@ -270,7 +270,7 @@ export class OrderService extends BaseService {
|
|
|
if (amount < 100) {
|
|
|
throw new CoolCommException('金额不能小于100');
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
// 检查对应钱包余额
|
|
|
const wallet = await this.walletEntity.findOne({
|
|
@@ -411,7 +411,7 @@ export class OrderService extends BaseService {
|
|
|
.setChannel(channel)
|
|
|
.confirmPayOut(orderInfo.out_order_no);
|
|
|
return ''
|
|
|
- }
|
|
|
+ }
|
|
|
async openApiCancel(orderNo) {
|
|
|
const channel = 'SUBPAY'
|
|
|
// 查询订单是否存在
|
|
@@ -444,7 +444,7 @@ export class OrderService extends BaseService {
|
|
|
}
|
|
|
|
|
|
return orderInfo
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private generateOrderNo() {
|
|
@@ -487,14 +487,14 @@ export class OrderService extends BaseService {
|
|
|
manager.findOne(WalletEntity, {
|
|
|
where: {
|
|
|
id: from_wallet_id,
|
|
|
- merchantId: merchant.id.toString(),
|
|
|
+ merchantId: merchant.mchId,
|
|
|
},
|
|
|
lock: { mode: 'pessimistic_write' },
|
|
|
}),
|
|
|
manager.findOne(WalletEntity, {
|
|
|
where: {
|
|
|
id: to_wallet_id,
|
|
|
- merchantId: merchant.id.toString(),
|
|
|
+ merchantId: merchant.mchId,
|
|
|
},
|
|
|
lock: { mode: 'pessimistic_write' },
|
|
|
}),
|
|
@@ -504,7 +504,7 @@ export class OrderService extends BaseService {
|
|
|
throw new CoolCommException('钱包不存在');
|
|
|
}
|
|
|
|
|
|
- if (fromWallet.balance < amount) {
|
|
|
+ if (fromWallet.balance < Number(amount)) {
|
|
|
throw new CoolCommException('余额不足');
|
|
|
}
|
|
|
const availableBalance = this.amountCalculator.subtract(
|
|
@@ -512,7 +512,7 @@ export class OrderService extends BaseService {
|
|
|
fromWallet.frozenAmount
|
|
|
);
|
|
|
// 如果钱包金额减去划转金额小于0 则不能划转
|
|
|
- if (availableBalance < amount) {
|
|
|
+ if (availableBalance < Number(amount)) {
|
|
|
throw new CoolCommException('可用余额不足');
|
|
|
}
|
|
|
if (fromWallet.channel !== toWallet.channel) {
|
|
@@ -532,13 +532,13 @@ export class OrderService extends BaseService {
|
|
|
}
|
|
|
|
|
|
const convertedAmount = this.amountCalculator.multiply(
|
|
|
- amount,
|
|
|
+ Number(amount),
|
|
|
changeRate.rate
|
|
|
);
|
|
|
|
|
|
// 创建划转订单
|
|
|
const order = await manager.save(OrderEntity, {
|
|
|
- merchantId: merchant.id.toString(),
|
|
|
+ merchantId: merchant.mchId,
|
|
|
order_no: this.generateOrderNo(),
|
|
|
out_order_no: this.generateOrderNo(),
|
|
|
channel: toWallet.channel,
|
|
@@ -603,10 +603,10 @@ export class OrderService extends BaseService {
|
|
|
const amount = this.getOrderFee(order)
|
|
|
if (order.status == 'SUCCESS') {
|
|
|
await this.customeCallback('SUCCESS', biz_type, {
|
|
|
- order_no: order.out_order_no,
|
|
|
- out_order_no: order.order_no,
|
|
|
- out_user_id: order.merchantId,
|
|
|
- amount: order.amount,
|
|
|
+ order_no: order.out_order_no,
|
|
|
+ out_order_no: order.order_no,
|
|
|
+ out_user_id: order.merchantId,
|
|
|
+ amount: order.amount,
|
|
|
fee: Number(amount) - order.amount,
|
|
|
currency: order.currency
|
|
|
})
|
|
@@ -617,10 +617,10 @@ export class OrderService extends BaseService {
|
|
|
}
|
|
|
if (order.status == 'FAILED') {
|
|
|
await this.customeCallback('FAIL',biz_type, {
|
|
|
- order_no: order.out_order_no,
|
|
|
- out_order_no: order.order_no,
|
|
|
- out_user_id: order.merchantId,
|
|
|
- amount: order.amount,
|
|
|
+ order_no: order.out_order_no,
|
|
|
+ out_order_no: order.order_no,
|
|
|
+ out_user_id: order.merchantId,
|
|
|
+ amount: order.amount,
|
|
|
fee: Number(amount) - order.amount,
|
|
|
currency: order.currency
|
|
|
})
|
|
@@ -829,11 +829,11 @@ export class OrderService extends BaseService {
|
|
|
wallet.frozenAmount = newFrozenAmount;
|
|
|
await manager.save(wallet);
|
|
|
this.customeCallback('SUCCESS','PAYOUT', {
|
|
|
- order_no: order.out_order_no,
|
|
|
- out_order_no: order.order_no,
|
|
|
- out_user_id: order.merchantId,
|
|
|
- amount: order.amount,
|
|
|
- fee: amount - order.amount,
|
|
|
+ order_no: order.out_order_no,
|
|
|
+ out_order_no: order.order_no,
|
|
|
+ out_user_id: order.merchantId,
|
|
|
+ amount: order.amount,
|
|
|
+ fee: amount - order.amount,
|
|
|
currency: order.currency
|
|
|
})
|
|
|
}
|
|
@@ -854,13 +854,13 @@ export class OrderService extends BaseService {
|
|
|
method: 'post',
|
|
|
url: orderInfo.webhook_url,
|
|
|
data: {
|
|
|
- biz_status,
|
|
|
+ biz_status,
|
|
|
biz_type,
|
|
|
data: {
|
|
|
- order_no,
|
|
|
- out_order_no,
|
|
|
- out_user_id,
|
|
|
- amount,
|
|
|
+ order_no,
|
|
|
+ out_order_no,
|
|
|
+ out_user_id,
|
|
|
+ amount,
|
|
|
fee,
|
|
|
currency
|
|
|
}
|