timeZone = 0; $this->nowtime = phpcommon\getNowTime(); } public function _handlePre() { } public function _handlePost() { } public function _giveContributionPoint($point) { //$this->contributionPoint += $point; } public function _getNowTime() { return $this->nowtime + $this->timeOffset; } public function _getTimeOffset() { return $this->timeOffset; } public function _setTimeOffset($seconds) { $this->timeOffset = $seconds; } public function _getTodayLeadStr() { $leadStr = strftime('%y%m%d', $this->_getNowTime()); return $leadStr; } public function _getNowDaySeconds() { return $this->_getDaySeconds($this->_getNowTime()); } public function _getDaySeconds($time) { return phpcommon\getDaySeconds($time, $this->timeZone); } public function _getDaySecondsOffset($time) { return $time - phpcommon\getDaySeconds($time, $this->timeZone); } public function _getTodayRemainSeconds() { return max(0, $this->_getNowDaySeconds() + 3600 * 24 - $this->_getNowTime()); } public function _getMondaySeconds() { return phpcommon\getMondaySeconds($this->_getNowTime(), $this->timeZone); } public function _getMondaySecondsByTime($time) { return phpcommon\getMondaySeconds($time, $this->timeZone); } public function _getMonthFirstDaySeconds() { return phpcommon\getThisMonthFirstDaySeconds($this->_getNowTime(), $this->timeZone); } public function _getMonthFirstDaySecondsByTime($time) { return phpcommon\getThisMonthFirstDaySeconds($time, $this->timeZone); } public function _getNextMonthFirstDaySeconds() { return phpcommon\getNextMonthFirstDaySeconds($this->_getNowTime(), $this->timeZone); } public function _getNextMonthFirstDaySecondsByTime($time) { return phpcommon\getNextMonthFirstDaySeconds($time, $this->timeZone); } public function _inTimeRangeStr($beginTimeStr, $endTimeStr) { $beginTimeOffset = myself()->_getDaySecondsOffset(strtotime("2024-6-22 ". $beginTimeStr)); $endTimeOffset = myself()->_getDaySecondsOffset(strtotime("2024-6-22 ". $endTimeStr)); $nowTimeOffset = myself()->_getDaySecondsOffset(myself()->_getNowTime()); error_log(json_encode(array( 'beginTimeOffset' => $beginTimeOffset, 'endTimeOffset' => $endTimeOffset, 'nowTimeOffset' => $nowTimeOffset, 'isOpen' => $nowTimeOffset >= $beginTimeOffset && $nowTimeOffset <= $endTimeOffset, ))); return $nowTimeOffset >= $beginTimeOffset && $nowTimeOffset <= $endTimeOffset; } public function _getZid() { $net = getReqVal('_net', ''); $values = explode('-', $net); $zid = $values[1]; return substr($zid, 1); } public function _rspErr($errcode, $errmsg) { if (SERVER_ENV != _ONLINE) { error_log(json_encode(array( 'c' => getReqVal('c', ''), 'a' => getReqVal('a', ''), 'errcode' => $errcode, 'errmsg' => $errmsg, ))); error_log('callstack:' . json_encode(debug_backtrace(), JSON_PRETTY_PRINT)); } echo json_encode(array( 'errcode' => $errcode, 'errmsg' => $errmsg, 'contributionPoint' => $this->contributionPoint )); } public function _rspOk() { echo json_encode(array( 'errcode' => 0, 'errmsg' => '', 'contributionPoint' => $this->contributionPoint )); } public function _rspData($data) { $rawData = array( 'errcode' => 0, 'errmsg' => '', 'contributionPoint' => $this->contributionPoint ); foreach ($data as $key => $val) { $rawData[$key] = $val; } echo json_encode($rawData); } public function _rspRawData($data) { echo json_encode($data); } public function _getMysql($data) { $mysql_conf = getMysqlConfig(crc32($data)); $conn = new phpcommon\Mysql(array( 'host' => $mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => DBNAME_PREFIX . $mysql_conf['instance_id'] )); return $conn; } public function _getAccountMysql() { if ($this->accountDbConn) { return $this->accountDbConn; } $mysql_conf = getAccountDbMysqlConfig(crc32('')); $this->accountDbConn = new phpcommon\Mysql(array( 'host' => $mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => getXVal($mysql_conf, 'dbname', 'accountdb1') )); return $this->accountDbConn; } public function _getMarketMysql() { if ($this->marketDbConn) { return $this->marketDbConn; } $mysql_conf = getMarketMysqlConfig(crc32('')); $this->marketDbConn = new phpcommon\Mysql(array( 'host' => $mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => getXVal($mysql_conf, 'dbname', 'marketdb2006') )); return $this->marketDbConn; } public function _getMailMysql() { if ($this->mailDbConn) { return $this->mailDbConn; } $mysql_conf = getMailMysqlConfig(); $this->mailDbConn = new phpcommon\Mysql(array( 'host' => $mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => $mysql_conf['dbname'], )); return $this->mailDbConn; } public function _getLogMysql() { if ($this->logDbConn) { return $this->logDbConn; } $mysql_conf = getLogMysqlConfig(); $this->logDbConn = new phpcommon\Mysql(array( 'host' => $mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => $mysql_conf['dbname'], )); return $this->logDbConn; } public function _getConfDbMysql() { if ($this->confDbConn) { return $this->confDbConn; } $mysql_conf = getConfDbMysqlConfig(); $this->confDbConn = new phpcommon\Mysql(array( 'host' => $mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => $mysql_conf['dbname'], )); return $this->confDbConn; } public function _getFriendDbMysql() { if ($this->friendDbConn) { return $this->friendDbConn; } $mysql_conf = getFriendDbMysqlConfig(); $this->friendDbConn = new phpcommon\Mysql(array( 'host' => $mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => $mysql_conf['dbname'], )); return $this->friendDbConn; } public function _getRelationDbMysql() { if ($this->relationDbConn) { return $this->relationDbConn; } $mysql_conf = getRelationMysqlConfig(crc32('')); $this->relationDbConn = new phpcommon\Mysql(array( 'host' => $mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => getXVal($mysql_conf, 'dbname', 'relationdb1') )); return $this->relationDbConn; } public function _getRedis($data) { $redis_conf = getRedisConfig(crc32($data)); $r = new phpcommon\Redis(array( 'host' => $redis_conf['host'], 'port' => $redis_conf['port'], 'passwd' => $redis_conf['passwd'] )); return $r; } public function _redisSetAndExpire($pk, $key, $val, $time) { $r = $this->_getRedis($pk); $r->set($key, $val); $r->pexpire($key, $time); } public function _redisGetJson($pk, $key) { $r = $this->_getRedis($pk); $dataStr = $r->get($key); $result = null; if (!empty($dataStr)) { $result = json_decode($dataStr, true); } return $result; } public function _addLogEx($accountId, $type, $subtype, $params) { myself()->_callServiceStatic('LogService', 'addGameLogEx', $accountId, $type, $subtype, $params); } public function _getAccountIdByAddress($address) { $row = SqlHelper::ormSelectOne( myself()->_getMysql(''), 't_user', array( 'address' => $address ) ); return $row ? $row['account_id'] : null; } public function _isAndroidAccountId($accountId) { $channel = phpcommon\extractChannel($accountId); return $channel == "0000"; } public function _getServiceConstant($serviceName, $name) { return $this->_internalGetModuleConstant('services', $serviceName, $name); } public function _callServiceStatic($serviceName, $funcName, ...$args) { return $this->_internalCallModuleStatic('services', $serviceName, $funcName, ... $args); } public function _getModelConstant($modelName, $name) { return $this->_internalGetModuleConstant('models', $modelName, $name); } public function _callModelStatic($modelName, $funcName, ...$args) { return $this->_internalCallModuleStatic('models', $modelName, $funcName, ... $args); } public function _getMtConstant($modelName, $name) { return $this->_internalGetModuleConstant('mt', $modelName, $name); } public function _callMtStatic($modelName, $funcName, ...$args) { return $this->_internalCallModuleStatic('mt', $modelName, $funcName, ... $args); } protected function _internalGetModuleConstant($dir, $moduleName, $name) { $fullName = $dir . '\\' . $moduleName; $this->_internalMustBeLoadModule($fullName); $reflectionConstant = new ReflectionClassConstant($fullName, $name); return $reflectionConstant->getValue();; } protected function _internalCallModuleStatic($dir, $moduleName, $funcName, ...$args) { $fullName = $dir . '\\' . $moduleName; $this->_internalMustBeLoadModule($fullName); $method = new ReflectionMethod($fullName, $funcName); $ret = $method->invoke(null, ...$args); return $ret; } private function _internalMustBeLoadModule($fullName) { if (!array_key_exists($fullName, $this->moduleHash)) { require_once(str_replace('\\', '/', $fullName) . '.php'); $this->moduleHash[$fullName] = $this->_getNowTime(); } } public function _getGameId() { return 2006; } public function _isSubAccountId($accountId) { $str_list = explode('_', $accountId); if (count($str_list) < 4) { return false; } $channel = $str_list[0]; $gameId = $str_list[1]; if ($channel != BC_POLY_CHANNEL) { return false; } if ($gameId != $this->_getGameId()) { return false; } return $str_list[2][0] == 's'; } public function _getShortAccountId($accountId) { if (!$this->_isSubAccountId($accountId)) { return $accountId; } // $str_list = explode('_', $accountId); unset($str_list[2]); return implode("_",$str_list); } public function _upgradeToSafeApi() { echo json_encode(array( 'errcode' => 1006, 'errmsg' => 'already upgrade to safe api', 'payload' => 1, )); die(); } public function _checkS() { $sign = getReqVal('__sign', ''); if (empty($sign)) { error_log('waring unsafe call---------------' . json_encode($_REQUEST)); } } public static function _verifySwitch($name) { myself()->_callServiceStatic('ServerSwitchService', 'verifySwitch', $name); } public static function _switchIsOpen($name) { return myself()->_callServiceStatic('ServerSwitchService', 'switchIsOpen', $name); } public function _mergeAlikeItemKey($items){ $hashItems = array(); foreach ($items as $item){ if (isset($hashItems[$item['item_id']])){ $hashItems[$item['item_id']]['item_num'] += $item['item_num']; }else{ $hashItems[$item['item_id']] = $item; } } $finalItems = array(); foreach ($hashItems as $hashItem){ array_push($finalItems,$hashItem); } return $finalItems; } function arraySort($arr, $keys, $type = 'asc') { $keys_value = $new_array = array(); foreach ($arr as $k => $v){ $keys_value[$k] = $v[$keys]; } $type == 'asc' ? asort($keys_value) : arsort($keys_value); reset($keys_value); foreach ($keys_value as $k => $v) { $new_array[$k] = $arr[$k]; } return $new_array; } }