body); if (!is_array($data)) { noticeUtil::push("通知的消费者报错:Invalid notify message format: {$msg->body}", '15280215347'); return ConsumerInterface::MSG_REJECT; } print_r($data); // 根据通知类型分发处理 $type = $data['type'] ?? null; switch ($type) { case 'ghs_new_order_notify': //供货商的新订单通知 $result = $this->ghsNewOrderNotify($data); break; case 'hd_new_order_notify': //花店的新订单通知 $result = $this->hdNewOrderNotify($data); break; case 'hd_new_cg_notify': //花店的新采购单通知 $result = $this->hdNewCgNotify($data); break; default: noticeUtil::push("通知的消费者提示:Unknown notify type: {$type}", '15280215347'); $result = false; } if ($result) { return ConsumerInterface::MSG_ACK; } else { noticeUtil::push("通知的消费者提示:Notify message processing failed", '15280215347'); return ConsumerInterface::MSG_REQUEUE; } } catch (\Exception $e) { noticeUtil::push("Notify consumer exception: " . $e->getMessage(), '15280215347'); return ConsumerInterface::MSG_REQUEUE; } } private function ghsNewOrderNotify($data) { $orderId = $data['orderId'] ?? 0; if (empty($orderId)) { return false; } $order = OrderClass::getById($orderId, true); if (empty($order)) { return false; } $shopId = $order->shopId ?? 0; $shop = ShopClass::getById($shopId, true); if (empty($shop)) { return false; } WxMessageClass::ghsHasNewOrderInform($shop, $order); // 向供货商App发通知 $cgId = $order->purchaseId ?? 0; $cg = PurchaseClass::getById($cgId, true); $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName'); $push = new push('ghs', push::MSG_TYPE_ORDER); $push->ghsOrderMessage($shop, $cgShop, $order); return true; } private function hdNewOrderNotify($data) { return true; } private function hdNewCgNotify($data) { noticeUtil::push("花店已经通知了。。。", '15280215347'); $cgId = $data['cgId'] ?? 0; $cg = PurchaseClass::getById($cgId, true); $shopId = $cg->shopId ?? 0; $shop = ShopClass::getById($shopId, true); $allDevices = \bizHd\device\classes\HdDeviceClass::getAllByCondition(['shopId' => $shopId]); $cids = array_column($allDevices, 'clientId'); $title = '买花成功'; $shopName = $shop->merchantName . ($shop->shopName != '首店' ? '(' . $shop->shopName . ')' : ''); $content = $shopName . ' ¥' . $cg->actPrice; $payload = [ "page" => "pagesPurchase/purDetails", "params" => ["id" => $cgId] ]; $push = new push('hd', push::MSG_TYPE_ORDER); $push->pushByCloud($cids, $title, $content, $payload); return true; } }