|
@@ -179,4 +179,51 @@ class relation_helperTest extends PHPUnit_Framework_TestCase
|
|
|
perfor_end("testRelation","10000 pass_subscribe");
|
|
|
performance_helper::instance()->format_log();
|
|
|
}
|
|
|
+
|
|
|
+ public function testInitInvitors()
|
|
|
+ {
|
|
|
+ $path = BASE_DATA_PATH . "/mobile/invitors.txt";
|
|
|
+ $file = fopen($path,'r');
|
|
|
+ if(!is_resource($file)) {
|
|
|
+ Log::record(__METHOD__ . " file is not exist",Log::ERR);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ while(!feof($file)) {
|
|
|
+ $line = fgets($file);
|
|
|
+ $kv = preg_split('/,/',$line);
|
|
|
+ if(count($kv) != 2) continue;
|
|
|
+
|
|
|
+ $key = trim($kv[0]);
|
|
|
+ $val = trim($kv[1]);
|
|
|
+
|
|
|
+ $this->update_invitor($key,$val);
|
|
|
+ }
|
|
|
+
|
|
|
+ fclose($file);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function update_invitor($invitor,$user)
|
|
|
+ {
|
|
|
+ if(empty($invitor)) return false;
|
|
|
+
|
|
|
+ $mod = Model('member');
|
|
|
+ $invitor_info = $mod->where(['member_mobile' => $invitor])->find();
|
|
|
+ if(empty($invitor_info)) return false;
|
|
|
+ $member_id = intval($invitor_info['member_id']);
|
|
|
+
|
|
|
+ $user_info = $mod->where(['member_mobile' => $user])->find();
|
|
|
+ if(empty($user_info)) return false;
|
|
|
+
|
|
|
+ $inviter_id = intval($user_info['inviter_id']);
|
|
|
+ if($inviter_id > 0) return false;
|
|
|
+
|
|
|
+ $ret = $mod->where(['member_mobile' => $user])->update(['inviter_id' => $member_id]);
|
|
|
+ if($ret == false) {
|
|
|
+ Log::record(__METHOD__ . " update {$user} invitor id err",Log::ERR);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Log::record(__METHOD__ . " update {$user} invitor id success",Log::DEBUG);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|