From cf118c81ffdbaaca2620dcfbcd276e0679022a2d Mon Sep 17 00:00:00 2001
From: mkm <727897186@qq.com>
Date: Mon, 10 Jun 2024 09:11:59 +0800
Subject: [PATCH] =?UTF-8?q?feat(OrderLogic,=20UserLogic,=20PayNotifyLogic,?=
 =?UTF-8?q?=20PushDeliverySend):=20=E4=BF=AE=E6=94=B9=E8=AE=A2=E5=8D=95?=
 =?UTF-8?q?=E4=B8=8E=E7=94=A8=E6=88=B7=E9=80=BB=E8=BE=91=EF=BC=8C=E6=94=AF?=
 =?UTF-8?q?=E6=8C=81=E6=96=B0=E6=94=AF=E4=BB=98=E6=96=B9=E5=BC=8F=E4=B8=8E?=
 =?UTF-8?q?=E5=BA=93=E5=AD=98=E8=AE=A1=E7=AE=97=EF=BC=8C=E4=BC=98=E5=8C=96?=
 =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E9=80=9A=E7=9F=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/api/logic/order/OrderLogic.php   |  4 ++--
 app/api/logic/user/UserLogic.php     |  2 +-
 app/common/logic/PayNotifyLogic.php  |  2 +-
 app/queue/redis/PushDeliverySend.php | 30 ++++++++++++++++++++++++++++
 4 files changed, 34 insertions(+), 4 deletions(-)
 create mode 100644 app/queue/redis/PushDeliverySend.php

diff --git a/app/api/logic/order/OrderLogic.php b/app/api/logic/order/OrderLogic.php
index ca2c98f48..6f854771a 100644
--- a/app/api/logic/order/OrderLogic.php
+++ b/app/api/logic/order/OrderLogic.php
@@ -210,8 +210,8 @@ class OrderLogic extends BaseLogic
                 $_order['user_phone'] = $address['phone'];
                 $_order['user_address'] = $address['detail'];
             }
-        } else {
-            //没有地址时,默认为门店自提
+        } 
+        if($params['shipping_type'] == 2){
             $_order['status'] = 1;
         }
 
diff --git a/app/api/logic/user/UserLogic.php b/app/api/logic/user/UserLogic.php
index d76341db5..0428c03a3 100644
--- a/app/api/logic/user/UserLogic.php
+++ b/app/api/logic/user/UserLogic.php
@@ -66,7 +66,7 @@ class UserLogic extends BaseLogic
     public static function info($uid)
     {
         $data =  User::with(['userShip'])->where('id',$uid)
-            ->field('avatar,real_name,nickname,account,mobile,sex,login_ip,now_money,total_recharge_amount,user_ship')
+            ->field('id,avatar,real_name,nickname,account,mobile,sex,login_ip,now_money,total_recharge_amount,user_ship')
             ->find();
         //判断是不是员工
         if($data){
diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php
index 439fa8e10..acbcbfebc 100644
--- a/app/common/logic/PayNotifyLogic.php
+++ b/app/common/logic/PayNotifyLogic.php
@@ -126,7 +126,7 @@ class PayNotifyLogic extends BaseLogic
             Redis::send('push-platform-print', ['id' => $order['id']], 60);
             //            Db::name('order_middle')->insert(['c_order_id' => $order['id']]);
         }
-        if (!empty($extra['payer']['openid']) && $order->pay_type != 9) {
+        if (!empty($extra['payer']['openid']) && $order->pay_type == 7) {
             Redis::send('push-delivery', ['order_sn' => $order['order_id'], 'openid' => $extra['payer']['openid']], 5);
         }
         return true;
diff --git a/app/queue/redis/PushDeliverySend.php b/app/queue/redis/PushDeliverySend.php
new file mode 100644
index 000000000..92ac7301b
--- /dev/null
+++ b/app/queue/redis/PushDeliverySend.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace app\queue\redis;
+
+use app\common\service\wechat\WeChatMnpService;
+use Webman\RedisQueue\Consumer;
+
+use support\Log;
+
+class PushDeliverySend implements Consumer
+{
+    // 要消费的队列名
+    public $queue = 'push-delivery';
+
+    // 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
+    public $connection = 'default';
+
+    // 消费
+    public function consume($data)
+    {
+        (new WeChatMnpService)->delivery($data['order_id'], $data['openid']);
+
+    }
+    public function onConsumeFailure(\Throwable $e, $package)
+    {
+        $package['max_attempts']=0;
+        Log::error('推送小程序发货通知失败:'.$package['data']['order_id']);
+        return $package;
+    }
+}
\ No newline at end of file