From 76e1076f45ea90c68cf2a18181c6185efd6801b3 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 28 Jul 2023 19:24:34 +0800 Subject: [PATCH] 1 --- webapp/controller/ShopController.class.php | 59 ++++++++++++---------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/webapp/controller/ShopController.class.php b/webapp/controller/ShopController.class.php index 28232d02..a9906dde 100644 --- a/webapp/controller/ShopController.class.php +++ b/webapp/controller/ShopController.class.php @@ -90,30 +90,36 @@ class ShopController extends BaseAuthedController { $shop_id = getReqVal('shop_id', 0); if ($shop_id == 0) { - $goodsList = mt\ShopGoods::all(); + $goodsMetaList = mt\ShopGoods::all(); } else { - $goodsList = mt\ShopGoods::getGoodsList($shop_id); + $goodsMetaList = mt\ShopGoods::getGoodsList($shop_id); } - $goodsList = $goodsList ? $goodsList : array(); + $goodsMetaList = $goodsMetaList ? $goodsMetaList : array(); $buyRecordHash = ShopBuyRecord::allToHash(); - foreach ($goodsList as &$goods) { - $goods['bought_times'] = 0; - switch ($goods['limit_type']) { + $goodsList = array(); + foreach ($goodsMetaList as $goodsMeta) { + $goodsDto = array( + 'goods_meta' => $this->goodsMetaToInfo($goodsMeta), + 'bought_times' => 0, + 'free_num' => 0, + ); + array_push($goodsList, $goodsDto); + switch ($goodsMeta['limit_type']) { case mt\Item::DAILY_BUY_LIMIT: { - $buyRecord = getXVal($buyRecordHash, $goods['id']); - $goods['bought_times'] = $buyRecord ? $buyRecord['this_day_buy_times'] : 0; + $buyRecord = getXVal($buyRecordHash, $goodsMeta['id']); + $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_day_buy_times'] : 0; } break; case mt\Item::WEEKLY_BUY_LIMIT: { - $buyRecord = getXVal($buyRecordHash, $goods['id']); - $goods['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; + $buyRecord = getXVal($buyRecordHash, $goodsMeta['id']); + $goodsDto['bought_times'] = $buyRecord ? $buyRecord['this_week_buy_times'] : 0; } break; case mt\Item::TOTAL_BUY_LIMIT: { - $buyRecord = getXVal($buyRecordHash, $goods['id']); - $goods['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0; + $buyRecord = getXVal($buyRecordHash, $goodsMeta['id']); + $goodsDto['bought_times'] = $buyRecord ? $buyRecord['total_buy_times'] : 0; } break; default: { @@ -121,8 +127,8 @@ class ShopController extends BaseAuthedController break; } - $goods_id = $goods['goods_id']; - $itemMeta = mt\Item::get($goods_id); + $goodsId = $goodsMeta['goods_id']; + $itemMeta = mt\Item::get($goodsId); if ($itemMeta) { // 如果是皮肤,判断是否已经拥有,如果已经拥有,不能购买 if ($itemMeta['type'] == mt\Item::HERO_SKIN_TYPE) { @@ -136,23 +142,16 @@ class ShopController extends BaseAuthedController } } else { // error !!!!!! - error_log('item not found:' . $goods_id); + error_log('item not found:' . $goodsId); } - if (empty($goods['goods_num'])) { - $goods['goods_num'] = 1; - } if (!empty($goods['free_type'])) { - $count = $this->countFreeBuyTimes($goods['free_type'], $goods['id'], $goods['goods_id']); + $count = $this->countFreeBuyTimes($goodsMeta['free_type'], + $goodsMeta['id'], + $goodsMeta['goods_id']); $goods['free_num'] = $goods['free_num'] - $count; // error_log('free_num:' . $goods['free_num']); } - - $address = $this->_getAddress(); - if ($address) { - // $goods['pending'] = $this->checkPendingBuyGoodsNormal($address, $goods['goods_id'], $goods['shop_id'], $goods['id']); - $goods['pending'] = 0; - } } $this->_rspData( @@ -905,9 +904,7 @@ class ShopController extends BaseAuthedController private function countFreeBuyTimes($free_type, $id, $goods_id) { - $conn = myself()->_getMysql(''); - $account = myself()->_getAccountId(); - + return 0; switch ($free_type) { case 1: { $dayTime = myself()->_getNowDaySeconds(); @@ -948,4 +945,10 @@ class ShopController extends BaseAuthedController } } + private function goodsMetaToInfo($goodsMeta) { + return array( + + ); + } + }