dever 6 years ago
parent
commit
012f783734
3 changed files with 55 additions and 1 deletions
  1. 24 1
      src/App.php
  2. 2 0
      src/Applet.php
  3. 29 0
      src/Lib/Base.php

+ 24 - 1
src/App.php

@@ -40,7 +40,30 @@ class App extends Base
             Dever::alert('无效的用户id,请重新登录');
         }
 
-        $result = Dever::load('passport/user-one', $uid);
+        $result = Dever::db('passport/user')->one($uid);
+        if ($name) {
+            $result['username'] = $name;
+        }
+        if ($pic) {
+            $result['avatar'] = $pic;
+        }
+        if ($sex) {
+            $result['sex'] = $sex;
+        }
+        if ($city) {
+            $result['city'] = $city;
+        }
+        if ($province) {
+            $result['province'] = $province;
+        }
+        if ($country) {
+            $result['country'] = $country;
+        }
+        if ($country && $province && $city) {
+            $result['area'] = $update['set_area'];
+        }
+
+        
         $result['uid'] = $uid;
         $result['signature'] = Dever::login($uid);
 

+ 2 - 0
src/Applet.php

@@ -148,6 +148,8 @@ class Applet extends Base
             $uid = $info['uid'];
             if (isset($data['unionid']) && $data['unionid']) {
                 $wechat['unionid'] = $data['unionid'];
+                # 判断用户是否存在,是否需要合并
+                $wechat['uid'] = $this->combine($uid, $data['unionid']);
             }
             
             $wechat['session_key'] = $data['session_key'];

+ 29 - 0
src/Lib/Base.php

@@ -22,6 +22,35 @@ class Base
         $this->save = new Save(false, 'cookie');
     }
 
+    # 合并用户
+    protected function combine($uid, $unionid, $col = 'unionid')
+    {
+        return;
+        $user_wechat = Dever::load('passport/wechat-state', array($col => $unionid));
+        if ($user_wechat) {
+            # 合并去
+            $cur = $uid;//1 1,2
+            $drop = array();
+            foreach ($user_wechat as $k => $v) {
+                if ($v['uid'] < $cur) {
+                    $drop[$cur] = $cur;
+                    $cur = $v['uid'];
+                } elseif ($v['uid'] > $cur) {
+                    $drop[$v['uid']] = $v['uid'];
+                }
+            }
+            if ($drop) {
+                foreach ($drop as $k => $v) {
+                    Dever::load('passport/user-update', array('set_state' => 2, 'where_id' => $v));
+                }
+                $combine = Dever::project('combine');
+                if ($combine) {
+                    Dever::load('combine/lib/core')->handle($cur, $drop);
+                }
+            }
+        }
+    }
+
     /**
      * 检测用户有效性
      *