lrf402788946 4 years ago
parent
commit
3fdfb08003
3 changed files with 13 additions and 14 deletions
  1. 5 6
      app/service/card.js
  2. 3 3
      app/service/cash.js
  3. 5 5
      app/service/wxpay.js

+ 5 - 6
app/service/card.js

@@ -54,7 +54,6 @@ class CardService extends CrudService {
   async create(data) {
     // 先创建用户
     // 1,检查手机号是否存在
-    console.log(moment().format('YYYY-MM-DD HH:mm:ss'));
     const { password, mobile, set, r_mobile } = data;
     const is_exists = await this.model.count({ mobile });
     if (is_exists) { throw new BusinessError(ErrorCode.DATA_EXISTED, '手机号已存在'); }
@@ -62,7 +61,7 @@ class CardService extends CrudService {
     let user;
     try {
       data.password = { secret: password };
-      user = await this.model.create(data);
+      user = await this.model.create({ ...data, create_time: moment().format('YYYY-MM-DD HH:mm:ss') });
       user = _.omit(user, [ 'password' ]);
     } catch (e) {
       this.ctx.logger.error(e);
@@ -121,7 +120,7 @@ class CardService extends CrudService {
     record.opera = '1';
     record.params = { name: user.name, mobile: user.mobile, level: user.level };
     try {
-      await this.record.create(record);
+      await this.record.create({ ...record, create_time: moment().format('YYYY-MM-DD HH:mm:ss') });
     } catch (error) {
       this.logger.error(`line-121-积分记录添加失败${JSON.stringify(record)}`);
     }
@@ -202,7 +201,7 @@ class CardService extends CrudService {
           record.points = this.car_point;
           record.opera = '2';
           try {
-            await this.record.create(record);
+            await this.record.create({ ...record, create_time: moment().format('YYYY-MM-DD HH:mm:ss') });
           } catch (error) {
             this.logger.error(`line-202-积分记录添加失败${JSON.stringify(record)}`);
           }
@@ -250,7 +249,7 @@ class CardService extends CrudService {
       try {
         record.points = 20;
         record.opera = '3';
-        await this.record.create(record);
+        await this.record.create({ ...record, create_time: moment().format('YYYY-MM-DD HH:mm:ss') });
       } catch (error) {
         this.logger.error(`line-250-积分记录添加失败${JSON.stringify(record)}`);
       }
@@ -282,7 +281,7 @@ class CardService extends CrudService {
       try {
         record.points = points;
         record.opera = '4';
-        await this.record.create(record);
+        await this.record.create({ ...record, create_time: moment().format('YYYY-MM-DD HH:mm:ss') });
       } catch (error) {
         this.logger.error(`line-282-积分记录添加失败${JSON.stringify(record)}`);
       }

+ 3 - 3
app/service/cash.js

@@ -2,7 +2,7 @@
 const { CrudService } = require('naf-framework-mongoose/lib/service');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
 const _ = require('lodash');
-
+const moment = require('moment');
 // 提现
 class CashService extends CrudService {
   constructor(ctx) {
@@ -25,14 +25,14 @@ class CashService extends CrudService {
       user.points = user.points - (i_point + _.ceil(i_point * 0.06));
       data.e_point = user.points;
     }
-    await this.model.create(data);
+    await this.model.create({ ...data, create_time: moment().format('YYYY-MM-DD HH:mm:ss') });
     await user.save();
     const record = _.pick(user, [ 'mobile', 'name' ]);
     record.points = -i_point;
     record.opera = '提现';
     record.params = { charge: -_.ceil(i_point * 0.06) };
     try {
-      await this.record.create(record);
+      await this.record.create({ ...record, create_time: moment().format('YYYY-MM-DD HH:mm:ss') });
     } catch (error) {
       this.logger.error(`积分记录添加失败${JSON.stringify(record)}`);
     }

+ 5 - 5
app/service/wxpay.js

@@ -76,21 +76,21 @@ class WxpayService extends CrudService {
     const { return_code, return_msg, result_code, err_code, err_code_des } = result;
     // 请求是否成功
     if (return_code !== 'SUCCESS') {
-      this.cashError.create({ word: `${return_code}:${return_msg}` });
+      this.cashError.create({ word: `${return_code}:${return_msg}`, create_time: moment().format('YYYY-MM-DD HH:mm:ss') });
       throw new BusinessError(ErrorCode.SERVICE_FAULT, `${return_code}:${return_msg}`);
     }
     // 请求失败具体问题
     if (result_code === 'FAIL') {
-      this.cashError.create({ word: `${err_code}:${err_code_des}` });
+      this.cashError.create({ word: `${err_code}:${err_code_des}`, create_time: moment().format('YYYY-MM-DD HH:mm:ss') });
       throw new BusinessError(ErrorCode.SERVICE_FAULT, `${err_code}:${err_code_des}`);
     }
     // 成功,添加记录=>减去积分
     const cashRecord = { name: user.name, mobile: user.mobile, b_point: opoints, i_point: points, e_point: pres };
     try {
-      await this.cashModel.create(cashRecord);
+      await this.cashModel.create({ ...cashRecord, create_time: moment().format('YYYY-MM-DD HH:mm:ss') });
     } catch (error) {
       const word = '添加提现记录失败!但钱已转出.';
-      this.cashError.create({ word });
+      this.cashError.create({ word, create_time: moment().format('YYYY-MM-DD HH:mm:ss') });
       throw new BusinessError(ErrorCode.SERVICE_FAULT, word);
     }
     user.points = pres;
@@ -98,7 +98,7 @@ class WxpayService extends CrudService {
       await user.save();
     } catch (error) {
       const word = '用户减掉已转出积分失败!钱已转出;提现记录已添加';
-      this.cashError.create({ word });
+      this.cashError.create({ word, create_time: moment().format('YYYY-MM-DD HH:mm:ss') });
       throw new BusinessError(ErrorCode.SERVICE_FAULT, word);
     }
     let newUser = await this.model.findById(id);