wxMenuController.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. class WXMenuController extends Controller {
  4. async one() {
  5. // console.log('one');
  6. const { ctx, service } = this;
  7. const query = ctx.query;
  8. const { id } = query;
  9. const result = await service.wxMenuService.one(id);
  10. if (result) {
  11. ctx.body = {
  12. data: result,
  13. code: 0,
  14. };
  15. } else {
  16. ctx.body = {
  17. message: '微信菜单信息查询失败',
  18. code: 0,
  19. };
  20. }
  21. }
  22. async add() {
  23. // console.log('add');
  24. const { ctx, service } = this;
  25. const query = ctx.request.body;
  26. const result = await service.wxMenuService.add(query);
  27. ctx.body = {
  28. data: result,
  29. code: 0,
  30. };
  31. }
  32. async update() {
  33. // console.log('update');
  34. const { ctx, service } = this;
  35. const query = ctx.request.body;
  36. const { id } = query;
  37. delete query.id;
  38. if (id) {
  39. const result = await service.wxMenuService.update(id, query);
  40. ctx.body = {
  41. data: result,
  42. code: 0,
  43. };
  44. } else {
  45. ctx.body = {
  46. code: 1,
  47. message: 'id is null',
  48. };
  49. }
  50. }
  51. async delete() {
  52. // console.log('delete');
  53. const { ctx, service } = this;
  54. const query = ctx.query;
  55. const { id } = query;
  56. const result = await service.wxMenuService.dele(id);
  57. ctx.body = {
  58. data: result,
  59. code: 0,
  60. };
  61. }
  62. async list() {
  63. // console.log('list');
  64. const { ctx, service } = this;
  65. const query = ctx.query;
  66. const result = await service.wxMenuService.list(query);
  67. ctx.body = {
  68. data: result,
  69. code: 0,
  70. };
  71. }
  72. }
  73. module.exports = WXMenuController;