123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- 'use strict';
- const ManagerController = require('../manager.js');
- /**
- * [exports 配送方式]
- * @type {[type]}
- */
- module.exports = class ShippingsConfigController extends ManagerController {
- /**
- * [useModel 使用模型]
- * @return {[type]} [description]
- */
- get useModel() {
- let that = this;
- return that.app.model.ShippingsConfig;
- }
- /**
- * [createValidate 添加配送方式]
- * @return {[type]} [description]
- */
- get createValidate() {
- let that = this;
- return {
- shipping_name:that.ctx.rules.name('配送名称').required().notEmpty().trim(),
- shipping_logo:that.ctx.rules.default('').required(),
- shipping_params_index:that.ctx.rules.default('').required(),
- shipping_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 {
- shipping_id:that.ctx.rules.name('配送ID').required().notEmpty().number().extend(async (field,value,row) => {
- let shippingCount = await that.app.model.Orders.findOne({where:{shipping_id:value},attributes:['shipping_id']});
- if(shippingCount) 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:[['shipping_id','desc']]};
- return options;
- }
- }
|