SmsPublicTemp.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\admin\controller\sms;
  3. use app\admin\controller\AuthController;
  4. use crmeb\services\{
  5. JsonService, sms\Sms, UtilService
  6. };
  7. /**
  8. * 公共短信模板
  9. * Class SmsPublicTemp
  10. * @package app\admin\controller\sms
  11. */
  12. class SmsPublicTemp extends AuthController
  13. {
  14. /**
  15. * @var Sms
  16. */
  17. protected $smsHandle;
  18. protected function initialize()
  19. {
  20. parent::initialize(); // TODO: Change the autogenerated stub
  21. $this->smsHandle = new Sms('yunxin', [
  22. 'sms_account' => sys_config('sms_account'),
  23. 'sms_token' => sys_config('sms_token'),
  24. 'site_url' => sys_config('site_url')
  25. ]);
  26. }
  27. public function index()
  28. {
  29. if (!$this->smsHandle->isLogin()) return $this->failed('请先填写短信配置');
  30. return $this->fetch();
  31. }
  32. /**
  33. * 异步获取公共模板列表
  34. */
  35. public function lst()
  36. {
  37. $where = UtilService::getMore([
  38. ['is_have', ''],
  39. ['page', 1],
  40. ['limit', 20],
  41. ]);
  42. $templateList = $this->smsHandle->publictemp($where);
  43. if ($templateList['status'] == 400) return JsonService::fail($templateList['msg']);
  44. return JsonService::successlayui($templateList['data']);
  45. }
  46. /**
  47. * 添加公共短信模板
  48. */
  49. public function status()
  50. {
  51. list($id, $tempId) = UtilService::postMore([
  52. ['id', 0],
  53. ['tempId', 0]
  54. ], null, true);
  55. if (!(int)$id) return JsonService::fail('参数错误');
  56. if (!strlen(trim($tempId))) return JsonService::fail('参数错误');
  57. $useStatus = $this->smsHandle->use($id, $tempId);
  58. if ($useStatus['status'] == 400) return JsonService::fail($useStatus['msg']);
  59. return JsonService::success($useStatus['msg']);
  60. }
  61. }