diff --git a/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java b/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java index a2bae762..c2bf4d6d 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java @@ -6,13 +6,10 @@ import com.github.pagehelper.PageInfo; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; -import com.hai.common.security.AESEncodeUtil; import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; import com.hai.common.utils.*; -import com.hai.config.RechargeConfig; import com.hai.entity.*; -import com.hai.enum_type.DiscountUseScope; import com.hai.model.*; import com.hai.service.*; import io.swagger.annotations.Api; @@ -20,14 +17,13 @@ import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import java.math.BigDecimal; -import java.math.RoundingMode; import java.util.*; @Controller @@ -45,20 +41,6 @@ public class OutRechargeOrderController { @Resource private OutRechargePriceService outRechargePriceService; - @Resource - private SecConfigService secConfigService; - - @Resource - private HighUserPayPasswordService highUserPayPasswordService; - - @Resource - private HighDiscountUserRelService highDiscountUserRelService; - - @Resource - private BsConfigService bsConfigService; - - @Resource - private RechargeConfig rechargeConfig; @RequestMapping(value="/addOrder",method = RequestMethod.POST) @ResponseBody @@ -72,169 +54,17 @@ public class OutRechargeOrderController { if (StringUtils.isBlank(object.getString("rechargeContent")) || - StringUtils.isBlank(object.getString("regionId")) || object.getLong("goodsId") == null ) { log.error("addOrder error!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } - OutRechargeOrder outRechargeOrder = new OutRechargeOrder(); - - // 产品id - Long goodsId = object.getLong("goodsId"); - - // 充值内容 - String rechargeContent = object.getString("rechargeContent"); - - // 查询产品详情 - OutRechargePriceModel outRechargePrice = outRechargePriceService.findById(goodsId , null); + object.put("userId" , userInfoModel.getHighUser().getId()); + object.put("userName" , userInfoModel.getHighUser().getName()); + object.put("phone" , userInfoModel.getHighUser().getPhone()); - Map listMap = new HashMap<>(); - listMap.put("productType", "3"); - listMap.put("returnType", 1); - listMap.put("sourceId", goodsId); - - // 查询产品积分抵扣比例 - BsProductDiscount bsProductDiscount = bsConfigService.getProductDiscountByMap(listMap); - - // 判断充值系统是否关闭 - if (!secConfigService.isConfig("RECHARGE" , "1")) { - log.error("addOrder error!"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.RECHARGE_CLOSE, ""); - } - - HighDiscountUserRel highDiscountUserRel = null; - // 判断是否有优惠券 - if (object.getLong("memDiscountId") != null) { - // 卡优惠券信息 - highDiscountUserRel = highDiscountUserRelService.getRelById(object.getLong("memDiscountId")); - if (highDiscountUserRel == null || highDiscountUserRel.getStatus() != 1) { - log.error("HighOrderController --> addOrder() error!", "优惠券状态错误"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券状态错误"); - } - if (!highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type1.getType()) - && !highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type3.getType())) { - log.error("HighOrderController --> addOrder() error!", "无法使用此优惠券"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法使用此优惠券"); - } - } - - // 优惠券抵扣 - if (highDiscountUserRel != null) { - outRechargeOrder.setMemDiscountName(highDiscountUserRel.getHighDiscount().getDiscountName()); - - // 卡卷类型 1:满减 2:抵扣 3:折扣 - if (highDiscountUserRel.getHighDiscount().getDiscountType() == 1) { - // 如果商品支付总额 小于 满减价格 - if (outRechargePrice.getPayPrice().compareTo(highDiscountUserRel.getHighDiscount().getDiscountCondition()) > 1) { - log.error("HighOrderController --> addOrder() error!", "订单未达到满减额度"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "订单未达到"+highDiscountUserRel.getHighDiscount().getDiscountCondition()+"元,无法使用此优惠券"); - } - // 计算支付金额 = 商品支付总额 - 满减额度 - BigDecimal payPrice = outRechargePrice.getPayPrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); - - outRechargeOrder.setDiscountDeductionPrice(highDiscountUserRel.getHighDiscount().getDiscountPrice()); - // 如果总额小于0 - if (payPrice.compareTo(new BigDecimal("0")) < 0) { - outRechargeOrder.setPayRealPrice(new BigDecimal("0")); - } else { - outRechargeOrder.setPayRealPrice(payPrice); - } - } - - // 卡卷类型 1:满减 2:抵扣 3:折扣 - if (highDiscountUserRel.getHighDiscount().getDiscountType() == 2) { - // 计算支付金额 = 商品支付总额 - 满减额度 - BigDecimal payPrice = outRechargePrice.getPayPrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); - outRechargeOrder.setDiscountDeductionPrice(highDiscountUserRel.getHighDiscount().getDiscountPrice()); - - // 如果总额小于0 - if (payPrice.compareTo(new BigDecimal("0")) < 0) { - outRechargeOrder.setPayRealPrice(new BigDecimal("0")); - } else { - outRechargeOrder.setPayRealPrice(payPrice); - } - } - - // 卡卷类型 1:满减 2:抵扣 3:折扣 - if (highDiscountUserRel.getHighDiscount().getDiscountType() == 3) { - BigDecimal discountPrice = highDiscountUserRel.getHighDiscount().getDiscountPrice(); - // 订单总额 * 折扣 - BigDecimal payPrice = outRechargePrice.getPayPrice().multiply(discountPrice); - outRechargeOrder.setDiscountDeductionPrice(outRechargePrice.getPayPrice().subtract(payPrice)); - outRechargeOrder.setPayRealPrice(payPrice); - } - } - - // 判断积分数量是否大于0 - if (object.getLong("integralNum") > 0 && bsProductDiscount.getDiscount().compareTo(new BigDecimal("0")) > 0) { - - - // 判断用户积分是否够 - if (object.getLong("integralNum") > userInfoModel.getHighUser().getGold()) { - log.error("HighOrderController --> addOrder() error!", "积分大于用户积分额度"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "用户积分" + userInfoModel.getHighUser().getGold()); - } - - // 积分抵扣金额 - BigDecimal integralDeductionPrice = BigDecimal.valueOf(object.getLong("integralNum") / 100); - // 最高可抵扣金额 - BigDecimal maxIntegralDeductionPrice = outRechargeOrder.getPayRealPrice().multiply(bsProductDiscount.getDiscount()).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_DOWN); - // 判读积分是否大于限制额度 - if (maxIntegralDeductionPrice.compareTo(integralDeductionPrice) > 0) { - log.error("HighOrderController --> addOrder() error!", "积分大于限制额度"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "订单最大抵扣积分数量" + object.getLong("integralNum")); - } - - // 判断积分抵扣比例是否为100% 并且积分数量是否可以抵扣最后的支付金额 - if (bsProductDiscount.getDiscount().compareTo(new BigDecimal(100)) == 0 && integralDeductionPrice.compareTo(outRechargeOrder.getPayRealPrice()) == 0) { - // 查询用户支付密码 - HighUserPayPassword userPayPassword = highUserPayPasswordService.getDetailByUser(userInfoModel.getHighUser().getId()); - if (userPayPassword == null) { - log.error("orderToPay error!", "未设置支付密码"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_SET_USER_PAY_PWD, ""); - } - if (StringUtils.isBlank(object.getString("password"))) { - log.error("orderToPay error!", "未输入支付密码"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_ENTER_USER_PAY_PWD, ""); - } - // 校验支付密码 - if (!AESEncodeUtil.aesEncrypt(object.getString("password")).equals(userPayPassword.getPassword())) { - log.error("orderToPay error!", ""); - throw ErrorHelp.genException(SysCode.System, ErrorCode.USER_PAY_PWD_ERROR, ""); - } - } - - outRechargeOrder.setIntegralDeductionPrice(integralDeductionPrice); - outRechargeOrder.setPayRealPrice(outRechargeOrder.getPayRealPrice().subtract(outRechargeOrder.getIntegralDeductionPrice())); - - } - - outRechargeOrder.setUserId(userInfoModel.getHighUser().getId()); - outRechargeOrder.setRechargeContent(rechargeContent); - outRechargeOrder.setRegionId(object.getString("regionId")); - outRechargeOrder.setUserName(userInfoModel.getHighUser().getName()); - outRechargeOrder.setRechargeType(outRechargePrice.getRechargeType()); - outRechargeOrder.setUserPhone(userInfoModel.getHighUser().getPhone()); - outRechargeOrder.setOrderNo("RCG" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5)); - outRechargeOrder.setCreateTimed(new Date()); - - // 判断积分支付是否扣完金额 - if (outRechargeOrder.getPayRealPrice().compareTo(new BigDecimal(0)) == 0) { - // 201:充值中 202:充值成功 203:充值失败 204:未充值 - outRechargeOrder.setRechargeStatus(201); - // 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款 - outRechargeOrder.setPayStatus(102); - } else { - // 201:充值中 202:充值成功 203:充值失败 204:未充值 - outRechargeOrder.setRechargeStatus(204); - // 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款 - outRechargeOrder.setPayStatus(101); - } - - outRechargeOrderService.insertOrder(outRechargeOrder); - return ResponseMsgUtil.success(outRechargeOrder); + return ResponseMsgUtil.success(outRechargeOrderService.insertOrder(object)); } catch (Exception e) { log.error("HighOrderController -> addOrder() error!",e); @@ -249,7 +79,15 @@ public class OutRechargeOrderController { public ResponseData getOrderById(@RequestParam(name = "orderId", required = true) Long orderId) { try { - return ResponseMsgUtil.success(outRechargeOrderService.findByOrderId(orderId)); + OutRechargeOrderDetailModel rechargeOrderDetailModel = new OutRechargeOrderDetailModel(); + + OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); + + BeanUtils.copyProperties(order, rechargeOrderDetailModel); + + rechargeOrderDetailModel.setOutRechargePrice(outRechargePriceService.findByGoodsId(order.getGoodsId())); + + return ResponseMsgUtil.success(rechargeOrderDetailModel); } catch (Exception e) { log.error("HighOrderController --> getOrderById() error!", e); @@ -265,7 +103,7 @@ public class OutRechargeOrderController { OutRechargeOrder outRechargeOrder = outRechargeOrderService.findByOrderId(orderId); - if (outRechargeOrder.getRechargeStatus() == 1) { + if (outRechargeOrder.getPayStatus() == 101 && (outRechargeOrder.getRechargeStatus() != 201 || outRechargeOrder.getRechargeStatus() != 202)) { outRechargeOrderService.cancelOrder(orderId); } else { log.error("orderToPay error!"); diff --git a/hai-cweb/src/main/java/com/cweb/controller/WechatController.java b/hai-cweb/src/main/java/com/cweb/controller/WechatController.java index 69ed7e06..80b94913 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/WechatController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/WechatController.java @@ -75,7 +75,7 @@ public class WechatController { final WxMaService wxService = WxMaConfiguration.getMaService(); WxMaJscode2SessionResult session = wxService.jsCode2SessionInfo(code); //保存小程序用户登录的openId及sessionKey信息 - redisUtil.hset(WX_OPENID_SESSION_REDIS,session.getOpenid(),session); + redisUtil.hset(WX_OPENID_SESSION_REDIS, session.getOpenid(), session); JSONObject jo = new JSONObject(); jo.put("openId", session.getOpenid()); return ResponseMsgUtil.success(jo); @@ -88,9 +88,9 @@ public class WechatController { @ResponseBody @ApiOperation(value = "小程序根据手机号登录或注册") public ResponseData loginByPhone(@RequestParam(value = "encryptedData", required = true) String encryptedData, - @RequestParam(value = "iv", required = true) String iv, - @RequestParam(value = "openId", required = true) String openId, - HttpServletRequest request, HttpServletResponse response) { + @RequestParam(value = "iv", required = true) String iv, + @RequestParam(value = "openId", required = true) String openId, + HttpServletRequest request, HttpServletResponse response) { try { log.error("origin encryptedData:" + encryptedData + ";iv:" + iv); //校验openId不能为空 @@ -104,10 +104,10 @@ public class WechatController { } //请求微信api,获取用户session_key以及openId Object skObject = redisUtil.hget(WX_OPENID_SESSION_REDIS, openId); - if (skObject == null){ + if (skObject == null) { throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_LOGIN_ERROR); } - WxMaJscode2SessionResult session = (WxMaJscode2SessionResult)skObject; + WxMaJscode2SessionResult session = (WxMaJscode2SessionResult) skObject; final WxMaService wxService = WxMaConfiguration.getMaService(); WxMaPhoneNumberInfo phoneNoInfo = wxService.getUserService().getPhoneNoInfo(session.getSessionKey(), encryptedData, iv); @@ -145,7 +145,7 @@ public class WechatController { HighUser detailData = highUserService.getDetailDataByUser(user.getId()); detailData.setPassword(null); highUserModel.setHighUser(detailData); - SessionObject so = new SessionObject(user.getPhone(), 1 , highUserModel); + SessionObject so = new SessionObject(user.getPhone(), 1, highUserModel); userCenter.save(request, response, so); return ResponseMsgUtil.success(so); @@ -177,11 +177,11 @@ public class WechatController { throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.REQ_PARAMS_ERROR, ""); } //请求微信api,获取用户session_key以及openId - Object skObject = redisUtil.hget(WX_OPENID_SESSION_REDIS,openId); - if (skObject == null){ + Object skObject = redisUtil.hget(WX_OPENID_SESSION_REDIS, openId); + if (skObject == null) { throw ErrorHelp.genException(SysCode.MiniProgram, ErrorCode.WECHAT_LOGIN_ERROR); } - WxMaJscode2SessionResult session = (WxMaJscode2SessionResult)skObject; + WxMaJscode2SessionResult session = (WxMaJscode2SessionResult) skObject; final WxMaService wxService = WxMaConfiguration.getMaService(); WxMaUserInfo userInfo = wxService.getUserService().getUserInfo(session.getSessionKey(), encryptedData, iv); @@ -217,7 +217,7 @@ public class WechatController { log.error("login error!", "未绑定手机号"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未绑定手机号"); } - SessionObject so = new SessionObject(user.getPhone(), 1 , highUserModel); + SessionObject so = new SessionObject(user.getPhone(), 1, highUserModel); userCenter.save(request, response, so); return ResponseMsgUtil.success(so); @@ -244,38 +244,27 @@ public class WechatController { } } - @RequestMapping(value = "/loginByTel", method = RequestMethod.POST) + @RequestMapping(value = "/loginByTel", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据手机号码登陆") - public ResponseData loginByTel(@RequestBody JSONObject body, + public ResponseData loginByTel(@RequestParam(value = "phone", required = true) String phone, HttpServletRequest request, HttpServletResponse response) { try { - if (body == null - || StringUtils.isBlank(body.getString("phone")) - || StringUtils.isBlank(body.getString("smsCode"))) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); - } // 根据手机号查询用户 - HighUser user = highUserService.findByPhone(body.getString("phone")); - - // 获取手机号验证码 - String phoneSmsCode = (String) redisUtil.get("SMS_"+ body.getString("phone")); + HighUser user = highUserService.findByPhone(phone); // 验证码校验 - if (StringUtils.isNotBlank(phoneSmsCode) && Objects.equals(phoneSmsCode,body.getString("smsCode"))) { - // 定义个人所有数据 - HighUserModel highUserModel = new HighUserModel(); - HighUser detailData = highUserService.getDetailDataByUser(user.getId()); - detailData.setPassword(null); - highUserModel.setHighUser(detailData); - SessionObject so = new SessionObject(user.getPhone(), 1 , highUserModel); - userCenter.save(request, response, so); - return ResponseMsgUtil.success(so); - } + // 定义个人所有数据 + HighUserModel highUserModel = new HighUserModel(); + HighUser detailData = highUserService.getDetailDataByUser(user.getId()); + detailData.setPassword(null); + highUserModel.setHighUser(detailData); + SessionObject so = new SessionObject(user.getPhone(), 1, highUserModel); + userCenter.save(request, response, so); + return ResponseMsgUtil.success(so); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "验证码错误"); } catch (Exception e) { return ResponseMsgUtil.exception(e); diff --git a/hai-cweb/src/main/java/com/cweb/controller/pay/CzOrderController.java b/hai-cweb/src/main/java/com/cweb/controller/pay/CzOrderController.java index 4c18fda8..1b86c2f7 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/pay/CzOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/pay/CzOrderController.java @@ -226,9 +226,9 @@ public class CzOrderController { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); } - // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已退款 5.已取消 - if (order.getRechargeStatus() != 1) { - log.error("orderToPay error!", "无法支付,订单不处于待支付状态"); + // 订单状态 : 订单支付状态 : 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款 + if (order.getPayStatus() != 101) { + log.error("orderToPayByWx error!", "无法支付,订单不处于待支付状态"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); } @@ -307,8 +307,8 @@ public class CzOrderController { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); } - // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已退款 5.已取消 - if (order.getRechargeStatus() != 1) { + // 订单状态 : 订单支付状态 : 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款 + if (order.getPayStatus() != 101) { log.error("hltUnionCardPay error!", "无法支付,订单不处于待支付状态"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); } @@ -349,8 +349,8 @@ public class CzOrderController { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); } - // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已退款 5.已取消 - if (order.getPayStatus() != 1) { + // 订单状态 : 订单支付状态 : 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款 + if (order.getPayStatus() != 101) { log.error("hltUnionCardPay error!", "无法支付,订单不处于待支付状态"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法支付,订单不处于待支付状态"); } diff --git a/hai-cweb/src/main/java/com/cweb/controller/pay/UnionPayController.java b/hai-cweb/src/main/java/com/cweb/controller/pay/UnionPayController.java index d621d2cb..f5b8ea93 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/pay/UnionPayController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/pay/UnionPayController.java @@ -383,27 +383,22 @@ public class UnionPayController { // 转换成JSON格式 JSONObject body = JSONObject.parseObject(paramsStr.substring(0, paramsStr.length() - 1)); -// if (StringUtils.isNotBlank(body.getString("tradetrace"))) { -// OutRechargeOrder order = outRechargeOrderService.findByOrderNo(body.getString("tradetrace")); -// if (order == null) { -// throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); -// } -// -// order.setPaySerialNo(body.getString("wtorderid")); // 支付流水号 -// order.setPayRealPrice(order.getPayPrice()); // 实付金额 -// -// order.setStatus(2); -// order.setPayType(4); -// order.setPayTime(new Date()); // 支付时间 -// if (order.getRechargeType() == 1) { -// JSONObject object = outRechargeOrderService.getMobile(order.getRechargeContent() , order.getOrderPrice().intValue() , order.getOrderNo() , order.getRechargeType()); -// if (object.getInteger("code") != 200) { -// order.setRechargeStatus(1); -// order.setAbnormalMsg(object.getString("message")); -// } -// } -// outRechargeOrderService.updateOrder(order); -// } + if (StringUtils.isNotBlank(body.getString("tradetrace"))) { + OutRechargeOrder order = outRechargeOrderService.findByOrderNo(body.getString("tradetrace")); + if (order == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息"); + } + + order.setPaySerialNo(body.getString("wtorderid")); // 支付流水号 + order.setPayRealPrice(order.getPayRealPrice()); // 实付金额 + + order.setPayStatus(102); + order.setRechargeStatus(204); + order.setPayType(4); + order.setPayTime(new Date()); // 支付时间 + outRechargeOrderService.updateOrder(order); + outRechargeOrderService.pollRequest(order); + } } BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); diff --git a/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java b/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java index 09f645b5..f49e434c 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java +++ b/hai-schedule/src/main/java/com/hai/schedule/HighOrderSchedule.java @@ -6,9 +6,11 @@ import com.hai.config.QianZhuConfig; import com.hai.config.WxOrderConfig; import com.hai.entity.HighChildOrder; import com.hai.entity.HighOrder; +import com.hai.entity.OutRechargeChildOrder; import com.hai.entity.OutRechargeOrder; import com.hai.model.OrderRefundModel; import com.hai.service.HighOrderService; +import com.hai.service.OutRechargeChildOrderService; import com.hai.service.OutRechargeOrderService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,6 +40,9 @@ public class HighOrderSchedule { @Resource private OutRechargeOrderService outRechargeOrderService; + @Resource + private OutRechargeChildOrderService rechargeChildOrderService; + /** * @Author 胡锐 * @Description 取消订单 15分钟 @@ -79,6 +84,57 @@ public class HighOrderSchedule { } } + /** + * @Author Sum1Dream + * @name cancelOrder.java + * @Description // 定时发起 + * @Date 14:18 2022/5/31 + * @Param [] + * @return void + */ + @Scheduled(cron="0 0/1 * * * ?") //每1分钟执行一次 + public void initRechargeOrder() { + Map map = new HashMap<>(); + map.put("status" , String.valueOf(102)); + map.put("rechargeStatus" , String.valueOf(204)); + List orderList = outRechargeOrderService.getListRechargeOrder(map); + + if (orderList != null && orderList.size() > 0) { + for (OutRechargeOrder order : orderList) { + try { + // 查询充值子订单 + Map childOrderMap = new HashMap<>(); + + childOrderMap.put("parent_order_id" , order.getId()); + childOrderMap.put("status" , 102); + + List childOrderList = rechargeChildOrderService.getListRechargeChildOrder(childOrderMap); + + if (childOrderList.size() == 0) { + Date rechargeTime = order.getCreateTimed(); + Date currentTime = new Date(); + int hours = (int) ((currentTime.getTime() - rechargeTime.getTime()) / (1000 * 60 * 60)); + + // 判断快充 并且 充值时间小于6 + if (order.getRechargeType() == 1 && hours < 6) { + outRechargeOrderService.pollRequest(order); + return; + } + // 判断慢充 并且 充值时间小于72 + if (order.getRechargeType() == 2 && hours < 72) { + outRechargeOrderService.pollRequest(order); + return; + } + outRechargeOrderService.rechargeOrderToRefund(order.getId()); + + } + } catch (Exception e) { + log.error("HighCouponSchedule --> expiredCoupon() error!", e); + } + } + } + } + /** * @Author 胡锐 * @Description 处理话费充值订单 diff --git a/hai-service/src/main/java/com/hai/enum_type/OperatorEnum.java b/hai-service/src/main/java/com/hai/enum_type/OperatorEnum.java new file mode 100644 index 00000000..5dddc084 --- /dev/null +++ b/hai-service/src/main/java/com/hai/enum_type/OperatorEnum.java @@ -0,0 +1,43 @@ +package com.hai.enum_type; + +import java.util.Objects; + +/** + * 订单状态 + * @author hurui + */ +public enum OperatorEnum { + type1(1 , "电信运营商"), + type2(2 , "移动运营商"), + type3(3 , "联通运营商"), + ; + + private Integer type; + private String name; + + OperatorEnum(int type , String name) { + this.type = type; + this.name = name; + } + public static String getNameByType(Integer type) { + for (OperatorEnum ele : values()) { + if(Objects.equals(type,ele.getType())) return ele.getName(); + } + return null; + } + public Integer getType() { + return type; + } + + public void setType(Integer type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/hai-service/src/main/java/com/hai/model/OutRechargeOrderDetailModel.java b/hai-service/src/main/java/com/hai/model/OutRechargeOrderDetailModel.java new file mode 100644 index 00000000..cf739e09 --- /dev/null +++ b/hai-service/src/main/java/com/hai/model/OutRechargeOrderDetailModel.java @@ -0,0 +1,17 @@ +package com.hai.model; + +import com.hai.entity.OutRechargeOrder; +import com.hai.entity.OutRechargePrice; + +public class OutRechargeOrderDetailModel extends OutRechargeOrder { + // 产品模型 + private OutRechargePrice outRechargePrice; + + public OutRechargePrice getOutRechargePrice() { + return outRechargePrice; + } + + public void setOutRechargePrice(OutRechargePrice outRechargePrice) { + this.outRechargePrice = outRechargePrice; + } +} diff --git a/hai-service/src/main/java/com/hai/model/UserModel.java b/hai-service/src/main/java/com/hai/model/UserModel.java index 2ab4c6d4..3f85b06d 100644 --- a/hai-service/src/main/java/com/hai/model/UserModel.java +++ b/hai-service/src/main/java/com/hai/model/UserModel.java @@ -20,6 +20,9 @@ public class UserModel { // 待支付数量 private Integer unpaid; + // 充值订单待支付数量 + private Integer rechargeOrderNum; + // 是否设置支付密码 private Boolean isSetPayPwd; @@ -114,4 +117,12 @@ public class UserModel { public void setIsSetHltCard(Boolean setHltCard) { isSetHltCard = setHltCard; } + + public Integer getRechargeOrderNum() { + return rechargeOrderNum; + } + + public void setRechargeOrderNum(Integer rechargeOrderNum) { + this.rechargeOrderNum = rechargeOrderNum; + } } diff --git a/hai-service/src/main/java/com/hai/service/OutRechargeOrderService.java b/hai-service/src/main/java/com/hai/service/OutRechargeOrderService.java index f46d8caf..d9e7577e 100644 --- a/hai-service/src/main/java/com/hai/service/OutRechargeOrderService.java +++ b/hai-service/src/main/java/com/hai/service/OutRechargeOrderService.java @@ -49,7 +49,7 @@ public interface OutRechargeOrderService { * @Param [outRechargeOrder] * @return void **/ - void insertOrder(OutRechargeOrder outRechargeOrder) throws Exception; + OutRechargeOrder insertOrder(JSONObject object) throws Exception; /*** * @Author Sum1Dream @@ -165,4 +165,14 @@ public interface OutRechargeOrderService { */ void pollRequest(OutRechargeOrder outRechargeOrder) throws Exception; + /** + * @Author Sum1Dream + * @name rechargeOrderNum.java + * @Description // 查询充值订单待支付数量 + * @Date 17:49 2022/5/30 + * @Param [java.lang.Long] + * @return java.lang.Integer + */ + Integer rechargeOrderNum(Long userId); + } diff --git a/hai-service/src/main/java/com/hai/service/OutRechargePriceService.java b/hai-service/src/main/java/com/hai/service/OutRechargePriceService.java index eb69e260..7539e09e 100644 --- a/hai-service/src/main/java/com/hai/service/OutRechargePriceService.java +++ b/hai-service/src/main/java/com/hai/service/OutRechargePriceService.java @@ -37,6 +37,15 @@ public interface OutRechargePriceService { **/ OutRechargePriceModel findById(Long id , Integer platformId); + /** + * @Author Sum1Dream + * @Description //查询详情 Administrator + * @Date 17:40 2021/6/12 + * @Param [id] + * @return com.hai.entity.OutRechargePrice + **/ + OutRechargePrice findByGoodsId(Long goodsId); + /** * @Author Sum1Dream * @Description //新增 Administrator diff --git a/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java index b267c21f..142dd10a 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighUserServiceImpl.java @@ -40,6 +40,9 @@ public class HighUserServiceImpl implements HighUserService { @Resource private HighUserCouponService highUserCouponService; + @Resource + private OutRechargeOrderService outRechargeOrderService; + @Resource private HighUserCardService highUserCardService; @@ -98,6 +101,7 @@ public class HighUserServiceImpl implements HighUserService { } user.setUnusedCouponNum(highUserCouponService.getCouponList(userId, 1).size()); //未使用卡卷数量 user.setUnpaid(highOrderService.countOrderByUserId(userId , 1)); + user.setRechargeOrderNum(outRechargeOrderService.rechargeOrderNum(userId)); user.setUnusedDiscount(highOrderService.countUnusedDiscountByUserId(userId , 1)); user.setIsSetPayPwd(highUserPayPasswordService.isSetPayPwd(userId)); user.setIsSetHltCard(highUserCardService.isBindHtlCard(userId)); @@ -218,7 +222,7 @@ public class HighUserServiceImpl implements HighUserService { } @Override - @Transactional(propagation= Propagation.REQUIRES_NEW) + @Transactional(propagation= Propagation.REQUIRED) public void goldHandle(Long userId, Integer goldNum, Integer goldType, Integer resType, Long resId) { // 查询用户信息 HighUser user = highUserMapper.selectByPrimaryKey(userId); diff --git a/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java index 8589aa60..6c3987b5 100644 --- a/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/OutRechargeOrderServiceImpl.java @@ -7,12 +7,15 @@ import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; +import com.hai.common.security.AESEncodeUtil; import com.hai.common.utils.*; import com.hai.config.*; import com.hai.dao.HighGasOrderPushMapper; import com.hai.dao.OutRechargeOrderMapper; import com.hai.dao.OutRechargeOrderMapperExt; import com.hai.entity.*; +import com.hai.enum_type.DiscountUseScope; +import com.hai.enum_type.OperatorEnum; import com.hai.enum_type.OrderPushType; import com.hai.enum_type.RechargePayType; import com.hai.model.*; @@ -28,12 +31,14 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.RequestParam; import javax.annotation.Resource; import java.math.BigDecimal; +import java.math.RoundingMode; import java.text.SimpleDateFormat; import java.util.*; @@ -76,6 +81,17 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { @Resource private BsRequestRecordService bsRequestRecordService; + @Resource + private BsConfigService bsConfigService; + + @Resource + private SecConfigService secConfigService; + + @Resource + private HighUserPayPasswordService highUserPayPasswordService; + + + @Override public List getListRechargeOrder(Map map) { OutRechargeOrderExample example = new OutRechargeOrderExample(); @@ -105,6 +121,13 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { criteria.andUserPhoneEqualTo(MapUtils.getString(map, "phone")); } + if (MapUtils.getInteger(map, "status") != null) { + criteria.andPayStatusEqualTo(MapUtils.getInteger(map, "status")); + } + + if (MapUtils.getInteger(map, "rechargeStatus") != null) { + criteria.andRechargeStatusEqualTo(MapUtils.getInteger(map, "rechargeStatus")); + } if (StringUtils.isNotBlank(map.get("payTimeS")) && StringUtils.isNotBlank(map.get("payTimeE"))) { criteria.andPayTimeBetween( @@ -134,8 +157,167 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { } @Override - @Transactional(propagation= Propagation.REQUIRES_NEW) - public void insertOrder(OutRechargeOrder outRechargeOrder) throws Exception { + @Transactional( + isolation = Isolation.SERIALIZABLE, + propagation= Propagation.REQUIRES_NEW) + public OutRechargeOrder insertOrder(JSONObject object) throws Exception { + + OutRechargeOrder outRechargeOrder = new OutRechargeOrder(); + + + HighUser user = highUserService.findByUserId(object.getLong("userId")); + + // 产品id + Long goodsId = object.getLong("goodsId"); + + // 充值内容 + String rechargeContent = object.getString("rechargeContent"); + + // 查询产品详情 + OutRechargePriceModel outRechargePrice = outRechargePriceService.findById(goodsId , null); + + Map listMap = new HashMap<>(); + listMap.put("productType", "3"); + listMap.put("returnType", 1); + listMap.put("sourceId", goodsId); + + // 查询产品积分抵扣比例 + BsProductDiscount bsProductDiscount = bsConfigService.getProductDiscountByMap(listMap); + + // 判断充值系统是否关闭 + if (!secConfigService.isConfig("RECHARGE" , "1")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.RECHARGE_CLOSE, ""); + } + + HighDiscountUserRel highDiscountUserRel = null; + // 判断是否有优惠券 + if (object.getLong("memDiscountId") != null) { + outRechargeOrder.setMemDiscountId(object.getLong("memDiscountId")); + // 卡优惠券信息 + highDiscountUserRel = highDiscountUserRelService.getRelById(object.getLong("memDiscountId")); + if (highDiscountUserRel == null || highDiscountUserRel.getStatus() != 1) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券状态错误"); + } + if (!highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type1.getType()) + && !highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type3.getType())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法使用此优惠券"); + } + } else { + outRechargeOrder.setPayRealPrice(outRechargePrice.getPayPrice()); + } + + // 优惠券抵扣 + if (highDiscountUserRel != null) { + + outRechargeOrder.setMemDiscountName(highDiscountUserRel.getHighDiscount().getDiscountName()); + BigDecimal payPrice = new BigDecimal(0); + + // 卡卷类型 1:满减 2:抵扣 3:折扣 + if (highDiscountUserRel.getHighDiscount().getDiscountType() == 1) { + // 如果商品支付总额 小于 满减价格 + if (outRechargePrice.getRechargePrice().compareTo(highDiscountUserRel.getHighDiscount().getDiscountCondition()) > 0) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "订单未达到"+highDiscountUserRel.getHighDiscount().getDiscountCondition()+"元,无法使用此优惠券"); + } + // 计算支付金额 = 商品充值总额 - 满减额度 + payPrice = outRechargePrice.getRechargePrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); + outRechargeOrder.setDiscountDeductionPrice(highDiscountUserRel.getHighDiscount().getDiscountPrice()); + + } + + // 卡卷类型 1:满减 2:抵扣 3:折扣 + if (highDiscountUserRel.getHighDiscount().getDiscountType() == 2) { + // 计算支付金额 = 商品充值总额 - 满减额度 + payPrice = outRechargePrice.getRechargePrice().subtract(highDiscountUserRel.getHighDiscount().getDiscountPrice()); + outRechargeOrder.setDiscountDeductionPrice(highDiscountUserRel.getHighDiscount().getDiscountPrice()); + + } + + // 卡卷类型 1:满减 2:抵扣 3:折扣 + if (highDiscountUserRel.getHighDiscount().getDiscountType() == 3) { + BigDecimal discountPrice = highDiscountUserRel.getHighDiscount().getDiscountPrice(); + // 订单总额 * 折扣 + payPrice = outRechargePrice.getRechargePrice().multiply(discountPrice); + outRechargeOrder.setDiscountDeductionPrice(outRechargePrice.getRechargePrice().subtract(payPrice)); + outRechargeOrder.setPayRealPrice(payPrice); + } + + // 如果总额小于0 + if (payPrice.compareTo(new BigDecimal("0")) < 0) { + outRechargeOrder.setPayRealPrice(new BigDecimal("0")); + } else { + outRechargeOrder.setPayRealPrice(payPrice); + } + } + + // 判断积分数量是否大于0 + if (object.getLong("integralNum") > 0 && bsProductDiscount.getDiscount().compareTo(new BigDecimal("0")) > 0) { + + // 判断用户积分是否够 + if (object.getLong("integralNum") > user.getGold()) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户积分不足"); + } + + // 积分抵扣金额 + BigDecimal integralDeductionPrice = object.getBigDecimal("integralNum").divide(new BigDecimal(100).setScale(2, RoundingMode.HALF_DOWN)); + // 最高可抵扣金额 + BigDecimal maxIntegralDeductionPrice = outRechargeOrder.getPayRealPrice().multiply(bsProductDiscount.getDiscount()).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_DOWN); + // 判读积分是否大于限制额度 + if (maxIntegralDeductionPrice.compareTo(integralDeductionPrice) < 0) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "订单最大抵扣积分金额:" + maxIntegralDeductionPrice); + } + + // 判断积分抵扣比例是否为100% 并且积分数量是否可以抵扣最后的支付金额 + if (bsProductDiscount.getDiscount().compareTo(new BigDecimal(100)) == 0 && integralDeductionPrice.compareTo(outRechargeOrder.getPayRealPrice()) == 0) { + // 查询用户支付密码 + HighUserPayPassword userPayPassword = highUserPayPasswordService.getDetailByUser(object.getLong("userId")); + if (userPayPassword == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_SET_USER_PAY_PWD, ""); + } + if (StringUtils.isBlank(object.getString("password"))) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_ENTER_USER_PAY_PWD, ""); + } + // 校验支付密码 + if (!AESEncodeUtil.aesEncrypt(object.getString("password")).equals(userPayPassword.getPassword())) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.USER_PAY_PWD_ERROR, ""); + } + } + + outRechargeOrder.setIntegralDeductionPrice(integralDeductionPrice); + outRechargeOrder.setPayRealPrice(outRechargeOrder.getPayRealPrice().subtract(outRechargeOrder.getIntegralDeductionPrice())); + + } + + outRechargeOrder.setUserId(object.getLong("userId")); + outRechargeOrder.setIntegralNum(object.getBigDecimal("integralNum")); + outRechargeOrder.setRechargeContent(rechargeContent); + outRechargeOrder.setCompanyId(outRechargePrice.getCompanyId()); + outRechargeOrder.setUserName(object.getString("username")); + outRechargeOrder.setRechargeType(outRechargePrice.getRechargeType()); + outRechargeOrder.setUserPhone(object.getString("phone")); + outRechargeOrder.setOrderNo("RCG" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5)); + outRechargeOrder.setCreateTimed(new Date()); + outRechargeOrder.setGoodsId(goodsId); + outRechargeOrder.setType(1); + outRechargeOrder.setOrderPrice(outRechargePrice.getRechargePrice()); + outRechargeOrder.setOperatorName(OperatorEnum.getNameByType(outRechargePrice.getOperatorType())); + outRechargeOrder.setOperatorType(outRechargePrice.getOperatorType()); + + + // 判断积分支付是否扣完金额 + if (outRechargeOrder.getPayRealPrice().compareTo(new BigDecimal(0)) == 0) { + // 201:充值中 202:充值成功 203:充值失败 204:未充值 + outRechargeOrder.setRechargeStatus(204); + // 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款 + outRechargeOrder.setPayStatus(102); + outRechargeOrder.setPayTime(new Date()); + outRechargeOrder.setPaySerialNo("22" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5)); + } else { + // 201:充值中 202:充值成功 203:充值失败 204:未充值 + outRechargeOrder.setRechargeStatus(204); + // 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款 + outRechargeOrder.setPayStatus(101); + } + // 使用优惠券 if (outRechargeOrder.getMemDiscountId() != null) { HighDiscountUserRel discountUserRel = highDiscountUserRelService.getRelById(outRechargeOrder.getMemDiscountId()); @@ -147,16 +329,22 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { code.setStatus(3); highDiscountAgentCodeService.updateCode(code); } + + if (outRechargeOrder.getIntegralNum() != null) { + highUserService.goldHandle(outRechargeOrder.getUserId(), outRechargeOrder.getIntegralNum().intValue(), 2, 2, outRechargeOrder.getId()); + } + outRechargeOrderMapper.insert(outRechargeOrder); - if (outRechargeOrder.getRechargeStatus() == 201 && outRechargeOrder.getPayStatus() == 102) { + if (outRechargeOrder.getPayStatus() == 102) { pollRequest(outRechargeOrder); } + return outRechargeOrder; + } @Override - @Transactional(propagation= Propagation.REQUIRES_NEW) public void updateOrder(OutRechargeOrder outRechargeOrder) { outRechargeOrderMapper.updateByPrimaryKey(outRechargeOrder); } @@ -366,13 +554,14 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { } order.setPaySerialNo(consumptionResult.getString("orderId")); // 支付流水号 order.setPayRealPrice(order.getPayRealPrice()); // 实付金额 - outRechargeOrderService.pollRequest(order); order.setPayStatus(102); - order.setRechargeStatus(201); + order.setRechargeStatus(204); order.setLaborUnionCard(userCard.getCardNo()); order.setPayType(3); order.setPayTime(new Date()); // 支付时间 updateOrder(order); + outRechargeOrderService.pollRequest(order); + } @Override @@ -387,7 +576,6 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { @Override - @Transactional(propagation= Propagation.REQUIRES_NEW) public void rechargeOrderToRefund(Long orderId) throws Exception { OutRechargeOrder order = outRechargeOrderService.findByOrderId(orderId); @@ -396,78 +584,96 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法退款,订单不处于已支付状态"); } - // 微信退款 - if (order.getPayType() == 1) { - Map param = new HashMap<>(); - param.put("appid", "wx637bd6f7314daa46"); - param.put("mch_id", "1289663601"); - param.put("sub_mch_id" , "1614670195"); - param.put("nonce_str", WxUtils.makeNonStr()); - param.put("transaction_id", order.getPaySerialNo()); - param.put("out_refund_no", "HFR"+new Date().getTime()); - param.put("total_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue())); - param.put("refund_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue())); - param.put("sign_type", "HMAC-SHA256"); - - String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); - param.put("sign", signStr); - - String resultXmL = doRefundRequest(param.get("mch_id"), WxUtils.mapToXml(param)); - OrderRefundModel orderRefundModel = XmlUtil.getObjectFromXML(resultXmL, OrderRefundModel.class); - if(orderRefundModel.getResult_code().equals("SUCCESS")) { - order.setPayStatus(105); - order.setRechargeStatus(203); - order.setRefundTime(new Date()); - order.setOutRefundNo(orderRefundModel.getOut_refund_no()); - order.setRefundId(orderRefundModel.getRefund_id()); - order.setRefundFee(new BigDecimal(orderRefundModel.getRefund_fee()).divide(new BigDecimal("100"))); - outRechargeOrderService.updateOrder(order); - } else { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "退款失败!错误代码:"+orderRefundModel.getErr_code()+",错误描述"+orderRefundModel.getErr_code_des()); - } + // 充值状态:201:充值中 202:充值成功 203:充值失败 204:未充值 + if (order.getRechargeStatus() == 201) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法退款,订单处于充值中状态"); } - // 工会卡退款 - if (order.getPayType() == 2) { - JSONObject jsonObject = HuiLianTongUnionCardConfig.refund( "HFR"+new Date().getTime() , order.getOrderNo()); - - if (jsonObject == null) { - jsonObject = HuiLianTongUnionCardConfig.refund( "HFR"+new Date().getTime() , order.getOrderNo()); + // 1:支付宝 2:微信 3:汇联通工会卡 4:银联 5:银联分期 + if (order.getPayType() == null) { + // 退还积分 + if (order.getIntegralNum() != null) { + highUserService.goldHandle(order.getUserId(), order.getIntegralNum().intValue(), 1, 3, order.getId()); + if (order.getPayRealPrice().compareTo(new BigDecimal(0)) == 0) { + order.setPayStatus(105); + order.setRechargeStatus(203); + order.setRefundTime(new Date()); + outRechargeOrderService.updateOrder(order); + } + } + } else { + // 微信退款 + if (order.getPayType() == 2) { + Map param = new HashMap<>(); + param.put("appid", "wx637bd6f7314daa46"); + param.put("mch_id", "1289663601"); + param.put("sub_mch_id" , "1614670195"); + param.put("nonce_str", WxUtils.makeNonStr()); + param.put("transaction_id", order.getPaySerialNo()); + param.put("out_refund_no", "HFR"+new Date().getTime()); + param.put("total_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue())); + param.put("refund_fee", String.valueOf(order.getPayRealPrice().multiply(new BigDecimal("100")).intValue())); + param.put("sign_type", "HMAC-SHA256"); + + String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); + param.put("sign", signStr); + + String resultXmL = doRefundRequest(param.get("mch_id"), WxUtils.mapToXml(param)); + OrderRefundModel orderRefundModel = XmlUtil.getObjectFromXML(resultXmL, OrderRefundModel.class); + if(orderRefundModel.getResult_code().equals("SUCCESS")) { + order.setPayStatus(105); + order.setRechargeStatus(203); + order.setRefundTime(new Date()); + order.setOutRefundNo(orderRefundModel.getOut_refund_no()); + order.setRefundId(orderRefundModel.getRefund_id()); + order.setRefundFee(new BigDecimal(orderRefundModel.getRefund_fee()).divide(new BigDecimal("100"))); + outRechargeOrderService.updateOrder(order); + } else { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "退款失败!错误代码:"+orderRefundModel.getErr_code()+",错误描述"+orderRefundModel.getErr_code_des()); + } } - JSONObject dataObject = HuiLianTongUnionCardConfig.resolveResponse(jsonObject.getString("data")); + // 工会卡退款 + if (order.getPayType() == 3) { + JSONObject jsonObject = HuiLianTongUnionCardConfig.refund( "HFR"+new Date().getTime() , order.getOrderNo()); + + if (jsonObject == null) { + jsonObject = HuiLianTongUnionCardConfig.refund( "HFR"+new Date().getTime() , order.getOrderNo()); + } + + JSONObject dataObject = HuiLianTongUnionCardConfig.resolveResponse(jsonObject.getString("data")); - if (dataObject.getBoolean("success") || Objects.equals(dataObject.getString("message"), "原交易已撤销,不可再次操作")) { + if (dataObject.getBoolean("success") || Objects.equals(dataObject.getString("message"), "原交易已撤销,不可再次操作")) { + order.setPayStatus(105); + order.setRechargeStatus(203); + order.setRefundTime(new Date()); + order.setOutRefundNo("HFR"+new Date().getTime() ); + order.setRefundFee(order.getPayRealPrice()); + order.setRefundId(dataObject.getString("orderId")); + outRechargeOrderService.updateOrder(order); + + } else { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, dataObject.getString("message")); + } + } + + // 银联退款 + if (order.getPayType() == 4) { + // 订单退款 + JSONObject refund = UnionPayConfig.zwrefund(UnionPayConfig.MER_ID2, UnionPayConfig.TERM_ID2, order.getOrderNo(), order.getPaySerialNo(), order.getPayRealPrice().multiply(new BigDecimal("100")).longValue()); + if (!refund.getString("resultcode").equals("W6")) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, refund.getString("returnmsg")); + } order.setPayStatus(105); order.setRechargeStatus(203); order.setRefundTime(new Date()); - order.setOutRefundNo("HFR"+new Date().getTime() ); + order.setOutRefundNo(refund.getString("oriwtorderid")); order.setRefundFee(order.getPayRealPrice()); - order.setRefundId(dataObject.getString("orderId")); outRechargeOrderService.updateOrder(order); - - } else { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, dataObject.getString("message")); } } - - // 银联退款 - if (order.getPayType() == 4) { - // 订单退款 - JSONObject refund = UnionPayConfig.zwrefund(UnionPayConfig.MER_ID2, UnionPayConfig.TERM_ID2, order.getOrderNo(), order.getPaySerialNo(), order.getPayRealPrice().multiply(new BigDecimal("100")).longValue()); - if (!refund.getString("resultcode").equals("W6")) { - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, refund.getString("returnmsg")); - } - order.setPayStatus(105); - order.setRechargeStatus(203); - order.setRefundTime(new Date()); - order.setOutRefundNo(refund.getString("oriwtorderid")); - order.setRefundFee(order.getPayRealPrice()); - outRechargeOrderService.updateOrder(order); - } - if (order.getMemDiscountId() != null) { HighDiscountUserRel rel = highDiscountUserRelService.getRelById(order.getMemDiscountId()); if (rel != null) { @@ -514,7 +720,6 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { } @Override - @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public void pollRequest(OutRechargeOrder outRechargeOrder) throws Exception { // 查询充值产品 @@ -552,14 +757,20 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { for (String s : rechargePlatform) { // 尖椒充值 - if (s.equals("1") && type == 2) { + if (s.equals("1") && (type == 2 || type == 0)) { object.put("out_order_id" ,orderNo ); object.put("amount" , outRechargePrice.getRechargePrice()); object.put("mobile" , outRechargeOrder.getRechargeContent()); if (outRechargePrice.getRechargeType() == 1) { object.put("is_fast" , 1); } - RechargeConfig.rechargeOrderByJj(object); + JSONObject returnObject = RechargeConfig.rechargeOrderByJj(object); + object.put("return_content" , returnObject); + if (returnObject != null && returnObject.getLong("code") == 200) { + childOrder.setStatus(102); + } else { + childOrder.setStatus(103); + } rechargePlatformType = 1; break; } @@ -567,7 +778,13 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { object.put("out_trade_num" , orderNo); object.put("product_id" , outRechargePrice.getGoodsId()); object.put("mobile" , outRechargeOrder.getRechargeContent()); - RechargeConfig.rechargeOrderByLy(object); + JSONObject returnObject = RechargeConfig.rechargeOrderByLy(object); + object.put("return_content" , returnObject); + if (returnObject != null && returnObject.getLong("errno") == 0) { + childOrder.setStatus(102); + } else { + childOrder.setStatus(103); + } rechargePlatformType = 2; break; } @@ -576,7 +793,6 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { childOrder.setOrderNo(orderNo); childOrder.setCreateTime(new Date()); childOrder.setParentOrderId(outRechargeOrder.getId()); - childOrder.setStatus(102); childOrder.setRechargePlatform(rechargePlatformType); childOrder.setUpdateTime(new Date()); outRechargeChildOrderService.insertOrder(childOrder); @@ -586,7 +802,7 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { requestRecord.setCreateTime(new Date()); requestRecord.setUpdateTime(new Date()); requestRecord.setOrderNo(orderNo); - requestRecord.setRequestContent(String.valueOf(object)); + requestRecord.setRequestContent(object.toJSONString()); requestRecord.setOperatorId(0L); requestRecord.setOperatorName("系统生成"); requestRecord.setSourceId(childOrder.getId().toString()); @@ -594,6 +810,21 @@ public class OutRechargeOrderServiceImpl implements OutRechargeOrderService { bsRequestRecordService.insertRequestRecord(requestRecord); + // 判断是否充值提交成功 + if (childOrder.getStatus() == 102) { + outRechargeOrder.setRechargeStatus(201); + outRechargeOrderService.updateOrder(outRechargeOrder); + } + + } + + @Override + public Integer rechargeOrderNum(Long userId) { + OutRechargeOrderExample example = new OutRechargeOrderExample(); + OutRechargeOrderExample.Criteria criteria = example.createCriteria(); + criteria.andUserIdEqualTo(userId); + criteria.andPayStatusEqualTo(101); + return outRechargeOrderMapper.selectByExample(example).size(); } } diff --git a/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java index e356627e..67e3cb45 100644 --- a/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/OutRechargePriceServiceImpl.java @@ -90,6 +90,22 @@ public class OutRechargePriceServiceImpl implements OutRechargePriceService { return outRechargePriceModel; } + @Override + public OutRechargePrice findByGoodsId(Long goodsId) { + + OutRechargePriceExample example = new OutRechargePriceExample(); + OutRechargePriceExample.Criteria criteria = example.createCriteria(); + + criteria.andIdEqualTo(goodsId).andStatusEqualTo(1); + + List list = outRechargePriceMapper.selectByExample(example); + + if (list.size() > 0) { + return list.get(0); + } + + return null; + } @Override @Transactional(propagation = Propagation.REQUIRES_NEW) diff --git a/hai-service/src/main/java/com/hai/service/pay/impl/RechargeOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/pay/impl/RechargeOrderServiceImpl.java index a9675089..242873dd 100644 --- a/hai-service/src/main/java/com/hai/service/pay/impl/RechargeOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/pay/impl/RechargeOrderServiceImpl.java @@ -55,8 +55,8 @@ public class RechargeOrderServiceImpl implements PayService { @Override - @Transactional(propagation= Propagation.REQUIRES_NEW) public void paySuccess(Map map, String payType) throws Exception { + if (payType.equals("Alipay")) { // 支付宝支付 todo 暂未开发 return; @@ -64,11 +64,23 @@ public class RechargeOrderServiceImpl implements PayService { if (payType.equals("WechatPay")) { // 查询订单信息 OutRechargeOrder order = outRechargeOrderService.findByOrderNo(map.get("out_trade_no")); -// if (order != null && order.getStatus() == 1) { -// order.setPaySerialNo(map.get("transaction_id")); // 支付流水号 -// order.setPayRealPrice(new BigDecimal(map.get("total_fee")).divide(new BigDecimal("100"))); // 实付金额 -// order.setPayTime(new Date()); // 支付时间 -// order.setStatus(2); // 订单状态 : 1.待支付 2.已支付 3.已完成 4.已取消 5.已退款 + // 推送订单记录 + HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); + highGasOrderPush.setType(OrderPushType.type2.getType()); + highGasOrderPush.setOrderNo(order.getOrderNo()); + highGasOrderPush.setCreateTime(new Date()); + highGasOrderPush.setRequestContent(order.getOrderNo()); + highGasOrderPush.setReturnContent(String.valueOf(map)); + highGasOrderPushMapper.insert(highGasOrderPush); + if (order.getPayStatus() == 101) { + order.setPaySerialNo(map.get("transaction_id")); // 支付流水号 + order.setPayRealPrice(new BigDecimal(map.get("total_fee")).divide(new BigDecimal("100"))); // 实付金额 + order.setPayTime(new Date()); // 支付时间 + // 订单支付状态 : 101.待支付 102.已支付 100.已完成 104.已取消 105.已退款 + order.setPayStatus(102); + order.setRechargeStatus(204); + order.setPayType(2); + outRechargeOrderService.updateOrder(order); // if (order.getRechargeType() == 1) { // JSONObject object = outRechargeOrderService.getMobile(order.getRechargeContent() , order.getOrderPrice().intValue() , order.getOrderNo() , order.getRechargeType()); // if (object.getInteger("code") != 200) { @@ -76,16 +88,9 @@ public class RechargeOrderServiceImpl implements PayService { // order.setAbnormalMsg(object.getString("message")); // } // } -// outRechargeOrderService.updateOrder(order); -// // 推送订单记录 -// HighGasOrderPush highGasOrderPush = new HighGasOrderPush(); -// highGasOrderPush.setType(OrderPushType.type2.getType()); -// highGasOrderPush.setOrderNo(order.getOrderNo()); -// highGasOrderPush.setCreateTime(new Date()); -// highGasOrderPush.setRequestContent(order.getOrderNo()); -// highGasOrderPush.setReturnContent(String.valueOf(map)); -// highGasOrderPushMapper.insert(highGasOrderPush); -// } + outRechargeOrderService.pollRequest(order); + + } } }