Search in sources :

Example 1 with Charge

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

the class GameUserService method bindReferrer.

// 
// public int getRecord(Player player,int type) {
// User user = player.getUser();
// user.getRecord().getRoomRecords().get(type);
// 
// 
// return 0;
// }
// 
// 
public int bindReferrer(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;
    }
    boolean isExist = RpcManager.getInstance().referrerIsExist(referrerId);
    if (!isExist) {
        return ErrorCode.REFERRER_NOT_EXIST;
    }
    double money = 100;
    userBean.setReferee(referrerId);
    RedisManager.getUserRedisService().updateUserBean(userBean.getId(), userBean);
    RedisManager.getUserRedisService().addUserMoney(msgKey.getUserId(), money);
    ResponseVo vo = new ResponseVo("userService", "bindReferrer", 0);
    sendMsg(msgKey, vo);
    // 充值记录
    Charge charge = new Charge();
    charge.setRecharge_source("" + IChargeType.BIND_REFERRER);
    charge.setUserid(userBean.getId());
    charge.setUsername(userBean.getUsername());
    charge.setStatus(1);
    charge.setCreatetime(new Date());
    charge.setMoney_point(money);
    charge.setMoney(money);
    charge.setOrderId("" + IdWorker.getDefaultInstance().nextId());
    SpringUtil.getBean(ChargeService.class).save(charge);
    return 0;
}
Also used : Charge(com.code.server.db.model.Charge) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 2 with Charge

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

the class GameUserService method shareWX.

public int shareWX(KafkaMsgKey msgKey, String game) {
    UserBean userBean = RedisManager.getUserRedisService().getUserBean(msgKey.getUserId());
    if (userBean == null) {
        return ErrorCode.YOU_HAVE_NOT_LOGIN;
    }
    long lastShareTime = userBean.getUserInfo().getLastShareTime();
    long now = System.currentTimeMillis();
    if (DateUtil.isSameDate(lastShareTime, now)) {
        return ErrorCode.CANNOT_SHARE;
    }
    double money = getShareMoney(game);
    int shareCount = userBean.getUserInfo().getShareWXCount();
    // 加钱
    double nowMoney = RedisManager.getUserRedisService().addUserMoney(msgKey.getUserId(), money);
    userBean.setMoney(nowMoney);
    // 分享时间
    userBean.getUserInfo().setLastShareTime(now);
    // 分享次数
    userBean.getUserInfo().setShareWXCount(shareCount + 1);
    // 保存
    RedisManager.getUserRedisService().updateUserBean(userBean.getId(), userBean);
    // 分享记录
    Charge charge = new Charge();
    charge.setOrderId("" + IdWorker.getDefaultInstance().nextId());
    charge.setUsername(userBean.getUsername());
    charge.setMoney(money);
    charge.setMoney_point(money);
    charge.setCreatetime(new Date());
    charge.setCallbacktime(new Date());
    charge.setRecharge_source("" + IChargeType.SHARE);
    charge.setStatus(1);
    chargeService.save(charge);
    ResponseVo vo = new ResponseVo("userService", "shareWX", 0);
    sendMsg(msgKey, vo);
    return 0;
}
Also used : Charge(com.code.server.db.model.Charge) ResponseVo(com.code.server.constant.response.ResponseVo)

Example 3 with Charge

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

the class TestAction method pay.

// @RequestMapping("/index")
// public String index(){
// return "index";
// }
@RequestMapping("/pay")
public void pay(@RequestParam(value = "money", required = true) Double money, @RequestParam(value = "uid", required = true) Long uid, HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
    String orderId = PayUtil.getOrderIdByUUId();
    Charge charge = new Charge();
    charge.setOrderId(orderId);
    charge.setUserid(uid);
    charge.setMoney(money);
    charge.setMoney_point(money * 10);
    charge.setStatus(0);
    chargeService.save(charge);
    logger.info(charge.getOrderId());
    request.setAttribute("Moneys", money + "");
    request.setAttribute("orderId", orderId);
    request.getRequestDispatcher("/WEB-INF/jsp/pay.jsp").forward(request, resp);
}
Also used : Charge(com.code.server.db.model.Charge) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with Charge

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

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

the class GameRpcNewHandler 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()) {
            double nowGold = RedisManager.getUserRedisService().addUserGold(userId, order.getNum());
            user.setGold(nowGold);
            userService.save(user);
        }
    }
    // 充值记录
    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)

Aggregations

Charge (com.code.server.db.model.Charge)10 UserBean (com.code.server.constant.game.UserBean)5 ResponseVo (com.code.server.constant.response.ResponseVo)5 User (com.code.server.db.model.User)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Date (java.util.Date)3 ChargeService (com.code.server.db.Service.ChargeService)2 UserService (com.code.server.db.Service.UserService)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 HashMap (java.util.HashMap)2 Element (org.dom4j.Element)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1