SmsPublicTemp.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 crmeb\exceptions\AdminException;
  14. use crmeb\services\sms\Sms;
  15. use crmeb\services\SystemConfigService;
  16. /**
  17. * 公共短信模板
  18. * Class SmsPublicTemp
  19. * @package app\controller\admin\v1\notification\sms
  20. */
  21. class SmsPublicTemp extends AuthController
  22. {
  23. /**
  24. * @var Sms
  25. */
  26. protected $smsHandle;
  27. public function initialize()
  28. {
  29. parent::initialize();
  30. $data = SystemConfigService::more(['sms_account', 'sms_token', 'site_url']);
  31. $this->smsHandle = new Sms('yunxin', $data);
  32. if (!$this->smsHandle->isLogin()) {
  33. throw new AdminException('请先填写短息配置');
  34. }
  35. }
  36. /**
  37. * 异步获取公共模板列表
  38. */
  39. public function index()
  40. {
  41. $where = $this->request->getMore([
  42. ['is_have', ''],
  43. ['page', 1],
  44. ['limit', 20],
  45. ]);
  46. $templateList = $this->smsHandle->publictemp($where);
  47. if ($templateList['status'] == 400) return $this->fail($templateList['msg']);
  48. $arr = $templateList['data']['data'];
  49. foreach ($arr as $key => $value) {
  50. switch ($value['type']) {
  51. case 1:
  52. $arr[$key]['type'] = '验证码';
  53. break;
  54. case 2:
  55. $arr[$key]['type'] = '通知';
  56. break;
  57. case 3:
  58. $arr[$key]['type'] = '推广';
  59. break;
  60. default:
  61. $arr[$key]['type'] = '';
  62. break;
  63. }
  64. }
  65. $templateList['data']['data'] = $arr;
  66. return $this->success($templateList['data']);
  67. }
  68. }