partnerInfo.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. 'use strict';
  2. const shopController = require('./shop.js');
  3. // 合作餐厅控制器
  4. module.exports = class PartnerInfoController extends shopController {
  5. // 使用模型
  6. get useModel() {
  7. const that = this;
  8. return that.app.model.PartnerInfo;
  9. }
  10. /**
  11. * [selectValidate 查询合作餐店]
  12. * @return {[type]} [description]
  13. */
  14. get selectValidate() {
  15. const that = this;
  16. return {
  17. /* user_id: that.ctx.rules.default(that.service.shop.getWebUserId())
  18. .number(),*/
  19. county_name: that.ctx.rules.default('市辖区')
  20. .trim(),
  21. };
  22. }
  23. /**
  24. * [select 所有餐店列表]
  25. * @return {[type]} [description]
  26. */
  27. async selectAll() {
  28. const that = this;
  29. try {
  30. const options = {
  31. where: { online: true },
  32. order: [[ 'top', 'desc' ], [ 'order_amount', 'desc' ]],
  33. };
  34. const selectBean = await that.app.comoBean.instance({}, options);
  35. const result = await that.service.base.select(selectBean, that.useModel, '合作餐店查询失败,请稍候重试', true, true);
  36. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  37. } catch (err) {
  38. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', false, false));
  39. }
  40. }
  41. /**
  42. * [select 餐店列表]
  43. * @return {[type]} [description]
  44. */
  45. async select() {
  46. const that = this;
  47. try {
  48. const data = await that.ctx.validate(that.selectValidate, await that.ctx.getParse());
  49. const options = {
  50. where: { county_name: data.county_name, online: true },
  51. order: [[ 'top', 'desc' ], [ 'order_amount', 'desc' ]],
  52. };
  53. const selectBean = await that.app.comoBean.instance(data, options);
  54. const result = await that.service.base.select(selectBean, that.useModel, '合作餐店查询失败,请稍候重试', true, true);
  55. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  56. } catch (err) {
  57. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', false, false));
  58. }
  59. }
  60. /*
  61. async create() {
  62. const that = this;
  63. try {
  64. const data = await that.ctx.validate(that.createValidate, await that.ctx.postParse());
  65. const createBean = await that.app.comoBean.instance(data);
  66. const result = await that.service.base.create(createBean, that.useModel, '添加合作餐店失败,请重试');
  67. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  68. } catch (err) {
  69. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  70. }
  71. }
  72. async update() {
  73. const that = this;
  74. try {
  75. const data = await that.ctx.validate(that.updateValidate, await that.ctx.anyParse());
  76. if (data.fore) {
  77. const updateBean = await that.app.comoBean.instance({
  78. is_use: 0,
  79. update_time: that.app.szjcomo.date('Y-m-d H:i:s'),
  80. }, { where: { user_id: data.user_id } });
  81. await that.service.base.update(updateBean, that.useModel, '更新合作餐店失败,请重试');
  82. }
  83. const options = { where: { user_id: data.user_id, address_id: data.address_id } };
  84. const updateBean = await that.app.comoBean.instance(data, options);
  85. const result = await that.service.base.update(updateBean, that.useModel, '更新合作餐店失败,请稍候重试');
  86. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  87. } catch (err) {
  88. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  89. }
  90. }
  91. async delete() {
  92. const that = this;
  93. try {
  94. const data = await that.ctx.validate(that.deleteValidate, await that.ctx.anyParse());
  95. const options = { where: { user_id: data.user_id, address_id: data.address_id } };
  96. const deleteBean = await that.app.comoBean.instance(data, options);
  97. const result = await that.service.base.delete(deleteBean, that.useModel, '删除合作餐店失败,请稍候重试');
  98. return that.ctx.appJson(that.app.szjcomo.appResult('SUCCESS', result, false));
  99. } catch (err) {
  100. return that.ctx.appJson(that.app.szjcomo.appResult(err.message));
  101. }
  102. }
  103. */
  104. };