|
@@ -4,7 +4,7 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
|
|
|
const _ = require('lodash');
|
|
|
const assert = require('assert');
|
|
|
const Transaction = require('mongoose-transactions');
|
|
|
-
|
|
|
+const moment = require('moment');
|
|
|
//
|
|
|
class PayService extends CrudService {
|
|
|
constructor(ctx) {
|
|
@@ -14,6 +14,8 @@ class PayService extends CrudService {
|
|
|
this.orderModel = this.ctx.model.Trade.Order;
|
|
|
this.dictDataModel = this.ctx.model.Dev.DictData;
|
|
|
this.payOrderReturnUrl = this.app.config.payReturn.order;
|
|
|
+ this.userModel = this.ctx.model.User.User;
|
|
|
+ this.pointModel = this.ctx.model.User.Point;
|
|
|
this.wxDomain = _.get(this.app, 'config.httpPrefix.wechat');
|
|
|
this.tran = new Transaction();
|
|
|
}
|
|
@@ -108,6 +110,25 @@ class PayService extends CrudService {
|
|
|
payData.result = result;
|
|
|
// 修改状态
|
|
|
await this.orderModel.updateOne(query, { pay: payData, status: '1' });
|
|
|
+
|
|
|
+ // 10块钱给1积分,不到10块不给
|
|
|
+ const pay_money = _.get(orderData, 'pay.pay_money');
|
|
|
+ if (!_.isNumber(pay_money) || pay_money < 10) return;
|
|
|
+ const point = _.floor(pay_money / 10);
|
|
|
+ // 添加积分
|
|
|
+ const user = await this.userModel.findOne({ openid });
|
|
|
+ if (!user) {
|
|
|
+ console.error('未找到用户信息----添加积分');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const customer = _.get(user, '_id');
|
|
|
+ const pointData = {
|
|
|
+ customer,
|
|
|
+ point,
|
|
|
+ time: moment().format('YYYY-MM-D HH:mm:ss'),
|
|
|
+ source: '0',
|
|
|
+ };
|
|
|
+ await this.pointModel.create(pointData);
|
|
|
}
|
|
|
|
|
|
/**
|