SmsTemplate.php 4.2 KB

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