mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 11:24:46 +00:00
充值礼包
This commit is contained in:
parent
79c5ef00f7
commit
8af1ac9484
Binary file not shown.
@ -16,7 +16,7 @@ export const RData = (data:any,isTips:boolean = false) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
//如果有 rewards 字段 表示要弹出获得资源
|
//如果有 rewards 字段 表示要弹出获得资源
|
||||||
if(data.data['rewards']){
|
if(data.data['rewards'] && data.data['rewards'].length){
|
||||||
//弹出获得资源
|
//弹出获得资源
|
||||||
app.layer.Open(GUI.RewardClaimView,data.data['rewards'])
|
app.layer.Open(GUI.RewardClaimView,data.data['rewards'])
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||||
import org.springframework.retry.annotation.EnableRetry;
|
import org.springframework.retry.annotation.EnableRetry;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
@EnableRetry
|
@EnableRetry
|
||||||
@MapperScan(basePackages = "cn.jisol.game.mapper")
|
@MapperScan(basePackages = "cn.jisol.game.mapper")
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@EnableScheduling
|
||||||
public class JGameApplication {
|
public class JGameApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringBeanUtils.context = SpringApplication.run(JGameApplication.class);
|
SpringBeanUtils.context = SpringApplication.run(JGameApplication.class);
|
||||||
|
@ -24,4 +24,7 @@ public interface GActionEnum {
|
|||||||
int CR_REFEREE_PVP_MODE = 4001; //裁决PVP模式
|
int CR_REFEREE_PVP_MODE = 4001; //裁决PVP模式
|
||||||
int CR_REFEREE_PVP_END = 4002; //裁决PVP结束
|
int CR_REFEREE_PVP_END = 4002; //裁决PVP结束
|
||||||
|
|
||||||
|
/************** 任务推送 ****************/
|
||||||
|
int C_TASK_PUSH_DAY_RESET = 5001; //任务推送 - 每天重置
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,11 @@ public class HTTPExceptionHandler {
|
|||||||
return NewsContext.onMessage("Token 失效",null,LOGIN_TOKEN);
|
return NewsContext.onMessage("Token 失效",null,LOGIN_TOKEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
//材料不够
|
//资源不够
|
||||||
@ExceptionHandler(value = ResourceNotException.class)
|
@ExceptionHandler(value = ResourceNotException.class)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public NewsContext<String> retryExceptionHandler(ResourceNotException e){
|
public NewsContext<String> retryExceptionHandler(ResourceNotException e){
|
||||||
return NewsContext.onFail("材料不够.");
|
return NewsContext.onFail(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
//并发异常
|
//并发异常
|
||||||
|
@ -0,0 +1,114 @@
|
|||||||
|
package cn.jisol.game.controller.game;
|
||||||
|
|
||||||
|
|
||||||
|
import cfg.TB.TbGGift;
|
||||||
|
import cfg.TbGEnum.TGiftLimit;
|
||||||
|
import cn.jisol.game.controller.argsresolver.CurrentPlayer;
|
||||||
|
import cn.jisol.game.controller.exception.ResourceNotException;
|
||||||
|
import cn.jisol.game.data.ResourceId;
|
||||||
|
import cn.jisol.game.data.TD;
|
||||||
|
import cn.jisol.game.entity.table.GiftDayRecord;
|
||||||
|
import cn.jisol.game.entity.table.GiftRecord;
|
||||||
|
import cn.jisol.game.entity.table.Player;
|
||||||
|
import cn.jisol.game.entity.table.PlayerPet;
|
||||||
|
import cn.jisol.game.service.GiftDayRecordService;
|
||||||
|
import cn.jisol.game.service.GiftRecordService;
|
||||||
|
import cn.jisol.game.service.ResourceService;
|
||||||
|
import cn.jisol.game.vo.news.NewsReward;
|
||||||
|
import cn.jisol.game.vo.news.ov.ResourceUpdateOV;
|
||||||
|
import cn.jisol.ngame.util.NewsContext;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Api(value = "JNGameDemo - API", tags = {"礼包 - API"})
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/game/gift")
|
||||||
|
@ResponseBody
|
||||||
|
public class GiftController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ResourceService resourceService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
GiftRecordService giftRecordService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
GiftDayRecordService giftDayRecordService;
|
||||||
|
|
||||||
|
//购买指定礼包
|
||||||
|
@ApiImplicitParams({})
|
||||||
|
@ApiOperation(value = "购买指定礼包")
|
||||||
|
@PostMapping("/buy/{giftId}")
|
||||||
|
@Transactional
|
||||||
|
public NewsReward<Boolean> buy(@CurrentPlayer Player player, @PathVariable Integer giftId){
|
||||||
|
|
||||||
|
TbGGift gift = TD.DATA.getTbGGift().get(giftId);
|
||||||
|
|
||||||
|
if(Objects.isNull(gift)) return NewsReward.onFail("暂无该礼包");
|
||||||
|
|
||||||
|
//判断是否可以购买当前礼包
|
||||||
|
if(gift.limit == TGiftLimit.DayLimit){
|
||||||
|
//每天限制购买
|
||||||
|
if(gift.limitValue <= giftDayRecordService.count(Wrappers.lambdaQuery(GiftDayRecord.class).eq(GiftDayRecord::getPlayerId,player.getPlayerId()).eq(GiftDayRecord::getGiftCfgId,gift.id))){
|
||||||
|
return NewsReward.onFail("今天买太多啦 每天再买哦");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(gift.limit == TGiftLimit.Limit){
|
||||||
|
//每天限制购买
|
||||||
|
if(gift.limitValue <= giftRecordService.count(Wrappers.lambdaQuery(GiftRecord.class).eq(GiftRecord::getPlayerId,player.getPlayerId()).eq(GiftRecord::getGiftCfgId,gift.id))){
|
||||||
|
return NewsReward.onFail("当前礼包买太多了 看看其他礼包哦");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resourceService.addResourceValue(player.getPlayerId(), ResourceId.GiftCoupons.id, (long) -gift.price);
|
||||||
|
|
||||||
|
//发放奖励
|
||||||
|
List<ResourceUpdateOV> ovs = resourceService.rewards(player.getPlayerId(), gift.rewards);
|
||||||
|
|
||||||
|
|
||||||
|
GiftRecord giftRecord = GiftRecord.builder()
|
||||||
|
.playerId(player.getPlayerId())
|
||||||
|
.giftCfgId(gift.id)
|
||||||
|
.giftCfgName(gift.name)
|
||||||
|
.giftCfgRewards(Arrays.asList(gift.rewards))
|
||||||
|
.giftCfgPrice(gift.price)
|
||||||
|
.giftBuyingTime(new Date().getTime())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
//保存购买记录
|
||||||
|
giftRecordService.save(giftRecord);
|
||||||
|
giftDayRecordService.save(GiftDayRecord.builder()
|
||||||
|
.playerId(giftRecord.getPlayerId())
|
||||||
|
.giftId(giftRecord.getGiftId())
|
||||||
|
.giftCfgId(giftRecord.getGiftCfgId())
|
||||||
|
.build());
|
||||||
|
|
||||||
|
|
||||||
|
return NewsReward.onSuccess("购买成功",true,ovs, Arrays.asList(gift.rewards));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//查询当天购买记录
|
||||||
|
@ApiImplicitParams({})
|
||||||
|
@ApiOperation(value = "查询当天购买记录")
|
||||||
|
@GetMapping("/record/day")
|
||||||
|
public NewsContext<List<GiftDayRecord>> getGiftDayRecord(@CurrentPlayer Player player){
|
||||||
|
return NewsContext.onSuccess("查询成功",giftDayRecordService.list(
|
||||||
|
Wrappers.lambdaQuery(GiftDayRecord.class)
|
||||||
|
.eq(GiftDayRecord::getPlayerId,player.getPlayerId())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -14,6 +14,8 @@ public enum ResourceId {
|
|||||||
DungeonForgedStones(90005),
|
DungeonForgedStones(90005),
|
||||||
//魂:一品宠物魂
|
//魂:一品宠物魂
|
||||||
Q1S(90006),
|
Q1S(90006),
|
||||||
|
//兑换券
|
||||||
|
GiftCoupons(90007),
|
||||||
;
|
;
|
||||||
|
|
||||||
public int id;
|
public int id;
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
package cn.jisol.game.entity.table;
|
||||||
|
|
||||||
|
import cfg.TbGEntity.TReward;
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@Data
|
||||||
|
@TableName("`gift_day_record`")
|
||||||
|
public class GiftDayRecord {
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long giftDayId; //礼包Id
|
||||||
|
private Long playerId; //玩家Id
|
||||||
|
private Long giftId; //礼包价格
|
||||||
|
private Integer giftCfgId; //礼包配置表Id
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package cn.jisol.game.entity.table;
|
||||||
|
|
||||||
|
import cfg.TbGEntity.TReward;
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@Data
|
||||||
|
@TableName("`gift_record`")
|
||||||
|
public class GiftRecord {
|
||||||
|
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
|
private Long giftId; //礼包Id
|
||||||
|
private Long playerId; //玩家Id
|
||||||
|
private Integer giftCfgId; //礼包配置表Id
|
||||||
|
private String giftCfgName; //礼包名称
|
||||||
|
|
||||||
|
@TableField(typeHandler = FastjsonTypeHandler.class)
|
||||||
|
private List<TReward> giftCfgRewards; //礼包奖励
|
||||||
|
|
||||||
|
private Integer giftCfgPrice; //礼包价格
|
||||||
|
private Long giftBuyingTime; //礼包购买时间戳
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
package cn.jisol.game.manager;
|
||||||
|
|
||||||
|
import cn.jisol.game.actions.GActionEnum;
|
||||||
|
import cn.jisol.game.entity.table.GiftDayRecord;
|
||||||
|
import cn.jisol.game.network.WebSocket;
|
||||||
|
import cn.jisol.game.network.client.GClient;
|
||||||
|
import cn.jisol.game.service.GiftDayRecordService;
|
||||||
|
import cn.jisol.game.service.GiftRecordService;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class GScheduledManager {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
GiftDayRecordService giftDayRecordService;
|
||||||
|
|
||||||
|
//获取所有在线玩家
|
||||||
|
public Map<String, GClient> getClients(){
|
||||||
|
return WebSocket.CLIENTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
//每天重置 任务
|
||||||
|
@Scheduled(cron="0 0 0 * * ?")
|
||||||
|
public void dayReset(){
|
||||||
|
|
||||||
|
System.out.println("定时器执行[每天重置] ScheduledManager - dayReset");
|
||||||
|
|
||||||
|
//重置每日礼包记录
|
||||||
|
giftDayRecordService.remove(Wrappers.lambdaQuery(GiftDayRecord.class));
|
||||||
|
System.out.println("定时器执行[每天重置] ScheduledManager - dayReset : 重置每日礼包记录");
|
||||||
|
|
||||||
|
//通知所有玩家 - 每天重置结束
|
||||||
|
getClients().values().forEach(client1 -> {
|
||||||
|
client1.invoke(GActionEnum.C_TASK_PUSH_DAY_RESET);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package cn.jisol.game.mapper;
|
||||||
|
|
||||||
|
import cn.jisol.game.entity.table.GiftDayRecord;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public interface GiftDayRecordMapper extends BaseMapper<GiftDayRecord> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package cn.jisol.game.mapper;
|
||||||
|
|
||||||
|
import cn.jisol.game.entity.table.GiftRecord;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public interface GiftRecordMapper extends BaseMapper<GiftRecord> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package cn.jisol.game.service;
|
||||||
|
|
||||||
|
import cn.jisol.game.entity.table.GiftDayRecord;
|
||||||
|
import cn.jisol.game.entity.table.GiftRecord;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
public interface GiftDayRecordService extends IService<GiftDayRecord> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package cn.jisol.game.service;
|
||||||
|
|
||||||
|
import cn.jisol.game.entity.table.Dungeon;
|
||||||
|
import cn.jisol.game.entity.table.GiftRecord;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
public interface GiftRecordService extends IService<GiftRecord> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package cn.jisol.game.service.impl;
|
||||||
|
|
||||||
|
import cn.jisol.game.entity.table.GiftDayRecord;
|
||||||
|
import cn.jisol.game.mapper.GiftDayRecordMapper;
|
||||||
|
import cn.jisol.game.service.GiftDayRecordService;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class GiftDayRecordServiceImpl extends ServiceImpl<GiftDayRecordMapper, GiftDayRecord> implements GiftDayRecordService {
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package cn.jisol.game.service.impl;
|
||||||
|
|
||||||
|
import cn.jisol.game.entity.table.GiftRecord;
|
||||||
|
import cn.jisol.game.mapper.GiftRecordMapper;
|
||||||
|
import cn.jisol.game.service.GiftRecordService;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class GiftRecordServiceImpl extends ServiceImpl<GiftRecordMapper, GiftRecord> implements GiftRecordService {
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package cn.jisol.game.service.impl;
|
package cn.jisol.game.service.impl;
|
||||||
|
|
||||||
|
import cfg.TB.TbGResource;
|
||||||
import cfg.TbGEntity.TResource;
|
import cfg.TbGEntity.TResource;
|
||||||
import cfg.TbGEntity.TReward;
|
import cfg.TbGEntity.TReward;
|
||||||
import cn.jisol.game.controller.exception.GeneralException;
|
import cn.jisol.game.controller.exception.GeneralException;
|
||||||
@ -39,6 +40,7 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
|
|||||||
@Override
|
@Override
|
||||||
public Resource addResourceValue(Long playerId, int type, Long value) {
|
public Resource addResourceValue(Long playerId, int type, Long value) {
|
||||||
|
|
||||||
|
TbGResource tbGResource = TD.DATA.getTbGResource().get(type);
|
||||||
|
|
||||||
LambdaUpdateWrapper<Resource> eq = Wrappers.lambdaUpdate(Resource.class)
|
LambdaUpdateWrapper<Resource> eq = Wrappers.lambdaUpdate(Resource.class)
|
||||||
.eq(Resource::getPlayerId, playerId) //玩家
|
.eq(Resource::getPlayerId, playerId) //玩家
|
||||||
@ -71,17 +73,17 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
|
|||||||
throw new RetryException("服务器忙碌啦");
|
throw new RetryException("服务器忙碌啦");
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
throw new ResourceNotException("资源不够");
|
throw new ResourceNotException(tbGResource.name+"不够");
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
//更新失败 材料不够
|
//更新失败 材料不够
|
||||||
throw new ResourceNotException("资源不够");
|
throw new ResourceNotException(tbGResource.name+"资源不够");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//如果资源不够则报错
|
//如果资源不够则报错
|
||||||
if(res.getResourceValue() < 0) throw new ResourceNotException("资源不够");
|
if(res.getResourceValue() < 0) throw new ResourceNotException(tbGResource.name+"资源不够");
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user