Submsg.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\store\controller\wxapp;
  3. use app\store\controller\Controller;
  4. use app\store\model\Setting as SettingModel;
  5. use app\store\service\wxapp\SubMsg as SubMsgService;
  6. /**
  7. * 小程序订阅消息设置
  8. * Class Submsg
  9. * @package app\store\controller\wxapp
  10. */
  11. class Submsg extends Controller
  12. {
  13. /**
  14. * 小程序订阅消息设置
  15. * @return array|bool|mixed
  16. * @throws \think\exception\DbException
  17. */
  18. public function index()
  19. {
  20. if (!$this->request->isAjax()) {
  21. $values = SettingModel::getItem('submsg');
  22. return $this->fetch('index', compact('values'));
  23. }
  24. $model = new SettingModel;
  25. if ($model->edit('submsg', $this->postData('submsg'))) {
  26. return $this->renderSuccess('操作成功');
  27. }
  28. return $this->renderError($model->getError() ?: '操作失败');
  29. }
  30. /**
  31. * 一键添加订阅消息
  32. * @return array
  33. * @throws \app\common\exception\BaseException
  34. * @throws \think\Exception
  35. * @throws \think\exception\DbException
  36. */
  37. public function shuttle()
  38. {
  39. $SubMsgService = new SubMsgService;
  40. if ($SubMsgService->shuttle()) {
  41. return $this->renderSuccess('操作成功');
  42. }
  43. return $this->renderError($SubMsgService->getError() ?: '操作失败');
  44. }
  45. }