Explorar el Código

保证xhDeliveryAuthToken表一个mainId 与一个platform 组成唯一索引

shizhongqi hace 8 meses
padre
commit
bab1da4674

+ 17 - 11
app-ghs/controllers/DeliveryController.php

@@ -782,22 +782,28 @@ class DeliveryController extends BaseController
         $result = $auth->getAccessToken($code, $merchantId);
 
         if (!$result['success']) {
+            noticeUtil::push("mainId=" . $mainId . ' 授权时,获取token失败,请让其重新发起授权');
             Yii::error(json_encode($result));
             throw new \yii\web\HttpException(500, '获取授权失败:' . $result['error']);
         }
         $result = $result['data'];
 
-        // 保存授权信息到数据库
-        $data = [
-            'mainId' => $mainId,
-            'shopId' => '',
-            'accessToken' => $result['access_token'],
-            'refreshToken' => $result['refresh_token'],
-            'expiresAt' => $result['expire_in'],
-            'authType' => 'all_store',
-            'platform' => 'fengniao'
-        ];
-        DeliveryAuthTokenClass::add($data);
+        $exist = DeliveryAuthTokenClass::exists(['mainId' => $mainId, 'platform' => 'fengniao']);
+        if($exist){
+            noticeUtil::push("mainId=" . $mainId . ' 已成功授权了。如果蜂鸟不能正确使用,请查询数据库进行检查。');
+        }else{
+            // 保存授权信息到数据库
+            $data = [
+                'mainId' => $mainId,
+                'shopId' => '',
+                'accessToken' => $result['access_token'],
+                'refreshToken' => $result['refresh_token'],
+                'expiresAt' => $result['expire_in'] + time(),
+                'authType' => 'all_store',
+                'platform' => 'fengniao'
+            ];
+            DeliveryAuthTokenClass::add($data);
+        }
 
         return $this->asJson(['return_code' => 0, 'return_msg' => 'OK']);
     }

+ 6 - 1
common/base/classes/BaseClass.php

@@ -178,7 +178,12 @@ class BaseClass
         return $model->getByCondition($condition, $returnObject, $order, $field);
     }
 
-    //是否存在  ssh 2019.8.30
+    /**
+     * 是否存在
+     * @param $condition
+     * @return bool
+     * @throws \yii\base\InvalidConfigException
+     */
     public static function exists($condition)
     {
         $model = self::getModel();

+ 5 - 1
common/base/models/Base.php

@@ -276,7 +276,11 @@ class Base extends ActiveRecord
         return $query;
     }
 
-    //是否存在数据 ssh 2019.
+    /**
+     * 是否存在数据
+     * @param $condition
+     * @return bool
+     */
     public function exists($condition)
     {
         return $this->conditionQuery($condition)->exists();