AdminWxappController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2014 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: Dean <zxxjjforever@163.com>
  8. // +----------------------------------------------------------------------
  9. namespace plugins\wxapp\controller; //Demo插件英文名,改成你的插件英文就行了
  10. use cmf\controller\PluginAdminBaseController;
  11. class AdminWxappController extends PluginAdminBaseController
  12. {
  13. /**
  14. * 添加小程序
  15. * @adminMenu(
  16. * 'name' => '添加小程序',
  17. * 'parent' => 'AdminIndex/index',
  18. * 'display'=> false,
  19. * 'hasView'=> true,
  20. * 'order' => 10000,
  21. * 'icon' => '',
  22. * 'remark' => '添加小程序',
  23. * 'param' => ''
  24. * )
  25. */
  26. public function add()
  27. {
  28. return $this->fetch();
  29. }
  30. /**
  31. * 添加小程序提交保存
  32. * @adminMenu(
  33. * 'name' => '添加小程序提交保存',
  34. * 'parent' => 'AdminIndex/index',
  35. * 'display'=> false,
  36. * 'hasView'=> false,
  37. * 'order' => 10000,
  38. * 'icon' => '',
  39. * 'remark' => '添加小程序提交保存',
  40. * 'param' => ''
  41. * )
  42. */
  43. public function addPost()
  44. {
  45. $data = $this->request->param();
  46. $result = $this->validate($data, "AdminWxapp");
  47. if ($result !== true) {
  48. $this->error($result);
  49. }
  50. $wxappSettings = cmf_get_option('wxapp_settings');
  51. if (!empty($data['is_default'])) {
  52. $wxappSettings['default'] = $data;
  53. }
  54. unset($data['is_default']);
  55. $wxappSettings['wxapps'][$data['app_id']] = $data;
  56. cmf_set_option('wxapp_settings', $wxappSettings);
  57. $this->success('添加成功!', cmf_plugin_url('Wxapp://AdminWxapp/edit', ['id' => $data['app_id']]));
  58. }
  59. /**
  60. * 编辑小程序
  61. * @adminMenu(
  62. * 'name' => '编辑小程序',
  63. * 'parent' => 'AdminIndex/index',
  64. * 'display'=> false,
  65. * 'hasView'=> true,
  66. * 'order' => 10000,
  67. * 'icon' => '',
  68. * 'remark' => '编辑小程序',
  69. * 'param' => ''
  70. * )
  71. */
  72. public function edit()
  73. {
  74. $appId = $this->request->param('id');
  75. $wxappSettings = cmf_get_option('wxapp_settings');
  76. if (!empty($wxappSettings['wxapps'][$appId])) {
  77. $this->assign('wxapp', $wxappSettings['wxapps'][$appId]);
  78. }
  79. $defaultWxapp = empty($wxappSettings['default']) ? [] : $wxappSettings['default'];
  80. $this->assign('default_wxapp', $defaultWxapp);
  81. return $this->fetch();
  82. }
  83. /**
  84. * 编辑小程序提交保存
  85. * @adminMenu(
  86. * 'name' => '编辑小程序提交保存',
  87. * 'parent' => 'AdminIndex/index',
  88. * 'display'=> false,
  89. * 'hasView'=> false,
  90. * 'order' => 10000,
  91. * 'icon' => '',
  92. * 'remark' => '编辑小程序',
  93. * 'param' => ''
  94. * )
  95. */
  96. public function editPost()
  97. {
  98. $data = $this->request->param();
  99. $result = $this->validate($data, "AdminWxapp");
  100. if ($result !== true) {
  101. $this->error($result);
  102. }
  103. $wxappSettings = cmf_get_option('wxapp_settings');
  104. if (!empty($data['is_default'])) {
  105. $wxappSettings['default'] = $data;
  106. }
  107. unset($data['is_default']);
  108. $wxappSettings['wxapps'][$data['app_id']] = $data;
  109. cmf_set_option('wxapp_settings', $wxappSettings);
  110. $this->success('保存成功!');
  111. }
  112. /**
  113. * 删除小程序
  114. * @adminMenu(
  115. * 'name' => '删除小程序',
  116. * 'parent' => 'AdminIndex/index',
  117. * 'display'=> false,
  118. * 'hasView'=> false,
  119. * 'order' => 10000,
  120. * 'icon' => '',
  121. * 'remark' => '删除小程序',
  122. * 'param' => ''
  123. * )
  124. */
  125. public function delete()
  126. {
  127. $appId = $this->request->param('id');
  128. $wxappSettings = cmf_get_option('wxapp_settings');
  129. $defaultWxapp = empty($wxappSettings['default']) ? [] : $wxappSettings['default'];
  130. if (!empty($defaultWxapp['app_id']) && $appId == $defaultWxapp['app_id']) {
  131. $this->error(' 默认小程序无法删除!');
  132. }
  133. unset($wxappSettings['wxapps'][$appId]);
  134. cmf_set_option('wxapp_settings', $wxappSettings);
  135. $this->success('删除成功!');
  136. }
  137. }