From 404cc97468754af0c3e5c6aa4ca76d91890a3556 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 30 Nov 2021 17:48:23 +0800 Subject: [PATCH] 1 --- sql/gamedb.sql | 19 +++--- webapp/controller/BaseController.class.php | 5 ++ webapp/controller/ShopController.class.php | 79 ++++++++-------------- webapp/models/ShopBuyRecord.php | 68 +++++++++++++++++++ webapp/mt/Shop.php | 57 +--------------- webapp/mt/ShopGoods.php | 62 +++++++++++++++++ 6 files changed, 176 insertions(+), 114 deletions(-) create mode 100644 webapp/models/ShopBuyRecord.php create mode 100644 webapp/mt/ShopGoods.php diff --git a/sql/gamedb.sql b/sql/gamedb.sql index f98fbb5..0481045 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -177,22 +177,25 @@ CREATE TABLE `t_dyndata` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `t_shop_data` +-- Table structure for table `t_shop_buy_record` -- -DROP TABLE IF EXISTS `t_shop_data`; +DROP TABLE IF EXISTS `t_shop_buy_record`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `t_shop_data` ( +CREATE TABLE `t_shop_buy_record` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', - `shop_id` int(11) NOT NULL DEFAULT '0' COMMENT '商店id', - `blobdata` mediumblob COMMENT '商店数据json', - `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', - `modify_time` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + `item_id` int(11) NOT NULL DEFAULT '0' COMMENT '道具id', + `this_day_buy_times` int(11) NOT NULL DEFAULT '0' COMMENT '今日购买次数', + `this_week_buy_times` int(11) NOT NULL DEFAULT '0' COMMENT '本周购买次数', + `total_buy_times` int(11) NOT NULL DEFAULT '0' COMMENT '总购买次数', + `last_buy_time` int(11) NOT NULL DEFAULT '0' COMMENT '最后一次购买时间', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), KEY `account_id` (`account_id`), - UNIQUE KEY `account_id_shop_id` (`account_id`, `shop_id`) + UNIQUE KEY `account_id_item_id` (`account_id`, `item_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; -- Dump completed on 2015-08-19 18:51:22 diff --git a/webapp/controller/BaseController.class.php b/webapp/controller/BaseController.class.php index 6b3ae11..8631802 100644 --- a/webapp/controller/BaseController.class.php +++ b/webapp/controller/BaseController.class.php @@ -36,6 +36,11 @@ class BaseController { return max(0, $this->_getNowDaySeconds() + 3600 * 24 - $this->_getNowTime()); } + public function _getMondaySeconds() + { + return phpcommon\getMondaySeconds($this->_getNowTime()); + } + public function _rspErr($errcode, $errmsg) { echo json_encode(array( diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 8ef0dcd..49f69eb 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -1,6 +1,7 @@ _rspData(array( + 'info' => array( + 'goods_list1' => array(), + 'goods_list2' => array(), + ) + )); + return; + } + $goodsDtoList1 = array(); + $goodsDtoList2 = array(); + foreach ($goodsList as $goods) { + + } + $this->_rspData(array( + 'info' => array( + 'goods_list1' => $goodsDtoList1, + 'goods_list2' => $goodsDtoList2, + ) + )); } - public function buyHero() + public function buyGoods() { - $heroId = getReqVal('hero_id', 0); - $buyType = getReqVal('buy_type', 0); - $heroMeta = mt\Hero::get($heroId); - if (!$heroMeta) { - $this->_rspErr(1, 'hero_id参数错误'); - return; - } - if (empty($heroMeta['itemid'])) { - $this->_rspErr(2, 'hero.item_id配置错误'); - return; - } - if (!in_array($buyType, array(0, 1))) { - $this->_rspErr(1, 'buy_type参数错误'); - return; - } - $shopMeta = mt\Shop::get(mt\Shop::HERO_SHOP_ID); - if (!$shopMeta) { - $this->_rspErr(2, '配置表错误1'); - return; - } - $goodsInfo = mt\Shop::getGoodsInfo($shopMeta, $heroMeta['itemid']); - if (empty($goodsInfo)) { - $this->_rspErr(2, '配置表错误2'); - return; - } - if (Hero::find($heroId)) { - $this->_rspErr(3, '你已经有该英雄'); - return; - } - $costItems = array( - 'item_id' => $goodsInfo['costItemId'], - 'item_num' => $goodsInfo['costItemNum'], - ); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(3, '道具不足'); - return; - } - $this->_decItems($costItems); - $this->internalAddItem($heroMeta); - $awardService = new services\AwardService(); - $heroDb = Hero::find($heroId); - if ($heroDb) { - $awardService->addHero(Hero::toDto($heroDb)); - } - $this->rspData(array( - 'award' => $awardService->toDto() - )); } public function outsideBuy() @@ -247,4 +221,9 @@ class ShopController extends BaseAuthedController { } } + private function updateBuyRecord($itemId, $itemNum) + { + + } + } diff --git a/webapp/models/ShopBuyRecord.php b/webapp/models/ShopBuyRecord.php new file mode 100644 index 0000000..162ca22 --- /dev/null +++ b/webapp/models/ShopBuyRecord.php @@ -0,0 +1,68 @@ +_getSelfMysql(), + 't_hero', + array( + 'account_id' => myself()->_getAccountId(), + 'hero_id' => $heroId, + ) + ); + return $row; + } + + public static function toDto($row) + { + return array( + ); + } + + public static function add($itemId, $itemNum) + { + SqlHelper::upsert( + myself()->_getSelfMysql(), + 't_shop_buy_record', + array( + 'account_id' => myself()->_getAccountId(), + 'item_id' => $itemId, + ), + array( + 'this_day_buy_times' => function () { + $nowDaySeconds = myself()->_getNowDaySeconds(); + $cond = " last_buy_time>=${nowDaySeconds} AND last_buy_time<=${nowDaySeconds} + 3600 * 24 "; + return "CASE WHEN (${cond}) THEN this_day_buy_times + 1 ELSE 0 END"; + }, + 'this_week_buy_times' => function () { + $mondaySeconds = myself()->_getNowDaySeconds(); + $cond = " last_buy_time>=${mondaySeconds} AND last_buy_time<=${mondaySeconds} + 3600 * 24 * 7 "; + return "CASE WHEN (${cond}) THEN this_week_buy_times + 1 ELSE 0 END"; + }, + 'total_buy_times' => function () { + return 'total_buy_times + 1'; + }, + 'last_buy_time' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime(), + ), + array( + 'account_id' => myself()->_getAccountId(), + 'item_id' => $itemId, + 'this_day_buy_times' => 1, + 'this_week_buy_times' => 1, + 'total_buy_times' => 1, + 'last_buy_time' => myself()->_getNowTime(), + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime(), + ) + ); + } + +} diff --git a/webapp/mt/Shop.php b/webapp/mt/Shop.php index ecde5dd..8a3bf28 100644 --- a/webapp/mt/Shop.php +++ b/webapp/mt/Shop.php @@ -6,70 +6,15 @@ use phpcommon; class Shop { - const HERO_SHOP_ID = 1; - const HEROSKIN_SHOP_ID = 2; - const GUNSKIN1_SHOP_ID = 3; - const GUNSKIN2_SHOP_ID = 4; - public static function get($id) { return getXVal(self::getMetaList(), $id); } - public static function getGoodsInfo($meta, $goodsId) - { - $goodsStrArr = explode("|", $meta['goods']); - $priceStrArr = explode("|", $meta['price']); - if (count($goodsStrArr) != count($priceStrArr)) { - echo '111'; - return null; - } - $idx = -1; - { - $i = 0; - array_filter($goodsStrArr, function($str) use(&$i, &$idx, $goodsId) { - if ($idx == -1) { - $strArr = explode(":", $str); - if (count($strArr) >= 2) { - if ($strArr[0] == $goodsId) { - $idx = $i; - return true; - } - } - } - ++$i; - return false; - }); - } - if ($idx < 0) { - return null; - } - $info = array( - 'goodsId' => 0, - 'goodsNum' => 0, - 'costItemId' => 0, - 'costItemNum' => 0 - ); - { - $strArr = explode(":", $goodsStrArr[$idx]); - $info['goodsId'] = $strArr[0]; - $info['goodsNum'] = $strArr[1]; - } - { - $strArr = explode(":", $priceStrArr[$idx]); - if (count($strArr) < 2) { - return null; - } - $info['costItemId'] = $strArr[0]; - $info['costItemNum'] = $strArr[1]; - } - return $info; - } - protected static function getMetaList() { if (!self::$metaList) { - self::$metaList = getMetaTable('newshop@newshop.php'); + self::$metaList = getMetaTable('shop@shop.php'); } return self::$metaList; } diff --git a/webapp/mt/ShopGoods.php b/webapp/mt/ShopGoods.php new file mode 100644 index 0000000..043bb93 --- /dev/null +++ b/webapp/mt/ShopGoods.php @@ -0,0 +1,62 @@ + array(), + 'goodsHash' => array() + ); + } + self::$shopGoodsHash['shop_id']['goodsHash'][$meta['goods_id']] = $meta; + array_push(self::$shopGoodsHash['shop_id']['goodsList'], $meta); + } + } + } + + protected static function getMetaList() + { + if (!self::$metaList) { + self::$metaList = getMetaTable('shopGoods@shopGoods.php'); + } + return self::$metaList; + } + + protected static $shopGoodsHash; + protected static $metaList; + +}