use of com.code.server.constant.db.UserInfo in project summer by foxsugar.
the class WechatPayController method pay.
private void pay(HttpServletRequest request, HttpServletResponse response, String mchKey) {
try {
synchronized (lock) {
Map<String, String> kvm = XMLUtil.parseRequestXmlToMap(request);
if (SignUtils.checkSign(kvm, null, mchKey)) {
if (kvm.get("result_code").equals("SUCCESS")) {
String orderId = kvm.get("out_trade_no");
Charge charge = chargeService.getChargeByOrderid(orderId);
if (0 == charge.getStatus()) {
long userId = charge.getUserid();
// System.out.println("修改订单状态");
// 修改支付订单状态 已支付
charge.setStatus(1);
charge.setCallbacktime(new Date());
UserBean userBeanRedis = userRedisService.getUserBean(userId);
double rmb = charge.getMoney();
double addMoney = charge.getMoney_point();
double before = 0;
double after = 0;
int referee = 0;
long a1 = 0;
long a2 = 0;
long a3 = 0;
if (userBeanRedis != null) {
referee = userBeanRedis.getReferee();
UserInfo userInfo = userBeanRedis.getUserInfo();
if (charge.getChargeType() == 0) {
userInfo.setChargeMoneyNum(userInfo.getChargeMoneyNum() + rmb);
before = userBeanRedis.getMoney();
after = userRedisService.addUserMoney(userId, addMoney);
} else {
userInfo.setChargeGoldNum(userInfo.getChargeGoldNum() + rmb);
before = userBeanRedis.getGold();
after = userRedisService.addUserGold(userId, addMoney);
}
} else {
// 查询玩家
User user = userService.getUserByUserId(userId);
referee = user.getReferee();
UserInfo userInfo = user.getUserInfo();
// 修改玩家货币
if (charge.getChargeType() == 0) {
before = user.getMoney();
user.setMoney(user.getMoney() + addMoney);
after = user.getMoney() + addMoney;
userInfo.setChargeMoneyNum(userInfo.getChargeMoneyNum() + rmb);
} else {
before = user.getGold();
user.setGold(user.getGold() + addMoney);
after = user.getGold() + addMoney;
userInfo.setChargeGoldNum(userInfo.getChargeGoldNum() + rmb);
}
userService.save(user);
}
AgentBean agent1 = RedisManager.getAgentRedisService().getAgentBean(userId);
if (agent1 == null) {
agent1 = RedisManager.getAgentRedisService().getAgentBean(referee);
}
if (agent1 != null) {
a1 = agent1.getId();
a2 = agent1.getParentId();
AgentBean agent2 = RedisManager.getAgentRedisService().getAgentBean(a2);
if (agent2 != null) {
a3 = agent2.getParentId();
}
}
charge.setA1(a1);
charge.setA2(a2);
charge.setA3(a3);
// 保存充值记录
charge.setCharge_before_money(before);
charge.setCharge_after_money(after);
chargeService.save(charge);
// 记录到reids
RedisManager.getLogRedisService().logCharge(1, charge.getChargeType(), charge.getMoney());
Map<String, String> rs = new HashMap<>();
MsgSender.sendMsg2Player(new ResponseVo("userService", "refresh", rs), charge.getUserid());
// 如果在游戏中 刷新
String roomId = RedisManager.getUserRedisService().getRoomId(userId);
if (roomId != null) {
String serverId = RedisManager.getRoomRedisService().getServerId(roomId);
if (serverId != null) {
KafkaMsgKey msgKey = new KafkaMsgKey();
msgKey.setRoomId(roomId);
int partitionId = Integer.valueOf(serverId);
msgKey.setPartition(partitionId);
msgKey.setUserId(userId);
MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
ResponseVo responseVo = new ResponseVo();
responseVo.setService("roomService");
responseVo.setMethod("pushScoreChange");
responseVo.setParams("inner");
msgProducer.send2Partition("roomService", partitionId, msgKey, responseVo);
}
}
// 扣6%的税
if (charge.getChargeType() == 0) {
// double num = charge.getMoney() * 94 / 100;
double num = charge.getMoney();
RedisManager.getAgentRedisService().addRebate(userId, referee, charge.getChargeType(), num, 0);
}
}
logger.info("out_trade_no: " + kvm.get("out_trade_no") + " pay SUCCESS!");
response.getWriter().write("<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[ok]]></return_msg></xml>");
} else {
this.logger.error("out_trade_no: " + kvm.get("out_trade_no") + " result_code is FAIL");
response.getWriter().write("<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[result_code is FAIL]]></return_msg></xml>");
}
} else {
response.getWriter().write("<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[check signature FAIL]]></return_msg></xml>");
this.logger.error("out_trade_no: " + kvm.get("out_trade_no") + " check signature FAIL");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations