lrf %!s(int64=2) %!d(string=hai) anos
pai
achega
a5efc68a29

+ 39 - 0
app/controller/shop/config/.shopCashOut.js

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

+ 13 - 0
app/controller/shop/shopCashOut.js

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

+ 30 - 0
app/model/shop/shopCashOut.js

@@ -0,0 +1,30 @@
+'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 shopCashOut = {
+  shop: { type: String, required: false, zh: '店铺', ref: 'Shop.Shop' }, //
+  apply_time: { type: String, required: false, zh: '申请时间' }, //
+  deal_person: { type: String, required: false, zh: '审核处理人' }, //
+  exam_time: { type: String, required: false, zh: '审核时间' }, //
+  card: { type: String, required: false, zh: '银行卡号' }, //
+  card_name: { type: String, required: false, zh: '银行卡所属' }, //
+  card_bank: { type: String, required: false, zh: '所属银行' }, //
+  status: { type: String, required: false, default: '0', zh: '审核状态' }, // 字典表:withdrawal_exam_status
+};
+const schema = new Schema(shopCashOut, { toJSON: { getters: true, virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ 'meta.createdAt': 1 });
+schema.index({ shop: 1 });
+schema.index({ status: 1 });
+
+schema.plugin(metaPlugin);
+schema.plugin(MoneyPlugin({ zh: '提现金额', required: false, key: 'money' }));
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('ShopCashOut', schema, 'shopCashOut');
+};

+ 43 - 0
app/service/shop/shopCashOut.js

@@ -0,0 +1,43 @@
+'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 ShopCashOutService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'shopcashout');
+    this.model = this.ctx.model.Shop.ShopCashOut;
+    this.shopInBillModel = this.ctx.model.Shop.ShopInBill;
+  }
+  async beforeCreate(data) {
+    const { shop } = data;
+    if (!shop) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '缺少提款人');
+    const num = await this.model.count({ shop, status: '0' });
+    if (num > 0) throw new BusinessError(ErrorCode.DATA_EXISTED, '您有未处理提现申请,请联系管理员先处理之前的申请');
+    return data;
+  }
+
+  async beforeUpdate(filter, update) {
+    if (_.get(update, 'status') !== '0') {
+      update.deal_person = _.get(this.ctx, 'admin._id');
+    }
+    return { filter, update };
+  }
+
+  async afterUpdate(filter, body, data) {
+    const { status } = body;
+    if (status === '1') {
+      const { customer: inviter, money } = data;
+      const obj = { inviter, money, time: moment().format('YYYY-MM-DD HH:mm:ss'), status: '-1', source: '-1', source_id: data._id };
+      const num = await this.shopInBillModel.count({ inviter, status: '-1', source: '-1', source_id: data._id });
+      // 说明该申请没有流水,添加流水;有流水就不加了
+      if (num <= 0) await this.shopInBillModel.create(obj);
+    }
+    return data;
+  }
+}
+
+module.exports = ShopCashOutService;

+ 19 - 0
app/z_router/shop/shopCashOut.js

@@ -0,0 +1,19 @@
+'use strict';
+// 路由配置
+const path = require('path');
+const regPath = path.resolve('app', 'public', 'routerRegister');
+const routerRegister = require(regPath);
+const rkey = 'shopCashOut';
+const ckey = 'shop.shopCashOut';
+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);
+};