SmsTemplateApply.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\v1\notification\sms;
  12. use app\controller\admin\AuthController;
  13. use app\services\serve\ServeServices;
  14. use think\facade\App;
  15. /**
  16. * 短信模板申请
  17. * Class SmsTemplateApply
  18. * @package app\controller\admin\v1\notification\sms
  19. */
  20. class SmsTemplateApply extends AuthController
  21. {
  22. public function __construct(App $app, ServeServices $services)
  23. {
  24. parent::__construct($app);
  25. $this->services = $services;
  26. }
  27. /**
  28. * 异步获取模板列表
  29. */
  30. public function index()
  31. {
  32. $where = $this->request->getMore([
  33. [['type', 'd'], 0],
  34. ['status', ''],
  35. ['title', ''],
  36. [['page', 'd'], 1],
  37. [['limit', 'd'], 20],
  38. ]);
  39. $where['temp_type'] = $where['type'];
  40. $templateList = $this->services->sms()->temps($where['page'], $where['limit'], $where['type']);
  41. $templateList['data'] = $templateList['data'] ?? [];
  42. foreach ($templateList['data'] as $key => &$item) {
  43. $item['templateid'] = $item['temp_id'];
  44. switch ((int)$item['temp_type']) {
  45. case 1:
  46. $item['type'] = '验证码';
  47. break;
  48. case 2:
  49. $item['type'] = '通知';
  50. break;
  51. case 30:
  52. $item['type'] = '营销短信';
  53. break;
  54. }
  55. }
  56. return $this->success($templateList);
  57. }
  58. /**
  59. * 显示创建资源表单页.
  60. *
  61. * @return string
  62. * @throws \FormBuilder\Exception\FormBuilderException
  63. */
  64. public function create()
  65. {
  66. return $this->success($this->services->getSmsTemplateForm());
  67. }
  68. /**
  69. * 保存新建的资源
  70. */
  71. public function save()
  72. {
  73. $data = $this->request->postMore([
  74. ['title', ''],
  75. ['content', ''],
  76. ['type', 0]
  77. ]);
  78. if (!strlen(trim($data['title']))) {
  79. return $this->fail('请输入模板名称');
  80. }
  81. if (!strlen(trim($data['content']))) {
  82. return $this->fail('请输入模板内容');
  83. }
  84. $this->services->sms()->apply($data['title'], $data['content'], $data['type']);
  85. return $this->success('申请成功');
  86. }
  87. }