SmsTemplate.php 4.3 KB

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