ClientMessageEvent.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace app\event;
  3. use app\model\ClientMessage;
  4. use app\model\Order;
  5. use app\model\OrderReturn;
  6. use app\model\OrderSheet;
  7. use support\Log;
  8. class ClientMessageEvent
  9. {
  10. /**
  11. * @Desc 发货通知
  12. * @Author Gorden
  13. * @Date 2024/7/16 10:28
  14. *
  15. * @param $params
  16. * @return void
  17. */
  18. public function delivery($params)
  19. {
  20. Log::info("发送消息", $params);
  21. try {
  22. $order = Order::where('order_id', $params['order_id'])
  23. ->select('join_order_member_id')
  24. ->first();
  25. $clientMessage = new ClientMessage();
  26. $clientMessage->client_message_classify = 'ORDER';
  27. $clientMessage->join_client_message_send = 'SYSTEM';
  28. $clientMessage->join_client_message_recv_member_id = $order->join_order_member_id;
  29. $clientMessage->client_message_sendtime = date('Y-m-d H:i:s');
  30. $clientMessage->client_message_status = 'PENDING';
  31. $clientMessage->client_message_category = 'NORMAL';
  32. $clientMessage->client_message_header_json = json_encode(['title' => '订单消息']);
  33. $clientMessage->client_message_addtimes = time();
  34. $sheet = OrderSheet::with([
  35. 'goods' => function ($query) {
  36. $query->select('goods_id', 'goods_name');
  37. }
  38. ])->where('join_sheet_order_id', $params['order_id'])
  39. ->select('order_sheet_id', 'join_sheet_goods_id', 'join_sheet_order_id', 'order_sheet_num')
  40. ->first();
  41. if ($params['express_type'] == '自提') {
  42. $clientMessage->client_message_body_json = json_encode([
  43. 'content' => '提货通知:您于' . date('Y年m月d日') . '在' . $params['order_express_premises'] . '提取了您购买的商品【' . $sheet->goods->goods_name . '】,数量:【' . intval($sheet->order_sheet_num) . '】。'
  44. ]);
  45. } else {
  46. $clientMessage->client_message_body_json = json_encode([
  47. 'content' => '发货通知:您购买的商品【' . $sheet->goods->goods_name . '】,数量:【' . intval($sheet->order_sheet_num) . '】已发货,物流公司:' . $params['order_express_company'] . ',物流单号:' . $params['order_express_code'] . ',请注意查收。'
  48. ]);
  49. }
  50. $clientMessage->save();
  51. } catch (\Exception $e) {
  52. Log::error("消息发送失败", ['msg' => $e->getMessage()]);
  53. }
  54. }
  55. /**
  56. * @Desc 退货/退款状态变更站内信
  57. * @Author Gorden
  58. * @Date 2024/7/16 14:19
  59. *
  60. * @param $params
  61. * @return void
  62. */
  63. public function returnStatus($params)
  64. {
  65. try {
  66. $orderReturn = OrderReturn::where('orders_return_id', $params['orders_return_id'])->first();
  67. if (!$orderReturn) {
  68. return;
  69. }
  70. if ($params['order_return_status'] == 'DOING') {
  71. $content = "商家已同意您的退货/退款申请。";
  72. } else {
  73. $content = "商家已拒绝您的退货/退款申请。";
  74. }
  75. $clientMessage = new ClientMessage();
  76. $clientMessage->client_message_classify = 'ORDER';
  77. $clientMessage->join_client_message_send = 'SYSTEM';
  78. $clientMessage->join_client_message_recv_member_id = $orderReturn->join_return_member_id;
  79. $clientMessage->client_message_sendtime = date('Y-m-d H:i:s');
  80. $clientMessage->client_message_status = 'PENDING';
  81. $clientMessage->client_message_category = 'NORMAL';
  82. $clientMessage->client_message_header_json = json_encode(['title' => '订单消息']);
  83. $clientMessage->client_message_body_json = json_encode(['content' => '退货/退款通知:' . $content]);
  84. $clientMessage->client_message_addtimes = time();
  85. $clientMessage->save();
  86. } catch (\Exception $e) {
  87. }
  88. }
  89. /**
  90. * @Desc 退款成功通知
  91. * @Author Gorden
  92. * @Date 2024/7/16 14:09
  93. *
  94. * @param $memberId
  95. * @return void
  96. */
  97. public function refund($memberId)
  98. {
  99. try {
  100. $clientMessage = new ClientMessage();
  101. $clientMessage->client_message_classify = 'ORDER';
  102. $clientMessage->join_client_message_send = 'SYSTEM';
  103. $clientMessage->join_client_message_recv_member_id = $memberId;
  104. $clientMessage->client_message_sendtime = date('Y-m-d H:i:s');
  105. $clientMessage->client_message_status = 'PENDING';
  106. $clientMessage->client_message_category = 'NORMAL';
  107. $clientMessage->client_message_header_json = json_encode(['title' => '订单消息']);
  108. $clientMessage->client_message_body_json = json_encode(['content' => '退款通知:您申请的退款已原路返回,请注意查收。']);
  109. $clientMessage->client_message_addtimes = time();
  110. $clientMessage->save();
  111. } catch (\Exception $e) {
  112. }
  113. }
  114. }