Преглед изворни кода

调整第三方解绑方法

sunxbiao пре 1 година
родитељ
комит
d25e524662
1 измењених фајлова са 15 додато и 1 уклоњено
  1. 15 1
      app/controller/api/user/User.php

+ 15 - 1
app/controller/api/user/User.php

@@ -2601,18 +2601,26 @@ class User extends BaseController
2601
         $type = $this->request->param('type');
2601
         $type = $this->request->param('type');
2602
         $uid = $this->request->uid();
2602
         $uid = $this->request->uid();
2603
         makeLock()->lock();
2603
         makeLock()->lock();
2604
+        Db::startTrans();
2604
         try {
2605
         try {
2605
             if ($type == 1) {
2606
             if ($type == 1) {
2606
                 $data = ["wechat_user_id" => 0];
2607
                 $data = ["wechat_user_id" => 0];
2608
+                $user_extract_openid = Db::name('user_extract_openid')->where('uid',$uid)->find();
2609
+                if (!empty($user_extract_openid)) {
2610
+                    Db::name('log')->insert(['data' => '三方授权解绑(' . $uid . ')' . json_encode($user_extract_openid)]);
2611
+                    Db::name('user_extract_openid')->where('uid', $uid)->delete();  // 使用 Db 对象删除
2612
+                }
2607
             } else {
2613
             } else {
2608
                 $data = ["ali_user_id" => 0];
2614
                 $data = ["ali_user_id" => 0];
2609
             }
2615
             }
2610
             $result = $this->repository->updateUser($uid, $data);
2616
             $result = $this->repository->updateUser($uid, $data);
2611
             if (!$result) throw new \Exception("修改失败");
2617
             if (!$result) throw new \Exception("修改失败");
2612
         } catch (\Throwable $e) {
2618
         } catch (\Throwable $e) {
2619
+            Db::rollback();
2613
             makeLock()->unlock();
2620
             makeLock()->unlock();
2614
             return app("json")->fail("失败" . $e->getMessage());
2621
             return app("json")->fail("失败" . $e->getMessage());
2615
         }
2622
         }
2623
+        Db::commit();
2616
         makeLock()->unlock();
2624
         makeLock()->unlock();
2617
         return app("json")->success("解绑成功", $data);
2625
         return app("json")->success("解绑成功", $data);
2618
     }
2626
     }
@@ -2639,8 +2647,14 @@ class User extends BaseController
2639
             if ($type == 1) {
2647
             if ($type == 1) {
2640
                 $data = ["wechat_user_id" => $openid];
2648
                 $data = ["wechat_user_id" => $openid];
2641
                 $unionId = $openid;
2649
                 $unionId = $openid;
2650
+                $check = Db::name('user_extract_openid')->where('openid',$openid)->value('uid');
2651
+                if (!empty($check) && $check != $uid){
2652
+                    throw new \Exception("此微信号已被其他用户绑定");
2653
+                }
2642
                 $check = Db::name('user_extract_openid')->where('uid',$uid)->value('openid');
2654
                 $check = Db::name('user_extract_openid')->where('uid',$uid)->value('openid');
2643
-                if ($check) throw new \Exception("此微信号已被绑定");
2655
+                if (!empty($check) && $check != $openid){
2656
+                    throw new \Exception("您已绑定其他微信号");
2657
+                }
2644
             } else {
2658
             } else {
2645
                 $alinfo = json_decode($alinfo, true);
2659
                 $alinfo = json_decode($alinfo, true);
2646
                 if (!$alinfo) throw new \Exception("参数异常");
2660
                 if (!$alinfo) throw new \Exception("参数异常");