From 56af030651ecad6ffe3f6eb9c2fcb31db745e520 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 11:45:51 +0800 Subject: [PATCH 1/3] 1 --- .../HashRateShopController.class.php | 26 +++ webapp/services/HashRateShopService.php | 157 ++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 webapp/controller/HashRateShopController.class.php create mode 100644 webapp/services/HashRateShopService.php diff --git a/webapp/controller/HashRateShopController.class.php b/webapp/controller/HashRateShopController.class.php new file mode 100644 index 00000000..bcc2a856 --- /dev/null +++ b/webapp/controller/HashRateShopController.class.php @@ -0,0 +1,26 @@ +_rspData( + array( + 'goods_list' => $goodsList, + ) + ); + } + + public function buyGoodsS() + { + + } + +} diff --git a/webapp/services/HashRateShopService.php b/webapp/services/HashRateShopService.php new file mode 100644 index 00000000..5dbf6a14 --- /dev/null +++ b/webapp/services/HashRateShopService.php @@ -0,0 +1,157 @@ + $goodsMeta['goods_id'], + 'goods_meta' => self::goodsMetaToInfo($goodsMeta), + 'bought_times' => 0, + 'free_num' => 0, + ); + array_push($goodsList, $goodsDto); + switch ($goodsMeta['limit_type']) { + case mt\Shop::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: { + $buyRecord = getXVal($buyRecordHash, $goodsMeta['goods_id']); + $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; + } + break; + case mt\Shop::TOTAL_BUY_LIMIT: { + $buyRecord = getXVal($buyRecordHash, $goodsMeta['goods_id']); + $goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0; + } + break; + default: { + } + break; + } + + $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)); + } + } + return $goodsList; + } + + public static function buyLimitCheck($goodsMeta, &$errCode, &$errMsg) + { + $errCode = 0; + $errMsg = ''; + $buyRecordHash = ShopBuyRecord::allToHash(); + $boughtTimes = 1; + $goodsId = $goodsMeta['goods_id']; + { + switch ($goodsMeta['limit_type']) { + case mt\Shop::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']) { + $errCode = 2; + $errMsg = 'Daily purchase limit'; + return false; + } + } + break; + case mt\Shop::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']) { + $errCode = 2; + $errMsg = 'Weekly purchase limit reached'; + return false; + } + } + break; + case mt\Shop::TOTAL_BUY_LIMIT: { + // error_log("total buy limit " . $address . " " . $goodsId . " " . $goodsMeta['limit_num']); + $buyRecord = getXVal($buyRecordHash, $goodsId); + $boughtTimes = $buyRecord ? $buyRecord['total_buy_times'] + 1 : 1; + if ($buyRecord && getXVal($buyRecord, 'total_buy_times', 0) >= $goodsMeta['limit_num']) { + $errCode = 2; + $errMsg = 'Purchase limit reached'; + return false; + } + } + break; + default: { + } + break; + } + } + 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 ac5ac6fbf12197142e092969ae1b7361830cc226 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 10 Oct 2024 14:12:29 +0800 Subject: [PATCH 2/3] 1 --- webapp/mt/HashRateShop.php | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 webapp/mt/HashRateShop.php diff --git a/webapp/mt/HashRateShop.php b/webapp/mt/HashRateShop.php new file mode 100644 index 00000000..554934bf --- /dev/null +++ b/webapp/mt/HashRateShop.php @@ -0,0 +1,39 @@ + Date: Thu, 10 Oct 2024 14:13:18 +0800 Subject: [PATCH 3/3] 1 --- webapp/mt/HashRateShop.php | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/webapp/mt/HashRateShop.php b/webapp/mt/HashRateShop.php index 554934bf..6542405c 100644 --- a/webapp/mt/HashRateShop.php +++ b/webapp/mt/HashRateShop.php @@ -10,10 +10,6 @@ class HashRateShop { return getXVal(self::getMetaList(), $id, null); } - public static function findHash($itemId){ - return getXVal(self::getHashMetaList(), $itemId, null); - } - protected static function getMetaList() { if (!self::$metaList) { @@ -22,18 +18,6 @@ class HashRateShop { return self::$metaList; } - protected static function getHashMetaList() - { - if (!self::$hashMetaList) { - self::$hashMetaList = array(); - foreach (self::getMetaList() as $meta) { - self::$hashMetaList[$meta['item_id']] = $meta; - } - } - return self::$hashMetaList; - } - protected static $metaList; - protected static $hashMetaList; }