Browse Source

external buy service

master
gsd 11 months ago
parent
commit
5b4b06dcc7
  1. 118
      src/main/java/app/controllers/user/ProfileController.java
  2. 48
      src/main/java/app/entities/VipGiveMethod.java
  3. 18
      src/main/java/app/entities/VipPrice.java
  4. 10
      src/main/java/app/services/db/VIPService.java

118
src/main/java/app/controllers/user/ProfileController.java

@ -3,7 +3,10 @@ package app.controllers.user;
import app.annotations.enums.AuthMethod;
import app.annotations.enums.CollectStages;
import app.annotations.interfaces.*;
import app.controllers.other.ExternalVIPController;
import app.entities.SocialAuth;
import app.entities.VipGiveMethod;
import app.entities.VipPrice;
import app.services.ProfileService;
import app.services.ReportService;
import app.services.db.FreeVIPService;
@ -16,6 +19,9 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
@RestController
@RequestMapping("api/profile/current")
public class ProfileController {
@ -23,12 +29,12 @@ public class ProfileController {
private final FreeVIPService freeVIPService;
private final ReportService reportService;
private final VIPService vipService;
private final ExternalVIPController externalVIPController;
@Value("${backend.vip.buy.steam}")
private String STEAM_TRADE;
@Value("${backend.vip.buy.qiwi}")
private String QIWI_LINK;
@Value("${backend.vip.buy.donationalerts}")
private String DONATIONALERTS_LINK;
@ -36,11 +42,13 @@ public class ProfileController {
public ProfileController(ProfileService profileService,
FreeVIPService freeVIPService,
ReportService reportService,
VIPService vipService) {
VIPService vipService,
ExternalVIPController externalVIPController) {
this.profileService = profileService;
this.freeVIPService = freeVIPService;
this.reportService = reportService;
this.vipService = vipService;
this.externalVIPController = externalVIPController;
}
@GetMapping
@ -94,37 +102,105 @@ public class ProfileController {
), HttpStatus.OK);
}
public String generateLink(String steam64, VipGiveMethod vipGiveMethod, String cost, boolean external) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("/api/profile/current/buyvip?");
stringBuilder.append("steam64=").append(steam64).append("&");
stringBuilder.append("buy_type=").append(vipGiveMethod.name().toUpperCase()).append("&");
stringBuilder.append("cost=").append(cost.replace(VipPrice.SYMBOL, ""));
switch (vipGiveMethod) {
case STEAM -> {
return external ? STEAM_TRADE : stringBuilder.toString();
}
case QIWI -> {
String steam2 = profileService.GetProfile(steam64, "").getSteamids().steam2;
return external ? String.valueOf(QIWI_LINK).replace("(AMOUNT)", String.valueOf(cost)).replace("(COMMENT)", steam2) : stringBuilder.toString();
}
case DONATIONALERTS -> {
return external ? DONATIONALERTS_LINK : stringBuilder.toString();
}
default -> {
return "http://www.consultant.ru/document/cons_doc_LAW_6300/4e3d0ddc5edee16d48ad06866de7851fa2a55b3e/";
}
}
}
@GetMapping("/buyvip")
@CollectStatistic(stage = CollectStages.COMBINED)
public ResponseEntity BuyVIP(HttpServletRequest request,
@RequestParam(value = "steam64", defaultValue = "") String steam64,
@RequestParam String buy_type,
@RequestParam(required = false, defaultValue = "") Integer cost) {
@RequestParam(required = false, defaultValue = "") String cost) {
VipGiveMethod buy_type_enum = VipGiveMethod.valueOf(buy_type.toUpperCase());
if (!vipService.getServices().getOrDefault(buy_type, true)) {
return new ResponseEntity("Service " + buy_type.toUpperCase() + " is not active long time", HttpStatus.OK);
return new ResponseEntity("Service " + buy_type_enum.name().toUpperCase() + " is not active long time", HttpStatus.OK);
}
switch (buy_type) {
case "steam":{
return ResponseEntity.status(HttpStatus.FOUND)
.header("Location", STEAM_TRADE)
.header("Location", generateLink(steam64, buy_type_enum, cost, true))
.build();
}
case "qiwi":
if (cost != null && cost < 0) return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).build();
String steam2 = profileService.GetProfile(steam64, "").getSteamids().steam2;
return ResponseEntity.status(HttpStatus.FOUND)
.header("Location", String.valueOf(QIWI_LINK).replace("(AMOUNT)", String.valueOf(cost)).replace("(COMMENT)", steam2))
.build();
case "donationalerts":{
return ResponseEntity.status(HttpStatus.FOUND)
.header("Location", DONATIONALERTS_LINK)
.build();
@GetMapping("/buyvip/list")
public ResponseEntity<List<DayItem>> BuyVipList(HttpServletRequest request, @RequestParam(required = false, defaultValue = "") String steam64) {
return new ResponseEntity<>(externalVIPController.getPrices().stream()
.filter(p -> !p.isFree())
.map(p -> new DayItem(p.getHuman_duration(),
Arrays.stream(VipGiveMethod.values())
.filter(VipGiveMethod::isBuyType)
.filter(g -> vipService.getServices().getOrDefault(g.name().toLowerCase(), true))
.map(g -> new PayItem(steam64, g, p))
.toList()))
.toList(), HttpStatus.OK);
}
default:
return ResponseEntity.status(HttpStatus.FOUND)
.header("Location", "http://www.consultant.ru/document/cons_doc_LAW_6300/4e3d0ddc5edee16d48ad06866de7851fa2a55b3e/")
.build();
public class DayItem {
private final String name;
private final List<PayItem> items;
public DayItem(String name, List<PayItem> items) {
this.name = name;
this.items = items;
}
public String getName() {
return name;
}
public List<PayItem> getItems() {
return items;
}
}
public class PayItem {
private final String service_name;
private final String pay_value;
private final String url;
public PayItem(String service_name, String pay_value, String url) {
this.service_name = service_name;
this.pay_value = pay_value;
this.url = url;
}
public PayItem(String steam64, VipGiveMethod vipGiveMethod, VipPrice vipPrice) {
service_name = vipGiveMethod.name();
pay_value = vipPrice.grabPrice(vipGiveMethod);
url = generateLink(steam64, vipGiveMethod, pay_value, false);
}
public String getName() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(service_name);
stringBuilder.append(" - ");
stringBuilder.append(pay_value);
return stringBuilder.toString();
}
public String getUrl() {
return url;
}
}
}

48
src/main/java/app/entities/VipGiveMethod.java

@ -2,28 +2,66 @@ package app.entities;
public enum VipGiveMethod {
FREE("Бесплатно", "Free"),
STEAM("Steam"),
QIWI("Qiwi"),
STEAM("Steam", true, true, false),
QIWI("Qiwi", false, true, true),
MANUAL("Админ", "Admin"),
AFTERTIME("Убрана"),
TOTAL("Итого"),
DONATIONALERTS("Донейшон Алертс", "DonationAlerts"),
DONATIONALERTS("Донейшон Алертс", "DonationAlerts", true, true, true),
PROMOCODE("Промокод", "PromoCode");
String human_name;
String webhook_name;
private final String human_name;
private final String webhook_name;
private final boolean enabled;
private final boolean isBuyType;
private final boolean isRealMoney;
VipGiveMethod(String human_name, String webhook_name) {
this.human_name = human_name;
this.webhook_name = webhook_name;
this.enabled = true;
this.isBuyType = false;
this.isRealMoney = false;
}
VipGiveMethod(String human_name) {
this.human_name = human_name;
this.webhook_name = human_name;
this.enabled = true;
this.isBuyType = false;
this.isRealMoney = false;
}
VipGiveMethod(String human_name, boolean enabled, boolean isBuyType, boolean isRealMoney) {
this.human_name = human_name;
this.webhook_name = human_name;
this.enabled = enabled;
this.isBuyType = isBuyType;
this.isRealMoney = isRealMoney;
}
VipGiveMethod(String human_name, String webhook_name, boolean enabled, boolean isBuyType, boolean isRealMoney) {
this.human_name = human_name;
this.webhook_name = webhook_name;
this.enabled = enabled;
this.isBuyType = isBuyType;
this.isRealMoney = isRealMoney;
}
public String getWebhookName() {
return this.webhook_name;
}
public boolean isEnabled() {
return enabled;
}
public boolean isBuyType() {
return isBuyType;
}
public boolean isRealMoney() {
return isRealMoney;
}
}

18
src/main/java/app/entities/VipPrice.java

@ -19,10 +19,28 @@ public class VipPrice {
boolean donationalerts = true;
int da_percent = 10;
public final static String SYMBOL = "P";
@JsonIgnore
public void changeEnabled(HashMap<String, Boolean> services) {
steam = services.get("steam");
qiwi = services.get("qiwi");
donationalerts = services.get("donationalerts");
}
@JsonIgnore
public boolean isFree() {
return money_price == 0;
}
@JsonIgnore
public String grabPrice(VipGiveMethod vipGiveMethod) {
StringBuilder stringBuilder = new StringBuilder();
if (vipGiveMethod.equals(VipGiveMethod.DONATIONALERTS)) stringBuilder.append(money_price + money_price/100*da_percent).append(SYMBOL);
else if (vipGiveMethod.isRealMoney()) stringBuilder.append(money_price).append(SYMBOL);
else stringBuilder.append(item_price);
return stringBuilder.toString();
}
}

10
src/main/java/app/services/db/VIPService.java

@ -15,9 +15,11 @@ import org.springframework.web.client.RestTemplate;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class VIPService {
@ -45,9 +47,11 @@ public class VIPService {
this.donateService = donateService;
this.services = new HashMap<>(){{
put("steam", true);
put("qiwi", false);
put("donationalerts", true);
Arrays.stream(VipGiveMethod.values())
.filter(VipGiveMethod::isBuyType)
.toList().forEach(
g -> put(g.name().toLowerCase(), g.isEnabled())
);
}};
}

Loading…
Cancel
Save