Sms.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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\serve;
  12. use app\controller\admin\AuthController;
  13. use app\validate\admin\serve\ServeValidate;
  14. use app\services\serve\ServeServices;
  15. use think\facade\App;
  16. /**
  17. * Class Sms
  18. * @package app\controller\admin\v1\serve
  19. */
  20. class Sms extends AuthController
  21. {
  22. /**
  23. * Sms constructor.
  24. * @param App $app
  25. * @param ServeServices $services
  26. */
  27. public function __construct(App $app, ServeServices $services)
  28. {
  29. parent::__construct($app);
  30. $this->services = $services;
  31. }
  32. /**
  33. * 开通服务
  34. * @param string $sign
  35. * @return mixed
  36. */
  37. public function openServe(string $sign)
  38. {
  39. if (!$sign) {
  40. return $this->fail('请设置短信签名');
  41. }
  42. $this->services->sms()->setSign($sign)->open();
  43. return $this->success('开通成功');
  44. }
  45. /**
  46. * 修改短信签名
  47. * @param string $sign
  48. * @return mixed
  49. */
  50. public function editSign(string $sign)
  51. {
  52. [$sign, $phone, $code] = $this->request->postMore([
  53. ['sign', ''],
  54. ['phone', ''],
  55. ['code', ''],
  56. ], true);
  57. $this->validate(['phone' => $phone], ServeValidate::class, 'phone');
  58. if (!$sign) {
  59. return $this->fail('请设置短信签名');
  60. }
  61. $this->services->sms()->modify($sign, $phone, $code);
  62. return $this->success('修改短信签名成功');
  63. }
  64. /**
  65. * 获取短信模板
  66. * @return mixed
  67. */
  68. public function temps()
  69. {
  70. [$page, $limit, $type] = $this->request->getMore([
  71. ['page', 1],
  72. ['limit', 10],
  73. ['temp_type', 0],
  74. ], true);
  75. return $this->success($this->services->getSmsTempsList((int)$page, (int)$limit, (int)$type));
  76. }
  77. /**
  78. * 申请模板
  79. * @return mixed
  80. */
  81. public function apply()
  82. {
  83. [$title, $content, $type] = $this->request->postMore([
  84. ['title', ''],
  85. ['content', ''],
  86. ['type', 0]
  87. ], true);
  88. if (!$title || !$content || !$type) {
  89. return $this->success('请填写申请模板内容');
  90. }
  91. return $this->success($this->services->sms()->apply($title, $content, (int)$type));
  92. }
  93. /**
  94. * 获取申请记录
  95. * @return mixed
  96. */
  97. public function applyRecord()
  98. {
  99. [$page, $limit, $tempType] = $this->request->getMore([
  100. [['page', 'd'], 1],
  101. [['limit', 'd'], 10],
  102. [['temp_type', 'd'], 0],
  103. ], true);
  104. return $this->success($this->services->sms()->applys($tempType, $page, $limit));
  105. }
  106. }