Search in sources :

Example 1 with User

use of com.code.server.db.model.User in project summer by foxsugar.

the class CenterService method saveUser.

private static void saveUser() {
    Set<String> users = RedisManager.getUserRedisService().getSaveUsers();
    if (users != null) {
        UserService userService = SpringUtil.getBean(UserService.class);
        Set<String> removeList = new HashSet<>();
        users.forEach(userId -> {
            long uid = Long.valueOf(userId);
            UserBean userBean = RedisManager.getUserRedisService().getUserBean(uid);
            User user = GameUserService.userBean2User(userBean);
            // 保存
            userService.save(user);
            removeList.add(userId);
        });
        // 批量删除 需要保存的玩家
        if (removeList.size() > 0) {
            RedisManager.getUserRedisService().removeSaveUser(removeList.toArray());
        }
    }
    // 俱乐部 保存
    ClubManager.getInstance().saveAll();
}
Also used : User(com.code.server.db.model.User) UserBean(com.code.server.constant.game.UserBean) UserService(com.code.server.db.Service.UserService) HashSet(java.util.HashSet)

Example 2 with User

use of com.code.server.db.model.User in project summer by foxsugar.

the class GameUserService method guessCarBindReferrer.

public int guessCarBindReferrer(KafkaMsgKey msgKey, int referrerId) {
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(msgKey.getUserId());
    if (userBean == null) {
        return ErrorCode.YOU_HAVE_NOT_LOGIN;
    }
    if (referrerId <= 0 || userBean.getReferee() != 0) {
        return ErrorCode.CAN_NOT_BING_REFERRER;
    }
    if (referrerId == msgKey.getUserId()) {
        return ErrorCode.CAN_NOT_BING_REFERRER;
    }
    // boolean isExist = RpcManager.getInstance().referrerIsExist(referrerId);
    // if (!isExist) {
    // return ErrorCode.REFERRER_NOT_EXIST;
    // }
    UserBean referrUser = RedisManager.getUserRedisService().getUserBean(referrerId);
    if (referrUser != null) {
        if (referrUser.getVip() == 0) {
            return ErrorCode.REFERRER_NOT_EXIST;
        }
    } else {
        User user = userService.getUserByUserId(referrerId);
        if (user == null || user.getVip() == 0)
            return ErrorCode.REFERRER_NOT_EXIST;
    }
    userBean.setReferee(referrerId);
    RedisManager.getUserRedisService().updateUserBean(userBean.getId(), userBean);
    ResponseVo vo = new ResponseVo("userService", "guessCarBind", 0);
    sendMsg(msgKey, vo);
    return 0;
}
Also used : User(com.code.server.db.model.User) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 3 with User

use of com.code.server.db.model.User in project summer by foxsugar.

the class LoginAction method createUser.

/**
 * 创建玩家
 *
 * @param openId
 * @param username
 * @param image
 * @param sex
 * @return
 */
private User createUser(String openId, String username, String image, int sex) {
    User newUser = new User();
    newUser.setAccount(openId);
    newUser.setPassword("111111");
    newUser.setOpenId(openId);
    newUser.setUsername(decodeStr(username));
    newUser.setImage(image);
    newUser.setSex(sex);
    newUser.setVip(0);
    newUser.setUuid("0");
    newUser.setMoney(getConstant().getInitMoney());
    newUser.setRegistDate(new Date());
    newUser.setLastLoginDate(new Date());
    return newUser;
}
Also used : User(com.code.server.db.model.User) Date(java.util.Date)

Example 4 with User

use of com.code.server.db.model.User in project summer by foxsugar.

the class TestAction method noti.

@RequestMapping("/Pay/notify")
public String noti(HttpServletRequest request) {
    String memberid = request.getParameter("memberid");
    String orderid = request.getParameter("orderid");
    String amount = request.getParameter("amount");
    String datetime = request.getParameter("datetime");
    String returncode = request.getParameter("returncode");
    String reserved1 = request.getParameter("reserved1");
    String reserved2 = request.getParameter("reserved2");
    String sign = request.getParameter("sign");
    String transaction_id = request.getParameter("transaction_id");
    String SignTemp = "amount=" + amount + "&datetime=" + datetime + "&memberid=" + memberid + "&orderid=" + orderid + "&transaction_id=" + transaction_id + "&returncode=" + returncode + "&key=" + keyValue + "";
    String md5sign = null;
    try {
        md5sign = md5(SignTemp);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    logger.info("-------------------------------");
    logger.info("memberid{}, orderid{}, amount{}, datetime{}, requestcode{}, returncode{}, reserved1{}, reserverd2{}, sign{}, tempSign{}", memberid, orderid, amount, datetime, returncode, sign, SignTemp);
    logger.info("-------------------------------");
    logger.info("local sign:{}", md5sign);
    logger.info("sign:{}", sign);
    if (true) {
        if (returncode.equals("00")) {
            Charge charge = chargeService.getChargeByOrderid(orderid);
            if (charge.getStatus() == 1) {
                return "success";
            }
            charge.setStatus(1);
            chargeService.save(charge);
            logger.info("支付成功!");
            UserBean UserBeanRedis = userRedisService.getUserBean(charge.getUserid());
            double addMoney = charge.getMoney() * 10;
            if (UserBeanRedis != null) {
                userRedisService.addUserMoney(charge.getUserid(), addMoney);
            } else {
                User user = userService.getUserByUserId(charge.getUserid());
                System.out.println("修改玩家豆豆");
                user.setMoney(user.getMoney() + addMoney);
                userService.save(user);
            }
            System.out.println("通知客户端刷新充值");
            Map<String, String> rs = new HashMap<>();
            MsgSender.sendMsg2Player(new ResponseVo("userService", "refresh", rs), charge.getUserid());
        } else {
            logger.info("支付失败");
            return "failed";
        }
    } else {
        logger.info("支付失败");
        return "failed";
    }
    return "success";
}
Also used : User(com.code.server.db.model.User) UserBean(com.code.server.constant.game.UserBean) HashMap(java.util.HashMap) Charge(com.code.server.db.model.Charge) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ResponseVo(com.code.server.constant.response.ResponseVo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with User

use of com.code.server.db.model.User in project summer by foxsugar.

the class GameRpcHandler 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)

Aggregations

User (com.code.server.db.model.User)21 UserBean (com.code.server.constant.game.UserBean)12 UserService (com.code.server.db.Service.UserService)9 ResponseVo (com.code.server.constant.response.ResponseVo)5 Charge (com.code.server.db.model.Charge)5 Date (java.util.Date)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ChargeService (com.code.server.db.Service.ChargeService)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 HashMap (java.util.HashMap)2 ServerConfig (com.code.server.login.config.ServerConfig)1 IdWorker (com.code.server.util.IdWorker)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Transactional (javax.transaction.Transactional)1 Element (org.dom4j.Element)1