diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 558dc545..fe704e82 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -1798,7 +1798,7 @@ CREATE TABLE `t_gold_bullion` ( `open_address` varchar(60) COMMENT 'open_address', `open_time` int(11) NOT NULL DEFAULT '0' COMMENT 'open_time', `open_account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', - `open_try_count` int(11) NOT NULL DEFAULT '0' COMMENT 'open_try_count', + `open_uniqid` varchar(60) NOT NULL DEFAULT '' COMMENT '开启的本次唯一id', `returned` int(11) NOT NULL DEFAULT '0' COMMENT '是否已超时返还', `return_time` int(11) NOT NULL DEFAULT '0' COMMENT '返还时间', `activated` int(11) NOT NULL DEFAULT '0' COMMENT '是否已上连', @@ -1808,7 +1808,6 @@ CREATE TABLE `t_gold_bullion` ( PRIMARY KEY (`idx`), UNIQUE KEY `idx_token_id` (`token_id`), UNIQUE KEY `idx_token_id_net_id` (`token_id`, `net_id`), - KEY `idx_open_address_open_status` (`open_address`, `open_status`), - KEY `idx_address_createtime_activate_status` (`address`, `createtime`, `activate`, `status`) + KEY `idx_open_address_open_status` (`open_address`, `open_status`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/webapp/models/GoldBullion.php b/webapp/models/GoldBullion.php index ef68792d..1cbc530c 100644 --- a/webapp/models/GoldBullion.php +++ b/webapp/models/GoldBullion.php @@ -2,6 +2,9 @@ namespace models; +require_once('services/AwardService.php'); +require_once('services/PropertyChgService.php'); + class GoldBullion extends BaseModel { const OPEN_STATUS_SENT = 1; @@ -25,7 +28,9 @@ class GoldBullion extends BaseModel { ) ); if (count($rows) > 0) { + $confirmedRows = array(); foreach ($rows as $row) { + $uniqId = self::genUniqId(); SqlHelper::update( myself()->_getSelfMysql(), 't_gold_bullion', @@ -35,13 +40,56 @@ class GoldBullion extends BaseModel { ), array( 'open_status' => self::OPEN_STATUS_SEND_BEGIN, - 'open_try_count' => function () { - return "open_try_count + 1"; - }, + 'open_uniqid' => $uniqId ) ); + $newRow = SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_gold_bullion', + array( + 'idx' => $row['idx'], + ) + ); + if (!empty($newRow) && $newRow['open_uniqid'] == $uniqId) { + array_push($confirmedRows, $row); + } + self::doSendAward($confirmedRows); } } } + public static function doSendAward($confirmedRows) + { + $propertyChgService = new services\PropertyChgService(); + $awardService = new services\AwardService(); + if (empty($confirmedRows)) { + return; + } + foreach ($confirmedRows as $row) { + $items = array( + array( + 'item_id' => V_ITEM_GOLD, + 'item_num' => $row['gold'] + ) + ); + myself()->_addItems($items, $awardService, $propertyChgService); + SqlHelper::update( + myself()->_getSelfMysql(), + 't_gold_bullion', + array( + 'idx' => $row['idx'], + ), + array( + 'open_status' => self::OPEN_STATUS_SEND_END, + ) + ); + } + } + + private static function genUniqId() + { + $uniqId = uniqid(md5(rand() . rand() . rand() . myself()->_getSessionId()), true); + return $uniqId; + } + }