NoticeSmsService.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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\services\message\notice;
  12. use app\jobs\notice\SmsJob;
  13. use app\services\message\NoticeService;
  14. use app\services\message\service\StoreServiceServices;
  15. use think\facade\Log;
  16. /**
  17. * 短信发送消息列表
  18. * Created by PhpStorm.
  19. * User: xurongyao <763569752@qq.com>
  20. * Date: 2021/9/22 1:23 PM
  21. */
  22. class NoticeSmsService extends NoticeService
  23. {
  24. /**
  25. * 判断是否开启权限
  26. * @var bool
  27. */
  28. private $isopend = true;
  29. /**
  30. * 是否开启权限
  31. * @param string $mark
  32. * @return $this
  33. */
  34. public function isOpen(string $mark)
  35. {
  36. $this->isopend = $this->notceinfo['is_sms'] === 1 ? true : false;
  37. return $this;
  38. }
  39. /**
  40. * 发送短信消息
  41. * @param string $tempCode 模板消息常量名称
  42. * @param $uid uid
  43. * @param array $data 模板内容
  44. * @param string $link 跳转链接
  45. * @param string|null $color 文字颜色
  46. * @return bool|mixed
  47. */
  48. public function sendSms($phone, array $data, string $template)
  49. {
  50. try {
  51. $this->isopend = $this->notceinfo['is_sms'] === 1 ? true : false;
  52. if ($this->isopend) {
  53. SmsJob::dispatch('doJob', [$phone, $data, $template]);
  54. }
  55. } catch (\Exception $e) {
  56. Log::error($e->getMessage());
  57. return true;
  58. }
  59. }
  60. /**
  61. * 退款发送管理员消息任务
  62. * @param $order
  63. * @return bool
  64. */
  65. public function sendAdminRefund($order)
  66. {
  67. /** @var StoreServiceServices $StoreServiceServices */
  68. $StoreServiceServices = app()->make(StoreServiceServices::class);
  69. $adminList = $StoreServiceServices->getStoreServiceOrderNotice();
  70. foreach ($adminList as $item) {
  71. $data = ['order_id' => $order['order_id'], 'admin_name' => $item['nickname']];
  72. $this->sendSms($item['phone'], $data, 'ADMIN_RETURN_GOODS_CODE');
  73. }
  74. return true;
  75. }
  76. /**
  77. * 用户确认收货管理员短信提醒
  78. * @param $switch
  79. * @param $adminList
  80. * @param $order
  81. * @return bool
  82. */
  83. public function sendAdminConfirmTakeOver($order)
  84. {
  85. /** @var StoreServiceServices $StoreServiceServices */
  86. $StoreServiceServices = app()->make(StoreServiceServices::class);
  87. $adminList = $StoreServiceServices->getStoreServiceOrderNotice();
  88. foreach ($adminList as $item) {
  89. $data = ['order_id' => $order['order_id'], 'admin_name' => $item['nickname']];
  90. $this->sendSms($item['phone'], $data, 'ADMIN_TAKE_DELIVERY_CODE');
  91. }
  92. return true;
  93. }
  94. /**
  95. * 下单成功给客服管理员发送短信
  96. * @param $switch
  97. * @param $adminList
  98. * @param $order
  99. * @return bool
  100. */
  101. public function sendAdminPaySuccess($order)
  102. {
  103. /** @var StoreServiceServices $StoreServiceServices */
  104. $StoreServiceServices = app()->make(StoreServiceServices::class);
  105. $adminList = $StoreServiceServices->getStoreServiceOrderNotice();
  106. foreach ($adminList as $item) {
  107. $data = ['order_id' => $order['order_id'], 'admin_name' => $item['nickname']];
  108. $this->sendSms($item['phone'], $data, 'ADMIN_PAY_SUCCESS_CODE');
  109. }
  110. return true;
  111. }
  112. }