|
@@ -10,7 +10,7 @@ namespace relation;
|
|
|
|
|
|
use \Exception;
|
|
|
use \session_helper;
|
|
|
-use \algorithm_helper;
|
|
|
+use \algorithm;
|
|
|
use \errcode;
|
|
|
use \member_info;
|
|
|
use \Log;
|
|
@@ -25,12 +25,13 @@ use \Log;
|
|
|
|
|
|
class mem_relation
|
|
|
{
|
|
|
+ //对应数据库表中字段
|
|
|
private $member_id;
|
|
|
private $member_mobile;
|
|
|
private $contact_name;
|
|
|
- private $subscriber;
|
|
|
+ private $subscriber; //关注我的
|
|
|
private $new_subscriber;
|
|
|
- private $follower;
|
|
|
+ private $follower; //我关注的
|
|
|
private $build_mobiles;
|
|
|
private $unbuild_mobiles;
|
|
|
|
|
@@ -50,7 +51,7 @@ class mem_relation
|
|
|
$this->mod_relation = Model('member_relation');
|
|
|
$member_id = intval($member_id);
|
|
|
|
|
|
- if(isset($member_id) && intval($member_id) > 0)
|
|
|
+ if(isset($member_id) && $member_id > 0)
|
|
|
{
|
|
|
$member_info = new member_info($member_id);
|
|
|
if(!empty($member_info))
|
|
@@ -95,7 +96,7 @@ class mem_relation
|
|
|
if($mobile == false) {
|
|
|
throw new Exception("member_relation __construct error",errcode::ErrParamter);
|
|
|
}
|
|
|
-
|
|
|
+ $mobile = intval($mobile);
|
|
|
$info = $this->mod_relation->findByMobile($mobile);
|
|
|
if(!empty($info)) {
|
|
|
$this->init($info);
|
|
@@ -123,56 +124,56 @@ class mem_relation
|
|
|
|
|
|
public function __destruct()
|
|
|
{
|
|
|
- Log::record(__METHOD__,Log::DEBUG);
|
|
|
if($this->dirty) {
|
|
|
$this->save();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //用户($member_id) 关注 我($this)
|
|
|
private function subscribe_me($member_id)
|
|
|
{
|
|
|
- $ret = algorithm_helper::bsearch($member_id,$this->subscriber);
|
|
|
- if($ret == -1) {
|
|
|
- array_push($this->subscriber,$member_id);
|
|
|
- sort($this->subscriber);
|
|
|
- $this->dirty = true;
|
|
|
+ if(algorithm::binary_search($this->subscriber,$member_id)) {
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- $ret = algorithm_helper::bsearch($member_id,$this->new_subscriber);
|
|
|
- if($ret == -1) {
|
|
|
- array_push($this->new_subscriber,$member_id);
|
|
|
- sort($this->new_subscriber);
|
|
|
+ if(algorithm::binary_search($this->new_subscriber,$member_id) == false) {
|
|
|
+ $pos = algorithm::lower_bonud($this->new_subscriber,$member_id);
|
|
|
+ algorithm::array_insert($this->new_subscriber,$pos,$member_id);
|
|
|
$this->dirty = true;
|
|
|
}
|
|
|
}
|
|
|
+ //用户($member_id) 取消关注 我($this)
|
|
|
private function unsubscribe_me($member_id)
|
|
|
{
|
|
|
- $pos = algorithm_helper::bsearch($member_id,$this->subscriber);
|
|
|
- if($pos != -1) {
|
|
|
- array_splice($this->subscriber,$pos,1);
|
|
|
+ if(algorithm::binary_search($this->subscriber,$member_id)) {
|
|
|
+ $pos = algorithm::lower_bonud($this->subscriber,$member_id);
|
|
|
+ algorithm::array_erase($this->subscriber,$pos);
|
|
|
$this->dirty = true;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- $pos = algorithm_helper::bsearch($member_id,$this->new_subscriber);
|
|
|
- if($pos != -1) {
|
|
|
- array_splice($this->new_subscriber,$pos,1);
|
|
|
+ if(algorithm::binary_search($this->new_subscriber,$member_id)) {
|
|
|
+ $pos = algorithm::lower_bonud($this->new_subscriber,$member_id);
|
|
|
+ algorithm::array_erase($this->new_subscriber,$pos);
|
|
|
$this->dirty = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private function doUnSubscribe($member_id,$mobile)
|
|
|
+ private function doUnSubscribe($member_id)
|
|
|
{
|
|
|
- $someone = new mem_relation($member_id, $mobile);
|
|
|
+ $someone = new mem_relation($member_id, null);
|
|
|
$someone->unsubscribe_me($this->member_id);
|
|
|
$someone->save();
|
|
|
return $someone->member_id;
|
|
|
}
|
|
|
|
|
|
- private function doSubscribe($member_id,$mobile)
|
|
|
+ private function doSubscribe($member_id,&$mobile)
|
|
|
{
|
|
|
$someone = new mem_relation($member_id, $mobile);
|
|
|
$someone->subscribe_me($this->member_id);
|
|
|
$someone->save();
|
|
|
+ $mobile = intval($someone->member_mobile);
|
|
|
+
|
|
|
return $someone->member_id;
|
|
|
}
|
|
|
public function member_id()
|
|
@@ -196,23 +197,32 @@ class mem_relation
|
|
|
public function unfollower() {
|
|
|
return $this->unbuild_mobiles;
|
|
|
}
|
|
|
- public function subscribe($member_id,$mobile = null)
|
|
|
+ //关注某人
|
|
|
+ public function subscribe($member_id)
|
|
|
{
|
|
|
if(!isset($member_id) || intval($member_id) == 0 || $this->member_id == $member_id) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- $someone_id = $this->doSubscribe($member_id,$mobile);
|
|
|
- if($someone_id > 0) {
|
|
|
- $this->add_fllower($someone_id);
|
|
|
- $this->remove_unbuild($mobile);
|
|
|
- $this->add_build($mobile);
|
|
|
- } else {
|
|
|
- $this->add_unbuild($mobile);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ $member_id = intval($member_id);
|
|
|
+ $someone_id = $this->doSubscribe($member_id,$some_mobile);
|
|
|
+ if($someone_id > 0) {
|
|
|
+ $this->add_fllower($someone_id);
|
|
|
+ $this->remove_unbuild($some_mobile);
|
|
|
+ $this->add_build($some_mobile);
|
|
|
+ } else {
|
|
|
+ $this->add_unbuild($some_mobile);
|
|
|
+ }
|
|
|
+ $this->save();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ catch (Exception $ex) {
|
|
|
+ Log::record($ex->getMessage(),Log::ERR);
|
|
|
+ return false;
|
|
|
}
|
|
|
- $this->save();
|
|
|
|
|
|
- return true;
|
|
|
}
|
|
|
public function unsubscribe($member_id)
|
|
|
{
|
|
@@ -220,11 +230,17 @@ class mem_relation
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- $this->doUnSubscribe($member_id);
|
|
|
- $this->remove_fllower($member_id);
|
|
|
- $this->save();
|
|
|
-
|
|
|
- return true;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ $member_id = intval($member_id);
|
|
|
+ $this->doUnSubscribe($member_id);
|
|
|
+ $this->remove_fllower($member_id);
|
|
|
+ $this->save();
|
|
|
+ return true;
|
|
|
+ } catch (Exception $ex) {
|
|
|
+ Log::record($ex->getMessage(),Log::ERR);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function pass_subscribe()
|
|
@@ -238,11 +254,19 @@ class mem_relation
|
|
|
|
|
|
foreach ($this->new_subscriber as $someone_id)
|
|
|
{
|
|
|
- $someone = new mem_relation($someone_id);
|
|
|
- $someone->add_fllower($this->member_id);
|
|
|
- $someone->remove_unbuild($this->member_mobile);
|
|
|
- $someone->add_build($this->member_mobile);
|
|
|
- $someone->save();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ $someone = new mem_relation($someone_id);
|
|
|
+ $someone->add_fllower($this->member_id);
|
|
|
+ if(!empty($this->member_mobile)) {
|
|
|
+ $mobile = intval($this->member_mobile);
|
|
|
+ $someone->remove_unbuild($mobile);
|
|
|
+ $someone->add_build($mobile);
|
|
|
+ }
|
|
|
+ $someone->save();
|
|
|
+ } catch (Exception $ex) {
|
|
|
+ Log::record($ex->getMessage(),Log::ERR);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
$this->new_subscriber = array();
|
|
@@ -255,24 +279,17 @@ class mem_relation
|
|
|
{
|
|
|
if($this->member_id == $other_id) {
|
|
|
return false;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- $pos = algorithm_helper::bsearch($other_id,$this->follower);
|
|
|
- if($pos == -1) {
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- return true;
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ return algorithm::binary_search($this->follower,$other_id);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private function subscribed($mobile)
|
|
|
{
|
|
|
- if(algorithm_helper::bsearch($mobile,$this->build_mobiles) != -1) {
|
|
|
+ if(algorithm::binary_search($this->build_mobiles,$mobile)) {
|
|
|
return true;
|
|
|
}
|
|
|
- if(algorithm_helper::bsearch($mobile,$this->unbuild_mobiles) != -1) {
|
|
|
+ if(algorithm::binary_search($this->unbuild_mobiles,$mobile)) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
@@ -280,46 +297,44 @@ class mem_relation
|
|
|
|
|
|
private function add_fllower($someone_id)
|
|
|
{
|
|
|
- if(algorithm_helper::bsearch($someone_id,$this->follower) == -1) {
|
|
|
- array_push($this->follower,$someone_id);
|
|
|
- sort($this->follower);
|
|
|
+ if(algorithm::binary_search($this->follower,$someone_id) == false) {
|
|
|
+ $pos = algorithm::lower_bonud($this->follower,$someone_id);
|
|
|
+ algorithm::array_insert($this->follower,$pos,$someone_id);
|
|
|
$this->dirty = true;
|
|
|
}
|
|
|
}
|
|
|
private function remove_fllower($someone_id)
|
|
|
{
|
|
|
- $pos = algorithm_helper::bsearch($someone_id,$this->follower);
|
|
|
- if($pos != -1) {
|
|
|
- array_splice($this->follower,$pos,1);
|
|
|
+ if(algorithm::binary_search($this->follower,$someone_id)) {
|
|
|
+ $pos = algorithm::lower_bonud($this->follower,$someone_id);
|
|
|
+ algorithm::array_erase($this->follower,$pos);
|
|
|
$this->dirty = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private function add_unbuild($mobile)
|
|
|
{
|
|
|
- $pos = algorithm_helper::bsearch($mobile,$this->unbuild_mobiles);
|
|
|
- if($pos == -1) {
|
|
|
- array_push($this->unbuild_mobiles,$mobile);
|
|
|
- sort($this->unbuild_mobiles);
|
|
|
+ if(algorithm::binary_search($this->unbuild_mobiles,$mobile) == false) {
|
|
|
+ $pos = algorithm::lower_bonud($this->unbuild_mobiles,$mobile);
|
|
|
+ algorithm::array_insert($this->unbuild_mobiles,$pos,$mobile);
|
|
|
$this->dirty = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private function remove_unbuild($mobile)
|
|
|
{
|
|
|
- $pos = algorithm_helper::bsearch($mobile,$this->unbuild_mobiles);
|
|
|
- if($pos != -1) {
|
|
|
- array_splice($this->unbuild_mobiles,$pos,1);
|
|
|
+ if(algorithm::binary_search($this->unbuild_mobiles,$mobile)) {
|
|
|
+ $pos = algorithm::lower_bonud($this->unbuild_mobiles,$mobile);
|
|
|
+ algorithm::array_erase($this->unbuild_mobiles,$pos);
|
|
|
$this->dirty = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private function add_build($mobile)
|
|
|
{
|
|
|
- $ret = algorithm_helper::bsearch($mobile,$this->build_mobiles);
|
|
|
- if($ret == -1) {
|
|
|
- array_push($this->build_mobiles,$mobile);
|
|
|
- sort($this->build_mobiles);
|
|
|
+ if(algorithm::binary_search($this->build_mobiles,$mobile) == false) {
|
|
|
+ $pos = algorithm::lower_bonud($this->build_mobiles,$mobile);
|
|
|
+ algorithm::array_insert($this->build_mobiles,$pos,$mobile);
|
|
|
$this->dirty = true;
|
|
|
}
|
|
|
}
|
|
@@ -328,7 +343,8 @@ class mem_relation
|
|
|
{
|
|
|
foreach ($contacts as $mobile)
|
|
|
{
|
|
|
- if($this->member_mobile == $mobile) { //自己不能订阅自己
|
|
|
+ $mobile = intval($mobile);
|
|
|
+ if($this->member_mobile == $mobile || $mobile < 100000000000) { //自己不能订阅自己
|
|
|
continue;
|
|
|
}
|
|
|
|
|
@@ -348,6 +364,45 @@ class mem_relation
|
|
|
$this->save();
|
|
|
}
|
|
|
|
|
|
+ private function init($info)
|
|
|
+ {
|
|
|
+ $this->member_id = intval($info['member_id']);
|
|
|
+ $this->member_mobile = $info['member_mobile'];
|
|
|
+ $this->contact_name = $info['contact_name'];
|
|
|
+ $this->subscriber = unserialize($info['subscriber']);
|
|
|
+ $this->new_subscriber = unserialize($info['new_subscriber']);
|
|
|
+ $this->follower = unserialize($info['follower']);
|
|
|
+ $this->build_mobiles = unserialize($info['build_mobiles']);
|
|
|
+ $this->unbuild_mobiles = unserialize($info['unbuild_mobiles']);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function mobile_int($mobiles)
|
|
|
+ {
|
|
|
+ foreach ($mobiles as $mobile)
|
|
|
+ {
|
|
|
+ $val = intval($mobile);
|
|
|
+ if($val > 10000000000) {
|
|
|
+ $ret[] = $val;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(isset($ret)) {
|
|
|
+ return $ret;
|
|
|
+ } else {
|
|
|
+ return array();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function sort_mobile()
|
|
|
+ {
|
|
|
+ $this->mobile_int($this->build_mobiles);
|
|
|
+ sort($this->build_mobiles);
|
|
|
+
|
|
|
+ $this->mobile_int($this->unbuild_mobiles);
|
|
|
+ sort($this->unbuild_mobiles);
|
|
|
+
|
|
|
+ $this->dirty = true;
|
|
|
+ }
|
|
|
+
|
|
|
private function save()
|
|
|
{
|
|
|
if($this->dirty) {
|
|
@@ -365,31 +420,4 @@ class mem_relation
|
|
|
$this->dirty = false;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- private function from_text($text)
|
|
|
- {
|
|
|
- if(is_null($text) || empty($text)) {
|
|
|
- return array();
|
|
|
- } else {
|
|
|
- return unserialize($text);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private function init($info)
|
|
|
- {
|
|
|
- $this->member_id = intval($info['member_id']);
|
|
|
- $this->member_mobile = $info['member_mobile'];
|
|
|
- $this->contact_name = $info['contact_name'];
|
|
|
- $this->subscriber = $this->from_text($info['subscriber']);
|
|
|
- $this->new_subscriber = $this->from_text($info['new_subscriber']);
|
|
|
- $this->follower = $this->from_text($info['follower']);
|
|
|
- $this->build_mobiles = $this->from_text($info['build_mobiles']);
|
|
|
- $this->unbuild_mobiles = $this->from_text($info['unbuild_mobiles']);
|
|
|
-
|
|
|
- sort($this->subscriber);
|
|
|
- sort($this->new_subscriber);
|
|
|
- sort($this->follower);
|
|
|
- sort($this->build_mobiles);
|
|
|
- sort($this->unbuild_mobiles);
|
|
|
- }
|
|
|
}
|