SmsTemplate.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-05-18
  7. *
  8. *
  9. */
  10. namespace app\controller\admin\system\sms;
  11. use crmeb\basic\BaseController;
  12. use crmeb\services\YunxinSmsService;
  13. use FormBuilder\Exception\FormBuilderException;
  14. use think\App;
  15. /**
  16. * Class SmsTemplate
  17. * @package app\controller\admin\system\sms
  18. * @author xaboy
  19. * @day 2020-05-18
  20. */
  21. class SmsTemplate extends BaseController
  22. {
  23. /**
  24. * @var YunxinSmsService
  25. */
  26. protected $service;
  27. /**
  28. * Sms constructor.
  29. * @param App $app
  30. */
  31. public function __construct(App $app)
  32. {
  33. parent::__construct($app);
  34. $this->service = YunxinSmsService::create();
  35. }
  36. /**
  37. * 异步获取公共模板列表
  38. */
  39. public function public()
  40. {
  41. $where = $this->request->params([
  42. ['is_have', ''],
  43. ['page', 1],
  44. ['limit', 20],
  45. ]);
  46. $templateList = $this->service->publictemp($where);
  47. if ($templateList['status'] == 400) return app('json')->fail($templateList['msg']);
  48. $arr = $templateList['data']['data'];
  49. foreach ($arr as $key => $value) {
  50. switch ($value['type']) {
  51. case 1:
  52. $arr[$key]['type'] = '验证码';
  53. break;
  54. case 2:
  55. $arr[$key]['type'] = '通知';
  56. break;
  57. case 3:
  58. $arr[$key]['type'] = '推广';
  59. break;
  60. default:
  61. $arr[$key]['type'] = '';
  62. break;
  63. }
  64. }
  65. $templateList['data']['data'] = $arr;
  66. return app('json')->success($templateList['data']);
  67. }
  68. /**
  69. * @return mixed
  70. * @throws FormBuilderException
  71. * @author xaboy
  72. * @day 2020-05-18
  73. */
  74. public function form()
  75. {
  76. return app('json')->success(formToData($this->service->form()));
  77. }
  78. /**
  79. * @return mixed
  80. * @author xaboy
  81. * @day 2020-05-18
  82. */
  83. public function template()
  84. {
  85. $where = $this->request->params([
  86. ['status', ''],
  87. ['title', ''],
  88. ['temp_type', ''],
  89. ['page', 1],
  90. ['limit', 20]
  91. ]);
  92. $templateList = $this->service->template($where);
  93. if ($templateList['status'] == 400) return app('json')->fail($templateList['msg']);
  94. $arr = $templateList['data']['data'];
  95. foreach ($arr as $key => $value) {
  96. switch ($value['type']) {
  97. case 1:
  98. $arr[$key]['type'] = '验证码';
  99. break;
  100. case 2:
  101. $arr[$key]['type'] = '通知';
  102. break;
  103. case 3:
  104. $arr[$key]['type'] = '推广';
  105. break;
  106. default:
  107. $arr[$key]['type'] = '';
  108. break;
  109. }
  110. }
  111. $templateList['data']['data'] = $arr;
  112. return app('json')->success($templateList['data']);
  113. }
  114. /**
  115. * @return mixed
  116. * @author xaboy
  117. * @day 2020-05-18
  118. */
  119. public function apply()
  120. {
  121. $data = $this->request->params([
  122. 'title',
  123. 'content',
  124. ['type', 0]
  125. ]);
  126. if (!$data['title']) return app('json')->fail('请输入模板名称');
  127. if (!$data['content']) return app('json')->fail('请输入模板内容');
  128. $applyStatus = $this->service->apply($data['title'], $data['content'], $data['type']);
  129. if ($applyStatus['status'] == 400) return app('json')->fail($applyStatus['msg']);
  130. return app('json')->success('申请成功');
  131. }
  132. }