Ver Fonte

Merge branch 'dev'

lrf há 2 anos atrás
pai
commit
b621ee0da9

+ 1 - 1
app/controller/dev/config/.dictIndex.js

@@ -22,7 +22,7 @@ module.exports = {
         'meta.createdAt@start': 'meta.createdAt@start',
         'meta.createdAt@end': 'meta.createdAt@end',
         name: 'name',
-        code: 'code',
+        code: '%code%',
         status: 'status',
       },
       // options: {

+ 13 - 0
app/controller/user/cashOut.js

@@ -0,0 +1,13 @@
+'use strict';
+const meta = require('./config/.cashOut.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose-free/lib/controller');
+
+//
+class CashOutController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.user.cashOut;
+  }
+}
+module.exports = CrudController(CashOutController, meta);

+ 43 - 0
app/controller/user/config/.cashOut.js

@@ -0,0 +1,43 @@
+
+module.exports = {
+  create: {
+    requestBody: ['!money','!customer','!apply_time','!apply_reason','deal_person','exam_time','exam_reason','status'],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ['money','customer','apply_time','apply_reason','deal_person','exam_time','exam_reason','status'],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        "meta.createdAt@start": "meta.createdAt@start",
+        "meta.createdAt@end": "meta.createdAt@end",
+        'customer': 'customer' ,
+        'apply_time': 'apply_time' ,
+        'deal_person': 'deal_person' ,
+        'exam_time': 'exam_time' ,
+        'status': 'status' ,
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 31 - 0
app/model/user/cashOut.js

@@ -0,0 +1,31 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose-free/lib/model/meta-plugin');
+const MoneyPlugin = require('naf-framework-mongoose-free/lib/model/type-money-plugin');
+
+// 提现表
+const cashOut = {
+  customer: { type: String, required: false, zh: '申请人', ref: 'User.User' }, //
+  apply_time: { type: String, required: true, zh: '申请时间' }, //
+  apply_reason: { type: String, required: true, zh: '申请理由' }, //
+  deal_person: { type: String, required: false, zh: '审核处理人', ref: 'User.Admin' }, //
+  exam_time: { type: String, required: false, zh: '审核时间' }, //
+  exam_reason: { type: String, required: false, zh: '审核理由' }, //
+  status: { type: String, required: true, default: '0', zh: '审核状态' }, // 字典表:withdrawal_exam_status
+};
+const schema = new Schema(cashOut, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ customer: 1 });
+schema.index({ apply_time: 1 });
+schema.index({ deal_person: 1 });
+schema.index({ exam_time: 1 });
+schema.index({ status: 1 });
+
+schema.plugin(metaPlugin);
+schema.plugin(MoneyPlugin({ zh: '提现金额', required: true, key: 'money' }));
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('CashOut', schema, 'cashOut');
+};

+ 1 - 1
app/service/trade/order.js

@@ -104,7 +104,7 @@ class OrderService extends CrudService {
       // 处理库存,删除购物车
       await this.dealGoodsNum(goodsData);
       // 处理优惠券,改为使用过
-      if (coupon.length > 1) await this.ctx.service.user.userCoupon.useCoupon(coupon, this.tran);
+      if (coupon.length > 0) await this.ctx.service.user.userCoupon.useCoupon(coupon, this.tran);
       await this.tran.run();
       // 创建定时任务(mq死信机制任务)
       await this.toMakeTask(order_id);

+ 1 - 0
app/service/trade/pay.js

@@ -141,6 +141,7 @@ class PayService extends CrudService {
       // 加销量
       await this.addSell(orderData, this.tran);
       await this.tran.run();
+      // TODO: 将该订单的数据在mq队列中释放掉,不要让信息进入死信队列
     } catch (error) {
       console.error(error);
       await this.tran.rollback();

+ 17 - 0
app/service/user/cashOut.js

@@ -0,0 +1,17 @@
+
+'use strict';
+const { CrudService } = require('naf-framework-mongoose-free/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const _ = require('lodash');
+const assert = require('assert');
+const moment = require('moment');
+//
+class CashOutService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'cashout');
+    this.model = this.ctx.model.User.CashOut;
+  }
+}
+
+module.exports = CashOutService;
+

+ 3 - 3
app/z_router/user/cashBack.js

@@ -10,9 +10,9 @@ const routes = [
   { method: 'get', path: `${rkey}/computedTotal`, controller: `${ckey}.computedTotal`, name: `${ckey}computedTotal`, zh: `${keyZh}计算总分` },
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
-  { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, name: `${ckey}Create`, zh: `创建${keyZh}` },
-  { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
-  { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
+  // { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, name: `${ckey}Create`, zh: `创建${keyZh}` },
+  // { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
+  // { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
 ];
 
 module.exports = app => {

+ 19 - 0
app/z_router/user/cashOut.js

@@ -0,0 +1,19 @@
+'use strict';
+// 路由配置
+const path = require('path');
+const regPath = path.resolve('app', 'public', 'routerRegister');
+const routerRegister = require(regPath);
+const rkey = 'cashOut';
+const ckey = 'user.cashOut';
+const keyZh = '提现';
+const routes = [
+  { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
+  { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
+  { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, name: `${ckey}Create`, zh: `创建${keyZh}` },
+  { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
+  { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
+];
+
+module.exports = app => {
+  routerRegister(app, routes, keyZh, rkey, ckey);
+};

+ 1 - 0
app/z_router/user/index.js

@@ -10,4 +10,5 @@ module.exports = app => {
   require('./storeShop')(app); // 收藏店铺
   require('./storeGoods')(app); // 收藏商品
   require('./cashBack')(app); // 返现
+  require('./cashOut')(app); // 提现
 };

+ 3 - 3
app/z_router/user/point.js

@@ -10,9 +10,9 @@ const routes = [
   { method: 'get', path: `${rkey}/computedTotal`, controller: `${ckey}.computedTotal`, name: `${ckey}computedTotal`, zh: `${keyZh}计算总分` },
   { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
   { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
-  { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, name: `${ckey}Create`, zh: `创建${keyZh}` },
-  { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
-  { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
+  // { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, name: `${ckey}Create`, zh: `创建${keyZh}` },
+  // { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
+  // { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
 ];
 
 module.exports = app => {