Search in sources :

Example 16 with User

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

the class PayCallback method callback.

/**
 * 接受微信回调
 *
 * @param
 */
@RequestMapping(value = "/callback")
public String callback(HttpServletRequest request, HttpServletResponse response) {
    System.out.println("接受回调参数");
    // 获取微信返回结果
    String parameterstr = PayUtil.ObtainParameterString(request);
    System.out.println("parameterstr:" + parameterstr);
    // 解析xmlString
    Element element = PayUtil.ParsingXML(parameterstr);
    SortedMap<String, String> secondParams = new TreeMap<>();
    secondParams.put("appid", element.elementText("appid"));
    secondParams.put("bank_type", element.elementText("bank_type"));
    secondParams.put("cash_fee", element.elementText("cash_fee"));
    secondParams.put("fee_type", element.elementText("fee_type"));
    secondParams.put("is_subscribe", element.elementText("is_subscribe"));
    secondParams.put("mch_id", element.elementText("mch_id"));
    secondParams.put("nonce_str", element.elementText("nonce_str"));
    secondParams.put("openid", element.elementText("openid"));
    secondParams.put("out_trade_no", element.elementText("out_trade_no"));
    secondParams.put("result_code", element.elementText("result_code"));
    secondParams.put("return_code", element.elementText("return_code"));
    secondParams.put("time_end", element.elementText("time_end"));
    secondParams.put("total_fee", element.elementText("total_fee"));
    secondParams.put("trade_type", element.elementText("trade_type"));
    secondParams.put("transaction_id", element.elementText("transaction_id"));
    String paySign = PayUtil.createSign("UTF-8", serverConfig.getKey(), secondParams);
    System.out.println(paySign);
    // 解析返回结果
    String returnXML = null;
    System.out.println("回调成功");
    // 业务返回成功
    Charge charge = chargeService.getChargeByOrderid(element.elementText("out_trade_no"));
    if ("SUCCESS".equals(element.elementText("result_code"))) {
        String transaction_id = element.elementText("transaction_id");
        charge.setTransaction_id(transaction_id);
        System.out.println("业务成功");
        System.out.println(charge.getMoney());
        System.out.println(element.elementText("cash_fee"));
        System.out.println(paySign);
        System.out.println(element.elementText("sign"));
        int money_total = Integer.valueOf(element.elementText("total_fee")) / 100;
        if (paySign.equals(element.elementText("sign")) && charge.getMoney() == money_total) {
            if (0 == charge.getStatus()) {
                System.out.println("修改订单状态");
                // 修改支付订单状态 已支付
                charge.setStatus(1);
                charge.setCallbacktime(new Date());
                chargeService.save(charge);
                UserBean UserBeanRedis = userRedisService.getUserBean(charge.getUserid());
                int addMoney = Integer.valueOf(element.elementText("total_fee")) / 10;
                // 龙七分档
                if (chargeMoney.containsKey(money_total)) {
                    addMoney = chargeMoney.get(money_total);
                }
                if (UserBeanRedis != null) {
                    // userRedisService.setUserMoney(charge.getUserid(),UserBeanRedis.getMoney() + Double.valueOf(element.elementText("total_fee")) / 10);
                    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 {
                Map<String, String> rs = new HashMap<>();
                rs.put("err_code", element.elementText("err_code"));
                rs.put("err_code_des", element.elementText("err_code_des"));
                ResponseVo vo = new ResponseVo("userService", "refresh", rs);
                vo.setCode(ErrorCode.ORDER_WAS_PAID);
                MsgSender.sendMsg2Player(vo, charge.getUserid());
            }
            /*returnXML = "<xml>";
                        returnXML += "<return_code>![CDATA[SUCCESS]]</return_code>";
		    		    returnXML += "<return_msg>![CDATA[OK]]</return_msg>";
		    		    returnXML += "</xml>";*/
            returnXML = "SUCCESS";
        } else {
            Map<String, String> rs = new HashMap<>();
            rs.put("err_code", element.elementText("err_code"));
            rs.put("err_code_des", element.elementText("err_code_des"));
            ResponseVo vo = new ResponseVo("userService", "refresh", rs);
            vo.setCode(ErrorCode.PARAMETER_SIGN_MONEY_ERROR);
            MsgSender.sendMsg2Player(vo, charge.getUserid());
            returnXML = "SUCCESS";
        }
    } else {
        // 余额不足
        if ("NOTENOUGH".equals(element.elementText("err_code"))) {
            Map<String, String> rs = new HashMap<>();
            rs.put("err_code", element.elementText("err_code"));
            rs.put("err_code_des", element.elementText("err_code_des"));
            ResponseVo vo = new ResponseVo("userService", "refresh", rs);
            vo.setCode(ErrorCode.BALANCE_INSUFFICIENT);
            MsgSender.sendMsg2Player(vo, charge.getUserid());
        // 订单已支付
        } else if ("ORDERPAID".equals(element.elementText("err_code"))) {
            Map<String, String> rs = new HashMap<>();
            rs.put("err_code", element.elementText("err_code"));
            rs.put("err_code_des", element.elementText("err_code_des"));
            ResponseVo vo = new ResponseVo("userService", "refresh", rs);
            vo.setCode(ErrorCode.ORDER_WAS_PAID);
            MsgSender.sendMsg2Player(vo, charge.getUserid());
        // 订单已关闭
        } else if ("ORDERCLOSED".equals(element.elementText("err_code"))) {
            Map<String, String> rs = new HashMap<>();
            rs.put("err_code", element.elementText("err_code"));
            rs.put("err_code_des", element.elementText("err_code_des"));
            ResponseVo vo = new ResponseVo("userService", "refresh", rs);
            vo.setCode(ErrorCode.ORDER_WAS_CLOSED);
            MsgSender.sendMsg2Player(vo, charge.getUserid());
        }
        returnXML = "SUCCESS";
    }
    System.out.println("回调结束,返回微信成功信息");
    System.out.println(returnXML);
    try {
        response.getWriter().write(returnXML);
        response.getWriter().flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return returnXML;
}
Also used : User(com.code.server.db.model.User) Element(org.dom4j.Element) Charge(com.code.server.db.model.Charge) IOException(java.io.IOException) ResponseVo(com.code.server.constant.response.ResponseVo) UserBean(com.code.server.constant.game.UserBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with User

use of com.code.server.db.model.User 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 18 with User

use of com.code.server.db.model.User 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 19 with User

use of com.code.server.db.model.User 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 20 with User

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

the class GameUserService method giveOtherMoney.

/**
 * 给人充钱
 *
 * @param msgKey
 * @param rechargeUserId 充值玩家ID
 * @param money          充值数量
 * @return
 */
public int giveOtherMoney(KafkaMsgKey msgKey, Long rechargeUserId, double money) {
    // 充值玩家id
    Long userid = msgKey.getUserId();
    UserBean userBeanOwn = userRedisService.getUserBean(userid);
    if (userBeanOwn == null) {
        return ErrorCode.YOU_HAVE_NOT_LOGIN;
    }
    // 充值玩家钱数
    double userMoney = userRedisService.getUserMoney(userid);
    // 被充值玩家余额
    double rechargeUserMoney = userRedisService.getUserMoney(rechargeUserId);
    // 被充值玩家对象
    UserBean userBean = userRedisService.getUserBean(rechargeUserId);
    if (userMoney - money >= 0 && money > 0) {
        if (userBean != null) {
            userRedisService.addUserMoney(rechargeUserId, money);
            // 减掉充值玩家相应的钱数
            userRedisService.addUserMoney(userid, -money);
            Map<String, Object> results = new HashMap<String, Object>();
            results.put("result", "success");
            ResponseVo vo = new ResponseVo("userService", "giveOtherMoney", results);
            sendMsg(msgKey, vo);
        } else {
            User accepter = userService.getUserByUserId(rechargeUserId);
            if (accepter == null) {
                ResponseVo vo = new ResponseVo("userService", "giveOtherMoney", ErrorCode.NOT_HAVE_THIS_ACCEPTER);
                sendMsg(msgKey, vo);
            } else {
                accepter.setMoney(accepter.getMoney() + money);
                userService.save(accepter);
                // 减掉充值玩家相应的钱数
                userRedisService.setUserMoney(userid, userMoney - money);
                Map<String, Object> results = new HashMap<String, Object>();
                results.put("result", "success");
                ResponseVo vo = new ResponseVo("userService", "giveOtherMoney", results);
                sendMsg(msgKey, vo);
            }
        }
    } else {
        return ErrorCode.NOT_HAVE_MORE_MONEY;
    }
    return 0;
}
Also used : User(com.code.server.db.model.User) ResponseVo(com.code.server.constant.response.ResponseVo)

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