SmsTemplateApply.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\notification\sms;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\serve\ServeServices;
  14. use think\facade\App;
  15. /**
  16. * 短信模板申请
  17. * Class SmsTemplateApply
  18. * @package app\admin\controller\sms
  19. */
  20. class SmsTemplateApply extends AuthController
  21. {
  22. /**
  23. * @param App $app
  24. * @param ServeServices $services
  25. */
  26. public function __construct(App $app, ServeServices $services)
  27. {
  28. parent::__construct($app);
  29. $this->services = $services;
  30. }
  31. /**
  32. * 异步获取模板列表
  33. * @return mixed
  34. */
  35. public function index()
  36. {
  37. $where = $this->request->getMore([
  38. [['type', 'd'], 0],
  39. ['status', ''],
  40. ['title', ''],
  41. [['page', 'd'], 1],
  42. [['limit', 'd'], 20],
  43. ]);
  44. $where['temp_type'] = $where['type'];
  45. $templateList = $this->services->sms()->temps($where['page'], $where['limit'], $where['type']);
  46. $templateList['data'] = $templateList['data'] ?? [];
  47. foreach ($templateList['data'] as $key => &$item) {
  48. $item['templateid'] = $item['temp_id'];
  49. switch ((int)$item['temp_type']) {
  50. case 1:
  51. $item['type'] = '验证码';
  52. break;
  53. case 2:
  54. $item['type'] = '通知';
  55. break;
  56. case 30:
  57. $item['type'] = '营销短信';
  58. break;
  59. }
  60. }
  61. return app('json')->success($templateList);
  62. }
  63. /**
  64. * 显示创建资源表单页
  65. * @return mixed
  66. * @throws \FormBuilder\Exception\FormBuilderException
  67. */
  68. public function create()
  69. {
  70. return app('json')->success($this->services->getSmsTemplateForm());
  71. }
  72. /**
  73. * 保存新建的资源
  74. * @return mixed
  75. */
  76. public function save()
  77. {
  78. $data = $this->request->postMore([
  79. ['title', ''],
  80. ['content', ''],
  81. ['type', 0]
  82. ]);
  83. if (!strlen(trim($data['title']))) {
  84. return app('json')->fail(400142);
  85. }
  86. if (!strlen(trim($data['content']))) {
  87. return app('json')->fail(400143);
  88. }
  89. $this->services->sms()->apply($data['title'], $data['content'], $data['type']);
  90. return app('json')->success(100027);
  91. }
  92. }