ClientMessageEvent.php 4.9 KB

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