|
@@ -73,6 +73,10 @@ class PayService extends CrudService {
|
|
|
await this.tran.rollback();
|
|
|
console.error(error);
|
|
|
}
|
|
|
+ if (totalMoney <= 0) {
|
|
|
+ // 小于等于0的支付金额,不需要付款
|
|
|
+ return { needPay: false };
|
|
|
+ }
|
|
|
if (type === '0') {
|
|
|
res = await this.create(payData);
|
|
|
res = this.preparToUniAppWxPay(res);
|
|
@@ -80,6 +84,23 @@ class PayService extends CrudService {
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
+ async withoutPay({ order_id }) {
|
|
|
+ try {
|
|
|
+ this.tran.update('Order', order_id, { status: '1' });
|
|
|
+ await this.tran.run();
|
|
|
+ // 拆订单
|
|
|
+ await this.ctx.service.trade.orderDetail.create({ order_id }, this.tran);
|
|
|
+ await this.tran.run();
|
|
|
+ } catch (error) {
|
|
|
+ console.error(error);
|
|
|
+ await this.tran.rollback();
|
|
|
+ throw new BusinessError(ErrorCode.SERVICE_FAULT, '支付回调:修改失败');
|
|
|
+ } finally {
|
|
|
+ // 清空事务
|
|
|
+ this.tran.clean();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 支付订单回调函数
|
|
|
* @param {Object} body 请求地址参数
|
|
@@ -112,8 +133,6 @@ class PayService extends CrudService {
|
|
|
await this.tran.run();
|
|
|
// 拆订单
|
|
|
await this.ctx.service.trade.orderDetail.create({ order_id: orderData._id }, this.tran);
|
|
|
- // 加积分
|
|
|
- await this.ctx.service.user.point.afterPayOrder({ order_id: orderData._id, openid }, this.tran);
|
|
|
await this.tran.run();
|
|
|
} catch (error) {
|
|
|
console.error(error);
|
|
@@ -190,7 +209,10 @@ class PayService extends CrudService {
|
|
|
if (!detail) continue;
|
|
|
totalDiscount = this.ctx.plus(totalDiscount, Object.values(detail).reduce((p, n) => this.ctx.plus(p, n), 0));
|
|
|
}
|
|
|
+ console.log(total, totalDiscount);
|
|
|
total = this.ctx.minus(total, totalDiscount);
|
|
|
+ console.log(total);
|
|
|
+ if (total <= 0) total = 0;
|
|
|
}
|
|
|
return total;
|
|
|
}
|