pays_config.js 2.1 KB

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