'use strict'; const ManagerController = require('../manager.js'); /** * [exports 支付配置] * @type {[type]} */ module.exports = class PaysConfigController extends ManagerController { /** * [useModel 使用模型] * @return {[type]} [description] */ get useModel() { let that = this; return that.app.model.PaysConfig; } /** * [createValidate 添加支付方式] * @return {[type]} [description] */ get createValidate() { let that = this; return { pay_name:that.ctx.rules.name('支付名称').required().notEmpty().trim(), pay_logo:that.ctx.rules.default('').required(), pay_params_index:that.ctx.rules.default('').required(), pay_sort:that.ctx.rules.default(99).number().extend((field,value,row) => { if(!value) row[field] = 99; }), admin_id:that.ctx.rules.default(that.service.manager.ActionAdminUserId()).number(), create_time:that.ctx.rules.default(that.app.szjcomo.date('Y-m-d H:i:s')).required() }; } /** * [deleteValidate 删除支付方式] * @return {[type]} [description] */ get deleteValidate() { let that = this; return { pay_id:that.ctx.rules.name('支付ID').required().notEmpty().number().extend(async (field,value,row) => { let payCount = await that.app.model.Orders.findOne({where:{pay_id:value},attributes:['pay_id']}); if(payCount) return '当前支付方式下还有订单,无法删除'; }) }; } /** * [selectOptions 支付方式查询条件] * @param {Object} data [description] * @return {[type]} [description] */ async selectOptions(data = {}) { let that = this; let options = {offset:(data.page - 1) * data.limit,limit:data.limit,include:[ {model:that.app.model.AdminUser,as:'admin_user',attributes:[]} ],attributes:{ exclude:['admin_id'], include:[[that.app.Sequelize.col('admin_user.username'),'username']] },order:[['pay_id','desc']]}; return options; } }