|
@@ -11,6 +11,7 @@ class PayService extends CrudService {
|
|
|
super(ctx, 'pay');
|
|
|
this.httpUtil = this.ctx.service.util.httpUtil;
|
|
|
this.appConfig = this.app.config.wxPayConfig;
|
|
|
+ this.goodsModel = this.ctx.model.Shop.Goods;
|
|
|
this.orderModel = this.ctx.model.Trade.Order;
|
|
|
this.dictDataModel = this.ctx.model.Dev.DictData;
|
|
|
this.payOrderReturnUrl = this.app.config.payReturn.order;
|
|
@@ -87,10 +88,13 @@ class PayService extends CrudService {
|
|
|
|
|
|
async withoutPay({ order_id }) {
|
|
|
try {
|
|
|
+ const orderData = await this.orderModel.findById(order_id);
|
|
|
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.addSell(orderData, this.tran);
|
|
|
await this.tran.run();
|
|
|
} catch (error) {
|
|
|
console.error(error);
|
|
@@ -134,6 +138,8 @@ class PayService extends CrudService {
|
|
|
await this.tran.run();
|
|
|
// 拆订单
|
|
|
await this.ctx.service.trade.orderDetail.create({ order_id: orderData._id }, this.tran);
|
|
|
+ // 加销量
|
|
|
+ await this.addSell(orderData, this.tran);
|
|
|
await this.tran.run();
|
|
|
} catch (error) {
|
|
|
console.error(error);
|
|
@@ -159,6 +165,25 @@ class PayService extends CrudService {
|
|
|
this.tran.clean();
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 加销量
|
|
|
+ * @param {Object} order 支付订单数据
|
|
|
+ * @param {Transaction} tran 数据库事务
|
|
|
+ */
|
|
|
+ async addSell(order, tran) {
|
|
|
+ const goods = _.get(order, 'goods', []);
|
|
|
+ for (const sg of goods) {
|
|
|
+ const sgList = _.get(sg, 'goods', []);
|
|
|
+ for (const g of sgList) {
|
|
|
+ const buy_num = _.get(g, 'buy_num', 0);
|
|
|
+ const goods_id = _.get(goods, '_id');
|
|
|
+ if (!goods_id) return;
|
|
|
+ const goodsInfo = await this.goodsModel.findById(goods_id, { sell_num: 1 });
|
|
|
+ const newSell_num = this.ctx.plus(buy_num, _.get(goodsInfo, 'sell_num'));
|
|
|
+ tran.update('Goods', goods_id, { sell_num: newSell_num });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 关闭订单
|