stanley-king vor 7 Jahren
Ursprung
Commit
44394b3669
3 geänderte Dateien mit 1376 neuen und 0 gelöschten Zeilen
  1. 46 0
      crontab/control/date.php
  2. 1283 0
      data/mobile/invitors.txt
  3. 47 0
      test/relation_helperTest.php

+ 46 - 0
crontab/control/date.php

@@ -125,6 +125,52 @@ class dateControl extends BaseCronControl
             }
         }
     }
+    public function init_inviterOp()
+    {
+        $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);
+        }
+    }
 
     public function _stat_daily()
     {

Datei-Diff unterdrückt, da er zu groß ist
+ 1283 - 0
data/mobile/invitors.txt


+ 47 - 0
test/relation_helperTest.php

@@ -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);
+        }
+    }
 }