Bläddra i källkod

fix relation bug

stanley-king 7 år sedan
förälder
incheckning
4cace764e2

+ 3 - 3
helper/account_helper.php

@@ -338,17 +338,17 @@ class account_helper
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     public static function onRegister($member_id,$relay_id)
     {
-        relation_helper::onRegister($member_id);
         if($relay_id > 0) {
             relation_helper::onSubscribe($member_id,$relay_id);
             relation_helper::onInvite($relay_id,$member_id);
         }
+        relation_helper::onRegister($member_id);
         $publisher = new message\publisher();
-        $publisher->add_inviter($member_id,$relay_id);
         if($relay_id > 0) {
-            $publisher->add_fellow($relay_id,[$member_id]);
+            $publisher->add_follow($relay_id,[$member_id]);
         }
 
+        $publisher->add_inviter($member_id,$relay_id);
         QueueClient::push('onAsyncRegister',['user' => $member_id,'inviter' => $relay_id]);
     }
 

+ 1 - 1
helper/async/order.php

@@ -119,7 +119,7 @@ class order extends IAsync
     {
         $pd_amount = $this->simple_order->pd_amount();
         $bonus_rates = $this->simple_order->bonus_rates();
-        if(empty($bonus_rate)) {
+        if(empty($bonus_rates)) {
             $bonus_rates = [30 => $pd_amount];
         } else {
             $bonus_rates = unserialize($bonus_rates);

+ 1 - 1
helper/message/msgutil.php

@@ -134,7 +134,7 @@ function handler_redis($redis, $chan, $msg)
         if($chan == 'special') {
             UgcHandler::onSpecial($msg);
         }
-        elseif($chan == 'fellow') {
+        elseif($chan == 'follow') {
             UgcHandler::onFellow($msg);
         }
         elseif ($chan == 'inviter') {

+ 6 - 5
helper/message/publisher.php

@@ -147,7 +147,6 @@ class publisher
     }
 
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
     public function add_inviter($user,$inviter)
     {
         if($this->mConnected)
@@ -159,7 +158,7 @@ class publisher
         }
     }
 
-    public function add_fellow($user,$fellows)
+    public function add_follow($user, $fellows)
     {
         if($this->mConnected)
         {
@@ -172,10 +171,11 @@ class publisher
                 }
             }
 
-            $this->mRedis->publish('fellow',serialize(array('type'=>'add','params' => ['user_id' => $user,'friends' => $uids])));
+            $this->mRedis->publish('follow',serialize(array('type'=>'add','params' => ['user_id' => $user,'friends' => $uids])));
         }
     }
-    public function del_fellow($user,$fellows)
+
+    public function del_follow($user, $fellows)
     {
         if($this->mConnected)
         {
@@ -188,7 +188,7 @@ class publisher
                 }
             }
 
-            $this->mRedis->publish('fellow',serialize(array('type'=>'del','params' => ['user_id' => $user,'friends' => $uids])));
+            $this->mRedis->publish('follow',serialize(array('type'=>'del','params' => ['user_id' => $user,'friends' => $uids])));
         }
     }
     public function add_special($user,$specials)
@@ -199,6 +199,7 @@ class publisher
             $this->mRedis->publish('special',serialize(array('type'=>'add','params' => ['user_id' => $user,'specials' => $specials])));
         }
     }
+
     public function del_special($user,$specials)
     {
         if($this->mConnected)

+ 16 - 10
helper/relation/mem_relation.php

@@ -199,12 +199,16 @@ class mem_relation
         return $this->member_id;
     }
 
+    //关注我的
     public function subscriber() {
         return $this->subscriber;
     }
+
     public function subscriber_count() {
         return count($this->subscriber);
     }
+
+    //我关注的
     public function follower() {
         return $this->follower;
     }
@@ -212,20 +216,17 @@ class mem_relation
         return count($this->follower);
     }
 
-    public function unfollower() {
-        return $this->unbuild_mobiles;
-    }
-    //关注某人
-    public function subscribe($member_id)
+    //"我"关注某人
+    public function subscribe($user)
     {
-        if(!isset($member_id) || intval($member_id) == 0 || $this->member_id == $member_id) {
+        if(!isset($user) || intval($user) == 0 || $this->member_id == $user) {
             return false;
         }
 
         try
         {
-            $member_id = intval($member_id);
-            $someone_id = $this->doSubscribe($member_id,$some_mobile);
+            $user = intval($user);
+            $someone_id = $this->doSubscribe($user,$some_mobile);
             if($someone_id > 0) {
                 $this->add_fllower($someone_id);
                 $this->remove_unbuild($some_mobile);
@@ -242,6 +243,8 @@ class mem_relation
         }
 
     }
+
+    //"我"取消关注某人
     public function unsubscribe($member_id)
     {
         if(!isset($member_id) || intval($member_id) == 0 || $this->member_id == $member_id) {
@@ -261,6 +264,7 @@ class mem_relation
         }
     }
 
+    //我通过所有关注
     public function pass_subscribe()
     {
         if(count($this->new_subscriber) > 0) {
@@ -288,8 +292,8 @@ class mem_relation
                     algorithm::array_insert($this->subscriber,$pos,$someone_id);
                     $this->dirty = true;
                 }
-
-            } catch (Exception $ex) {
+            }
+            catch (Exception $ex) {
                 Log::record($ex->getMessage(),Log::ERR);
             }
         }
@@ -300,6 +304,7 @@ class mem_relation
         return true;
     }
 
+    //是否是我的粉丝
     public function is_follower($other_id)
     {
         if($this->member_id == $other_id) {
@@ -364,6 +369,7 @@ class mem_relation
         }
     }
 
+    //我关注我通讯录中所有人
     public function subscribe_contacts($contacts)
     {
         foreach ($contacts as $mobile)

+ 14 - 4
helper/relation_helper.php

@@ -105,7 +105,8 @@ class relation_helper
             $relation = new relation\mem_relation($me_id);
             $ret = $relation->subscribe($someone_id);
             if($ret == true) {
-                search\relation_client::instance()->add_follow(array('user_id' => $me_id,'friends'=>[$someone_id]));
+                $publisher = new message\publisher();
+                $publisher->add_follow($someone_id,[$me_id]);
                 $minfo = new member_info($me_id);
                 push_helper::notice_subscribe($someone_id,$minfo);
             }
@@ -127,7 +128,15 @@ class relation_helper
                 return false;
             }
             $relation = new relation\mem_relation($me_id);
-            return $relation->unsubscribe($someone_id);
+            $ret = $relation->unsubscribe($someone_id);
+
+            if($ret == true) {
+                $publisher = new message\publisher();
+                $publisher->del_follow($someone_id,[$me_id]);
+                $minfo = new member_info($me_id);
+                push_helper::notice_subscribe($someone_id,$minfo);
+            }
+            return $ret;
         }
         catch (Exception $ex)
         {
@@ -137,6 +146,7 @@ class relation_helper
         }
     }
 
+    //关注我的
     static public function subscriber($member_id)
     {
         try
@@ -163,7 +173,7 @@ class relation_helper
         {
             $msg = $ex->getMessage();
             Log::record("{$msg} member_id = {$member_id}");
-            return array();
+            return [];
         }
     }
 
@@ -181,7 +191,7 @@ class relation_helper
         {
             $msg = $ex->getMessage();
             Log::record("{$msg} member_id = {$member_id}");
-            return array();
+            return [];
         }
     }
 }

+ 26 - 7
helper/search/tcp_client.php

@@ -264,7 +264,7 @@ class relation_client extends tcp_client
     }
     public function add_inviter($param)
     {
-        $param = array("act" => 'inviter','op' => 'add', "params" => $param);
+        $param = ["act" => 'inviter','op' => 'add', "params" => $param];
         $result = $this->request($param);
         if(empty($result)) return false;
 
@@ -278,7 +278,7 @@ class relation_client extends tcp_client
     }
     public function fetch_inviters($param)
     {
-        $param = array("act" => 'inviter','op' => 'list', "params" => $param);
+        $param = ["act" => 'inviter','op' => 'list', "params" => $param];
         $result = $this->request($param);
         $code = intval($result['code']);
         if($code != 200) {
@@ -290,7 +290,7 @@ class relation_client extends tcp_client
     }
     public function fetch_invitees($param)
     {
-        $param = array("act" => 'inviter','op' => 'invitees', "params" => $param);
+        $param = ["act" => 'inviter','op' => 'invitees', "params" => $param];
         $result = $this->request($param);
         $code = intval($result['code']);
         if($code != 200) {
@@ -300,16 +300,35 @@ class relation_client extends tcp_client
             return $result['data']['invitees'];
         }
     }
+
     /////////////////////////////////////////////////////////////////////////
     public function add_follow($param)
     {
-        $param = array("act" => 'follow','op' => 'add', "params" => $param);
-        return $this->request($param);
+        $param = ["act" => 'follow','op' => 'add', "params" => $param];
+        $result = $this->request($param);
+        if(empty($result)) return false;
+
+        $code = intval($result['code']);
+        if($code != 200) {
+            return false;
+        }
+        else {
+            return true;
+        }
     }
     public function del_follow($param)
     {
-        $param = array("act" => 'follow','op' => 'del', "params" => $param);
-        return $this->request($param);
+        $param = ["act" => 'follow','op' => 'del', "params" => $param];
+        $result = $this->request($param);
+        if(empty($result)) return false;
+
+        $code = intval($result['code']);
+        if($code != 200) {
+            return false;
+        }
+        else {
+            return true;
+        }
     }
     public function fetch_follow($param)
     {

+ 1 - 3
helper/shaker_helper.php

@@ -394,10 +394,8 @@ class shaker_helper
             }
         }
 
-        $subscriber = relation_helper::subscriber($_SESSION['member_id']);
-        $follower = relation_helper::follower($_SESSION['member_id']);
+        $all_friends = relation_helper::friends(session_helper::memberid());
 
-        $all_friends = array_merge($subscriber,$follower);
         sort($all_friends,SORT_NUMERIC);
         $all_friends = array_merge(array_unique($all_friends,SORT_NUMERIC),[]);
         sort($all_friends);

+ 5 - 3
helper/ugc_helper.php

@@ -247,20 +247,21 @@ class ugciniter
             $i++;
 
             foreach ($items as $item) {
-                $this->add_fellow($item['member_id'],$item['inviter_id']);
+                $this->add_follow($item['member_id'],$item['inviter_id']);
             }
         }
     }
 
-    private function add_fellow($member_id,$inviter_id)
+    private function add_follow($member_id, $inviter_id)
     {
-        $member_id = intval($member_id);
+        $member_id  = intval($member_id);
         $inviter_id = intval($inviter_id);
 
         if($inviter_id > 0) {
             search\relation_client::instance()->add_follow(array('user_id' => $member_id,'friends'=>[$inviter_id]));
             search\relation_client::instance()->add_follow(array('user_id' => $inviter_id,'friends'=>[$member_id]));
         }
+
         if($member_id > 0)
         {
             $iRelation = new \relation\mem_relation($member_id);
@@ -277,6 +278,7 @@ class ugciniter
                 search\relation_client::instance()->add_follow(array('user_id' => $member_id,'friends' => $uids));
             }
         }
+
         if($member_id > 0)
         {
             $mod_member = Model('member');

+ 21 - 20
mobile/control/member_relation.php

@@ -23,7 +23,7 @@ class member_relationControl extends mbMemberControl
     //我关注的人
     public function subscriberOp()
     {
-        $iRelation = new \relation\mem_relation($_SESSION['member_id']);
+        $iRelation = new relation\mem_relation($_SESSION['member_id']);
         $follower = $iRelation->follower();
 
         $mem_desc = array();
@@ -43,10 +43,10 @@ class member_relationControl extends mbMemberControl
             $f_infos = Model('member_relation')->getRelationList(array('member_id' => array('in',$follower)));
             foreach ($f_infos as $val)
             {
-                $relation = new \relation\mem_relation($val);
-                $item = array('fans_count' =>$relation->subscriber_count(),
-                    'member_id' => $relation->member_id(),
-                    'subscribed' => true);
+                $relation = new relation\mem_relation($val);
+                $item = ['fans_count' =>$relation->subscriber_count(),
+                         'member_id' => $relation->member_id(),
+                         'subscribed' => true];
                 array_push($follower_infos,$item);
             }
         }
@@ -60,34 +60,35 @@ class member_relationControl extends mbMemberControl
     //我的粉丝
     public function followerOp()
     {
-        $iRelation = new \relation\mem_relation($_SESSION['member_id']);
-        $follower = $iRelation->subscriber();
+        $iRelation = new relation\mem_relation($_SESSION['member_id']);
+        $follows = $iRelation->subscriber();
 
         $mem_desc = array();
         $pages = 0;
         $follower_infos = array();
-        if(!empty($follower))
+        if(!empty($follows))
         {
-            $follower = self::separate_page($follower,$pages);
-            $members = Model('member')->getMemberList(array('member_id' => array('in',$follower)));
+            $follows = self::separate_page($follows,$pages);
+            $members = Model('member')->getMemberList(array('member_id' => array('in',$follows)));
             foreach ($members as $val) {
                 $info = new member_info($val);
                 array_push($mem_desc,$info->filter());
             }
-            $f_infos = Model('member_relation')->getRelationList(array('member_id' => array('in',$follower)));
-            foreach ($f_infos as $val) {
-                $relation = new \relation\mem_relation($val);
-                $item = array('fans_count' => $relation->subscriber_count(),
-                    'member_id' => $relation->member_id(),
-                    'subscribed' => $iRelation->is_follower($relation->member_id()));
+            $f_infos = Model('member_relation')->getRelationList(array('member_id' => array('in',$follows)));
+            foreach ($f_infos as $val)
+            {
+                $relation = new relation\mem_relation($val);
+                $item = [ 'fans_count' => $relation->subscriber_count(),
+                          'member_id'  => $relation->member_id(),
+                          'subscribed' => $iRelation->is_follower($relation->member_id())];
                 array_push($follower_infos,$item);
             }
         }
 
-        return self::outsuccess(array('followers' => $follower_infos,
-            'count' => $iRelation->subscriber_count(),
-            'mem_desc' => $mem_desc,
-            'mobile_page' => mobile_page($pages)));
+        return self::outsuccess(['followers' => $follower_infos,
+                                 'count' => $iRelation->subscriber_count(),
+                                 'mem_desc' => $mem_desc,
+                                 'mobile_page' => mobile_page($pages)]);
     }
 
     public function subscribeOp()

+ 8 - 2
test/TestFriends.php

@@ -73,12 +73,12 @@ class TestFriends extends PHPUnit_Framework_TestCase
     public function testAddFriend()
     {
         $publisher = new message\publisher();
-        $publisher->add_fellow(36490,[1,2,3,57]);
+        $publisher->add_follow(36490,[1,2,3,57]);
     }
     public function testDelFriend()
     {
         $publisher = new message\publisher();
-        $publisher->del_fellow(36490,[1,2,3,57]);
+        $publisher->del_follow(36490,[1,2,3,57]);
     }
     public function testAddSpecials()
     {
@@ -128,4 +128,10 @@ class TestFriends extends PHPUnit_Framework_TestCase
         }
     }
 
+    public function testFollows()
+    {
+        $iRelation = new \relation\mem_relation(39623);
+        $subscriber = $iRelation->subscriber();
+        $follower = $iRelation->follower();
+    }
 }

+ 1 - 1
ugc_srv.php

@@ -18,7 +18,7 @@ require_once(BASE_ROOT_PATH . '/helper/ugc_helper.php');
 require_once(BASE_ROOT_PATH . '/helper/search/tcp_client.php');
 
 function all_channels() {
-    return array('special','fellow','inviter');
+    return array('special','follow','inviter');
 }
 
 $gMessageStates = null;