public function process() { try { $oTableOperate = new SingleTableOperation('cUser', "MYZL"); $data = $oTableOperate->getObject(array('userId' => $this->_args['userId'])); if (count($data)) { $this->_retValue = EC_RECORD_EXIST; $this->_retMsg = "user already exist!"; interface_log(ERROR, $this->_retValue, $this->_retMsg); return false; } //添加用户记录,设置相关的字段,这里可以根据自己的策略设置 $oTableOperate->addObject(array('userId' => $this->_args['userId'], 'password' => $this->_args['password'], 'email' => $this->_args['email'], 'money' => 100, 'bulletNum' => 5, 'xsft' => 5, 'hdcx' => 5, 'chxs' => 5, 'sszm' => 5, 'addTimeStamp' => getCurrentTime())); $this->_responseText = MYZL_HINT_ADDUSER_SUC; } catch (DB_Exception $e) { $errorNum = $oTableOperate->getErrorNum(); $this->_retMsg = $oTableOperate->getErrorInfo() . $e->getMessage(); $this->_retValue = genRetCode($errorNum); interface_log(ERROR, $this->_retValue, $this->_retMsg); return false; } return true; }
$oTable = new SingleTableOperation('cWaitingUser', 'MYZL'); while (1) { $data = $oTable->getObject(array('_sortExpress' => 'addTimeStamp')); matcher_log(DEBUG, 0, json_encode($data)); if (count($data) < 2) { sleep(2); continue; } else { $length = count($data); for ($i = 0; $i + 1 < $length; $i = $i + 2) { $userId1 = $data[$i]['userId']; if ($i >= $length) { continue; } $userId2 = $data[$i + 1]['userId']; DbFactory::getInstance('MYZL')->autoCommit(); //minus bullets DbFactory::getInstance('MYZL')->update("update cUser set bulletNum=bulletNum-1 where userId IN('" . $userId1 . "', '" . $userId2 . "')"); //删除 $oTable->delObject(array('userId' => array($userId1, $userId2))); //添加 $oTable->addObject(array('_tableName' => 'cFight', 'user1' => $userId1, 'user2' => $userId2, 'first' => $userId1, 'current' => $userId1, 'operation' => START, 'maxMoney' => $maxMoney, 'minMoney' => $minMoney, 'operator' => 0)); matcher_log(DEBUG, 0, "add {$userId1} and {$userId2} to fight"); DbFactory::getInstance('MYZL')->tryCommit(); } } } } catch (DB_Exception $e) { DbFactory::getInstance()->rollback(); matcher_log(ERROR, 0, $oTable->getErrorInfo() . $e->getMessage()); }
<?php require_once dirname(__FILE__) . '/../common/Common.php'; $fightId = $argv[1]; try { $oTable = new SingleTableOperation('cFight'); $data = $oTable->getObject(array('fightId' => $fightId)); if (empty($data)) { echo 'fight with id:' . $fightId . ' not exists!'; exit(0); } $fightInfo = $data[0]; if (!$fightInfo['lastInfo']) { echo "lastInfo is empty, fightId:" . $fightId; exit(0); } $lastInfo = json_decode($fightInfo['lastInfo'], true); unset($lastInfo['fightId']); $oTable->updateObject($lastInfo, array('fightId' => $fightId)); } catch (DB_Exception $e) { echo 'mysql error!' . $oTable->getErrorInfo() . $e->getMessage(); }