From dd75807752b9b7ee4b7bb61e14cc7bd945a9b053 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 14:28:12 +0800 Subject: [PATCH 01/28] 1 --- webapp/services/HashRateShopService.php | 41 ++----------------------- 1 file changed, 2 insertions(+), 39 deletions(-) diff --git a/webapp/services/HashRateShopService.php b/webapp/services/HashRateShopService.php index 5dbf6a14..4ed45796 100644 --- a/webapp/services/HashRateShopService.php +++ b/webapp/services/HashRateShopService.php @@ -2,31 +2,16 @@ namespace services; -require_once('mt/ShopGoods.php'); +require_once('mt/HashRateShop.php'); require_once('mt/Item.php'); -require_once('mt/Shop.php'); - -require_once('models/ShopBuyRecord.php'); -require_once('models/Hero.php'); -require_once('models/HeroSkin.php'); -require_once('models/GunSkin.php'); use mt; use phpcommon; -use models\ShopBuyRecord; -use models\Hero; -use models\HeroSkin; -use models\GunSkin; class HashRateShopService { - public static function getGoodsList($shopId) + public static function getGoodsList() { - if ($shopId == 0) { - $goodsMetaList = mt\ShopGoods::all(); - } else { - $goodsMetaList = mt\ShopGoods::getGoodsList($shopId); - } $goodsMetaList = $goodsMetaList ? $goodsMetaList : array(); $buyRecordHash = ShopBuyRecord::allToHash(); @@ -132,26 +117,4 @@ class HashRateShopService { return true; } - public static function goodsMetaToInfo($goodsMeta) - { - return array( - 'item_id' => $goodsMeta['item_id'], - 'item_num' => $goodsMeta['item_num'], - 'max_amount' => $goodsMeta['max_amount'], - 'shop_id' => $goodsMeta['shop_id'], - 'shopstage' => $goodsMeta['shopstage'], - 'tag' => $goodsMeta['tag'], - 'recommend' => $goodsMeta['recommend'], - 'token_type' => $goodsMeta['token_type'], - 'price' => $goodsMeta['price'], - 'free_type' => $goodsMeta['free_type'], - 'shop_icon' => $goodsMeta['shop_icon'], - 'gg_product_id' => $goodsMeta['gg_product_id'], - 'ios_product_id' => $goodsMeta['ios_product_id'], - 'bonus' => $goodsMeta['bonus'], - 'bonus_num' => $goodsMeta['bonus_num'], - 'function' => $goodsMeta['function'], - ); - } - } From e3a33562d8e3e21a53b815e78cf6f7047d5ec224 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 14:41:02 +0800 Subject: [PATCH 02/28] 1 --- sql/gamedb.sql | 23 +++++++++++++++++++++++ sql/gamedb2006_migrate_241001_01.sql | 16 ++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 39c00db2..c312524e 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -2139,3 +2139,26 @@ CREATE TABLE `t_user_bind_gold_record` ( ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `t_hashrate_shop_buy_record` +-- + +DROP TABLE IF EXISTS `t_hashrate_shop_buy_record`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_hashrate_shop_buy_record` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `goods_id` int(11) NOT NULL DEFAULT '0' COMMENT '商品id', + `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_goods_id` (`account_id`, `goods_id`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; diff --git a/sql/gamedb2006_migrate_241001_01.sql b/sql/gamedb2006_migrate_241001_01.sql index a9d1b65d..51a84ac9 100644 --- a/sql/gamedb2006_migrate_241001_01.sql +++ b/sql/gamedb2006_migrate_241001_01.sql @@ -14,6 +14,22 @@ CREATE TABLE `t_user_bind_gold_record` ( PRIMARY KEY (`idx`) ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +CREATE TABLE `t_hashrate_shop_buy_record` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `goods_id` int(11) NOT NULL DEFAULT '0' COMMENT '商品id', + `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_goods_id` (`account_id`, `goods_id`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + insert into version (version) values(2024092401); commit; From b4d0c8f9dbe4c76f1316c8119867a0b43f30f65d Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 14:47:15 +0800 Subject: [PATCH 03/28] 1 --- webapp/models/HashRateShopBuyRecord.php | 148 ++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 webapp/models/HashRateShopBuyRecord.php diff --git a/webapp/models/HashRateShopBuyRecord.php b/webapp/models/HashRateShopBuyRecord.php new file mode 100644 index 00000000..488c738d --- /dev/null +++ b/webapp/models/HashRateShopBuyRecord.php @@ -0,0 +1,148 @@ +_getSelfMysql(), + 't_hashrate_shop_buy_record', + array( + 'account_id' => myself()->_getAccountId(), + 'goods_id' => $goodsId, + ) + ); + return $row; + } + + public static function all() + { + $rows = SqlHelper::ormSelect( + myself()->_getSelfMysql(), + 't_hashrate_shop_buy_record', + array( + 'account_id' => myself()->_getAccountId(), + ) + ); + return array_map(function ($row) { + $nowDaySeconds = myself()->_getNowDaySeconds(); + if (!($row['last_buy_time'] >= $nowDaySeconds && $row['last_buy_time'] <= $nowDaySeconds)) { + $row['this_day_buy_times'] = 0; + } + $mondaySeconds = myself()->_getMondaySeconds(); + if (!($row['last_buy_time'] >= $mondaySeconds && $row['last_buy_time'] <= $mondaySeconds)) { + $row['this_week_buy_times'] = 0; + } + return $row; + }, $rows); + } + + public static function allToHash() + { + $rows = self::all(); + $buyRecordHash = array(); + array_walk($rows, function ($row) use (&$buyRecordHash) { + $buyRecordHash[$row['goods_id']] = $row; + }); + return $buyRecordHash; + } + + 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()->_getMondaySeconds(); + $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(), + ) + ); + } + + public static function addWithAddress($address, $itemId, $itemNum) + { + $account_id = ShopBuyRecord::getAccountId($address); + SqlHelper::upsert( + myself()->_getMysql($address), + 't_shop_buy_record', + array( + 'account_id' => $account_id, + '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()->_getMondaySeconds(); + $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' => $account_id, + '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(), + ) + ); + } + + private static function getAccountId($address) + { + $row = SqlHelper::ormSelectOne( + myself()->_getMysql($address), + 't_user', + array( + 'address' => $address + ) + ); + + return $row['account_id']; + } + +} From 15ba2b0107261e0c1605b74f2c44dc94d6069ac4 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 14:50:07 +0800 Subject: [PATCH 04/28] 1 --- webapp/models/HashRateShopBuyRecord.php | 57 +------------------------ 1 file changed, 2 insertions(+), 55 deletions(-) diff --git a/webapp/models/HashRateShopBuyRecord.php b/webapp/models/HashRateShopBuyRecord.php index 488c738d..b2942791 100644 --- a/webapp/models/HashRateShopBuyRecord.php +++ b/webapp/models/HashRateShopBuyRecord.php @@ -53,11 +53,11 @@ class HashRateShopBuyRecord extends BaseModel return $buyRecordHash; } - public static function add($itemId, $itemNum) + public static function add($goodsId, $goodsNum) { SqlHelper::upsert( myself()->_getSelfMysql(), - 't_shop_buy_record', + 't_hashrate_shop_buy_record', array( 'account_id' => myself()->_getAccountId(), 'item_id' => $itemId, @@ -92,57 +92,4 @@ class HashRateShopBuyRecord extends BaseModel ); } - public static function addWithAddress($address, $itemId, $itemNum) - { - $account_id = ShopBuyRecord::getAccountId($address); - SqlHelper::upsert( - myself()->_getMysql($address), - 't_shop_buy_record', - array( - 'account_id' => $account_id, - '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()->_getMondaySeconds(); - $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' => $account_id, - '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(), - ) - ); - } - - private static function getAccountId($address) - { - $row = SqlHelper::ormSelectOne( - myself()->_getMysql($address), - 't_user', - array( - 'address' => $address - ) - ); - - return $row['account_id']; - } - } From 3dc1db46e23578dd633a96019765b68c11941cbd Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 14:52:09 +0800 Subject: [PATCH 05/28] 1 --- webapp/models/HashRateShopBuyRecord.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/webapp/models/HashRateShopBuyRecord.php b/webapp/models/HashRateShopBuyRecord.php index b2942791..395a7c67 100644 --- a/webapp/models/HashRateShopBuyRecord.php +++ b/webapp/models/HashRateShopBuyRecord.php @@ -53,14 +53,14 @@ class HashRateShopBuyRecord extends BaseModel return $buyRecordHash; } - public static function add($goodsId, $goodsNum) + public static function add($goodsId, $goodsNum, $itemId) { SqlHelper::upsert( myself()->_getSelfMysql(), 't_hashrate_shop_buy_record', array( 'account_id' => myself()->_getAccountId(), - 'item_id' => $itemId, + 'goods_id' => $goodsId, ), array( 'this_day_buy_times' => function () { @@ -81,10 +81,11 @@ class HashRateShopBuyRecord extends BaseModel ), array( 'account_id' => myself()->_getAccountId(), + 'goods_id' => $goodsId, 'item_id' => $itemId, - 'this_day_buy_times' => 1, - 'this_week_buy_times' => 1, - 'total_buy_times' => 1, + 'this_day_buy_times' => $goodsNum, + 'this_week_buy_times' => $goodsNum, + 'total_buy_times' => $goodsNum, 'last_buy_time' => myself()->_getNowTime(), 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime(), From 6d055ed7f66f0a394cf237b2aeef266487587afa Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 14:52:45 +0800 Subject: [PATCH 06/28] 1 --- webapp/models/HashRateShopBuyRecord.php | 1 + 1 file changed, 1 insertion(+) diff --git a/webapp/models/HashRateShopBuyRecord.php b/webapp/models/HashRateShopBuyRecord.php index 395a7c67..39c1e96f 100644 --- a/webapp/models/HashRateShopBuyRecord.php +++ b/webapp/models/HashRateShopBuyRecord.php @@ -55,6 +55,7 @@ class HashRateShopBuyRecord extends BaseModel public static function add($goodsId, $goodsNum, $itemId) { + $goodsNum = intval($goodsNum); SqlHelper::upsert( myself()->_getSelfMysql(), 't_hashrate_shop_buy_record', From 7d452682692c96561696402dede8a0f462cf6ae4 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 14:53:40 +0800 Subject: [PATCH 07/28] 1 --- webapp/models/HashRateShopBuyRecord.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webapp/models/HashRateShopBuyRecord.php b/webapp/models/HashRateShopBuyRecord.php index 39c1e96f..efe093c3 100644 --- a/webapp/models/HashRateShopBuyRecord.php +++ b/webapp/models/HashRateShopBuyRecord.php @@ -64,17 +64,17 @@ class HashRateShopBuyRecord extends BaseModel 'goods_id' => $goodsId, ), array( - 'this_day_buy_times' => function () { + 'this_day_buy_times' => function () use($goodsNum) { $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 () { + 'this_week_buy_times' => function () use($goodsNum) { $mondaySeconds = myself()->_getMondaySeconds(); $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 () { + 'total_buy_times' => function () use($goodsNum) { return 'total_buy_times + 1'; }, 'last_buy_time' => myself()->_getNowTime(), From 33346e5b5df5b80b855f52e6ab70ce957ad695ac Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 14:54:24 +0800 Subject: [PATCH 08/28] 1 --- webapp/models/HashRateShopBuyRecord.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/webapp/models/HashRateShopBuyRecord.php b/webapp/models/HashRateShopBuyRecord.php index efe093c3..b7bbdacd 100644 --- a/webapp/models/HashRateShopBuyRecord.php +++ b/webapp/models/HashRateShopBuyRecord.php @@ -67,15 +67,15 @@ class HashRateShopBuyRecord extends BaseModel 'this_day_buy_times' => function () use($goodsNum) { $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"; + return "CASE WHEN (${cond}) THEN this_day_buy_times + ${goodsNum} ELSE 0 END"; }, 'this_week_buy_times' => function () use($goodsNum) { $mondaySeconds = myself()->_getMondaySeconds(); $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"; + return "CASE WHEN (${cond}) THEN this_week_buy_times + ${goodsNum} ELSE 0 END"; }, 'total_buy_times' => function () use($goodsNum) { - return 'total_buy_times + 1'; + return 'total_buy_times + ${goodsNum}'; }, 'last_buy_time' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime(), From 6971d9ba42e5a267abe2459001665fd43bc671eb Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 15:04:58 +0800 Subject: [PATCH 09/28] 1 --- webapp/mt/HashRateShop.php | 5 +++++ webapp/services/HashRateShopService.php | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/webapp/mt/HashRateShop.php b/webapp/mt/HashRateShop.php index 6542405c..f3e65405 100644 --- a/webapp/mt/HashRateShop.php +++ b/webapp/mt/HashRateShop.php @@ -18,6 +18,11 @@ class HashRateShop { return self::$metaList; } + public static function all() + { + return self::$metaList; + } + protected static $metaList; } diff --git a/webapp/services/HashRateShopService.php b/webapp/services/HashRateShopService.php index 4ed45796..31fa7344 100644 --- a/webapp/services/HashRateShopService.php +++ b/webapp/services/HashRateShopService.php @@ -12,8 +12,7 @@ class HashRateShopService { public static function getGoodsList() { - - $goodsMetaList = $goodsMetaList ? $goodsMetaList : array(); + $goodsMetaList = mt\HashRateShop::all(); $buyRecordHash = ShopBuyRecord::allToHash(); $goodsList = array(); From a8fc429f712546504e4648a48913957da676b251 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 15:13:42 +0800 Subject: [PATCH 10/28] 1 --- webapp/mt/HashRateShop.php | 5 +++++ webapp/services/HashRateShopService.php | 24 ++++++------------------ 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/webapp/mt/HashRateShop.php b/webapp/mt/HashRateShop.php index f3e65405..e7cb3b7b 100644 --- a/webapp/mt/HashRateShop.php +++ b/webapp/mt/HashRateShop.php @@ -6,6 +6,11 @@ use phpcommon; class HashRateShop { + const TOTAL_BUY_LIMIT = 0; + const DAILY_BUY_LIMIT = 1; + const WEEKLY_BUY_LIMIT = 2; + const MONTH_BUY_LIMIT = 3; + public static function find($id){ return getXVal(self::getMetaList(), $id, null); } diff --git a/webapp/services/HashRateShopService.php b/webapp/services/HashRateShopService.php index 31fa7344..3b2e0210 100644 --- a/webapp/services/HashRateShopService.php +++ b/webapp/services/HashRateShopService.php @@ -28,17 +28,17 @@ class HashRateShopService { ); array_push($goodsList, $goodsDto); switch ($goodsMeta['limit_type']) { - case mt\Shop::DAILY_BUY_LIMIT: { + case mt\HashRateShop::DAILY_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $goodsMeta['goods_id']); $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_day_buy_times'] : 0; } break; - case mt\Shop::WEEKLY_BUY_LIMIT: { + case mt\HashRateShop::WEEKLY_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $goodsMeta['goods_id']); $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; } break; - case mt\Shop::TOTAL_BUY_LIMIT: { + case mt\HashRateShop::TOTAL_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $goodsMeta['goods_id']); $goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0; } @@ -50,17 +50,6 @@ class HashRateShopService { $itemMeta = mt\Item::get($goodsMeta['item_id']); if ($itemMeta) { - /* - // 如果是皮肤,判断是否已经拥有,如果已经拥有,不能购买 - if ($itemMeta['type'] == mt\Item::HERO_SKIN_TYPE) { - $errCode = 0; - $errMsg = ''; - if (!self::canBuy($itemMeta, $errCode, $errMsg)) { - $goods['bought_times'] = 1; - } else { - $goods['bought_times'] = 0; - } - }*/ } else if ($goodsMeta['goods_id'] != 9999){ error_log('item not found:' . json_encode($goodsMeta)); } @@ -77,7 +66,7 @@ class HashRateShopService { $goodsId = $goodsMeta['goods_id']; { switch ($goodsMeta['limit_type']) { - case mt\Shop::DAILY_BUY_LIMIT: { + case mt\HashRateShop::DAILY_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $goodsId); $boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1; if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $goodsMeta['limit_num']) { @@ -87,7 +76,7 @@ class HashRateShopService { } } break; - case mt\Shop::WEEKLY_BUY_LIMIT: { + case mt\HashRateShop::WEEKLY_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $goodsId); $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1; if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $goodsMeta['limit_num']) { @@ -97,8 +86,7 @@ class HashRateShopService { } } break; - case mt\Shop::TOTAL_BUY_LIMIT: { - // error_log("total buy limit " . $address . " " . $goodsId . " " . $goodsMeta['limit_num']); + case mt\HashRateShop::TOTAL_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $goodsId); $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1; if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $goodsMeta['limit_num']) { From 1f41de39d0934c19c774f0a22be86d944029dc58 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 15:15:41 +0800 Subject: [PATCH 11/28] 1 --- webapp/services/HashRateShopService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/webapp/services/HashRateShopService.php b/webapp/services/HashRateShopService.php index 3b2e0210..ef674115 100644 --- a/webapp/services/HashRateShopService.php +++ b/webapp/services/HashRateShopService.php @@ -32,20 +32,20 @@ class HashRateShopService { $buyRecord = getXVal($buyRecordHash, $goodsMeta['goods_id']); $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_day_buy_times'] : 0; } - break; + break; case mt\HashRateShop::WEEKLY_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $goodsMeta['goods_id']); $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; } - break; + break; case mt\HashRateShop::TOTAL_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $goodsMeta['goods_id']); $goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0; } - break; + break; default: { } - break; + break; } $itemMeta = mt\Item::get($goodsMeta['item_id']); From 11527e542ee6d396c392fd1b8231ce95314a78a1 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 15:20:29 +0800 Subject: [PATCH 12/28] 1 --- webapp/services/HashRateShopService.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/webapp/services/HashRateShopService.php b/webapp/services/HashRateShopService.php index ef674115..58867521 100644 --- a/webapp/services/HashRateShopService.php +++ b/webapp/services/HashRateShopService.php @@ -47,12 +47,6 @@ class HashRateShopService { } break; } - - $itemMeta = mt\Item::get($goodsMeta['item_id']); - if ($itemMeta) { - } else if ($goodsMeta['goods_id'] != 9999){ - error_log('item not found:' . json_encode($goodsMeta)); - } } return $goodsList; } From 229550dde88745aa210034469bab6a05fac3522c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 15:26:43 +0800 Subject: [PATCH 13/28] 1 --- sql/gamedb.sql | 1 + sql/gamedb2006_migrate_241001_01.sql | 1 + 2 files changed, 2 insertions(+) diff --git a/sql/gamedb.sql b/sql/gamedb.sql index c312524e..76445206 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -2153,6 +2153,7 @@ CREATE TABLE `t_hashrate_shop_buy_record` ( `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 '本周购买次数', + `this_month_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 '创建时间', diff --git a/sql/gamedb2006_migrate_241001_01.sql b/sql/gamedb2006_migrate_241001_01.sql index 51a84ac9..9fffb4f0 100644 --- a/sql/gamedb2006_migrate_241001_01.sql +++ b/sql/gamedb2006_migrate_241001_01.sql @@ -21,6 +21,7 @@ CREATE TABLE `t_hashrate_shop_buy_record` ( `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 '本周购买次数', + `this_month_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 '创建时间', From 0e3499e748879db4b00809142ace1245cd8a6c27 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 15:35:07 +0800 Subject: [PATCH 14/28] 1 --- webapp/controller/BaseController.class.php | 10 ++++++++++ webapp/models/HashRateShopBuyRecord.php | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/webapp/controller/BaseController.class.php b/webapp/controller/BaseController.class.php index 387e07fd..ec521724 100644 --- a/webapp/controller/BaseController.class.php +++ b/webapp/controller/BaseController.class.php @@ -88,6 +88,16 @@ class BaseController { 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 _inTimeRangeStr($beginTimeStr, $endTimeStr) { $beginTimeOffset = myself()->_getDaySecondsOffset(strtotime("2024-6-22 ". $beginTimeStr)); diff --git a/webapp/models/HashRateShopBuyRecord.php b/webapp/models/HashRateShopBuyRecord.php index b7bbdacd..5e4ad9b0 100644 --- a/webapp/models/HashRateShopBuyRecord.php +++ b/webapp/models/HashRateShopBuyRecord.php @@ -74,6 +74,11 @@ class HashRateShopBuyRecord extends BaseModel $cond = " last_buy_time>=${mondaySeconds} AND last_buy_time<=${mondaySeconds} + 3600 * 24 * 7 "; return "CASE WHEN (${cond}) THEN this_week_buy_times + ${goodsNum} ELSE 0 END"; }, + 'this_month_buy_times' => function () use($goodsNum) { + $mondaySeconds = myself()->_getMondaySeconds(); + $cond = " last_buy_time>=${mondaySeconds} AND last_buy_time<=${mondaySeconds} + 3600 * 24 * 7 "; + return "CASE WHEN (${cond}) THEN this_month_buy_times + ${goodsNum} ELSE 0 END"; + }, 'total_buy_times' => function () use($goodsNum) { return 'total_buy_times + ${goodsNum}'; }, @@ -86,6 +91,7 @@ class HashRateShopBuyRecord extends BaseModel 'item_id' => $itemId, 'this_day_buy_times' => $goodsNum, 'this_week_buy_times' => $goodsNum, + 'this_month_buy_times' => $goodsNum, 'total_buy_times' => $goodsNum, 'last_buy_time' => myself()->_getNowTime(), 'createtime' => myself()->_getNowTime(), From a14072433cf3c5288e8f44f822daf87512c95167 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 15:38:40 +0800 Subject: [PATCH 15/28] 1 --- webapp/models/HashRateShopBuyRecord.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/webapp/models/HashRateShopBuyRecord.php b/webapp/models/HashRateShopBuyRecord.php index 5e4ad9b0..b37dcbdb 100644 --- a/webapp/models/HashRateShopBuyRecord.php +++ b/webapp/models/HashRateShopBuyRecord.php @@ -39,6 +39,10 @@ class HashRateShopBuyRecord extends BaseModel if (!($row['last_buy_time'] >= $mondaySeconds && $row['last_buy_time'] <= $mondaySeconds)) { $row['this_week_buy_times'] = 0; } + $monthFirstDaySeconds = myself()->_getMonthFirstDaySeconds(); + if (!($row['last_buy_time'] >= $monthFirstDaySeconds && $row['last_buy_time'] <= $monthFirstDaySeconds)) { + $row['this_month_buy_times'] = 0; + } return $row; }, $rows); } @@ -75,8 +79,8 @@ class HashRateShopBuyRecord extends BaseModel return "CASE WHEN (${cond}) THEN this_week_buy_times + ${goodsNum} ELSE 0 END"; }, 'this_month_buy_times' => function () use($goodsNum) { - $mondaySeconds = myself()->_getMondaySeconds(); - $cond = " last_buy_time>=${mondaySeconds} AND last_buy_time<=${mondaySeconds} + 3600 * 24 * 7 "; + $monthFirstDaySeconds = myself()->_getMonthFirstDaySeconds(); + $cond = " last_buy_time>=${monthFirstDaySeconds} AND last_buy_time<=${monthFirstDaySeconds} + 3600 * 24 * 7 "; return "CASE WHEN (${cond}) THEN this_month_buy_times + ${goodsNum} ELSE 0 END"; }, 'total_buy_times' => function () use($goodsNum) { From 830a7951683ba6de791634375c6e4e664fc0cb33 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 15:39:59 +0800 Subject: [PATCH 16/28] 1 --- webapp/services/HashRateShopService.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/webapp/services/HashRateShopService.php b/webapp/services/HashRateShopService.php index 58867521..94dfb32e 100644 --- a/webapp/services/HashRateShopService.php +++ b/webapp/services/HashRateShopService.php @@ -38,6 +38,11 @@ class HashRateShopService { $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; } break; + case mt\HashRateShop::MONTH_BUY_LIMIT: { + $buyRecord = getXVal($buyRecordHash, $goodsMeta['goods_id']); + $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; + } + break; case mt\HashRateShop::TOTAL_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $goodsMeta['goods_id']); $goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0; From c936760e31d989ce8218f3c819facd1ba9f874c4 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 15:57:40 +0800 Subject: [PATCH 17/28] 1 --- .../HashRateShopController.class.php | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/webapp/controller/HashRateShopController.class.php b/webapp/controller/HashRateShopController.class.php index bcc2a856..9a32f0da 100644 --- a/webapp/controller/HashRateShopController.class.php +++ b/webapp/controller/HashRateShopController.class.php @@ -1,7 +1,9 @@ _verifySwitch('hashrate.shop.buy'); + $goodsId = getReqVal('goods_id', 0); + $goodsNum = getReqVal('goods_num', 0); + if ($goodsNum < 1) { + myself()->_rspErr(1, "goods_num parameter error, goods_num: {$goodsNum}"); + return; + } + + $goodsMeta = mt\HashRateShop::find($goodsId); + if (!$goodsMeta) { + myself()->_rspErr(1, 'goods not found'); + return; + } + if ($goodsMeta['is_close']) { + myself()->_rspErr(1, 'no right to purchase'); + return; + } + if ($goodsNum > $goodsMeta['max_amount']) { + myself()->_rspErr(1, "goods_num parameter error, max_amount: {$goodsMeta['max_amount']}"); + return; + } + $itemMeta = mt\Item::get($goodsMeta['item_id']); + if (!$itemMeta) { + myself()->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']); + return; + } + $errCode = 0; + $errMsg = ''; + if (!ShopService::buyLimitCheck($goodsMeta, $errCode, $errMsg)) { + myself()->_rspErr($errCode, $errMsg); + return; + } + $propertyChgService = new services\PropertyChgService(); + $awardService = new services\AwardService(); + $tokenType = $goodsMeta['token_type']; + $price = $goodsMeta['price']; + if (!in_array( + $tokenType, + array( + mt\Shop::TOKEN_TYPE_GOLD, + mt\Shop::TOKEN_TYPE_DIAMOND + ) + )) { + myself()->_rspErr(1, "token_type is unsupport, {$tokenType}"); + return; + } + if ($price < 1) { + myself()->_rspErr(1, "config error"); + return; + } + $costItemId = myself()->getCostItemIdByTokenType($tokenType); + $costItems = array( + array( + 'item_id' => $costItemId, + 'item_num' => $goodsNum * $price + ) + ); + $lackItem = null; + if (!myself()->_hasEnoughItems($costItems, $lackItem)) { + myself()->_rspErr(2, myself()->_getLackItemErrMsg($lackItem)); + return; + } + ShopBuyRecord::add($goodsMeta['goods_id'], $goodsNum); + myself()->_decItems($costItems); + for ($i = 0; $i < $goodsNum; $i++) { + $this->internalAddItem($awardService, + $propertyChgService, + $itemMeta, + $goodsMeta['item_num'] + ); + } + $propertyChgService->addUserChg(); + $this->_rspData( + array( + 'award' => $awardService->toDto(), + 'property_chg' => $propertyChgService->toDto(), + ) + ); } } From 0a4b16c84e5ec64e763fe7ca76dfb9a697eed36f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 16:12:22 +0800 Subject: [PATCH 18/28] 1 --- doc/_common.py | 2 +- .../HashRateShopController.class.php | 7 ++--- webapp/services/HashRateShopService.php | 26 +++++++++++++------ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/doc/_common.py b/doc/_common.py index e1d3586f..c65f6a64 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -1943,6 +1943,6 @@ class HashRateGoods(object): ['item_id', 0, '道具id'], ['item_num', 0, '道具数量'], ['purchased_num', 0, '已购买数量'], - ['stock_num', 0, '库存数量(-1不限购)'], + ['max_num', 0, '最大数量(-1不限购)'], ['count_down', 0, '倒计时(单位秒,只有已售罄才有效)'], ] diff --git a/webapp/controller/HashRateShopController.class.php b/webapp/controller/HashRateShopController.class.php index 9a32f0da..1b09a9cc 100644 --- a/webapp/controller/HashRateShopController.class.php +++ b/webapp/controller/HashRateShopController.class.php @@ -2,6 +2,7 @@ require_once('services/HashRateShopService.php'); require_once('mt/HashRateShop.php'); +require_once('mt/Item.php'); use mt; use phpcommon\SqlHelper; @@ -40,10 +41,6 @@ class HashRateShop extends BaseAuthedController { myself()->_rspErr(1, 'no right to purchase'); return; } - if ($goodsNum > $goodsMeta['max_amount']) { - myself()->_rspErr(1, "goods_num parameter error, max_amount: {$goodsMeta['max_amount']}"); - return; - } $itemMeta = mt\Item::get($goodsMeta['item_id']); if (!$itemMeta) { myself()->_rspErr(1, 'goods not found, goods_id: ' . $goodsMeta['goods_id']); @@ -51,7 +48,7 @@ class HashRateShop extends BaseAuthedController { } $errCode = 0; $errMsg = ''; - if (!ShopService::buyLimitCheck($goodsMeta, $errCode, $errMsg)) { + if (!HashRateShopService::buyLimitCheck($goodsMeta, $goodsNum, $errCode, $errMsg)) { myself()->_rspErr($errCode, $errMsg); return; } diff --git a/webapp/services/HashRateShopService.php b/webapp/services/HashRateShopService.php index 94dfb32e..97fdf8bd 100644 --- a/webapp/services/HashRateShopService.php +++ b/webapp/services/HashRateShopService.php @@ -56,7 +56,7 @@ class HashRateShopService { return $goodsList; } - public static function buyLimitCheck($goodsMeta, &$errCode, &$errMsg) + public static function buyLimitCheck($goodsMeta, $goodsNum, &$errCode, &$errMsg) { $errCode = 0; $errMsg = ''; @@ -67,37 +67,47 @@ class HashRateShopService { switch ($goodsMeta['limit_type']) { case mt\HashRateShop::DAILY_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $goodsId); - $boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + 1 : 1; + $boughtTimes = $buyRecord ? $buyRecord['this_day_buy_times'] + $goodsNum : 1; if ($buyRecord && getXVal($buyRecord, 'this_day_buy_times', 0) >= $goodsMeta['limit_num']) { $errCode = 2; $errMsg = 'Daily purchase limit'; return false; } } - break; + break; case mt\HashRateShop::WEEKLY_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $goodsId); - $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + 1 : 1; + $boughtTimes = $buyRecord ? $buyRecord['this_week_buy_times'] + $goodsNum : 1; if ($buyRecord && getXVal($buyRecord, 'this_week_buy_times', 0) >= $goodsMeta['limit_num']) { $errCode = 2; $errMsg = 'Weekly purchase limit reached'; return false; } } - break; + break; + case mt\HashRateShop::MONTH_BUY_LIMIT: { + $buyRecord = getXVal($buyRecordHash, $goodsId); + $boughtTimes = $buyRecord ? $buyRecord['this_month_buy_times'] + $goodsNum : 1; + if ($buyRecord && getXVal($buyRecord, 'this_month_buy_times', 0) >= $goodsMeta['limit_num']) { + $errCode = 2; + $errMsg = 'month purchase limit reached'; + return false; + } + } + break; case mt\HashRateShop::TOTAL_BUY_LIMIT: { $buyRecord = getXVal($buyRecordHash, $goodsId); - $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1; + $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + $goodsNum : 1; if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $goodsMeta['limit_num']) { $errCode = 2; $errMsg = 'Purchase limit reached'; return false; } } - break; + break; default: { } - break; + break; } } return true; From 9b2b25c5919203f1b95a1f0d2a5e116c4de112be Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 16:13:39 +0800 Subject: [PATCH 19/28] 1 --- webapp/services/HashRateShopService.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webapp/services/HashRateShopService.php b/webapp/services/HashRateShopService.php index 97fdf8bd..beaf950a 100644 --- a/webapp/services/HashRateShopService.php +++ b/webapp/services/HashRateShopService.php @@ -58,6 +58,11 @@ class HashRateShopService { public static function buyLimitCheck($goodsMeta, $goodsNum, &$errCode, &$errMsg) { + if ($goodsMeta['is_close']) { + $errCode = 1; + $errMsg = 'cant buy'; + return; + } $errCode = 0; $errMsg = ''; $buyRecordHash = ShopBuyRecord::allToHash(); @@ -90,7 +95,7 @@ class HashRateShopService { $boughtTimes = $buyRecord ? $buyRecord['this_month_buy_times'] + $goodsNum : 1; if ($buyRecord && getXVal($buyRecord, 'this_month_buy_times', 0) >= $goodsMeta['limit_num']) { $errCode = 2; - $errMsg = 'month purchase limit reached'; + $errMsg = 'Month purchase limit reached'; return false; } } From 8db0c59e8242ddefb88fef29750153464b28ed00 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 16:17:34 +0800 Subject: [PATCH 20/28] 1 --- webapp/services/HashRateShopService.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/webapp/services/HashRateShopService.php b/webapp/services/HashRateShopService.php index beaf950a..d7aff194 100644 --- a/webapp/services/HashRateShopService.php +++ b/webapp/services/HashRateShopService.php @@ -2,18 +2,22 @@ namespace services; +require_once('models/HashRateShopBuyRecord.php'); + require_once('mt/HashRateShop.php'); require_once('mt/Item.php'); use mt; use phpcommon; +use models\HashRateShopBuyRecord; + class HashRateShopService { public static function getGoodsList() { $goodsMetaList = mt\HashRateShop::all(); - $buyRecordHash = ShopBuyRecord::allToHash(); + $buyRecordHash = HashRateShopBuyRecord::allToHash(); $goodsList = array(); foreach ($goodsMetaList as $goodsMeta) { @@ -65,7 +69,7 @@ class HashRateShopService { } $errCode = 0; $errMsg = ''; - $buyRecordHash = ShopBuyRecord::allToHash(); + $buyRecordHash = HashRateShopBuyRecord::allToHash(); $boughtTimes = 1; $goodsId = $goodsMeta['goods_id']; { From 14d1be9105bc68cc2a928e7b08828fa26d733f8d Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 16:33:30 +0800 Subject: [PATCH 21/28] 1 --- .../HashRateShopController.class.php | 14 +----------- webapp/models/HashRate.php | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/webapp/controller/HashRateShopController.class.php b/webapp/controller/HashRateShopController.class.php index 1b09a9cc..65d7ac7a 100644 --- a/webapp/controller/HashRateShopController.class.php +++ b/webapp/controller/HashRateShopController.class.php @@ -54,23 +54,11 @@ class HashRateShop extends BaseAuthedController { } $propertyChgService = new services\PropertyChgService(); $awardService = new services\AwardService(); - $tokenType = $goodsMeta['token_type']; - $price = $goodsMeta['price']; - if (!in_array( - $tokenType, - array( - mt\Shop::TOKEN_TYPE_GOLD, - mt\Shop::TOKEN_TYPE_DIAMOND - ) - )) { - myself()->_rspErr(1, "token_type is unsupport, {$tokenType}"); - return; - } + $price = $goodsMeta['pile_price']; if ($price < 1) { myself()->_rspErr(1, "config error"); return; } - $costItemId = myself()->getCostItemIdByTokenType($tokenType); $costItems = array( array( 'item_id' => $costItemId, diff --git a/webapp/models/HashRate.php b/webapp/models/HashRate.php index 77255af3..ca34c85b 100644 --- a/webapp/models/HashRate.php +++ b/webapp/models/HashRate.php @@ -109,6 +109,26 @@ class HashRate extends BaseModel return $myHashRate; } + public static function getMyCurrentHashRate(){ + $currentPeriod = myself()->_callMtStatic('AchievementsCycle', 'getCurrentPeriod'); + if (empty($currentPeriod)) { + return 0; + } + $row = SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_hash_rate_reward', + array( + 'account_id' => myself()->_getAccountId(), + 'period' => $currentPeriod['id'], + ) + ); + $myHashRate = 0; + if ($row){ + $myHashRate = $row['reward']; + } + return $myHashRate; + } + public static function getTotalByAccount($accountId,$period){ $row = SqlHelper::ormSelectOne( myself()->_getSelfMysql(), @@ -126,4 +146,4 @@ class HashRate extends BaseModel } -} \ No newline at end of file +} From c23b6265e2d3b86ff0d9e4e455005e574c886669 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 17:05:15 +0800 Subject: [PATCH 22/28] 1 --- webapp/controller/HashRateShopController.class.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/webapp/controller/HashRateShopController.class.php b/webapp/controller/HashRateShopController.class.php index 65d7ac7a..2df85d2b 100644 --- a/webapp/controller/HashRateShopController.class.php +++ b/webapp/controller/HashRateShopController.class.php @@ -3,6 +3,7 @@ require_once('services/HashRateShopService.php'); require_once('mt/HashRateShop.php'); require_once('mt/Item.php'); +require_once('model/HashRate.php'); use mt; use phpcommon\SqlHelper; @@ -59,18 +60,11 @@ class HashRateShop extends BaseAuthedController { myself()->_rspErr(1, "config error"); return; } - $costItems = array( - array( - 'item_id' => $costItemId, - 'item_num' => $goodsNum * $price - ) - ); - $lackItem = null; - if (!myself()->_hasEnoughItems($costItems, $lackItem)) { - myself()->_rspErr(2, myself()->_getLackItemErrMsg($lackItem)); + if ($price < model\HashRate::getMyCurrentHashRate) { + myself()->_rspErr(2, "hashrate not enough"); return; } - ShopBuyRecord::add($goodsMeta['goods_id'], $goodsNum); + HashRateShopBuyRecord::add($goodsMeta['goods_id'], $goodsNum); myself()->_decItems($costItems); for ($i = 0; $i < $goodsNum; $i++) { $this->internalAddItem($awardService, From afadd312c945c5daa8209169f08b468171c5de9c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 17:10:22 +0800 Subject: [PATCH 23/28] 1 --- webapp/controller/HashRateShopController.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/webapp/controller/HashRateShopController.class.php b/webapp/controller/HashRateShopController.class.php index 2df85d2b..dc8b3d37 100644 --- a/webapp/controller/HashRateShopController.class.php +++ b/webapp/controller/HashRateShopController.class.php @@ -3,14 +3,13 @@ require_once('services/HashRateShopService.php'); require_once('mt/HashRateShop.php'); require_once('mt/Item.php'); -require_once('model/HashRate.php'); +require_once('models/HashRate.php'); -use mt; use phpcommon\SqlHelper; use services\HashRateShopService; -class HashRateShop extends BaseAuthedController { +class HashRateShopController extends BaseAuthedController { public function getGoodsList() { From ab80faccc6614f9c9a97327eab08a425135ae816 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 17:15:56 +0800 Subject: [PATCH 24/28] 1 --- webapp/mt/HashRateShop.php | 2 +- webapp/services/HashRateShopService.php | 26 +++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/webapp/mt/HashRateShop.php b/webapp/mt/HashRateShop.php index e7cb3b7b..6a58edba 100644 --- a/webapp/mt/HashRateShop.php +++ b/webapp/mt/HashRateShop.php @@ -25,7 +25,7 @@ class HashRateShop { public static function all() { - return self::$metaList; + return self::getMetaList(); } protected static $metaList; diff --git a/webapp/services/HashRateShopService.php b/webapp/services/HashRateShopService.php index d7aff194..37ab82be 100644 --- a/webapp/services/HashRateShopService.php +++ b/webapp/services/HashRateShopService.php @@ -25,31 +25,33 @@ class HashRateShopService { continue; } $goodsDto = array( - 'goods_id' => $goodsMeta['goods_id'], - 'goods_meta' => self::goodsMetaToInfo($goodsMeta), - 'bought_times' => 0, - 'free_num' => 0, + 'goods_id' => $goodsMeta['id'], + 'item_id' => $goodsMeta['type'], + 'item_num' => $goodsMeta['item_num'], + 'purchased_num' => 0, + 'max_num' => 0, + 'count_down' => 0, ); array_push($goodsList, $goodsDto); switch ($goodsMeta['limit_type']) { case mt\HashRateShop::DAILY_BUY_LIMIT: { - $buyRecord = getXVal($buyRecordHash, $goodsMeta['goods_id']); - $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_day_buy_times'] : 0; + $buyRecord = getXVal($buyRecordHash, $goodsMeta['id']); + $goodsDto['purchased_num'] = $buyRecord ? $buyRecord['this_day_buy_times'] : 0; } break; case mt\HashRateShop::WEEKLY_BUY_LIMIT: { - $buyRecord = getXVal($buyRecordHash, $goodsMeta['goods_id']); - $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; + $buyRecord = getXVal($buyRecordHash, $goodsMeta['id']); + $goodsDto['purchased_num'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; } break; case mt\HashRateShop::MONTH_BUY_LIMIT: { - $buyRecord = getXVal($buyRecordHash, $goodsMeta['goods_id']); - $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; + $buyRecord = getXVal($buyRecordHash, $goodsMeta['id']); + $goodsDto['purchased_num'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; } break; case mt\HashRateShop::TOTAL_BUY_LIMIT: { - $buyRecord = getXVal($buyRecordHash, $goodsMeta['goods_id']); - $goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0; + $buyRecord = getXVal($buyRecordHash, $goodsMeta['id']); + $goodsDto['purchased_num'] = $buyRecord ? $buyRecord['total_buy_times'] : 0; } break; default: { From eb025631a798c7d44f60a7b1c559d145508284ef Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 17:17:14 +0800 Subject: [PATCH 25/28] 1 --- webapp/services/HashRateShopService.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webapp/services/HashRateShopService.php b/webapp/services/HashRateShopService.php index 37ab82be..55e8395b 100644 --- a/webapp/services/HashRateShopService.php +++ b/webapp/services/HashRateShopService.php @@ -26,10 +26,11 @@ class HashRateShopService { } $goodsDto = array( 'goods_id' => $goodsMeta['id'], + 'price' => $goodsMeta['pile_price'], 'item_id' => $goodsMeta['type'], 'item_num' => $goodsMeta['item_num'], 'purchased_num' => 0, - 'max_num' => 0, + 'max_num' => $goodsMeta['limit_num'], 'count_down' => 0, ); array_push($goodsList, $goodsDto); From 780b765c2ae205eb991d3d36776081e45646b02e Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 19:10:48 +0800 Subject: [PATCH 26/28] 1 --- webapp/models/HashRate.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/webapp/models/HashRate.php b/webapp/models/HashRate.php index ca34c85b..61acb1dc 100644 --- a/webapp/models/HashRate.php +++ b/webapp/models/HashRate.php @@ -129,6 +129,24 @@ class HashRate extends BaseModel return $myHashRate; } + public static function decMyCurrentHashRate($val){ + $val = intval($val); + $currentPeriod = myself()->_callMtStatic('AchievementsCycle', 'getCurrentPeriod'); + if ($currentPeriod) { + SqlHelper::update( + myself()->_getSelfMysql(), + 't_hash_rate_reward', + array( + 'account_id' => myself()->_getAccountId(), + 'period' => $currentPeriod['id'], + 'reward' => function () use($val) { + return "GREATEST(0, reward - ${val})"; + }, + ) + ); + } + } + public static function getTotalByAccount($accountId,$period){ $row = SqlHelper::ormSelectOne( myself()->_getSelfMysql(), From 0caa884a24741dba872af0554bff481f1b52ca00 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 19:27:41 +0800 Subject: [PATCH 27/28] 1 --- webapp/controller/HashRateShopController.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/webapp/controller/HashRateShopController.class.php b/webapp/controller/HashRateShopController.class.php index dc8b3d37..a82ea703 100644 --- a/webapp/controller/HashRateShopController.class.php +++ b/webapp/controller/HashRateShopController.class.php @@ -25,7 +25,7 @@ class HashRateShopController extends BaseAuthedController { { myself()->_verifySwitch('hashrate.shop.buy'); $goodsId = getReqVal('goods_id', 0); - $goodsNum = getReqVal('goods_num', 0); + $goodsNum = intval(getReqVal('goods_num', 0)); if ($goodsNum < 1) { myself()->_rspErr(1, "goods_num parameter error, goods_num: {$goodsNum}"); @@ -59,12 +59,12 @@ class HashRateShopController extends BaseAuthedController { myself()->_rspErr(1, "config error"); return; } - if ($price < model\HashRate::getMyCurrentHashRate) { + if ($price * $goodsNum < model\HashRate::getMyCurrentHashRate()) { myself()->_rspErr(2, "hashrate not enough"); return; } - HashRateShopBuyRecord::add($goodsMeta['goods_id'], $goodsNum); - myself()->_decItems($costItems); + model\HashRate::decMyCurrentHashRate($price * $goodsNum); + HashRateShopBuyRecord::add($goodsMeta['goods_id'], $goodsNum, $goodsMeta['type']); for ($i = 0; $i < $goodsNum; $i++) { $this->internalAddItem($awardService, $propertyChgService, From eb36e338223bd8d44b419a62600c004fe2590764 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 19:32:25 +0800 Subject: [PATCH 28/28] 1 --- .../controller/HashRateShopController.class.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/webapp/controller/HashRateShopController.class.php b/webapp/controller/HashRateShopController.class.php index a82ea703..5fdb4d98 100644 --- a/webapp/controller/HashRateShopController.class.php +++ b/webapp/controller/HashRateShopController.class.php @@ -21,9 +21,23 @@ class HashRateShopController extends BaseAuthedController { ); } + public function testBuyGoods() + { + if (SERVER_ENV != _ONLINE) { + $this->internalBuyGoods(); + } + } + public function buyGoodsS() { - myself()->_verifySwitch('hashrate.shop.buy'); + $this->internalBuyGoods(); + } + + public function internalBuyGoods() + { + if (SERVER_ENV == _ONLINE) { + myself()->_verifySwitch('hashrate.shop.buy'); + } $goodsId = getReqVal('goods_id', 0); $goodsNum = intval(getReqVal('goods_num', 0));