Просмотр исходного кода

完善分享商品对新注册用户

sunxbiao 1 год назад
Родитель
Сommit
e8737484a8
2 измененных файлов с 32 добавлено и 14 удалено
  1. 4 2
      app/common/repositories/user/UserRepository.php
  2. 28 12
      app/controller/api/Auth.php

+ 4 - 2
app/common/repositories/user/UserRepository.php

@@ -1444,7 +1444,7 @@ class UserRepository extends BaseRepository
1444
     }
1444
     }
1445
 
1445
 
1446
     //$repository->registr($data['phone'], $data['password'],'APP',"","",$data['spread']);
1446
     //$repository->registr($data['phone'], $data['password'],'APP',"","",$data['spread']);
1447
-    public function registr(string $phone, ?string $pwd, $user_type = 'h5',$url="",$nickname="",$external=1,$spread_uid=null)
1447
+    public function registr(string $phone, ?string $pwd, $user_type = 'h5',$url="",$nickname="",$external=1,$spread_uid=0)
1448
     {
1448
     {
1449
         $user_res = Db::name('user')->where('phone', $phone)->find();
1449
         $user_res = Db::name('user')->where('phone', $phone)->find();
1450
         if ($user_res && !$user_res['account']) {
1450
         if ($user_res && !$user_res['account']) {
@@ -3266,7 +3266,7 @@ class UserRepository extends BaseRepository
3266
 
3266
 
3267
 
3267
 
3268
     /*微信支付宝绑定*/
3268
     /*微信支付宝绑定*/
3269
-    public function thirdBinding(string $phone, ?string $pwd, $user_type = 'APP',$third_user_id='',$type=0,$url)
3269
+    public function thirdBinding(string $phone, ?string $pwd, $user_type = 'APP',$third_user_id='',$type=0,$url, $spread_uid = 0)
3270
     {
3270
     {
3271
         $pwd = $pwd ? $this->encodePassword($pwd) : $this->encodePassword($this->dao->defaultPwd());
3271
         $pwd = $pwd ? $this->encodePassword($pwd) : $this->encodePassword($this->dao->defaultPwd());
3272
         $user = $this->accountByUser($phone);
3272
         $user = $this->accountByUser($phone);
@@ -3282,6 +3282,8 @@ class UserRepository extends BaseRepository
3282
                 'avatar' => $url.'/uploads/logo.jpg',
3282
                 'avatar' => $url.'/uploads/logo.jpg',
3283
                 'phone' => $phone,
3283
                 'phone' => $phone,
3284
                 'last_ip' => app('request')->ip(),
3284
                 'last_ip' => app('request')->ip(),
3285
+                "level_id"=>$spread_uid,
3286
+                "spread_uid"=>$spread_uid
3285
             ];
3287
             ];
3286
         }
3288
         }
3287
         if($type ==1){
3289
         if($type ==1){

+ 28 - 12
app/controller/api/Auth.php

@@ -1477,11 +1477,12 @@ class Auth extends BaseController
1477
 
1477
 
1478
         $user = $repository->accountByUser($data['phone']);
1478
         $user = $repository->accountByUser($data['phone']);
1479
         if (!$user){
1479
         if (!$user){
1480
-            if (!intval($data['spread'])) {
1480
+            $data['spread_uid'] = 0;
1481
+            if (!intval($data['share_id'])) {
1481
                 $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
1482
                 $spread_uid = Db::name('product_share')->where('id', $data['share_id'])->value('uid');
1482
-                $data['spread'] = $spread_uid;
1483
+                $data['spread_uid'] = $spread_uid;
1483
             }
1484
             }
1484
-            $user = $repository->registr($data['phone'], null, 'h5', $data['spread']);
1485
+            $user = $repository->registr($data['phone'], null, 'h5', '','',1, $data['spread_uid']);
1485
         }
1486
         }
1486
         $user = $repository->mainUser($user);
1487
         $user = $repository->mainUser($user);
1487
 
1488
 
@@ -1696,7 +1697,12 @@ class Auth extends BaseController
1696
      */
1697
      */
1697
     public function binding(UserAuthValidate $validate, UserRepository $repository)
1698
     public function binding(UserAuthValidate $validate, UserRepository $repository)
1698
     {
1699
     {
1699
-        $data = $this->request->params(['phone', 'sms_code', 'password','third_user_id','type','nickName','avatarUrl','sms']);
1700
+        $data = $this->request->params(['phone', 'sms_code', 'password','third_user_id','type','sms']);
1701
+
1702
+        $data['nickName'] = $this->request->param('nickName', null);
1703
+        $data['avatarUrl'] = $this->request->param('avatarUrl', null);
1704
+        $share_id = $this->request->param('share_id', null);
1705
+        $spread_uid = 0;
1700
 
1706
 
1701
         if(!$data['third_user_id'] || $data['third_user_id'] == '' || $data['third_user_id'] =='undefined'){
1707
         if(!$data['third_user_id'] || $data['third_user_id'] == '' || $data['third_user_id'] =='undefined'){
1702
             return app('json')->fail("绑定失败");
1708
             return app('json')->fail("绑定失败");
@@ -1707,7 +1713,11 @@ class Auth extends BaseController
1707
             if (!$this->checkSmsCode($data['phone'], $data['sms_code']))
1713
             if (!$this->checkSmsCode($data['phone'], $data['sms_code']))
1708
                 return app('json')->fail('验证码不正确');
1714
                 return app('json')->fail('验证码不正确');
1709
         }
1715
         }
1710
-        $user = $repository->thirdBinding($data['phone'], $data['password'],'APP',$data['third_user_id'],$data['type'],"https://". $this->request->host(true));//2222
1716
+        if (!empty($share_id)) {
1717
+            $spread_uid = Db::name('product_share')->where('id', $share_id)->value('uid');
1718
+        }
1719
+
1720
+        $user = $repository->thirdBinding($data['phone'], $data['password'],'APP',$data['third_user_id'],$data['type'],"https://". $this->request->host(true), $spread_uid);//2222
1711
         if($user){
1721
         if($user){
1712
 
1722
 
1713
             $userRepository = app()->make(UserRepository::class);
1723
             $userRepository = app()->make(UserRepository::class);
@@ -1752,12 +1762,15 @@ class Auth extends BaseController
1752
             } else {
1762
             } else {
1753
                 $data1 = ["ali_user_id" => $data['third_user_id']];
1763
                 $data1 = ["ali_user_id" => $data['third_user_id']];
1754
             }
1764
             }
1755
-            $data2 = [
1756
-                "type" => $data['type'],
1757
-                "uid" => $user->uid,
1758
-                "nickname" => !empty($data['nickName']) ? $data['nickName'] : $user -> nickname,
1759
-                "avater" => !empty($data['avatarUrl']) ? $data['avatarUrl'] : $user -> avater,
1760
-            ];
1765
+            $data2 = [];
1766
+            if (!is_null($data['nickName']) || !is_null($data['avatarUrl'])) {
1767
+                $data2 = [
1768
+                    "type" => $data['type'],
1769
+                    "uid" => $user->uid,
1770
+                    "nickname" => $data['nickName'],
1771
+                    "avater" => $data['avatarUrl'],
1772
+                ];
1773
+            }
1761
             $userRepository -> updateUser($user->uid,$data1,$data2);
1774
             $userRepository -> updateUser($user->uid,$data1,$data2);
1762
 
1775
 
1763
             $pid = $this->request->param('spread', 0);
1776
             $pid = $this->request->param('spread', 0);
@@ -1950,7 +1963,10 @@ class Auth extends BaseController
1950
 
1963
 
1951
             if(!$user_res){
1964
             if(!$user_res){
1952
                 $spread_uid=Db::name('product_share')->where('id',$share_id['share_id'])->value('uid');
1965
                 $spread_uid=Db::name('product_share')->where('id',$share_id['share_id'])->value('uid');
1953
-                $repository->registr($phone, 123456,'APP',$spread_uid);
1966
+                if (!intval($spread_uid)) {
1967
+                    $spread_uid = 0;
1968
+                }
1969
+                $repository->registr($phone, 123456,'APP','','','',$spread_uid);
1954
             }
1970
             }
1955
             $user = $repository->accountByUser($phone);
1971
             $user = $repository->accountByUser($phone);
1956
             if($this->source=='yhc' && $this->merId){
1972
             if($this->source=='yhc' && $this->merId){