| | |
| | | package com.matrix.system.shopXcx.api.action; |
| | | |
| | | import com.matrix.component.asyncmessage.AsyncMessageManager; |
| | | import com.matrix.component.rabbitmq.RabiitMqTemplate; |
| | | import com.matrix.component.wechat.externalInterface.common.Signature; |
| | | import com.matrix.component.wechat.externalInterface.common.Util; |
| | | import com.matrix.component.wechat.externalInterface.protocol.queryProtocol.NotifyData; |
| | | import com.matrix.config.RabbitMqConfig; |
| | | import com.matrix.core.pojo.AjaxResult; |
| | | import com.matrix.core.tools.LogUtil; |
| | | import com.matrix.system.common.bean.BusParameterSettings; |
| | | import com.matrix.system.common.constance.AppConstance; |
| | | import com.matrix.system.common.dao.BusParameterSettingsDao; |
| | | import com.matrix.system.hive.bean.MoneyCardUse; |
| | | import com.matrix.system.hive.bean.MoneyCardUseFlow; |
| | | import com.matrix.system.hive.bean.SysVipInfo; |
| | | import com.matrix.system.hive.dao.MoneyCardUseDao; |
| | | import com.matrix.system.hive.dao.MoneyCardUseFlowDao; |
| | | import com.matrix.system.hive.dao.SysVipInfoDao; |
| | | import com.matrix.system.score.service.ScoreVipDetailService; |
| | | import com.matrix.system.shopXcx.bean.ShopActivitiesGroupJoin; |
| | | import com.matrix.system.shopXcx.bean.ShopActivitiesGroupJoinUser; |
| | | import com.matrix.system.shopXcx.bean.ShopOrder; |
| | |
| | | import com.matrix.system.shopXcx.dao.ShopActivitiesGroupJoinUserDao; |
| | | import com.matrix.system.shopXcx.dao.ShopOrderDao; |
| | | import com.matrix.system.shopXcx.dao.ShopPayLogDao; |
| | | import com.matrix.system.shopXcx.mqTask.MQTaskRouting; |
| | | import com.matrix.system.shopXcx.mqTask.AsyncMessageRouting; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | @Autowired |
| | | BusParameterSettingsDao busParameterSettingsDao; |
| | | |
| | | @Autowired |
| | | ScoreVipDetailService scoreVipDetailService; |
| | | |
| | | @Autowired |
| | | AsyncMessageManager asyncMessageManager; |
| | | |
| | | |
| | | @Value("${evn}") |
| | | private String evn; |
| | | /** |
| | | * 微信支付回调接口 |
| | | * |
| | | * @param response |
| | | * @param request |
| | | * @throws IOException |
| | | * @throws Exception |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @RequestMapping(value = "/wxapi/wxpayCallback") |
| | |
| | | //设置支付状态为支付成功 |
| | | modifyMap.put("payStatus", ShopOrder.ORDER_PAY_STATUS_SUCCESS); |
| | | //设置订单状态 |
| | | if (ShopOrder.ORDER_TYPE_GOODS == order.getOrderType()) { |
| | | if (ShopOrder.SHIPPING_METHOD_WL == order.getShippingMethod()) { |
| | | //如果是商品订单则进入待发货 |
| | | modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_SEND); |
| | | } else { |
| | | //如果是服务订单则进入待评价 |
| | | modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_REMARK); |
| | | } else if (ShopOrder.SHIPPING_METHOD_MDZT == order.getShippingMethod()) { |
| | | //如果是门店自提则进入待收款 |
| | | modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_RECEIVE); |
| | | } |
| | | shopOrderDao.updateByMap(modifyMap); |
| | | |
| | |
| | | } |
| | | shopActivitiesGroupJoinDao.updateByModel(groupJoin); |
| | | |
| | | SysVipInfo sysVipInfo = sysVipInfoDao.selectByPhone(order.getUserTel()); |
| | | SysVipInfo sysVipInfo = sysVipInfoDao.selectByPhone(order.getUserTel(), order.getCompanyId()); |
| | | if(sysVipInfo!=null){ |
| | | sysVipInfo.setIsDeal(SysVipInfo.DEAL_VIP); |
| | | sysVipInfoDao.update(sysVipInfo); |
| | |
| | | } |
| | | |
| | | // 根据订单类型创建不同的处理任务 |
| | | rabiitMqTemplate.sendTopicMsg(RabbitMqConfig.MQ_EXCHANGE_TOPIC +evn, MQTaskRouting.CREATE_ORDER+evn, orderId); |
| | | asyncMessageManager.sendMsg(AsyncMessageRouting.CREATE_ORDER,"orderId=%s",orderId); |
| | | |
| | | |
| | | threadResult.putInMap("status", "success"); |
| | | resXml = AppConstance.RESULT_XML_SUCCESS; |
| | | |
| | | //支付记录 |
| | | recordPayLog(Integer.valueOf(orderId), payMoney, order, payLog, "支付成功", ShopOrder.ORDER_PAY_STATUS_SUCCESS); |
| | | recordPayLog(Integer.valueOf(orderId), 1, order.getOrderNo(), payMoney, "支付成功", ShopOrder.ORDER_PAY_STATUS_SUCCESS); |
| | | |
| | | |
| | | } else { |
| | |
| | | |
| | | } |
| | | |
| | | private void recordPayLog(Integer orderId, BigDecimal payMoney, ShopOrder order, ShopPayLog payLog, String payRemark, int payStatus) { |
| | | |
| | | @Autowired |
| | | MoneyCardUseFlowDao moneyCardUseFlowDao; |
| | | |
| | | @Autowired |
| | | MoneyCardUseDao moneyCardUseDao; |
| | | |
| | | /** |
| | | * 微信充值回调 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @RequestMapping(value = "/wxapi/rechargeCallBack") |
| | | public void rechargeCallBack(HttpServletResponse response, HttpServletRequest request) throws IOException { |
| | | LogUtil.info("微信充值回调start...."); |
| | | |
| | | // 获取输入参数 |
| | | String inputLine; |
| | | StringBuffer notityXml = new StringBuffer(); |
| | | String resXml = ""; |
| | | String moneyCardUseFlowId = ""; |
| | | |
| | | AjaxResult threadResult = new AjaxResult(AjaxResult.STATUS_SUCCESS, ""); |
| | | try { |
| | | while ((inputLine = request.getReader().readLine()) != null) { |
| | | notityXml.append(inputLine); |
| | | } |
| | | request.getReader().close(); |
| | | LogUtil.info("notityXml ---- :{} ", notityXml); |
| | | |
| | | |
| | | // XMl转对象 |
| | | Object bb = Util.getObjectFromXML(notityXml.toString(), NotifyData.class); |
| | | NotifyData data = new NotifyData(); |
| | | BeanUtils.copyProperties(bb,data); |
| | | LogUtil.info("----return_code = {}", data.getReturn_code()); |
| | | |
| | | |
| | | // 返回状态码 SUCCESS/FAIL |
| | | if (AppConstance.CODE_SUCCESS.equals(data.getReturn_code())) { |
| | | |
| | | moneyCardUseFlowId = data.getAttach(); |
| | | // 检验订单状态 |
| | | MoneyCardUseFlow moneyCardUseFlow = moneyCardUseFlowDao.selectById(Long.valueOf(moneyCardUseFlowId)); |
| | | SysVipInfo user=sysVipInfoDao.selectById(moneyCardUseFlow.getVipId()); |
| | | |
| | | // 校验签名 |
| | | BusParameterSettings paySecret = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_SECRET, user.getCompanyId()); |
| | | if (Signature.checkIsSignValidFromResponseString(notityXml.toString(),paySecret.getParamValue())) { |
| | | // 校验业务结果 |
| | | if (AppConstance.CODE_SUCCESS.equals(data.getResult_code())) { |
| | | // 返回SUCCESS报文 |
| | | resXml = AppConstance.RESULT_XML_SUCCESS; |
| | | // 支付费用 |
| | | Double total_fee = Double.parseDouble(data.getTotal_fee()); |
| | | // 商户订单号 |
| | | String payNum = data.getOut_trade_no(); |
| | | |
| | | LogUtil.info("支付回调关键信息---total_fee:{},payNum:{},moneyCardUseFlowId:{}", total_fee, payNum, moneyCardUseFlowId); |
| | | // 订单ID |
| | | Double payMoney = new BigDecimal(total_fee).divide(new BigDecimal(100), 2, |
| | | BigDecimal.ROUND_HALF_DOWN).doubleValue(); |
| | | |
| | | if (moneyCardUseFlow.getCarUseId()==null) { |
| | | |
| | | if(payMoney.equals(moneyCardUseFlow.getTotal())){ |
| | | threadResult.putInMap("status", "success"); |
| | | resXml = AppConstance.RESULT_XML_SUCCESS; |
| | | MoneyCardUse moneyCardUse = moneyCardUseDao.selectVipCard(user.getId()); |
| | | moneyCardUseFlow.setCarUseId(moneyCardUse.getId()); |
| | | moneyCardUseFlow.setCardName(moneyCardUse.getCardName()); |
| | | Double balance=moneyCardUse.getGiftMoney() + moneyCardUse.getRealMoney(); |
| | | moneyCardUseFlow.setBalance(balance==null?0:balance); |
| | | moneyCardUseFlowDao.update(moneyCardUseFlow); |
| | | |
| | | moneyCardUse.setRealMoney(moneyCardUse.getRealMoney()+payMoney.doubleValue()); |
| | | moneyCardUseDao.update(moneyCardUse); |
| | | |
| | | //充值记录 |
| | | recordPayLog(Integer.valueOf(moneyCardUseFlowId),2,moneyCardUseFlow.getPayNo(),new BigDecimal(payMoney), "充值成功", ShopOrder.ORDER_PAY_STATUS_SUCCESS); |
| | | }else{ |
| | | LogUtil.debug("支付金额不一致,检查支付金额payMoney={},order.getPayMoney()={}", payMoney, moneyCardUseFlow.getTotal()); |
| | | threadResult.putInMap("status", "err"); |
| | | threadResult.putInMap("msg", "支付金额不一致"); |
| | | resXml = AppConstance.RESULT_XML_FAIL.replace(ERRORMSG, "微信标识业务是失败"); |
| | | } |
| | | |
| | | } else { |
| | | LogUtil.info("充值已经确认"); |
| | | } |
| | | |
| | | } else { |
| | | LogUtil.info("微信标识业务是失败"); |
| | | threadResult.putInMap("status", "err"); |
| | | threadResult.putInMap("msg", "查询支付信息失败,请联系客服或者刷新支付信息(错误码:001)"); |
| | | resXml = AppConstance.RESULT_XML_FAIL.replace(ERRORMSG, "微信标识业务是失败"); |
| | | } |
| | | } else { |
| | | LogUtil.info("无效签名"); |
| | | threadResult.putInMap("status", "err"); |
| | | threadResult.putInMap("msg", "查询支付信息失败,请联系客服或者刷新支付信息(错误码:002)"); |
| | | resXml = AppConstance.RESULT_XML_FAIL.replace(ERRORMSG, "微信标识业务是失败"); |
| | | } |
| | | } else { |
| | | LogUtil.info("通信标识失败"); |
| | | threadResult.putInMap("status", "err"); |
| | | threadResult.putInMap("msg", "查询支付信息失败,请联系客服或者刷新支付信息(错误码:003)"); |
| | | resXml = AppConstance.RESULT_XML_FAIL.replace(ERRORMSG, "通信标识失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | LogUtil.error("支付回调签名错误", e); |
| | | threadResult.putInMap("status", "err"); |
| | | threadResult.putInMap("msg", "查询支付信息失败,请联系客服或者刷新支付信息(错误码:004)"); |
| | | resXml = AppConstance.RESULT_XML_FAIL.replace(ERRORMSG, "支付回调签名错误"); |
| | | } finally { |
| | | // 通知线程消息 |
| | | PayThreadPool.notifyThread(Integer.valueOf(moneyCardUseFlowId), threadResult); |
| | | sendResultBack(response, resXml); |
| | | } |
| | | return; |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | private void recordPayLog(Integer orderId, Integer type,String orderNo, BigDecimal payMoney, String payRemark, int payStatus) { |
| | | //设置支付类型为收款 |
| | | payLog.setPayType(1); |
| | | ShopPayLog payLog=new ShopPayLog(); |
| | | payLog.setPayType(type); |
| | | payLog.setJoinId(orderId); |
| | | payLog.setPayMoney(payMoney); |
| | | payLog.setPayOrderNo(order.getOrderNo()); |
| | | payLog.setPayOrderNo(orderNo); |
| | | payLog.setPayRemark(payRemark); |
| | | payLog.setPayStatus(payStatus); |
| | | payLog.setCreateBy(AppConstance.SYSTEM_USER); |