|
@@ -16,10 +16,6 @@
|
|
|
#include "IAPCtlShopUI.hpp"
|
|
|
#include "IAPUserData.hpp"
|
|
|
|
|
|
-#include <algorithm>
|
|
|
-#include <string>
|
|
|
-#include <regex>
|
|
|
-
|
|
|
NS_IAP_BEGIN
|
|
|
|
|
|
IAPCtlShop* IAPCtlShop::_instance = nullptr;
|
|
@@ -60,22 +56,21 @@ bool IAPCtlShop::addAPlacement(const IAPPlacement &plInfo){
|
|
|
bool ans = false;
|
|
|
|
|
|
|
|
|
- if(ans)placementIDs.insert(plInfo.id);
|
|
|
+ if(ans)_placements[plInfo.id] = plInfo;
|
|
|
return ans;
|
|
|
}
|
|
|
|
|
|
void IAPCtlShop::removePlacement(const std::string &id){
|
|
|
-
|
|
|
- placementIDs.erase(id);
|
|
|
+ _placements.erase(id);
|
|
|
}
|
|
|
|
|
|
size_t IAPCtlShop::getPlacementCount(){
|
|
|
- return placementIDs.size();
|
|
|
+ return _placements.size();
|
|
|
}
|
|
|
|
|
|
void IAPCtlShop::showInNode(cocos2d::Node *pParent, ShopRequirement &requirement){
|
|
|
_shopUI = IAPCtlShopUI::getInstance();
|
|
|
- _shopUI->create(pParent, _conf, requirement,1);
|
|
|
+ _shopUI->create(pParent, _conf, requirement);
|
|
|
}
|
|
|
|
|
|
void IAPCtlShop::showPlacementsInNode(cocos2d::Node *pParent, const vector<std::string> &plIds){
|
|
@@ -91,44 +86,23 @@ UserBuyType IAPCtlShop::getUserBuyType(){
|
|
|
vector<GoodsInfo> goodInfos;
|
|
|
conf->getAllGoods(goodInfos);
|
|
|
|
|
|
- struct SortVec{
|
|
|
- std::string id;
|
|
|
- std::string price;
|
|
|
- bool isSpecial;
|
|
|
- };
|
|
|
- vector<SortVec> vec;
|
|
|
-
|
|
|
- std::regex re(R"(\d+(\.\d{1,2})?)"); // 匹配整数或最多两位小数的数字
|
|
|
- for(const auto& goodInfo : goodInfos){
|
|
|
- bool isSpecial = goodInfo.style == "mostValued" ? true : false;
|
|
|
- std::smatch match;
|
|
|
- if (std::regex_search(goodInfo.cost, match, re)) {
|
|
|
- SortVec sv;
|
|
|
- sv.id = goodInfo.id;
|
|
|
- sv.price = match[0]; // 提取价格
|
|
|
- sv.isSpecial = isSpecial;
|
|
|
- vec.push_back(sv);
|
|
|
- } else {
|
|
|
- log("IAPUserData::getUserBuyType : 转换失败");
|
|
|
- }
|
|
|
- }
|
|
|
// 按照价格排序 , 价格相同按照是否为special商品排序
|
|
|
- sort(vec.begin(), vec.end(), [](SortVec a,SortVec b){
|
|
|
- if(a.price != b.price) return stof(a.price) < stof(b.price);
|
|
|
- if(a.isSpecial)return true;
|
|
|
- if(b.isSpecial)return false;
|
|
|
+ sort(goodInfos.begin(), goodInfos.end(), [](GoodsInfo a,GoodsInfo b){
|
|
|
+ if(a.getCostNumber() != b.getCostNumber()) return a.getCostNumber() < b.getCostNumber();
|
|
|
+ if(a.style == "mostValued")return true;
|
|
|
+ if(b.style == "mostValued")return false;
|
|
|
return true;
|
|
|
});
|
|
|
|
|
|
- bool onlySpecial = true;
|
|
|
- bool isBuyExpensive = false;
|
|
|
+ bool onlySpecial = true; // 是否仅购买特惠商品
|
|
|
+ bool isBuyExpensive = false; // 是否购买过最贵商品
|
|
|
float maxAmount = getMaxAmount();
|
|
|
for(const auto& buyInfo : buyInfos){
|
|
|
|
|
|
- for(size_t i = 0; i < vec.size(); i++){
|
|
|
- if(buyInfo != vec[i].id)continue;
|
|
|
- if(!vec[i].isSpecial) onlySpecial = false;
|
|
|
- if(stof(vec[i].price) == maxAmount) isBuyExpensive = true;
|
|
|
+ for(size_t i = 0; i < goodInfos.size(); i++){
|
|
|
+ if(buyInfo != goodInfos[i].id)continue;
|
|
|
+ if(goodInfos[i].type != "mostValued") onlySpecial = false;
|
|
|
+ if(goodInfos[i].getCostNumber() == maxAmount) isBuyExpensive = true;
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -161,14 +135,8 @@ float IAPCtlShop::getMaxAmount(){
|
|
|
vector<GoodsInfo> goodInfos;
|
|
|
conf->getAllGoods(goodInfos);
|
|
|
|
|
|
- std::regex re(R"(\d+(\.\d{1,2})?)"); // 匹配整数或最多两位小数的数字
|
|
|
for(const auto& goodInfo : goodInfos){
|
|
|
- std::smatch match;
|
|
|
- if (std::regex_search(goodInfo.cost, match, re)) {
|
|
|
- maxn = std::max(maxn, stof(match[0])); // 提取价格
|
|
|
- } else {
|
|
|
- log("IAPUserData::getUserBuyType : 转换失败");
|
|
|
- }
|
|
|
+ maxn = std::max(maxn, goodInfo.getCostNumber());
|
|
|
}
|
|
|
|
|
|
return maxn;
|