Search in sources :

Example 21 with UserBean

use of com.code.server.constant.game.UserBean in project summer by foxsugar.

the class GameRpcHandler method bindReferee.

@Override
public void bindReferee(long userId, int referee, AsyncMethodCallback<Integer> resultHandler) throws TException {
    logger.info("绑定邀请码 userId : " + userId);
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
    if (userBean != null) {
        userBean.setReferee(referee);
        RedisManager.getUserRedisService().updateUserBean(userBean.getId(), userBean);
    } else {
        UserService userService = SpringUtil.getBean(UserService.class);
        User user = userService.getUserByUserId(userId);
        user.setReferee(referee);
        userService.save(user);
    }
    resultHandler.onComplete(0);
}
Also used : User(com.code.server.db.model.User) UserBean(com.code.server.constant.game.UserBean) UserService(com.code.server.db.Service.UserService)

Example 22 with UserBean

use of com.code.server.constant.game.UserBean in project summer by foxsugar.

the class GameRpcHandler method charge.

@Override
public void charge(Order order, AsyncMethodCallback<Integer> resultHandler) throws TException {
    long userId = order.getUserId();
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
    UserService userService = SpringUtil.getBean(UserService.class);
    User user = userService.getUserByUserId(userId);
    String name = "";
    if (userBean == null) {
        if (user != null) {
            if (order.getType() == ChargeType.money.getValue()) {
                user.setMoney(user.getMoney() + order.getNum());
            } else if (order.getType() == ChargeType.gold.getValue()) {
                user.setGold(user.getGold() + order.getNum());
            }
            userService.save(user);
            name = user.getUsername();
        } else {
            resultHandler.onComplete(RPCError.NO_USER.getValue());
            return;
        }
    } else {
        // 在redis里
        name = userBean.getUsername();
        if (order.getType() == ChargeType.money.getValue()) {
            double nowMoney = RedisManager.getUserRedisService().addUserMoney(userId, order.getNum());
            user.setMoney(nowMoney);
            userService.save(user);
        } else if (order.getType() == ChargeType.gold.getValue()) {
            RedisManager.addGold(userId, order.getNum());
        }
    }
    // 充值记录
    if (order.getAgentId() != 0 && order.getType() == ChargeType.money.getValue()) {
        Charge charge = new Charge();
        charge.setOrderId("" + IdWorker.getDefaultInstance().nextId());
        charge.setUserid(order.getUserId());
        charge.setUsername(name);
        charge.setCreatetime(new Date());
        charge.setCallbacktime(new Date());
        charge.setOrigin(order.getAgentId());
        charge.setMoney(order.getNum());
        charge.setMoney_point(order.getNum());
        charge.setRecharge_source("" + IChargeType.AGENT);
        charge.setStatus(1);
        SpringUtil.getBean(ChargeService.class).save(charge);
    }
    resultHandler.onComplete(0);
}
Also used : User(com.code.server.db.model.User) UserBean(com.code.server.constant.game.UserBean) UserService(com.code.server.db.Service.UserService) Charge(com.code.server.db.model.Charge) ChargeService(com.code.server.db.Service.ChargeService) Date(java.util.Date)

Example 23 with UserBean

use of com.code.server.constant.game.UserBean in project summer by foxsugar.

the class GameRpcNewHandler method exchange.

@Override
public void exchange(Order order, AsyncMethodCallback<Integer> resultHandler) throws TException {
    long userId = order.getUserId();
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
    if (userBean == null) {
        UserService userService = SpringUtil.getBean(UserService.class);
        User user = userService.getUserByUserId(userId);
        user.setMoney(user.getMoney() - order.getNum());
        user.setGold(user.getGold() + order.getNum());
        userService.save(user);
    } else {
        UserRedisService userRedisService = RedisManager.getUserRedisService();
        userRedisService.addUserMoney(userId, -order.getNum());
        RedisManager.addGold(userId, order.getNum());
    }
    resultHandler.onComplete(0);
}
Also used : User(com.code.server.db.model.User) UserBean(com.code.server.constant.game.UserBean) UserService(com.code.server.db.Service.UserService) UserRedisService(com.code.server.redis.service.UserRedisService)

Example 24 with UserBean

use of com.code.server.constant.game.UserBean in project summer by foxsugar.

the class CenterMsgService method loadUserBean.

private static UserBean loadUserBean(long userId) {
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
    if (userBean == null) {
        User user = userService.getUserByUserId(userId);
        LoginAction.saveUser2Redis(user, LoginAction.getToken(userId));
        userBean = RedisManager.getUserRedisService().getUserBean(userId);
    }
    return userBean;
}
Also used : UserBean(com.code.server.constant.game.UserBean)

Example 25 with UserBean

use of com.code.server.constant.game.UserBean in project summer by foxsugar.

the class GameClubService method joinClub.

/**
 * 加入俱乐部
 *
 * @param msgKey
 * @param userId
 * @param clubId
 * @return
 */
public int joinClub(KafkaMsgKey msgKey, long userId, String clubId, String mark) {
    Club club = ClubManager.getInstance().getClubById(clubId);
    if (club == null) {
        return ErrorCode.CLUB_NO_THIS;
    }
    // 自己加入了几个俱乐部
    List<String> joinList = ClubManager.getInstance().getUserClubs(userId);
    if (joinList.size() >= JOIN_LIMIT) {
        return ErrorCode.CLUB_CANNOT_NUM;
    }
    if (joinList.contains(clubId)) {
        return ErrorCode.CLUB_CANNOT_JOIN;
    }
    // 加入申请列表
    if (isInApplyList(club, userId)) {
        return ErrorCode.CLUB_CANNOT_JOIN;
    }
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(userId);
    String name = userBean.getUsername();
    String image = userBean.getImage();
    ClubMember apply = new ClubMember().setTime(System.currentTimeMillis()).setUserId(userId).setMark(mark).setName(name).setImage(image);
    club.getClubInfo().getApplyList().add(apply);
    Map<String, Object> result = new HashMap<>();
    sendMsg(msgKey, new ResponseVo("clubService", "joinClub", result));
    return 0;
}
Also used : UserBean(com.code.server.constant.game.UserBean) HashMap(java.util.HashMap) Club(com.code.server.db.model.Club) ClubMember(com.code.server.constant.club.ClubMember) ResponseVo(com.code.server.constant.response.ResponseVo)

Aggregations

UserBean (com.code.server.constant.game.UserBean)32 User (com.code.server.db.model.User)12 UserService (com.code.server.db.Service.UserService)9 HashMap (java.util.HashMap)9 ResponseVo (com.code.server.constant.response.ResponseVo)8 ArrayList (java.util.ArrayList)6 Charge (com.code.server.db.model.Charge)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Date (java.util.Date)4 Club (com.code.server.db.model.Club)3 ClubMember (com.code.server.constant.club.ClubMember)2 UserRecord (com.code.server.constant.game.UserRecord)2 KafkaMsgKey (com.code.server.constant.kafka.KafkaMsgKey)2 ChargeService (com.code.server.db.Service.ChargeService)2 MsgProducer (com.code.server.kafka.MsgProducer)2 UserRedisService (com.code.server.redis.service.UserRedisService)2 com.code.server.rpc.idl (com.code.server.rpc.idl)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 GameRecord (com.code.server.constant.game.GameRecord)1 RoomRecord (com.code.server.constant.game.RoomRecord)1