mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-06-28 00:24:20 +00:00
Merge pull request #281 from nagisa77/codex/update-milk-tea-redemption-logic
Count real milk tea redemptions
This commit is contained in:
@@ -14,8 +14,8 @@
|
|||||||
<div class="milk-tea-status-container">
|
<div class="milk-tea-status-container">
|
||||||
<div class="milk-tea-status">
|
<div class="milk-tea-status">
|
||||||
<div class="status-title">🔥 已兑换奶茶人数</div>
|
<div class="status-title">🔥 已兑换奶茶人数</div>
|
||||||
<ProgressBar :value="info.level1Count" :max="50" />
|
<ProgressBar :value="info.redeemCount" :max="50" />
|
||||||
<div class="status-text">当前 {{ info.level1Count }} / 50</div>
|
<div class="status-text">当前 {{ info.redeemCount }} / 50</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="isLoadingUser" class="loading-user">
|
<div v-if="isLoadingUser" class="loading-user">
|
||||||
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
|
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
|
||||||
@@ -57,7 +57,7 @@ export default {
|
|||||||
components: { ProgressBar, LevelProgress, BaseInput, BasePopup },
|
components: { ProgressBar, LevelProgress, BaseInput, BasePopup },
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
info: { level1Count: 0, ended: false },
|
info: { redeemCount: 0, ended: false },
|
||||||
user: null,
|
user: null,
|
||||||
dialogVisible: false,
|
dialogVisible: false,
|
||||||
contact: '',
|
contact: '',
|
||||||
@@ -97,7 +97,12 @@ export default {
|
|||||||
body: JSON.stringify({ contact: this.contact })
|
body: JSON.stringify({ contact: this.contact })
|
||||||
})
|
})
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
toast.success('兑换成功!')
|
const data = await res.json()
|
||||||
|
if (data.message === 'updated') {
|
||||||
|
toast.success('您已提交过兑换,本次更新兑换信息')
|
||||||
|
} else {
|
||||||
|
toast.success('兑换成功!')
|
||||||
|
}
|
||||||
this.dialogVisible = false
|
this.dialogVisible = false
|
||||||
await this.loadInfo()
|
await this.loadInfo()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -27,26 +27,30 @@ public class ActivityController {
|
|||||||
@GetMapping("/milk-tea")
|
@GetMapping("/milk-tea")
|
||||||
public MilkTeaInfo milkTea() {
|
public MilkTeaInfo milkTea() {
|
||||||
Activity a = activityService.getByType(ActivityType.MILK_TEA);
|
Activity a = activityService.getByType(ActivityType.MILK_TEA);
|
||||||
long count = activityService.countLevel1Users();
|
long count = activityService.countParticipants(a);
|
||||||
if (!a.isEnded() && count > 50) {
|
if (!a.isEnded() && count >= 50) {
|
||||||
activityService.end(a);
|
activityService.end(a);
|
||||||
}
|
}
|
||||||
MilkTeaInfo info = new MilkTeaInfo();
|
MilkTeaInfo info = new MilkTeaInfo();
|
||||||
info.setLevel1Count(count);
|
info.setRedeemCount(count);
|
||||||
info.setEnded(a.isEnded());
|
info.setEnded(a.isEnded());
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/milk-tea/redeem")
|
@PostMapping("/milk-tea/redeem")
|
||||||
public void redeemMilkTea(@RequestBody RedeemRequest req, Authentication auth) {
|
public java.util.Map<String, String> redeemMilkTea(@RequestBody RedeemRequest req, Authentication auth) {
|
||||||
User user = userService.findByIdentifier(auth.getName()).orElseThrow();
|
User user = userService.findByIdentifier(auth.getName()).orElseThrow();
|
||||||
Activity a = activityService.getByType(ActivityType.MILK_TEA);
|
Activity a = activityService.getByType(ActivityType.MILK_TEA);
|
||||||
activityService.redeem(a, user, req.getContact());
|
boolean first = activityService.redeem(a, user, req.getContact());
|
||||||
|
if (first) {
|
||||||
|
return java.util.Map.of("message", "redeemed");
|
||||||
|
}
|
||||||
|
return java.util.Map.of("message", "updated");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
private static class MilkTeaInfo {
|
private static class MilkTeaInfo {
|
||||||
private long level1Count;
|
private long redeemCount;
|
||||||
private boolean ended;
|
private boolean ended;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,9 +37,20 @@ public class ActivityService {
|
|||||||
activityRepository.save(activity);
|
activityRepository.save(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void redeem(Activity activity, User user, String contact) {
|
public long countParticipants(Activity activity) {
|
||||||
|
return activity.getParticipants().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redeem an activity for the given user.
|
||||||
|
*
|
||||||
|
* @return true if the user redeemed for the first time, false if the
|
||||||
|
* information was simply updated
|
||||||
|
*/
|
||||||
|
public boolean redeem(Activity activity, User user, String contact) {
|
||||||
notificationService.createActivityRedeemNotifications(user, contact);
|
notificationService.createActivityRedeemNotifications(user, contact);
|
||||||
activity.getParticipants().add(user);
|
boolean added = activity.getParticipants().add(user);
|
||||||
activityRepository.save(activity);
|
activityRepository.save(activity);
|
||||||
|
return added;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user