|
@@ -12,19 +12,19 @@ use \Exception;
|
|
|
use \session_helper;
|
|
|
use \algorithm_helper;
|
|
|
use \errcode;
|
|
|
-use \Log;
|
|
|
use \member_info;
|
|
|
+use \Log;
|
|
|
+
|
|
|
+//member_mobile VARCHAR(11) PRIMARY KEY NOT NULL COMMENT '用户手机号',
|
|
|
+//member_id INT(11) DEFAULT '0' COMMENT '已经注册用户id',
|
|
|
+//contact_name VARCHAR(50) DEFAULT '',
|
|
|
+//subscriber TEXT COMMENT '订阅我为好友的人。',
|
|
|
+//follower TEXT COMMENT '我订阅别人成为好友通过的人。',
|
|
|
+//build_mobiles TEXT COMMENT '已经与我建立好友关系的手机号',
|
|
|
+//unbuild_mobiles TEXT COMMENT '还未与我建立好友关系的手机号'
|
|
|
|
|
|
class mem_relation
|
|
|
{
|
|
|
- //member_mobile VARCHAR(11) PRIMARY KEY NOT NULL COMMENT '用户手机号',
|
|
|
- //member_id INT(11) DEFAULT '0' COMMENT '已经注册用户id',
|
|
|
- //contact_name VARCHAR(50) DEFAULT '',
|
|
|
- //subscriber TEXT COMMENT '订阅我为好友的人。',
|
|
|
- //follower TEXT COMMENT '我订阅别人成为好友通过的人。',
|
|
|
- //build_mobiles TEXT COMMENT '已经与我建立好友关系的手机号',
|
|
|
- //unbuild_mobiles TEXT COMMENT '还未与我建立好友关系的手机号'
|
|
|
-
|
|
|
private $member_id;
|
|
|
private $member_mobile;
|
|
|
private $contact_name;
|
|
@@ -37,89 +37,86 @@ class mem_relation
|
|
|
private $mod_relation;
|
|
|
private $dirty;
|
|
|
|
|
|
- public function __construct($member_id,$mobile = null,$name = null)
|
|
|
+ public function __construct($member_id,$mobile = null)
|
|
|
{
|
|
|
- Log::record("member_id = {$member_id}",Log::DEBUG);
|
|
|
- $this->mod_relation = Model('member_relation');
|
|
|
+ $this->dirty = false;
|
|
|
|
|
|
+ $this->mod_relation = Model('member_relation');
|
|
|
$member_id = intval($member_id);
|
|
|
+
|
|
|
if(isset($member_id) && intval($member_id) > 0)
|
|
|
{
|
|
|
- $info = $this->mod_relation->findByID($member_id);
|
|
|
- if(!empty($info))
|
|
|
- {
|
|
|
- $this->init($info);
|
|
|
- if($this->member_id == 0 && $member_id > 0) {
|
|
|
- $this->member_id = $member_id;
|
|
|
- $this->dirty = true;
|
|
|
- }
|
|
|
- if(isset($name) && !empty($name)) {
|
|
|
- $this->contact_name = $name;
|
|
|
- $this->dirty = true;
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
- else
|
|
|
+ $member_info = new member_info($member_id);
|
|
|
+ if(!empty($member_info))
|
|
|
{
|
|
|
- $member_info = new member_info($member_id);
|
|
|
- $name = $member_info->nickname();
|
|
|
- echo ("member_id = {$member_id} name = {$name}.");
|
|
|
- if(!empty($member_info)) {
|
|
|
- $this->member_id = $member_id;
|
|
|
- $this->member_mobile = $member_info->mobile();
|
|
|
- $this->contact_name = $member_info->nickname();
|
|
|
-
|
|
|
- $this->dirty = true;
|
|
|
- $this->subscriber = array();
|
|
|
- $this->new_subscriber = array();
|
|
|
- $this->follower = array();
|
|
|
- $this->build_mobiles = array();
|
|
|
- $this->unbuild_mobiles = array();
|
|
|
-
|
|
|
+ $mobile = $member_info->mobile();
|
|
|
+ $info = $this->mod_relation->findByMobile($mobile);
|
|
|
+ if(!empty($info))
|
|
|
+ {
|
|
|
+ $this->init($info);
|
|
|
+ if($this->member_id == 0 && $member_id > 0) {
|
|
|
+ $this->member_id = $member_info->member_id();
|
|
|
+ $this->dirty = true;
|
|
|
+ }
|
|
|
+ if($this->contact_name != $member_info->nickname()) {
|
|
|
+ $this->contact_name = $member_info->nickname();
|
|
|
+ $this->dirty = true;
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if(!empty($member_info)) {
|
|
|
+ $this->member_id = $member_info->member_id();
|
|
|
+ $this->member_mobile = $member_info->mobile();
|
|
|
+ $this->contact_name = $member_info->nickname();
|
|
|
+ $this->subscriber = array();
|
|
|
+ $this->new_subscriber = array();
|
|
|
+ $this->follower = array();
|
|
|
+ $this->build_mobiles = array();
|
|
|
+ $this->unbuild_mobiles = array();
|
|
|
+
|
|
|
+ $this->dirty = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(isset($mobile) && !empty($mobile))
|
|
|
{
|
|
|
+ $mobile = session_helper::mobile_valid($mobile);
|
|
|
+ if($mobile == false) {
|
|
|
+ throw new Exception("member_relation __construct error",errcode::ErrParamter);
|
|
|
+ }
|
|
|
+
|
|
|
$info = $this->mod_relation->findByMobile($mobile);
|
|
|
- if(!empty($info))
|
|
|
- {
|
|
|
+ if(!empty($info)) {
|
|
|
$this->init($info);
|
|
|
- if($this->member_id == 0 && $member_id > 0) {
|
|
|
- $this->member_id = $member_id;
|
|
|
-
|
|
|
- $this->dirty = true;
|
|
|
- }
|
|
|
- if($member_id > 0 && isset($name) && !empty($name)) {
|
|
|
- $this->contact_name = $name;
|
|
|
- $this->dirty = true;
|
|
|
- }
|
|
|
return;
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $this->member_mobile = $mobile;
|
|
|
+ $this->member_id = $member_id;
|
|
|
+ $this->contact_name = '';
|
|
|
+ $this->subscriber = array();
|
|
|
+ $this->new_subscriber = array();
|
|
|
+ $this->follower = array();
|
|
|
+ $this->build_mobiles = array();
|
|
|
+ $this->unbuild_mobiles = array();
|
|
|
+
|
|
|
+ $this->dirty = true;
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- $mobile = session_helper::mobile_valid($mobile);
|
|
|
- if($mobile == false) {
|
|
|
- throw new Exception("member_relation __construct error",errcode::ErrParamter);
|
|
|
- } else {
|
|
|
- $this->member_mobile = $mobile;
|
|
|
- }
|
|
|
-
|
|
|
- $this->member_id = $member_id;
|
|
|
- if(isset($name) && !empty($name)) {
|
|
|
- $this->contact_name = $name;
|
|
|
- } else {
|
|
|
- $this->contact_name = '';
|
|
|
+ public function __destruct()
|
|
|
+ {
|
|
|
+ Log::record(__METHOD__,Log::DEBUG);
|
|
|
+ if($this->dirty) {
|
|
|
+ $this->save();
|
|
|
}
|
|
|
-
|
|
|
- $this->dirty = true;
|
|
|
- $this->subscriber = array();
|
|
|
- $this->new_subscriber = array();
|
|
|
- $this->follower = array();
|
|
|
- $this->build_mobiles = array();
|
|
|
- $this->unbuild_mobiles = array();
|
|
|
}
|
|
|
|
|
|
private function subscribe_me($member_id)
|
|
@@ -139,9 +136,9 @@ class mem_relation
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private function doSubscribe($member_id,$mobile, $name)
|
|
|
+ private function doSubscribe($member_id,$mobile)
|
|
|
{
|
|
|
- $someone = new mem_relation($member_id, $mobile, $name);
|
|
|
+ $someone = new mem_relation($member_id, $mobile);
|
|
|
$someone->subscribe_me($this->member_id);
|
|
|
$someone->save();
|
|
|
return $someone->member_id;
|
|
@@ -156,13 +153,13 @@ class mem_relation
|
|
|
public function unfollower() {
|
|
|
return $this->unbuild_mobiles;
|
|
|
}
|
|
|
- public function subscribe($member_id,$mobile = null,$name = null)
|
|
|
+ public function subscribe($member_id,$mobile = null)
|
|
|
{
|
|
|
if(!isset($member_id) || intval($member_id) == 0 || $this->member_id == $member_id) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- $someone_id = $this->doSubscribe($member_id,$mobile, $name);
|
|
|
+ $someone_id = $this->doSubscribe($member_id,$mobile);
|
|
|
if($someone_id > 0) {
|
|
|
$this->add_fllower($someone_id);
|
|
|
$this->remove_unbuild($mobile);
|
|
@@ -177,7 +174,7 @@ class mem_relation
|
|
|
|
|
|
public function pass_subscribe()
|
|
|
{
|
|
|
- if(count($this->new_subscriber) >0) {
|
|
|
+ if(count($this->new_subscriber) > 0) {
|
|
|
$this->dirty = true;
|
|
|
}
|
|
|
else {
|
|
@@ -186,7 +183,7 @@ class mem_relation
|
|
|
|
|
|
foreach ($this->new_subscriber as $someone_id)
|
|
|
{
|
|
|
- $someone = new mem_relation($someone_id, null, null);
|
|
|
+ $someone = new mem_relation($someone_id);
|
|
|
$someone->add_fllower($this->member_id);
|
|
|
$someone->remove_unbuild($this->member_mobile);
|
|
|
$someone->add_build($this->member_mobile);
|
|
@@ -260,7 +257,7 @@ class mem_relation
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- $someone_id = $this->doSubscribe(0,$mobile,null);
|
|
|
+ $someone_id = $this->doSubscribe(0,$mobile);
|
|
|
if($someone_id > 0) {
|
|
|
$this->add_fllower($someone_id);
|
|
|
$this->remove_unbuild($mobile);
|
|
@@ -272,20 +269,30 @@ class mem_relation
|
|
|
$this->save();
|
|
|
}
|
|
|
|
|
|
- public function save()
|
|
|
+ private function save()
|
|
|
{
|
|
|
if($this->dirty) {
|
|
|
$data = array();
|
|
|
$data['member_mobile'] = $this->member_mobile;
|
|
|
$data['member_id'] = $this->member_id;
|
|
|
$data['contact_name'] = $this->contact_name;
|
|
|
-
|
|
|
$data['subscriber'] = serialize($this->subscriber);
|
|
|
$data['new_subscriber '] = serialize($this->new_subscriber);
|
|
|
$data['follower'] = serialize($this->follower);
|
|
|
$data['build_mobiles'] = serialize($this->build_mobiles);
|
|
|
$data['unbuild_mobiles'] = serialize($this->unbuild_mobiles);
|
|
|
+
|
|
|
$this->mod_relation->replace($data);
|
|
|
+ $this->dirty = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function from_text($text)
|
|
|
+ {
|
|
|
+ if(is_null($text) || empty($text)) {
|
|
|
+ return array();
|
|
|
+ } else {
|
|
|
+ return unserialize($text);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -294,41 +301,11 @@ class mem_relation
|
|
|
$this->member_id = intval($info['member_id']);
|
|
|
$this->member_mobile = $info['member_mobile'];
|
|
|
$this->contact_name = $info['contact_name'];
|
|
|
- $subscriber = $info['subscriber'];
|
|
|
- $new_subscriber = $info['new_subscriber'];
|
|
|
- $follower = $info['follower'];
|
|
|
- $build_mobiles = $info['build_mobiles'];
|
|
|
- $unbuild_mobiles = $info['unbuild_mobiles'];
|
|
|
-
|
|
|
- if(is_null($subscriber) || empty($subscriber)) {
|
|
|
- $this->subscriber = array();
|
|
|
- } else {
|
|
|
- $this->subscriber = unserialize($subscriber);
|
|
|
- }
|
|
|
-
|
|
|
- if(is_null($new_subscriber) || empty($new_subscriber)) {
|
|
|
- $this->new_subscriber = array();
|
|
|
- } else {
|
|
|
- $this->new_subscriber = unserialize($new_subscriber);
|
|
|
- }
|
|
|
-
|
|
|
- if(is_null($follower) || empty($follower)) {
|
|
|
- $this->follower = array();
|
|
|
- } else {
|
|
|
- $this->follower = unserialize($follower);
|
|
|
- }
|
|
|
-
|
|
|
- if(is_null($build_mobiles) || empty($build_mobiles)) {
|
|
|
- $this->build_mobiles = array();
|
|
|
- } else {
|
|
|
- $this->build_mobiles = unserialize($build_mobiles);
|
|
|
- }
|
|
|
-
|
|
|
- if(is_null($unbuild_mobiles) || empty($unbuild_mobiles)) {
|
|
|
- $this->unbuild_mobiles = array();
|
|
|
- } else {
|
|
|
- $this->unbuild_mobiles = unserialize($unbuild_mobiles);
|
|
|
- }
|
|
|
+ $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);
|