NoticeSmsService.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 app\services\store\SystemStoreStaffServices;
  16. use app\services\system\admin\SystemAdminServices;use think\facade\Log;
  17. /**
  18. * 短信发送消息列表
  19. * Created by PhpStorm.
  20. * User: xurongyao <763569752@qq.com>
  21. * Date: 2021/9/22 1:23 PM
  22. */
  23. class NoticeSmsService extends NoticeService
  24. {
  25. /**
  26. * 判断是否开启权限
  27. * @var bool
  28. */
  29. private $isopend = true;
  30. /**
  31. * 是否开启权限
  32. * @param string $mark
  33. * @return $this
  34. */
  35. public function isOpen(string $mark)
  36. {
  37. $this->isopend = $this->noticeInfo['is_sms'] === 1;
  38. return $this;
  39. }
  40. /**
  41. * 发送短信消息
  42. * @param $phone
  43. * @param array $data
  44. * @param string $template
  45. * @return bool|void
  46. */
  47. public function sendSms($phone, array $data, string $template)
  48. {
  49. try {
  50. $this->isopend = $this->noticeInfo['is_sms'] === 1;
  51. if ($this->isopend && $phone) {
  52. SmsJob::dispatch('doJob', [$phone, $data, $template]);
  53. }
  54. } catch (\Exception $e) {
  55. Log::error($e->getMessage());
  56. return true;
  57. }
  58. }
  59. /**
  60. * 退款发送管理员消息任务
  61. * @param $order
  62. * @return bool
  63. */
  64. public function sendAdminRefund($order, $store_id = 0)
  65. {
  66. if ($store_id != 0) {
  67. /** @var SystemStoreStaffServices $systemStoreStaffServices */
  68. $systemStoreStaffServices = app()->make(SystemStoreStaffServices::class);
  69. $adminList = $systemStoreStaffServices->getNotifyStoreStaffList($store_id, 'phone,staff_name as nickname');
  70. } elseif (isset($order['supplier_id']) && $order['supplier_id']) {
  71. /** @var SystemAdminServices $systemAdminServices */
  72. $systemAdminServices = app()->make(SystemAdminServices::class);
  73. $adminList = $systemAdminServices->getNotifySupplierList((int)$order['supplier_id'], 'phone,real_name as nickname');
  74. } else {
  75. /** @var StoreServiceServices $StoreServiceServices */
  76. $StoreServiceServices = app()->make(StoreServiceServices::class);
  77. $adminList = $StoreServiceServices->getStoreServiceOrderNotice();
  78. }
  79. if ($adminList) {
  80. foreach ($adminList as $item) {
  81. $data = ['order_id' => $order['order_id'], 'admin_name' => $item['nickname'] ?? ''];
  82. $this->sendSms($item['phone'], $data, 'ADMIN_RETURN_GOODS_CODE');
  83. }
  84. }
  85. return true;
  86. }
  87. /**
  88. * 用户确认收货管理员短信提醒
  89. * @param $switch
  90. * @param $adminList
  91. * @param $order
  92. * @return bool
  93. */
  94. public function sendAdminConfirmTakeOver($order)
  95. {
  96. /** @var StoreServiceServices $StoreServiceServices */
  97. $StoreServiceServices = app()->make(StoreServiceServices::class);
  98. $adminList = $StoreServiceServices->getStoreServiceOrderNotice();
  99. foreach ($adminList as $item) {
  100. $data = ['order_id' => $order['order_id'], 'admin_name' => $item['nickname']];
  101. $this->sendSms($item['phone'], $data, 'ADMIN_TAKE_DELIVERY_CODE');
  102. }
  103. return true;
  104. }
  105. /**
  106. * 下单成功给客服管理员发送短信
  107. * @param $switch
  108. * @param $adminList
  109. * @param $order
  110. * @return bool
  111. */
  112. public function sendAdminPaySuccess($order, $store_id = 0)
  113. {
  114. if ($store_id != 0) {
  115. /** @var SystemStoreStaffServices $systemStoreStaffServices */
  116. $systemStoreStaffServices = app()->make(SystemStoreStaffServices::class);
  117. $adminList = $systemStoreStaffServices->getNotifyStoreStaffList($store_id, 'phone,staff_name as nickname');
  118. } elseif (isset($order['supplier_id']) && $order['supplier_id']) {
  119. /** @var SystemAdminServices $systemAdminServices */
  120. $systemAdminServices = app()->make(SystemAdminServices::class);
  121. $adminList = $systemAdminServices->getNotifySupplierList((int)$order['supplier_id'], 'phone,real_name as nickname');
  122. } else {
  123. /** @var StoreServiceServices $StoreServiceServices */
  124. $StoreServiceServices = app()->make(StoreServiceServices::class);
  125. $adminList = $StoreServiceServices->getStoreServiceOrderNotice();
  126. }
  127. if ($adminList) {
  128. foreach ($adminList as $item) {
  129. $data = ['order_id' => $order['order_id'], 'admin_name' => $item['nickname'] ?? ''];
  130. $this->sendSms($item['phone'], $data, 'ADMIN_PAY_SUCCESS_CODE');
  131. }
  132. }
  133. return true;
  134. }
  135. }