diff --git a/third_party/phpcommon b/third_party/phpcommon index 6efb9d7..3fc9e3c 160000 --- a/third_party/phpcommon +++ b/third_party/phpcommon @@ -1 +1 @@ -Subproject commit 6efb9d7831e4e69a2f7e7b75ce44ccfb13b9b685 +Subproject commit 3fc9e3c7657803eed51f7c2ee34af6185855409b diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index b1f26dd..1591987 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -8,11 +8,13 @@ require_once('mt/Parameter.php'); require_once('mt/Drop.php'); require_once('models/Hero.php'); +require_once('models/ShopBuyRecord.php'); require_once('services/AwardService.php'); use phpcommon\SqlHelper; use models\Hero; +use models\ShopBuyRecord; class ShopController extends BaseAuthedController { @@ -29,10 +31,51 @@ class ShopController extends BaseAuthedController { )); return; } + $buyRecordHash = ShopBuyRecord::allToHash(); $goodsDtoList1 = array(); $goodsDtoList2 = array(); foreach ($goodsList as $goods) { - + $itemMeta = mt\Item::get($goods['goods_id']); + if ($itemMeta) { + $goodsDto = array( + 'goods_id' => $goods['goods_id'], + 'item_id' => $itemMeta['id'], + 'price_info' => null, + 'flag_icon' => $goods['tag'], + 'limit_type' => $itemMeta['limit_type'], + 'bought_times' => 0, + 'total_buy_times' => $itemMeta['limit_num'], + ); + switch ($itemMeta['limit_type']) { + case mt\Item::DAILY_BUY_LIMIT: + { + $buyRecord = getXVal($buyRecordHash, $itemMeta['id']); + $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_day_buy_times'] : 0; + } + break; + case mt\Item::WEEKLY_BUY_LIMIT: + { + $buyRecord = getXVal($buyRecordHash, $itemMeta['id']); + $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; + } + break; + case mt\Item::TOTAL_BUY_LIMIT: + { + $buyRecord = getXVal($buyRecordHash, $itemMeta['id']); + $goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0; + } + break; + default: + { + } + break; + } + $priceInfo = mt\Item::getPriceInfo($itemMeta); + if (!empty($priceInfo)) { + $goodsDto['price_info'] = $priceInfo; + array_push($goodsDtoList1, $goodsDto); + } + } } $this->_rspData(array( 'info' => array( diff --git a/webapp/models/ShopBuyRecord.php b/webapp/models/ShopBuyRecord.php index c18a9e5..1ebbd7d 100644 --- a/webapp/models/ShopBuyRecord.php +++ b/webapp/models/ShopBuyRecord.php @@ -29,7 +29,7 @@ class ShopBuyRecord extends BaseModel { 'account_id' => myself()->_getAccountId(), ) ); - return array_map($rows, function($val) { + return array_map(function($val) { $nowDaySeconds = myself()->_getNowDaySeconds(); if (!($row['last_buy_time'] >= $nowDaySeconds && $row['last_buy_time'] <= $nowDaySeconds)) { $val['this_day_buy_times'] = 0; @@ -39,7 +39,17 @@ class ShopBuyRecord extends BaseModel { $val['this_week_buy_times'] = 0; } return $val; + }, $rows); + } + + public static function allToHash() + { + $rows = self::all(); + $buyRecordHash = array(); + array_walk($rows, function ($val) use(&$buyRecordHash) { + $buyRecordHash[$val['item_id']] = $val; }); + return $buyRecordHash; } public static function toDto($row) diff --git a/webapp/mt/Item.php b/webapp/mt/Item.php index 1f24ee8..2a55f96 100644 --- a/webapp/mt/Item.php +++ b/webapp/mt/Item.php @@ -53,6 +53,10 @@ class Item { const GUILD_RENAME_CARD_TYPE = 20; const HERO_EXP_TYPE = 21; + const DAILY_BUY_LIMIT = 1; + const WEEKLY_BUY_LIMIT = 2; + const TOTAL_BUY_LIMIT = 3; + public static function get($id) { return getXVal(self::getMetaList(), $id, null); diff --git a/webapp/mt/ShopGoods.php b/webapp/mt/ShopGoods.php index 043bb93..9de02e4 100644 --- a/webapp/mt/ShopGoods.php +++ b/webapp/mt/ShopGoods.php @@ -42,8 +42,8 @@ class ShopGoods { 'goodsHash' => array() ); } - self::$shopGoodsHash['shop_id']['goodsHash'][$meta['goods_id']] = $meta; - array_push(self::$shopGoodsHash['shop_id']['goodsList'], $meta); + self::$shopGoodsHash[$meta['shop_id']]['goodsHash'][$meta['goods_id']] = $meta; + array_push(self::$shopGoodsHash[$meta['shop_id']]['goodsList'], $meta); } } }