|
|
@@ -6,9 +6,11 @@ use App\Module\AppGame\Handler\BaseHandler;
|
|
|
use App\Module\Shop\Services\ShopService;
|
|
|
use Google\Protobuf\Internal\Message;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
-use Uraus\Kku\Common\DataShopCategory;
|
|
|
-use Uraus\Kku\Common\DataShopItem;
|
|
|
-use Uraus\Kku\Common\LastData;
|
|
|
+use Uraus\Kku\Response\ShopGoodItem;
|
|
|
+use Uraus\Kku\Common\Deduct;
|
|
|
+use Uraus\Kku\Common\DeductCoin;
|
|
|
+use Uraus\Kku\Common\Reward;
|
|
|
+use Uraus\Kku\Common\RewardItem;
|
|
|
use Uraus\Kku\Request\RequestShopQuery;
|
|
|
use Uraus\Kku\Response\ResponseShopQuery;
|
|
|
use UCore\Exception\LogicException;
|
|
|
@@ -37,91 +39,70 @@ class QueryHandler extends BaseHandler
|
|
|
|
|
|
try {
|
|
|
// 获取请求参数
|
|
|
- $categoryId = $data->getCategoryId() ?? 0;
|
|
|
- $promotionId = $data->getPromotionId() ?? 0;
|
|
|
- $onlyPromotion = $data->getOnlyPromotion() ?? false;
|
|
|
+ $times = $data->getTimes();
|
|
|
$userId = $this->user_id;
|
|
|
|
|
|
- // 构建过滤条件
|
|
|
- $filters = [];
|
|
|
- if ($categoryId > 0) {
|
|
|
- $filters['category_id'] = $categoryId;
|
|
|
- }
|
|
|
-
|
|
|
- if ($promotionId > 0) {
|
|
|
- $filters['promotion_id'] = $promotionId;
|
|
|
- }
|
|
|
-
|
|
|
- if ($onlyPromotion) {
|
|
|
- $filters['only_promotion'] = true;
|
|
|
- }
|
|
|
-
|
|
|
- // 获取商店商品列表
|
|
|
- $shopItems = ShopService::getShopItems($filters);
|
|
|
+ // 获取商店商品列表(传入用户ID以获取购买数量)
|
|
|
+ $shopItemDtos = ShopService::getShopItems([], $userId);
|
|
|
|
|
|
- // 获取商店分类列表
|
|
|
- $shopCategories = ShopService::getShopCategories();
|
|
|
-
|
|
|
- // 创建LastData对象,用于返回商店信息
|
|
|
- $lastData = new LastData();
|
|
|
-
|
|
|
- // 添加商品数据
|
|
|
+ // 创建商品列表
|
|
|
$itemList = [];
|
|
|
- foreach ($shopItems as $shopItem) {
|
|
|
- $dataItem = new DataShopItem();
|
|
|
- $dataItem->setId($shopItem->id);
|
|
|
- $dataItem->setName($shopItem->name);
|
|
|
- $dataItem->setDescription($shopItem->description);
|
|
|
- $dataItem->setCategoryId($shopItem->category_id);
|
|
|
- $dataItem->setItemId($shopItem->item_id);
|
|
|
- $dataItem->setItemQuantity($shopItem->item_quantity);
|
|
|
- $dataItem->setPrice($shopItem->price);
|
|
|
- $dataItem->setCurrencyId($shopItem->currency_id);
|
|
|
- $dataItem->setMaxBuy($shopItem->max_buy);
|
|
|
- $dataItem->setImage($shopItem->image);
|
|
|
-
|
|
|
- // 设置折扣价格信息
|
|
|
- $dataItem->setOriginalPrice($shopItem->original_price ?? $shopItem->price);
|
|
|
- $dataItem->setDiscountedPrice($shopItem->discounted_price ?? $shopItem->price);
|
|
|
- $dataItem->setHasDiscount($shopItem->has_discount ?? false);
|
|
|
- $dataItem->setDiscountPercentage($shopItem->discount_percentage ?? 0);
|
|
|
-
|
|
|
- // 如果有促销活动,设置促销信息
|
|
|
- $promotion = $shopItem->getActivePromotion();
|
|
|
- if ($promotion) {
|
|
|
- $dataItem->setPromotionId($promotion->id);
|
|
|
- $dataItem->setPromotionName($promotion->name);
|
|
|
- $dataItem->setPromotionEndTime($promotion->end_time ? $promotion->end_time->timestamp : 0);
|
|
|
+ foreach ($shopItemDtos as $shopItemDto) {
|
|
|
+ $goodItem = new ShopGoodItem();
|
|
|
+ $goodItem->setId($shopItemDto->id);
|
|
|
+
|
|
|
+ // 设置分类名称
|
|
|
+ $categoryName = $shopItemDto->categoryName ?? '未分类';
|
|
|
+ $goodItem->setCategory($categoryName);
|
|
|
+
|
|
|
+ // 设置消耗组信息(作为价格)
|
|
|
+ if ($shopItemDto->consumeGroupId) {
|
|
|
+ $deduct = new Deduct();
|
|
|
+ // TODO: 这里需要根据消耗组的具体内容来设置Deduct对象
|
|
|
+ // 暂时创建一个空的Deduct对象,实际需要解析消耗组的内容
|
|
|
+ $deductCoins = [];
|
|
|
+ $deductItems = [];
|
|
|
+
|
|
|
+ // 暂时添加一个占位符代币扣除
|
|
|
+ $deductCoin = new DeductCoin();
|
|
|
+ $deductCoin->setType(1); // 假设类型1表示金币
|
|
|
+ $deductCoin->setQuantity(100); // 假设价格100金币
|
|
|
+ $deductCoins[] = $deductCoin;
|
|
|
+
|
|
|
+ $deduct->setCoins($deductCoins);
|
|
|
+ $deduct->setItems($deductItems);
|
|
|
+ $goodItem->setCoin($deduct);
|
|
|
}
|
|
|
|
|
|
- // 如果有购买限制,获取用户已购买数量
|
|
|
- if ($shopItem->max_buy > 0) {
|
|
|
- $boughtCount = $shopItem->getUserBoughtCount($userId);
|
|
|
- $dataItem->setBoughtCount($boughtCount);
|
|
|
+ // 设置奖励组信息(作为商品)
|
|
|
+ if ($shopItemDto->rewardGroupId) {
|
|
|
+ // TODO: 这里需要根据奖励组的具体内容来创建Reward对象
|
|
|
+ // 暂时创建一个占位符,实际需要解析奖励组的内容
|
|
|
+ $reward = new Reward();
|
|
|
+ $rewardCoins = [];
|
|
|
+ $rewardItems = [];
|
|
|
+
|
|
|
+ // 暂时添加一个占位符物品奖励
|
|
|
+ $rewardItem = new RewardItem();
|
|
|
+ $rewardItem->setItemId(1); // 假设物品ID为1
|
|
|
+ $rewardItem->setInstanceId(0); // 实例ID为0
|
|
|
+ $rewardItem->setQuantity(1); // 数量为1
|
|
|
+ $rewardItems[] = $rewardItem;
|
|
|
+
|
|
|
+ $reward->setCoins($rewardCoins);
|
|
|
+ $reward->setItems($rewardItems);
|
|
|
+ $reward->setGods([]);
|
|
|
+ $reward->setLands([]);
|
|
|
+
|
|
|
+ // 设置单个Reward对象,而不是数组
|
|
|
+ $goodItem->setItem($reward);
|
|
|
}
|
|
|
|
|
|
- $itemList[] = $dataItem;
|
|
|
+ $itemList[] = $goodItem;
|
|
|
}
|
|
|
|
|
|
- // 添加分类数据
|
|
|
- $categoryList = [];
|
|
|
- foreach ($shopCategories as $category) {
|
|
|
- $dataCategory = new DataShopCategory();
|
|
|
- $dataCategory->setId($category->id);
|
|
|
- $dataCategory->setName($category->name);
|
|
|
- $dataCategory->setCode($category->code);
|
|
|
- $dataCategory->setIcon($category->icon);
|
|
|
- $dataCategory->setParentId($category->parent_id);
|
|
|
-
|
|
|
- $categoryList[] = $dataCategory;
|
|
|
- }
|
|
|
-
|
|
|
- // 设置商品列表和分类列表到LastData
|
|
|
- $lastData->setShopItems($itemList);
|
|
|
- $lastData->setShopCategories($categoryList);
|
|
|
-
|
|
|
- // 设置LastData到响应
|
|
|
- $this->response->setLastData($lastData);
|
|
|
+ // 设置商品列表到响应
|
|
|
+ $response->setItems($itemList);
|
|
|
|
|
|
// 设置响应状态
|
|
|
$this->response->setCode(0);
|
|
|
@@ -130,9 +111,8 @@ class QueryHandler extends BaseHandler
|
|
|
// 记录日志
|
|
|
Log::info('用户查询商店成功', [
|
|
|
'user_id' => $userId,
|
|
|
- 'category_id' => $categoryId,
|
|
|
- 'item_count' => count($itemList),
|
|
|
- 'category_count' => count($categoryList)
|
|
|
+ 'times' => $times,
|
|
|
+ 'item_count' => count($itemList)
|
|
|
]);
|
|
|
|
|
|
} catch (LogicException $e) {
|