Jelajahi Sumber

1.扫码付款--支持发跑腿 2.保存或修改推客户端id的接口新增接收参数 deviceId(设备Id)

shizhongqi 6 bulan lalu
induk
melakukan
de58efeb3d

+ 4 - 1
app-ghs/controllers/AdminController.php

@@ -99,6 +99,7 @@ class AdminController extends BaseController
     {
         $get = Yii::$app->request->get();
         $id = $get['id'] ?? '';
+        $deviceId = $get['deviceId'];
         $autoLogin = $get['auto'] ?? 0; // 是否自动登录的请求
         //noticeUtil::push("批发客户端ID: " . $id);
         if (empty($id)) {
@@ -107,9 +108,10 @@ class AdminController extends BaseController
         $this->admin->clientId = $id;
         $this->admin->save();
 
-        $ghsDevice = GhsDeviceClass::getByCondition(['clientId'=>$id], true);
+        $ghsDevice = GhsDeviceClass::getByCondition(['deviceId'=>$deviceId], true);
         if ($ghsDevice == null){
             $device = [
+                'deviceId' => $deviceId,
                 'clientId' => $id,
                 'mainId' => $this->mainId,
                 'shopId' => $this->shopId,
@@ -128,6 +130,7 @@ class AdminController extends BaseController
             } else {
                 $ghsDevice->pwdLoginTime = date('Y-m-d H:i:s');
             }
+            $ghsDevice->clientId = $id;
             $ghsDevice->mainId = $this->mainId;
             $ghsDevice->shopId = $this->shopId;
             $ghsDevice->adminId = $this->adminId;

+ 0 - 8
app-ghs/controllers/DeliveryController.php

@@ -129,14 +129,6 @@ class DeliveryController extends BaseController
 
 
     // ----------------------------------------------- 各业务接口 ---------------------------------------------------------------
-    // public function actionHuolalaVehicle()
-    // {
-    //     $mainId = $this->mainId;
-    //     $authPlatforms = DeliveryAuthTokenClass::getByCondition(['mainId' => $mainId, 'platform' => 'huolala']);
-    //     $huolalaAdapter = new HuolalaAdapter($authPlatforms['access_token']);
-    //     $cities = $huolalaAdapter->getCityVehicleList(1006);
-    //     return $this->asJson($cities);
-    // }
 
     /**
      * @deprecated

+ 1 - 1
app-ghs/controllers/OrderController.php

@@ -1149,7 +1149,7 @@ class OrderController extends BaseController
             $post['bookSn'] = $bookSn;
         }
 
-        $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay');
+        $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay'); //收款方式  0:扫码付(待付款) 1:线下(已付款) 2:赊账(欠款)3:现金 4:余额
         $post['debt'] = OrderClass::DEBT_NO;
         if ($hasPay == dict::getDict('hasPay', 'debt')) {
             $post['debt'] = OrderClass::DEBT_YES;

+ 78 - 32
biz-ghs/express/classes/GhsDeliveryOrderClass.php

@@ -17,9 +17,36 @@ class GhsDeliveryOrderClass extends BaseClass
 
     public static function payAfter($order)
     {
-        $orderId = $order->id ?? 0;
+        $orderId = $order->id;
         try {
-            //noticeUtil::push('批发,付款成功之后要发跑腿的订单:' . $order->id, '15280215347');
+            noticeUtil::push('批发,付款成功之后要发跑腿的订单:' . $orderId, '15280215347');
+            $cacheKey = 'ghs_pt_cacheData:' . $orderId;
+            $cachedData = Yii::$app->redis->get($cacheKey);
+            if (!empty($cachedData)) {
+                $cachedData = json_decode($cachedData, true);
+
+                $data = [
+                    'orderId' => $orderId,
+                    'shopId' => $order->shopId,
+                    'mainId' => $order->mainId,
+                    'platform' => $cachedData['deliveryPlatform'],
+                    'ip' => '127.0.0.1',
+                    'deliveryPrice' => $cachedData['deliveryPrice'],
+                    'deliveryDistance' => $cachedData['deliveryDistance'],
+                    'deliveryBracketContent' => $cachedData['deliveryBracketContent'],
+                    'pickupTime' => $cachedData['pickupTime'],
+                    'allParams' => $cachedData['deliveryAllParams'],
+                    'weight' => $cachedData['weight'] ?? 1,
+                    'remark' => $cachedData['deliveryRemark'] ?? '',
+                    'price' => $order->actPrice,
+                ];
+                self::askCreateOrder($data);
+            } else {
+                noticeUtil::push("批发-缓存数据不存在或已过期,cacheKey:{$cacheKey}");
+                // 发送 app 通知
+                
+                return;
+            }
         } catch (\Exception $e) {
             $msg = $e->getMessage();
             $remind = "批发,付款成功之后要发跑腿的订单,报错 {$orderId} {$msg}";
@@ -31,36 +58,55 @@ class GhsDeliveryOrderClass extends BaseClass
     public static function prepareAskData($post, $order)
     {
         try {
-            $callErrand = $post['callErrand'] ?? 0;
-            $sendType = $post['sendType'] ?? 0;
-            $saleId = $order->id ?? 0;
-            $shopId = $order->shopId ?? 0;
-            $mainId = $order->mainId ?? 0;
-            if ($callErrand == 1) {
-                if ($order->payStatus == 1 && $sendType == dict::getDict('sendType', 'thirdSend')) { // $post 中有 pickupTime,则说明是要立即发跑腿 或者 callErrand == 1
-                    $platform = $post['deliveryPlatform'];
-                    $deliveryPrice = $post['deliveryPrice'];
-                    $deliveryDistance = $post['deliveryDistance'];
-                    $deliveryBracketContent = $post['deliveryBracketContent'];
-                    $pickupTime = $post['pickupTime'];
-                    $allParams = $post['deliveryAllParams'];
-                    $data = [
-                        'orderId' => $saleId,
-                        'shopId' => $shopId,
-                        'mainId' => $mainId,
-                        'platform' => $platform,
-                        'ip' => Yii::$app->request->userIP,
-                        'deliveryPrice' => $deliveryPrice,
-                        'deliveryDistance' => $deliveryDistance,
-                        'deliveryBracketContent' => $deliveryBracketContent,
-                        'pickupTime' => $pickupTime,
-                        'allParams' => $allParams,
-                        // ----------
-                        'weight' => $post['weight'] ?? 1,
-                        'remark' => $post['deliveryRemark'] ?? '',
-                        'price' => $order->actPrice,
-                    ];
-                    GhsDeliveryOrderClass::askCreateOrder($data);
+            $callErrand = $post['callErrand']; // 是否立即发跑腿 1:是 0:否
+            $saleId = $order->id;
+
+            if ($callErrand == 1) { // 是否立即发跑腿 1:是 0:否
+                $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay'); //收款方式  0:扫码付(待付款) 1:线下(已付款) 2:赊账(欠款)3:现金 4:余额
+
+                if ($hasPay == dict::getDict('hasPay', 'unPay')) { // 0:扫码付(待付款)
+                    $deliveryPlatform = $post['deliveryPlatform'];
+                    $expireTime = 0;
+                    if($deliveryPlatform == 'shansong'){
+                        $expireTime = 1800 - 60;
+                    }elseif($deliveryPlatform == 'didi'){
+                        $expireTime = 7200;
+                    }else{
+                        $expireTime = 7200; // 默认缓存时长2小时
+                    } 
+
+                    // 把跑腿数据缓存到 redis 中,等待付款成功后,再发跑腿订单
+                    $cacheKey = 'ghs_pt_orderId hd_pt_' . $saleId;
+                    Yii::$app->redis->set($cacheKey, json_encode($post, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
+                    Yii::$app->redis->expire($cacheKey, $expireTime);
+                } else {
+                    $sendType = $post['sendType'];
+
+                    if ($order->payStatus == 1 && $sendType == dict::getDict('sendType', 'thirdSend')) {
+                        $platform = $post['deliveryPlatform'];
+                        $deliveryPrice = $post['deliveryPrice'];
+                        $deliveryDistance = $post['deliveryDistance'];
+                        $deliveryBracketContent = $post['deliveryBracketContent'];
+                        $pickupTime = $post['pickupTime'];
+                        $allParams = $post['deliveryAllParams'];
+                        $data = [
+                            'orderId' => $saleId,
+                            'shopId' => $order->shopId,
+                            'mainId' => $order->mainId,
+                            'platform' => $platform,
+                            'ip' => Yii::$app->request->userIP,
+                            'deliveryPrice' => $deliveryPrice,
+                            'deliveryDistance' => $deliveryDistance,
+                            'deliveryBracketContent' => $deliveryBracketContent,
+                            'pickupTime' => $pickupTime,
+                            'allParams' => $allParams,
+                            // ----------
+                            'weight' => $post['weight'] ?? 1,
+                            'remark' => $post['deliveryRemark'] ?? '',
+                            'price' => $order->actPrice,
+                        ];
+                        self::askCreateOrder($data);
+                    }
                 }
             }
         } catch (\Exception $e) {

+ 71 - 31
biz-hd/express/classes/HdDeliveryOrderClass.php

@@ -16,9 +16,34 @@ class HdDeliveryOrderClass extends BaseClass
 
     public static function payAfter($order)
     {
-        $orderId = $order->id ?? 0;
+        $orderId = $order->id;
         try {
-            //noticeUtil::push('零售,付款成功之后要发跑腿的订单:' . $order->id, '15280215347');
+            noticeUtil::push('零售,付款成功之后要发跑腿的订单:' . $orderId, '15280215347');
+            $cacheKey = 'hd_pt_cacheData:' . $orderId;
+            $cachedData = Yii::$app->redis->get($cacheKey);
+            if (!empty($cachedData)) {
+                $cachedData = json_decode($cachedData, true);
+
+                $data = [
+                    'orderId' => $orderId,
+                    'shopId' => $order->shopId,
+                    'mainId' => $order->mainId,
+                    'platform' => $cachedData['deliveryPlatform'],
+                    'ip' => '127.0.0.1',
+                    'deliveryPrice' => $cachedData['deliveryPrice'],
+                    'deliveryDistance' => $cachedData['deliveryDistance'],
+                    'deliveryBracketContent' => $cachedData['deliveryBracketContent'],
+                    'pickupTime' => $cachedData['pickupTime'],
+                    'allParams' => $cachedData['deliveryAllParams'],
+                    'weight' => $cachedData['weight'] ?? 1,
+                    'remark' => $cachedData['deliveryRemark'] ?? '',
+                    'price' => $order->actPrice,
+                ];
+                self::askCreateOrder($data);
+            } else {
+                noticeUtil::push("零售-缓存数据不存在或已过期,cacheKey:{$cacheKey}");
+                return;
+            }
         } catch (\Exception $e) {
             $msg = $e->getMessage();
             $remind = "零售,付款成功之后要发跑腿的订单,报错 {$orderId} {$msg}";
@@ -31,37 +56,52 @@ class HdDeliveryOrderClass extends BaseClass
     {
         try {
             //跑腿订单生产者创建订单
-            $sendType = $post['sendType'] ?? 0;
-            $callErrand = $post['callErrand'] ?? 0;
-            $shopId = $order->shopId ?? 0;
-            $mainId = $order->mainId ?? 0;
             $orderId = $order->id ?? 0;
-            $actPrice = $order->actPrice ?? 0;
+            $callErrand = $post['callErrand']; // 是否立即发跑腿 1:是 0:否
+
             if ($callErrand == 1) {
-                if ($order->payStatus == 1 && $sendType == dict::getDict('sendType', 'thirdSend')) { // $post 中有 pickupTime,则说明是要立即发跑腿 或者 callErrand == 1
-                    $platform = $post['deliveryPlatform'];
-                    $deliveryPrice = $post['deliveryPrice'];
-                    $deliveryDistance = $post['deliveryDistance'];
-                    $deliveryBracketContent = $post['deliveryBracketContent'];
-                    $pickupTime = $post['pickupTime'];
-                    $allParams = $post['deliveryAllParams'];
-                    $data = [
-                        'orderId' => $orderId,
-                        'mainId' => $mainId,
-                        'shopId' => $shopId,
-                        'platform' => $platform,
-                        'ip' => Yii::$app->request->userIP,
-                        'deliveryPrice' => $deliveryPrice,
-                        'deliveryDistance' => $deliveryDistance,
-                        'deliveryBracketContent' => $deliveryBracketContent,
-                        'pickupTime' => $pickupTime,
-                        'allParams' => $allParams,
-                        //-----------------------
-                        'weight' => $post['weight'] ?? 1,
-                        'remark' => $post['deliveryRemark'] ?? '',
-                        'price' => $actPrice,
-                    ];
-                    HdDeliveryOrderClass::askCreateOrder($data);
+                $hasPay = $post['hasPay'] ?? dict::getDict('hasPay', 'unPay'); //收款方式  0:扫码付(待付款) 1:线下(已付款) 2:赊账(欠款)3:现金 4:余额
+                if ($hasPay == dict::getDict('hasPay', 'unPay')) { // 0:扫码付(待付款)
+                    $deliveryPlatform = $post['deliveryPlatform'];
+                    $expireTime = 0;
+                    if($deliveryPlatform == 'shansong'){
+                        $expireTime = 1800 - 60;
+                    }elseif($deliveryPlatform == 'didi'){
+                        $expireTime = 7200;
+                    }else{
+                        $expireTime = 7200; // 默认缓存时长2小时
+                    }
+                    $cacheKey = 'hd_pt_orderId hd_pt_' . $orderId;
+                    Yii::$app->redis->set($cacheKey, json_encode($post, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
+                    Yii::$app->redis->expire($cacheKey, $expireTime);
+                } else {
+                    $sendType = $post['sendType'];
+
+                    if ($order->payStatus == 1 && $sendType == dict::getDict('sendType', 'thirdSend')) { // $post 中有 pickupTime,则说明是要立即发跑腿 或者 callErrand == 1
+                        $platform = $post['deliveryPlatform'];
+                        $deliveryPrice = $post['deliveryPrice'];
+                        $deliveryDistance = $post['deliveryDistance'];
+                        $deliveryBracketContent = $post['deliveryBracketContent'];
+                        $pickupTime = $post['pickupTime'];
+                        $allParams = $post['deliveryAllParams'];
+                        $data = [
+                            'orderId' => $orderId,
+                            'mainId' => $order->mainId,
+                            'shopId' => $$order->shopId,
+                            'platform' => $platform,
+                            'ip' => Yii::$app->request->userIP,
+                            'deliveryPrice' => $deliveryPrice,
+                            'deliveryDistance' => $deliveryDistance,
+                            'deliveryBracketContent' => $deliveryBracketContent,
+                            'pickupTime' => $pickupTime,
+                            'allParams' => $allParams,
+                            //-----------------------
+                            'weight' => $post['weight'] ?? 1,
+                            'remark' => $post['deliveryRemark'] ?? '',
+                            'price' => $order->actPrice,
+                        ];
+                        self::askCreateOrder($data);
+                    }
                 }
             }
         } catch (\Exception $e) {

+ 11 - 2
common/components/push.php

@@ -16,8 +16,8 @@ class push
     const MSG_TYPE_SUBSCRIPTION = 'subscription'; // 订阅消息
 
     const SECRET = 'RIVATE_KEY_S^@VJDy7'; // 👈 与云函数中保持一致
-    const GHS_URL = 'https://fc-mp-42d1a66f-2aec-4fc5-9d92-4d176bf3d337.next.bspapp.com/ghs/push';
-    const HD_URL = 'https://fc-mp-027cce01-d39a-4ed2-8b09-1f4ff43ec945.next.bspapp.com/hd/push';
+    const GHS_URL = 'https://fc-mp-42d1a66f-2aec-4fc5-9d92-4d176bf3d337.next.bspapp.com/ghs/push'; // 配置地点--(服务空间ghs-uni-admin):云函数/云对象--函数/对象列表/uni-pushProxy
+    const HD_URL = 'https://fc-mp-027cce01-d39a-4ed2-8b09-1f4ff43ec945.next.bspapp.com/hd/push'; // 配置地点--(服务空间hd-uni-admin):云函数/云对象--函数/对象列表/uni-pushProxy
 
     // 私有属性
     private $url = '';
@@ -231,6 +231,15 @@ class push
         return $optionsArr;
     }
 
+    /**
+     * 向设备端发送通知
+     * @param array $cids 设备ID
+     * @param string $title 通知标题
+     * @param string $content 通知内容
+     * @param array $payload 通知的附加数据
+     * @return bool|string 返回设备的响应
+     * @throws \Exception 抛出异常
+     */
     public function pushByCloud($cids, $title, $content, $payload = [])
     {
         $sign = md5($title . $content . self::SECRET);

+ 0 - 1
common/components/rabbitmq/notifyConsumer.php

@@ -15,7 +15,6 @@ use common\components\noticeUtil;
 use common\components\push;
 use mikemadisonweb\rabbitmq\components\ConsumerInterface;
 use PhpAmqpLib\Message\AMQPMessage;
-use Yii;
 
 class notifyConsumer implements ConsumerInterface
 {