From a02db34d4d77affd5da1825d1ce08b9db02f4e2e Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Sat, 12 Aug 2023 09:56:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8F=91=E9=80=81=E7=89=A9?= =?UTF-8?q?=E6=B5=81=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/listener/DeliveryGoods.php | 53 ++++++-------------------------- app/listener/paySuccessOrder.php | 39 +++++++++++++++++++++++ 2 files changed, 49 insertions(+), 43 deletions(-) diff --git a/app/listener/DeliveryGoods.php b/app/listener/DeliveryGoods.php index 0208441f..20f5fd70 100644 --- a/app/listener/DeliveryGoods.php +++ b/app/listener/DeliveryGoods.php @@ -19,52 +19,19 @@ class DeliveryGoods $this->event = $event; Log::info("============= handle监听order_id " . $this->event['order']['order_id']); $this->event = $event; - //发起物流信息返回快递员手机 - $logisticsPhone = $this->sendLogistics($this->event['order']['order_id'], $this->event['order']['order_sn']); - //生成用户的收货码、发生短信包含收货码 - $this->generateLogisticsCode($this->event['order']['uid'], $this->event['order']['order_id'], $this->event['order']['order_sn'], $logisticsPhone); + //发生短信包含收货码 + $this->sendLogisticsCode($this->event['order']['uid'], $this->event['order']['order_id'], $this->event['order']['order_sn'], $logisticsPhone); } - //用户收货码 - public function generateLogisticsCode($uid, $orderId, $orderSn, $logisticsPhone) { - $code = random_int(1000, 9999); - $res = app()->make(StoreOrderRepository::class)->update($orderId, [ - 'logistics_code' => $code - ]); - if ($res) { - //收货人短信 - $phone = StoreOrder::where('order_id', $orderId)->value('user_phone'); - if ($phone) { - Log::info("发送短信 {$phone}, orderId: {$orderId}"); - SmsService::create()->send($phone, 'TAKEGOOD_CODE', ['number' => substr($orderSn, -6), 'number2' => $code, 'phone' => $logisticsPhone]); - } + public function sendLogisticsCode($uid, $orderId, $orderSn, $logisticsPhone) { + //收货人短信 + $phone = StoreOrder::where('order_id', $orderId)->value('user_phone'); + $logisticsCode = StoreOrder::where('order_id', $orderId)->value('logistics_code'); + $logisticsPhone = StoreOrder::where('order_id', $orderId)->value('logistics_phone'); + if ($phone) { + Log::info("发送短信 {$phone}, orderId: {$orderId}"); + SmsService::create()->send($phone, 'TAKEGOOD_CODE', ['number' => substr($orderSn, -6), 'number2' => $logisticsCode, 'phone' => $logisticsPhone ?? '']); } } - //发送物流 - public function sendLogistics($orderId, $orderSn) - { - Log::info("发送物流信息 orderId: {$orderId}, orderSn: {$orderSn}"); - $postUrl = env('LOGISTICS_LOGIS_URL'); - $curlPost = [ - 'order_id' => $orderId, - 'order_sn' => $orderSn, - ]; - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $postUrl); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); - $data = curl_exec($ch); - curl_close($ch); - $phone = ''; - if (!empty($data) && is_string($data)) { - $logisticsInfo = json_decode($data, true); - $phone = $logisticsInfo['data']['phone']; - Log::info("物流联系信息" . json_encode($logisticsInfo)); - } - return $phone; - } - } \ No newline at end of file diff --git a/app/listener/paySuccessOrder.php b/app/listener/paySuccessOrder.php index 702ca14c..faef9f86 100644 --- a/app/listener/paySuccessOrder.php +++ b/app/listener/paySuccessOrder.php @@ -136,9 +136,48 @@ class paySuccessOrder } Log::error('订单分润出错', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString()]); DingTalk::exception($e, '订单分润出错'); + //发起物流信息返回快递员手机 + $logisticsPhone = $this->sendLogistics($this->event['order']['order_id'], $this->event['order']['order_sn']); + //生成用户的收货码、发生短信包含收货码 + $this->generateLogisticsCode($this->event['order']['uid'], $this->event['order']['order_id'], $this->event['order']['order_sn'], $logisticsPhone); } } + //用户收货码 + public function generateLogisticsCode($uid, $orderId, $orderSn, $logisticsPhone) { + $code = random_int(1000, 9999); + app()->make(StoreOrderRepository::class)->update($orderId, [ + 'logistics_code' => $code, + 'logistics_phone' => $logisticsPhone + ]); + } + + //发送物流 + public function sendLogistics($orderId, $orderSn) + { + Log::info("发送物流信息 orderId: {$orderId}, orderSn: {$orderSn}"); + $postUrl = env('LOGISTICS_LOGIS_URL'); + $curlPost = [ + 'order_id' => $orderId, + 'order_sn' => $orderSn, + ]; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $postUrl); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost); + $data = curl_exec($ch); + curl_close($ch); + $phone = ''; + if (!empty($data) && is_string($data)) { + $logisticsInfo = json_decode($data, true); + $phone = $logisticsInfo['data']['phone']; + Log::info("物流联系信息" . json_encode($logisticsInfo)); + } + return $phone; + } + public function calculate($type, $field) { $merId = Db::name('merchant')->where('type_id', $type)