Пример #1
0
 /**
  * 定时调用,返回true表示可以被释放了,返回false表示当前这个小时内还需要再次调用的
  * @param \Sooh\Base\Time $dt
  * @return boolean
  */
 protected function onRun($dt)
 {
     $this->lastMsg = "called " . $this->_counterCalled . "times(" . date('m-d H:i:s', $dt->timestamp()) . ")";
     error_log("\tCrond " . getmypid() . "#\t" . __CLASS__ . "\t" . $this->lastMsg);
     $this->toBeContinue = $this->_counterCalled < 3;
     return true;
 }
Пример #2
0
 /**
  * 
  * @param string $new
  * @param string $camefrom
  * @param string $old
  * @param int $intUidForce 强制userid
  * @return \Sooh\DB\Cases\AccountBase
  * @throws ErrorException
  */
 public function createAccount($new, $camefrom, $old = null, $intUidForce = null)
 {
     $me = static::getCopy(array('account' => $new, 'camefrom' => $camefrom));
     $me->load();
     if ($me->getField('status', true)) {
         throw new \ErrorException('user exists already');
     } else {
         if ($old !== null) {
             $tmp = static::getCopy(array('account' => $old, 'camefrom' => $camefrom));
             $tmp->load();
             if ($tmp->exists()) {
                 try {
                     $tmp->setField('status', 0);
                     $old = $tmp->getField('changelog', true);
                     $msg = '';
                     $tmp->setField('changelog', empty($old) ? $msg : $old . "\n" . $msg);
                     $tmp->update();
                 } catch (\ErrorException $ex) {
                     error_log("update old-user in AccountConv failed:" . $ex->getMessage() . "\n" . $ex->getTraceAsString());
                     throw new \ErrorException('user exists already');
                 }
             } else {
                 error_log("update old-user in AccountConv failed: missing" . $ex->getTraceAsString());
             }
         }
         if ($intUidForce === null) {
             $intUidForce = \Sooh\Base\Time::getInstance()->timestamp();
         }
         $me->setField('uid', $intUidForce);
         $me->setField('status', 1);
         $me->setField('changelog', '');
         $me->update();
         \Sooh\DB\Cases\AccountBase::getCopy($intUidForce);
     }
 }
Пример #3
0
 /**
  * 
  * @param \Sooh\Base\Log\Data $logData
  */
 public function write($logData)
 {
     $resChg = $logData->resChanged;
     $arr = $logData->toArray();
     unset($arr['resChanged']);
     unset($arr['logGuid']);
     \Sooh\DB\Cases\LogStorage::$__YMD = \Sooh\Base\Time::getInstance()->YmdFull;
     \Sooh\DB\Cases\LogStorage::$__id_in_dbByObj = 'dbgrpForLog';
     \Sooh\DB\Cases\LogStorage::$__type = 'a';
     \Sooh\DB\Cases\LogStorage::$__nSplitedBy = $this->tbSplit;
     //\Sooh\DB\Cases\LogStorage::$__fields=array(.....);
     $tmp = \Sooh\DB\Cases\LogStorage::getCopy($logData->logGuid);
     foreach ($arr as $k => $v) {
         $tmp->setField($k, $v);
     }
     $ret = $tmp->writeLog();
     if ($ret) {
         $tbSub = str_replace('_a_', '_b_', $tmp->tbname());
         foreach ($resChg as $r) {
             $r['logGuid'] = $logData->logGuid;
             try {
                 \Sooh\DB\Broker::errorMarkSkip(\Sooh\DB\Error::tableNotExists);
                 $tmp->db()->addRecord($tbSub, $r);
             } catch (\ErrorException $e) {
                 if (\Sooh\DB\Broker::errorIs($e, \Sooh\DB\Error::tableNotExists)) {
                     $tmp->db()->ensureObj($tbSub, array('logGuid' => 'bigint unsigned not null  default 0', 'resName' => "varchar(36) not null default ''", 'resChg' => "int not null default 0", 'resNew' => "int not null default 0"));
                     $tmp->db()->addRecord($tbSub, $r);
                 } else {
                     error_log("write log failed:" . $e->getMessage() . "\n" . \Sooh\DB\Broker::lastCmd());
                 }
             }
         }
     }
 }
Пример #4
0
 public function load($fields = '*')
 {
     parent::load($fields);
     $tmp = parent::getField('dat', true);
     $this->dt = \Sooh\Base\Time::getInstance();
     $cmp = $this->dt->timestamp() - 3600;
     if (!empty($tmp)) {
         if (is_string($tmp)) {
             $this->dat = json_decode($tmp, true);
         } else {
             $this->dat = $tmp;
         }
         foreach ($this->dat['errors'] as $k => $v) {
             if ($v < $cmp) {
                 unset($this->dat['errors'][$k]);
             }
         }
         foreach ($this->dat['codes'] as $k => $v) {
             if ($v < $cmp) {
                 unset($this->dat['codes'][$k]);
             }
         }
     } else {
         $this->dat = array();
     }
 }
Пример #5
0
 protected function init()
 {
     if (empty($_SESSION)) {
         session_start();
     }
     $this->now = \Sooh\Base\Time::getInstance()->timestamp();
 }
Пример #6
0
 /**
  * start session if session not init
  */
 protected function start()
 {
     if ($this->sessionArr === null) {
         $this->timestamp = \Sooh\Base\Time::getInstance()->timestamp();
         $tmp = $this->storage->load($this->sessionId);
         if (empty($tmp) || empty($tmp['trans'])) {
             $this->record = array('sessionId' => $this->sessionId);
             $this->sessionArr = array();
             //error_log("[TRACE-session ".$_COOKIE['SoohSessId']." data] skip init");
         } else {
             $this->record = $tmp['trans'];
             $this->sessionArr = $tmp['data'];
             if ($this->get('accountId')) {
                 $secLast = $this->sessionArr['__dTaCcOuNt__'] - 0;
                 $secPast = $this->timestamp - $secLast;
                 if ($secPast > 300) {
                     $this->sessionArr['__eXpIrE__']['accountId'] += min([$secPast, 900]);
                     $this->sessionArr['__dTaCcOuNt__'] = $this->timestamp;
                     $this->changed = true;
                     //error_log("[TRACE-session ".$_COOKIE['SoohSessId']." data] update expire as secPast=$secPast");
                 } else {
                     //error_log("[TRACE-session ".$_COOKIE['SoohSessId']." data] skip secPast=$secPast");
                 }
             } else {
                 //error_log("[TRACE-session ".$_COOKIE['SoohSessId']." data] skip not login");
             }
         }
         \Sooh\Base\Ini::registerShutdown(array($this, 'shutdown'), 'sessionOnShutdown');
     }
 }
Пример #7
0
 public function __construct($arrSteps, $step = 1, $maxForDone = self::dtDone)
 {
     $this->arrSteps = $arrSteps;
     $this->maxForDone = $maxForDone;
     $this->stepSize = $step;
     $this->dtNow = \Sooh\Base\Time::getInstance()->timestamp();
     $this->cmpVal = $this->dtNow . str_repeat('0', 7);
 }
Пример #8
0
 /**
  * CD 构造函数
  * 
  * @param string $numString 存取的字符串
  * @param int $add 一次增加多少秒
  * @param int $max 累计多少之后变红
  */
 public function __construct($numString, $add, $max)
 {
     $this->add = $add;
     $this->max = $max;
     $this->now = sooh_time::getInstance()->timestamp();
     $this->r = \Sooh\Base\NumStr::decode($numString, $this->define);
     if ($this->cdLeft() <= 0) {
         $this->r = array('start' => 0, 'red' => 0, 'dur' => 0);
     }
 }
Пример #9
0
 public function write($logData)
 {
     if ($this->rpc !== null) {
         return $this->rpc->initArgs(array('logData' => $logData))->send(__FUNCTION__);
     } else {
         $dt = \Sooh\Base\Time::getInstance();
         \Sooh\DB\Broker::getInstance()->addLog('db_monitor.tb_error_log', array('ymd' => $dt->YmdFull, 'hhiiss' => $dt->his, 'msg' => $logData));
         return 'done';
     }
 }
Пример #10
0
 /**
  * $guidtype 在构造时使用一次
  *   a 180组服务器,30几年后溢出,(每个请求需要一个进程处理至少1个毫秒,)
  *   b 18组服务器, 300年后溢出, (每个请求需要一个进程处理至少1个毫秒,)
  *   c 18组服务器, 30年后溢出,  (每个请求需要一个进程处理至少0.1个毫秒,)
  * @param string $guidtype 
  * @return \Sooh\Base\Log\Data
  */
 public static function getInstance($guidtype = 'c')
 {
     if (self::$_instance == null) {
         self::$_instance = new Data();
         $dt = \Sooh\Base\Time::getInstance();
         self::$_instance->ymd = $dt->YmdFull;
         self::$_instance->hhiiss = $dt->his;
         self::$_instance->ip = \Sooh\Base\Tools::remoteIP();
         self::$_instance->logGuid = self::$_instance->newLogId($guidtype);
         \Sooh\Base\Ini::registerShutdown(get_called_class() . '::onShutdown', 'logOnShutdown');
     }
     return self::$_instance;
 }
Пример #11
0
 public function indexAction()
 {
     \Lib\Services\SessionStorage::setStorageIni();
     \Sooh\Base\Session\Data::getInstance(\Lib\Services\SessionStorage::getInstance($this->getRpcDefault('SessionStorage')));
     \Sooh\Base\Ini::getInstance()->viewRenderType('json');
     $this->_view->assign('normal', true);
     $this->_view->assign('sessionId', \Sooh\Base\Session\Data::getSessId());
     $this->_view->assign('accountId', \Sooh\Base\Session\Data::getInstance()->get('accountId'));
     $today = \Sooh\Base\Time::getInstance()->YmdFull;
     $uri0 = 'http://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . '' . $_SERVER["SCRIPT_NAME"];
     $this->_view->assign('urls', array('login' => $uri0 . '?__=passport/login&loginname=qq01&passwd=123456', 'register' => $uri0 . '?__=passport/register&loginname=qq01&passwd=123456&contractId=34562342523534', 'checkin-checkin' => $uri0 . '?__=checkin/checkin&with_bonus=1', 'checkin-today' => $uri0 . '?__=checkin/today&with_bonus=1', 'checkin-reset' => $uri0 . '?__=checkin/resetday&ymd=' . $today, 'checkin-resetAll' => $uri0 . '?__=checkin/resetday&ymd=' . $today . '&num=0'));
     //$this->_view->assign('code1',\Lib\Subdir\Abc::run());
     throw new \ErrorException('msg append by exception');
     //$this->_view->assign('code2',  \Subdir\Test::run());
     //$this->_view->assign('code3',\Subdir_Type1::run());
 }
Пример #12
0
 public function giveToUser($curLeft, $num, $msg)
 {
     $mod = self::indexForSplit($this->pkey);
     $dt = \Sooh\Base\Time::getInstance()->timestamp();
     $this->setField('changed', $num);
     $this->setField('finalval', $curLeft + $num);
     $this->setField('finalstatus', self::status_init);
     $this->setField('descAdd', $msg);
     $this->setField('dtAdd', $dt);
     for ($retry = 0; $retry < 10; $retry++) {
         try {
             $sn = $dt . sprintf("%05d", rand(0, 99999)) . sprintf("%04d", $mod);
             $this->pkey['ShopPointOSN'] = $sn;
             $this->update();
             return $sn;
         } catch (\ErrorException $e) {
         }
     }
     throw new \ErrorException(\Sooh\Base\ErrException::msgServerBusy);
 }
Пример #13
0
 /**
  * 实际发送请求到server,默认http-get
  * @return mixed or null 
  */
 public function _send($host, $service, $cmd, $args, $dt, $sign)
 {
     $dt = \Sooh\Base\Time::getInstance()->timestamp();
     if (is_string($args)) {
         $url = $host . '&service=' . $service . '&cmd=' . $cmd . '&args=' . urlencode($args) . '&dt=' . ($dt - 0) . '&sign=' . urlencode($sign);
     } else {
         $url = $host . '&service=' . $service . '&cmd=' . $cmd . '&args=' . urlencode(json_encode($args)) . '&dt=' . ($dt - 0) . '&sign=' . urlencode($sign);
     }
     if ('rpcservices' != $service) {
         error_log("[RPC@" . getmypid() . "]" . $url);
     }
     $ret = \Sooh\Base\Tools::httpGet($url);
     if ('rpcservices' != $service) {
         error_log("[RPC@" . getmypid() . "]" . $ret);
     }
     if (200 == \Sooh\Base\Tools::httpCodeLast()) {
         return $ret;
     } else {
         return null;
     }
 }
Пример #14
0
 protected function onLogin($accountInfo)
 {
     $sess = \Sooh\Base\Session\Data::getInstance();
     $sess->set('accountId', $accountInfo['accountId']);
     $sess->set('nickname', $accountInfo['nickname']);
     $this->_view->assign('account', array('accountId' => $accountInfo['accountId'], 'nickname' => $accountInfo['nickname']));
     /**
     		$userOrAccountId = $this->user;
     		$checkinBook = \Lib\Services\CheckinBook::getInstance();
     */
     $userOrAccountId = $accountInfo['accountId'];
     $checkinBook = \Lib\Services\CheckinBook::getInstance($this->getRpcDefault('CheckinBook'));
     $this->_view->assign('checkinBook', $checkinBook->doGetTodayStatus(1, $userOrAccountId)['data']);
     $this->_view->assign('shopPoints', array('nleft' => 'todo', 'history' => array('todo')));
     $user = \Prj\Data\User::getCopy($userOrAccountId);
     setcookie('nickname', $accountInfo['nickname'], 0, '/', \Sooh\Base\Ini::getInstance()->cookieDomain());
     $user->load();
     $dt = \Sooh\Base\Time::getInstance();
     if ($user->exists() === false) {
         $user->setField('nickname', $accountInfo['nickname']);
         $user->setField('contractId', $accountInfo['contractId']);
         $user->setField('regYmd', $dt->YmdFull);
         $user->setField('regHHiiss', $dt->his);
         $user->setField('regClient', self::tmp_clientType);
         $user->setField('regIP', \Sooh\Base\Tools::remoteIP());
         //$user->setField(self::fieldUser, array());
         $user->update();
     } else {
         $user->setField('nickname', $accountInfo['nickname']);
         $user->setField('lastDt', $dt->timestamp());
         $user->setField('lastIP', \Sooh\Base\Tools::remoteIP());
         $user->update();
     }
     $sess->shutdown();
     $this->returnOK();
 }
Пример #15
0
 /**
  * 
  * @param string $taskname
  * @param string $fullpatch
  * @param \Sooh\Base\Crond\Task $_ignore_
  */
 protected function newTask($subdir, $taskname, $fullpatch, $_ignore_ = null)
 {
     //$this->_log->writeCrondLog(null,__FUNCTION__."($taskname,$fullpatch)");
     if (!isset($this->_tasks[$taskname])) {
         include $fullpatch;
         if ($this->_useSubdirAsNamespace !== null) {
             if ($this->_useSubdirAsNamespace) {
                 $realclass = $this->_baseNamespace . $subdir . '\\' . $taskname;
             } else {
                 $realclass = $this->_baseNamespace . $taskname;
             }
         } else {
             $realclass = $taskname;
         }
         //$this->_log->writeCrondLog(null,__FUNCTION__."new $realclass() from $fullpatch");
         $_ignore_ = new $realclass($this->_isManual);
         //$this->_log->writeCrondLog(null,__FUNCTION__."new $realclass() ->init()");
         $_ignore_->init();
         $_ignore_->subdir = $subdir;
         //$this->_log->writeCrondLog(null,__FUNCTION__."new $realclass() created");
         $this->_tasks[$taskname] = $_ignore_;
         $dt = \Sooh\Base\Time::getInstance();
         $this->_log->updCrondStatus($dt->YmdFull, $dt->hour, $subdir . '.' . $taskname, 'inited', 0, $this->_isManual ? 1 : 0);
     }
 }
Пример #16
0
 /**
  * 锁定一条记录(TODO: 分散设计后,应该没有很多的冲突几率,考虑加个冲突日志并酌情报警)
  * @param string $msg msg describe the reason
  * @param int $secExpire default 3year
  * @return boolean 
  * @throws ErrorException when record is locked already
  */
 public function lock($msg, $secExpire = 94608000)
 {
     $dt = \Sooh\Base\Time::getInstance();
     if ($this->lock !== null) {
         error_log('locked already:' . get_called_class() . ' ' . json_encode($this->pkey));
         return false;
     } else {
         $this->lock = new \Sooh\DB\Base\KVObjV2Lock();
         $this->lock->create = $dt->timestamp();
         $this->lock->expire = $this->lock->create + $secExpire;
         $this->lock->msg = $msg;
         $this->lock->ip = \Sooh\Base\Tools::remoteIP();
         $this->lock->lockedByThisProcess = true;
         $dbDisk = $this->db();
         $tbDisk = $this->tbname();
         if ($this->cacheWhenVerIDIs) {
             $dbCache = $this->db(true);
             $tbCache = $this->tbname(true);
         }
         $where = $this->pkey;
         $where[$this->fieldName_verid] = $this->r[$this->fieldName_verid];
         $nextId = \Sooh\DB\Base\SQLDefine::nextCircledInt($this->r[$this->fieldName_verid]);
         $tmp = $this->lock->toString();
         if ($this->cacheWhenVerIDIs == 0) {
             $ret = $dbDisk->updRecords($tbDisk, array($this->fieldName_verid => $nextId, $this->fieldName_lockmsg => $tmp), $where);
             $locked = $ret == 1;
         } elseif ($this->cacheWhenVerIDIs == 1) {
             $ret = $dbCache->updRecords($tbCache, array($this->fieldName_verid => $nextId, $this->fieldName_lockmsg => $tmp), $where);
             $locked = $ret == 1;
             if ($locked) {
                 $dbDisk->updRecords($tbDisk, array($this->fieldName_verid => $nextId, $this->fieldName_lockmsg => $tmp), $where);
             }
         } else {
             $ret = $dbCache->updRecords($tbCache, array($this->fieldName_verid => $nextId, $this->fieldName_lockmsg => $tmp), $where);
             $locked = $ret == 1;
         }
         if ($locked) {
             $this->r[$this->fieldName_verid] = $nextId;
             $this->r[$this->fieldName_lockmsg] = $tmp;
             return true;
         } else {
             error_log('locked failed:' . implode("\n", \Sooh\DB\Broker::lastCmd(false)));
             return false;
         }
     }
 }
Пример #17
0
 /**
  * 0下标开始的当月签到奖励, 根据需要(比如本月累计签到了几次)调整
  * @return type
  */
 protected function getBonusList()
 {
     $default = array();
     for ($i = 0; $i < 21; $i++) {
         $default[$i] = array('ShopPoint' => floor($i / 2) + 1);
     }
     $fetched = $this->r['bonusGot'];
     $activesFrom = strtotime(20150608);
     $activesTo = strtotime(20150619);
     //18日是最后一天的话,这里填19日
     $today = strtotime(\Sooh\Base\Time::getInstance()->YmdFull);
     if ($today < $activesFrom) {
         $keep = ($activesFrom - $today) / 86400;
         $dbl = ($activesTo - $activesFrom) / 86400;
     } else {
         $keep = 0;
         if ($today <= $activesTo) {
             $dbl = ($activesTo - $today) / 86400;
         }
     }
     foreach ($default as $k => $v) {
         if (!isset($fetched[$k])) {
             if ($keep > 0) {
                 $fetched[$k] = $v;
                 $keep--;
             } elseif ($dbl > 0) {
                 $dbl--;
                 if (key($v) === 'ShopPoint') {
                     $v[key($v)] *= 2;
                     $fetched[$k] = $v;
                 } else {
                     $fetched[$k] = $v;
                 }
             } else {
                 $fetched[$k] = $v;
             }
         }
     }
     return $fetched;
 }
Пример #18
0
 /**
  * 发送请求
  * @return mixed
  */
 public function send($cmd)
 {
     $this->final_cmd = $cmd;
     $hosts = $this->final_hosts;
     $timestamp = \Sooh\Base\Time::getInstance()->timestamp();
     while (sizeof($hosts)) {
         $rand = array_rand($hosts);
         $host = $hosts[$rand];
         unset($hosts[$rand]);
         //if('rpcservices'!=$this->final_service)
         //error_log("#######rpc-call####{$this->final_protocol}:{$host}, {$this->final_service}, {$this->final_cmd},".  json_encode($this->final_args));
         $ret = $this->getSender($this->final_protocol)->_send($host, $this->final_service, $this->final_cmd, $this->final_args, $timestamp, $this->clacSign($timestamp));
         //error_log("#######rpc-ret####".json_encode($ret));
         if (empty($ret)) {
             \Sooh\Base\Log\Data::error("found_rpc_server_down:" . $host . ' with cmd');
         } else {
             $arr = json_decode($ret, true);
             if (is_array($arr)) {
                 if ($arr['code'] == 200) {
                     return $arr['data'];
                 } else {
                     $err = new \Sooh\Base\ErrException($arr['msg'], $arr['code']);
                     $err->customData = $arr['data'];
                     throw $err;
                 }
             }
         }
     }
     throw new \Sooh\Base\ErrException('rpc_failed:' . $this->final_cmd);
 }
Пример #19
0
 /**
  * 删除过于久远的执行状态记录(默认半年)
  */
 public function remoreCrondLogExpired($dayExpired = 190)
 {
     if ($this->rpc !== null) {
         return $this->rpc->initArgs(array('dayExpired' => $dayExpired))->send(__FUNCTION__);
     } else {
         $dt = \Sooh\Base\Time::getInstance()->getInstance()->timestamp(-$dayExpired);
         $this->getDB()->delRecords($this->tbname, array('ymdh<' => date('YmdH', $dt)));
     }
 }
Пример #20
0
 /**
  * 
  * @param string $imei
  * @return int64 contractId
  */
 public static function getContractIdOfAndroid($imei)
 {
     $tmp = self::startAndroid($imei);
     try {
         \Sooh\DB\Broker::errorMarkSkip(\Sooh\DB\Error::tableNotExists);
         $pkey = $tmp->load();
         if ($pkey) {
             $dt = \Sooh\Base\Time::getInstance()->timestamp();
             if ($dt < $tmp->getField('expired')) {
                 $contractId = $tmp->getField('contractId');
                 try {
                     $tmp->update(array($tmp, 'markInstalled'));
                     return $contractId;
                 } catch (\ErrorException $e) {
                     error_log($e->getMessage() . "\n" . $e->getTraceAsString());
                     return 0;
                 }
             } else {
                 return 0;
             }
         } else {
             return 0;
         }
     } catch (\ErrorException $e) {
         if (\Sooh\DB\Broker::errorIs($e, \Sooh\DB\Error::tableNotExists)) {
             return 0;
         } else {
             error_log($e->getMessage() . "\n" . $e->getTraceAsString());
             return 0;
         }
     }
 }
Пример #21
0
 public function register($password, $arrLoginName = [], $customArgs = [])
 {
     if ($this->rpc !== null) {
         return $this->rpc->initArgs(array('password' => $password, 'arrLoginName' => $arrLoginName, 'customArgs' => $customArgs))->send(__FUNCTION__);
     } else {
         if ($arrLoginName !== null) {
             //生成AccountId
             for ($retry = 0; $retry < 10; $retry++) {
                 try {
                     $accountId = rand(10000, 99999) . sprintf('%05d', rand(0, 99999)) . sprintf('%04d', rand(0, 9999));
                     $this->setAccountStorage($accountId);
                     if ($this->account->exists()) {
                         throw new \Exception('account exists for registe');
                     } else {
                         break;
                     }
                 } catch (\Exception $e) {
                     error_log($e->getMessage() . "[try accountId:{$accountId}]");
                 }
                 if ($retry == 9) {
                     throw new \Sooh\Base\ErrException(self::errRetryLater, 400);
                 }
             }
             //检查loginName是否存在
             foreach ($arrLoginName as $_key => $_val) {
                 if ($this->loginPrepare($accountId, $_val[0], $_val[1]) === false) {
                     $this->loginRollback($arrLoginName, $_key);
                     throw new \Sooh\Base\ErrException(self::errAccountExists, 400);
                 }
             }
         } else {
             throw new \Sooh\Base\ErrException(self::errAccountEmpty, 400);
         }
         $this->account->load();
         $passwdSalt = substr(uniqid(), -4);
         if (!empty($customArgs['nickname'])) {
             $nickname = $customArgs['nickname'];
         } else {
             $nickname = $accountId;
         }
         $this->account->setField('passwdSalt', $passwdSalt);
         $cmp = md5($password . $passwdSalt);
         $this->account->setField('passwd', $cmp);
         $this->account->setField('nickname', $nickname);
         $customArgs['regClient'] = $customArgs['clientType'] - 0;
         $customArgs['regYmd'] = \Sooh\Base\Time::getInstance()->YmdFull;
         $customArgs['regHHiiss'] = \Sooh\Base\Time::getInstance()->his;
         foreach ($customArgs as $k => $v) {
             $this->account->setField($k, $v);
         }
         $this->account->update();
         $tmp = array('accountId' => $accountId, 'nickname' => $nickname);
         foreach ($customArgs as $k => $v) {
             $tmp[$k] = $v;
         }
         $this->loginCommit($arrLoginName);
         return $tmp;
     }
 }
Пример #22
0
 /**
  * 删除过期日志
  * @param int $dayExpired (默认删除190天前)
  */
 public function remoreCrondLogExpired($dayExpired = 190)
 {
     $dt = \Sooh\Base\Time::getInstance()->getInstance()->timestamp(-$dayExpired);
     \Sooh\DB\Broker::getInstance($this->dbConfID)->delRecords($this->tbName, array('ymdh<' => date('YmdH', $dt)));
 }
Пример #23
0
 /**
  * 
  * @param string $type [idfa|imei|md5|mac]
  * @param string $sn
  * @param string $phone
  * @param string $userIdentifier
  * @param string $contractId
  * @param array $extraData
  * @return \PrjLib\DataDig\Log\Device
  */
 public static function ensureOne($type, $sn, $phone = null, $userIdentifier = null, $contractId = null, $extraData = null)
 {
     $dt = \Sooh\Base\Time::getInstance();
     $deviceId = self::guidMaker($type, $sn);
     $ddd = \Yaf_Dispatcher::getInstance()->getRequest();
     error_log("trace device->ensure(" . $ddd->getModuleName() . '/' . $ddd->getControllerName() . '/' . $ddd->getActionName() . ") " . $deviceId . "  phone:{$phone}  user:{$userIdentifier}");
     $sys = parent::getCopy(array('deviceId' => $deviceId));
     try {
         \Sooh\DB\Broker::errorMarkSkip(\Sooh\DB\Error::tableNotExists);
         $sys->load();
     } catch (\ErrorException $e) {
         if (\Sooh\DB\Broker::errorIs($e, \Sooh\DB\Error::tableNotExists)) {
             $sys->createTable();
         }
     }
     $fields = array('ip' => \Sooh\Base\Tools::remoteIP(), 'ymd' => $dt->YmdFull, 'hhiiss' => $dt->his);
     try {
         if ($sys->exists() === false) {
             foreach ($fields as $k => $v) {
                 $sys->setField($k, $v);
             }
             $sys->setField('phone', empty($phone) ? '0' : $phone);
             $sys->setField('userIdentifier', empty($userIdentifier) ? '' : $userIdentifier);
             $sys->setField('extraData', empty($extraData) ? '' : json_encode($extraData));
             $sys->setField('extraRet', '');
             $sys->setField('contractId', empty($contractId) ? '0' : $contractId);
             try {
                 \Sooh\DB\Broker::errorMarkSkip(\Sooh\DB\Error::duplicateKey);
                 $sys->update();
                 $sys->flgNewCreate = true;
                 return $sys;
             } catch (\ErrorException $e) {
                 $sys->reload();
                 if ($sys->exists() === false) {
                     error_log('error create new device log:' . $e->getMessage() . "\n" . $e->getTraceAsString());
                     return $sys;
                 }
             }
         }
         $oldPhone = $sys->getField('phone', true);
         $oldUser = $sys->getField('userIdentifier', true);
         $oldContractId = $sys->getField('contractId', true);
         if (!empty($phone) && !empty($oldPhone) && $phone != $oldPhone || !empty($oldUser) && !empty($userIdentifier) && $oldUser != $userIdentifier || !empty($oldContractId) && !empty($contractId) && $oldContractId != $contractId) {
             $extraDataOld = $sys->getField('extraData', true);
             $extraRetOld = $sys->getField('extraRet', true);
             $extraRetOld = is_scalar($extraRetOld) === false ? json_encode($extraRetOld) : $extraRetOld;
             \Sooh\DB\Broker::getInstance(\PrjLib\Tbname::db_rpt)->addRecord(\PrjLib\Tbname::tb_device_log, array('deviceId' => $deviceId, 'dtChange' => $dt->YmdFull . sprintf('%06d', $dt->his), 'phoneOld' => $oldPhone, 'userIdentifierOld' => $oldUser, 'extraDataOld' => is_scalar($extraDataOld) === false ? json_encode($extraDataOld) : $extraDataOld, 'extraRetOld' => $extraRetOld, 'contractIdOld' => $oldContractId, 'phoneNew' => $phone, 'userIdentifierNew' => $userIdentifier, 'extraDataNew' => empty($extraData) ? '' : json_encode($extraData), 'extraRetNew' => $extraRetOld, 'contractIdNew' => empty($contractId) ? '0' : $contractId, 'ipOld' => $sys->getField('ip', true), 'ipNew' => $fields['ip']));
         }
         foreach ($fields as $k => $v) {
             $sys->setField($k, $v);
         }
         if (!empty($extraData)) {
             $sys->setField('extraData', empty($extraData) ? '' : json_encode($extraData));
         }
         if (!empty($phone)) {
             $sys->setField('phone', $phone);
         }
         if (!empty($userIdentifier)) {
             $sys->setField('userIdentifier', $userIdentifier);
         }
         //$sys->setField('extraRet', '');
         if (!empty($contractId)) {
             $sys->setField('contractId', $contractId);
         }
         $sys->update();
         //var_log($sys->dump(),'======================log->filled for '.$sys->tbname());
         \Sooh\DB\Broker::errorMarkSkip(\Sooh\DB\Error::tableNotExists);
     } catch (\ErrorException $e) {
         error_log("error: on ensure-device:" . $e->getMessage() . "\n" . $e->getTraceAsString());
     }
     return $sys;
 }
Пример #24
0
 protected function ifResetByDayChange($defaultOnDayChange)
 {
     if (isset($this->fieldDef['mdy'])) {
         $today = sooh_time::getInstance()->mdy;
         $cmp = $this->vals['mdy'];
         $field = 'mdy';
     } elseif (isset($this->fieldDef['ymd'])) {
         $today = sooh_time::getInstance()->ymd;
         $cmp = $this->vals['ymd'];
         $field = 'ymd';
     } elseif (isset($this->fieldDef['Ymd'])) {
         $today = sooh_time::getInstance()->YmdFull;
         $cmp = $this->vals['Ymd'];
         $field = 'Ymd';
     }
     if ($cmp !== $today) {
         if (is_array($defaultOnDayChange)) {
             foreach ($defaultOnDayChange as $k => $v) {
                 $this->vals[$k] = $v;
             }
         } else {
             $this->vals = array();
             foreach ($this->fieldDef as $k => $v) {
                 $this->vals[$k] = 0;
             }
         }
         $this->vals[$field] = $today;
     }
 }
Пример #25
0
 /**
  * 检查当前是否已经锁定
  * @return  string '' means not locked, otherwise lock-reason returned 
  */
 public function isLocked()
 {
     if (!empty($this->r[$this->fieldName_lockmsg])) {
         $tmp = null;
         parse_str($this->r[$this->fieldName_lockmsg], $tmp);
         var_export($tmp, true);
         if ($tmp['expire'] > \Sooh\Base\Time::getInstance()->timestamp()) {
             return $tmp['msg'];
         } else {
             return '';
         }
     } else {
         return '';
     }
 }
Пример #26
0
 /**
  * 检查是否维护时间,如果是,抛出异常(不支持任何写动作)
  * @throw \ErrorException
  */
 protected function onInit_chkMaintainTime()
 {
     $now = \Sooh\Base\Time::getInstance()->timestamp();
     $chk = $this->ini->get('maintainTime');
     if ($chk[1] > $now && $chk[0] <= $now) {
         throw new \ErrorException(\Prj\ErrCode::errMaintainTime);
     }
 }