Sms.php 3.3 KB

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