From b0eec19dcdb6aa6671f9527aa4cd0d7dd39efcd4 Mon Sep 17 00:00:00 2001 From: gsd Date: Sun, 23 Apr 2023 18:17:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=B5=D0=BD=D1=8C=D0=B3=D0=B8=20=D0=BC?= =?UTF-8?q?=D0=BD=D0=B5=20=D0=BD=D0=B5=D1=81=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../other/ExternalVIPController.java | 24 +++++++++++++++---- .../java/app/entities/DonateStatistic.java | 2 ++ src/main/java/app/entities/VipPrice.java | 14 +++++++++++ .../java/app/services/db/DonateService.java | 18 +++++++------- .../java/app/services/db/FreeVIPService.java | 2 +- 5 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 src/main/java/app/entities/VipPrice.java diff --git a/src/main/java/app/controllers/other/ExternalVIPController.java b/src/main/java/app/controllers/other/ExternalVIPController.java index 0549342..2c206c8 100644 --- a/src/main/java/app/controllers/other/ExternalVIPController.java +++ b/src/main/java/app/controllers/other/ExternalVIPController.java @@ -3,18 +3,16 @@ package app.controllers.other; import app.annotations.enums.AuthMethod; import app.annotations.interfaces.CheckWebAccess; import app.entities.VipGiveMethod; +import app.entities.VipPrice; import app.services.db.VIPService; import app.utils.SteamIDConverter; import jakarta.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; -import java.util.HashSet; +import java.util.*; @RestController @RequestMapping("api/external/vip") @@ -23,10 +21,21 @@ public class ExternalVIPController { HashSet unique_set; + List prices; + @Autowired public ExternalVIPController(VIPService vipService) { this.vipService = vipService; this.unique_set = new HashSet(); + setupPrices(); + } + + public void setupPrices() { + prices = new ArrayList<>(); + prices.add(new VipPrice("1 Месяц", 200, "1 ключ", "site_content/images/vip/VIP_1_MOUNTH.jpg", "month")); + prices.add(new VipPrice("1 Неделя", 100, "40 рефов", "site_content/images/vip/VIP_7_DAYS.jpg", "week")); + prices.add(new VipPrice("1 День", 35, "10 рефов", "site_content/images/vip/VIP_1_DAY.jpg", "day")); + prices.add(new VipPrice("1 День", 0, "бесплатно", "site_content/images/vip/freevip.jpg", "free")); } @PostMapping @@ -50,4 +59,9 @@ public class ExternalVIPController { extra); return new ResponseEntity(result, HttpStatus.OK); } + + @GetMapping + public ResponseEntity getPrices() { + return new ResponseEntity(prices, HttpStatus.OK); + } } diff --git a/src/main/java/app/entities/DonateStatistic.java b/src/main/java/app/entities/DonateStatistic.java index 4f04362..334b3e6 100644 --- a/src/main/java/app/entities/DonateStatistic.java +++ b/src/main/java/app/entities/DonateStatistic.java @@ -7,11 +7,13 @@ public class DonateStatistic { VipGiveMethod giveMethod; Integer count; String reserved; + Integer amount; //sub public DonateStatistic(Object[] raw) { giveMethod = VipGiveMethod.values()[(int) raw[0]]; count = ((Long) raw[1]).intValue(); reserved = raw[2]==null?"": (String) raw[2]; + amount = (int) raw[3]; } public DonateStatistic(Object o) { diff --git a/src/main/java/app/entities/VipPrice.java b/src/main/java/app/entities/VipPrice.java new file mode 100644 index 0000000..f3c2473 --- /dev/null +++ b/src/main/java/app/entities/VipPrice.java @@ -0,0 +1,14 @@ +package app.entities; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class VipPrice { + String human_duration; + int money_price; + String item_price; + String img_url; + String period; +} diff --git a/src/main/java/app/services/db/DonateService.java b/src/main/java/app/services/db/DonateService.java index 0a61ce8..8f469c7 100644 --- a/src/main/java/app/services/db/DonateService.java +++ b/src/main/java/app/services/db/DonateService.java @@ -68,7 +68,7 @@ public class DonateService { } public HashMap getGivedVipStatistic(StatisticRange statisticRange) { - List raw_donateStatistics = entityManager.createNativeQuery("SELECT `givemethod`,COUNT(*) as count,`reserved` FROM `gived_vip` WHERE `givemethod` IN (0,1,2) AND `timestamp` > CAST(DATE_FORMAT(NOW() ,?1) as DATE) GROUP BY `givemethod`, `reserved`") + List raw_donateStatistics = entityManager.createNativeQuery("SELECT `givemethod`,COUNT(*) as count,`reserved`, `amount` FROM `gived_vip` WHERE `givemethod` IN (0,1,2) AND `timestamp` > CAST(DATE_FORMAT(NOW() ,?1) as DATE) GROUP BY `givemethod`, `amount`") .setParameter(1, StatisticRange.cast(statisticRange)) .getResultList(); List donateStatistics = raw_donateStatistics.stream().map(DonateStatistic::new).toList(); @@ -81,17 +81,17 @@ public class DonateService { switch (ds.getGiveMethod()) { case FREE -> map.get("free").put("day", ds.getCount()); case STEAM -> { - switch (ds.getReserved()) { - case "keys=0;metal=20;" -> map.get("steam").put("week", ds.getCount()); - case "keys=0;metal=5;" -> map.get("steam").put("day", ds.getCount()); - case "keys=1;metal=0;" -> map.get("steam").put("month", ds.getCount()); + switch (ds.getAmount()) { + case 86400 -> map.get("steam").put("day", ds.getCount()); + case 604800 -> map.get("steam").put("week", ds.getCount()); + case 2678400, 2592000 -> map.get("steam").put("month", ds.getCount()); } } case QIWI -> { - switch (ds.getReserved()) { - case "rub=150;" -> map.get("qiwi").put("month", ds.getCount()); - case "rub=75;" -> map.get("qiwi").put("week", ds.getCount()); - case "rub=20;" -> map.get("qiwi").put("day", ds.getCount()); + switch (ds.getAmount()) { + case 86400 -> map.get("qiwi").put("day", ds.getCount()); + case 604800 -> map.get("qiwi").put("week", ds.getCount()); + case 2678400, 2592000 -> map.get("qiwi").put("month", ds.getCount()); } } } diff --git a/src/main/java/app/services/db/FreeVIPService.java b/src/main/java/app/services/db/FreeVIPService.java index 686c63d..65df6f6 100644 --- a/src/main/java/app/services/db/FreeVIPService.java +++ b/src/main/java/app/services/db/FreeVIPService.java @@ -89,7 +89,7 @@ public class FreeVIPService{ //1.имеются ли уже права if (vipService.CheckCurrentPermition(steamID) != null) return 0L; long current_server_time = getDBServerUTime(); - long timeout = 60 * 60 * 24 * 30; + long timeout = 60 * 60 * 24 * 30 * 3; // лимит месяцев long need_usertime = 60 * 60 * 24 * 2; //////////////////////////////////////////////////////////////// long last_free_vip_gived = getLastGivedFreeVIP(socialAuth);