SocketPushJob.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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\jobs\system;
  12. use crmeb\basic\BaseJobs;
  13. use crmeb\traits\QueueTrait;
  14. use app\webscoket\SocketPush;
  15. /**
  16. * socket推送
  17. * Class SocketPushJob
  18. * @package app\jobs\system
  19. */
  20. class SocketPushJob extends BaseJobs
  21. {
  22. use QueueTrait;
  23. /**
  24. * @return mixed
  25. */
  26. public static function queueName()
  27. {
  28. return 'CRMEB_PRO_SOCKET';
  29. }
  30. /**
  31. * 推送socket 消息
  32. * @param $to
  33. * @param $type
  34. * @param $data
  35. * @param $userType
  36. * @return bool
  37. */
  38. public function doJob($to, $type, $data, $userType = 'admin')
  39. {
  40. if (!$to || !$type) {
  41. return true;
  42. }
  43. //发送消息
  44. try {
  45. SocketPush::instance()->to($to)->setUserType($userType)->type($type)->data($data)->push();
  46. } catch (\Throwable $e) {
  47. }
  48. return true;
  49. }
  50. /**
  51. * 订单申请退款发送
  52. * @param $order
  53. * @return bool
  54. */
  55. public function sendApplyRefund($order)
  56. {
  57. if (!$order) {
  58. return true;
  59. }
  60. if ($order['store_id']) {
  61. //向门店后台发送退款订单消息
  62. try {
  63. SocketPush::store()->to($order['store_id'])->data(['order_id' => $order['order_id']])->type('NEW_REFUND_ORDER')->push();
  64. } catch (\Exception $e) {
  65. }
  66. } elseif ($order['supplier_id']) {
  67. //向门店后台发送退款订单消息
  68. try {
  69. SocketPush::instance()->setUserType('supplier')->to($order['supplier_id'])->data(['order_id' => $order['order_id']])->type('NEW_REFUND_ORDER')->push();
  70. } catch (\Exception $e) {
  71. }
  72. } else {
  73. //向后台发送退款订单消息
  74. try {
  75. SocketPush::admin()->data(['order_id' => $order['order_id']])->type('NEW_REFUND_ORDER')->push();
  76. } catch (\Exception $e) {
  77. }
  78. }
  79. return true;
  80. }
  81. }