product_suppliers.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use strict';
  2. const ManagerController = require('../manager.js');
  3. /**
  4. * [exports 产品供货商]
  5. * @type {[type]}
  6. */
  7. module.exports = class ProductSuppliersController extends ManagerController {
  8. /**
  9. * [useModel 使用模型]
  10. * @return {[type]} [description]
  11. */
  12. get useModel() {
  13. let that = this;
  14. return that.app.model.ProductSuppliers;
  15. }
  16. /**
  17. * [createValidate 添加供货商]
  18. * @return {[type]} [description]
  19. */
  20. get createValidate() {
  21. let that = this;
  22. return {
  23. supplier_name:that.ctx.rules.name('供货商名称').required().notEmpty().trim(),
  24. supplier_phone:that.ctx.rules.name('供货商电话').required().notEmpty().trim(),
  25. supplier_status:that.ctx.rules.default(1).number(),
  26. admin_id:that.ctx.rules.default(that.service.manager.ActionAdminUserId()).number(),
  27. create_time:that.ctx.rules.default(that.app.szjcomo.date('Y-m-d H:i:s')).required()
  28. };
  29. }
  30. /**
  31. * [deleteValidate 删除供货商]
  32. * @return {[type]} [description]
  33. */
  34. get deleteValidate() {
  35. let that = this;
  36. return {
  37. supplier_id:that.ctx.rules.name('供货商ID').required().notEmpty().number().extend(async (field,value,row) => {
  38. let productsCount = await that.app.model.Products.findOne({where:{brand_id:value},attributes:['product_id']});
  39. if(productsCount) return '当前供货商下还有商品,无法删除';
  40. })
  41. };
  42. }
  43. /**
  44. * [selectOptions 查询条件]
  45. * @param {[type]} data [description]
  46. * @return {[type]} [description]
  47. */
  48. async selectOptions(data) {
  49. let that = this;
  50. let seq = that.app.Sequelize;
  51. let options = {offset:(data.page - 1) * data.limit,limit:data.limit,include:[
  52. {model:that.app.model.AdminUser,as:'admin_user',attributes:[]}
  53. ],attributes:{
  54. exclude:['admin_id'],
  55. include:[[seq.col('admin_user.username'),'username']]
  56. },order:[['supplier_id','desc']]};
  57. return options;
  58. }
  59. }