select(['id','order_num','money', 'pay_type', 'store_id', 'type']); if ($isMain) { $orders = $orders->where(['order_main_id' => $orderId])->get()->toArray(); } else { $orders = $orders->where(['id' => $orderId])->get()->toArray(); } if(empty($orders)) return; // 循环发送 foreach ($orders as $k => &$order) { $order['template'] = "懒族生活支付到账".floatval($order['money'])."元"; // 获取终端ID $order['to_client_id'] = Store::query()->where(['id' => $order['store_id']])->value('loudspeaker_imei'); // 发布订阅消息 $this->pubToMqtt($order['template'], self::TOPIC, $order['to_client_id']); } } /** * @inheritDoc */ public function pubToMqtt($message, $topic, $toClientId) { $task = ApplicationContext::getContainer()->get(MQTTClientTask::class); $task->publish($message, $topic, $toClientId); } }