'use strict'; const ManagerController = require('../manager.js'); /** * [exports 产品供货商] * @type {[type]} */ module.exports = class ProductSuppliersController extends ManagerController { /** * [useModel 使用模型] * @return {[type]} [description] */ get useModel() { let that = this; return that.app.model.ProductSuppliers; } /** * [createValidate 添加供货商] * @return {[type]} [description] */ get createValidate() { let that = this; return { supplier_name:that.ctx.rules.name('供货商名称').required().notEmpty().trim(), supplier_phone:that.ctx.rules.name('供货商电话').required().notEmpty().trim(), supplier_status:that.ctx.rules.default(1).number(), 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 { supplier_id:that.ctx.rules.name('供货商ID').required().notEmpty().number().extend(async (field,value,row) => { let productsCount = await that.app.model.Products.findOne({where:{brand_id:value},attributes:['product_id']}); if(productsCount) return '当前供货商下还有商品,无法删除'; }) }; } /** * [selectOptions 查询条件] * @param {[type]} data [description] * @return {[type]} [description] */ async selectOptions(data) { let that = this; let seq = that.app.Sequelize; 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:[[seq.col('admin_user.username'),'username']] },order:[['supplier_id','desc']]}; return options; } }