| | |
| | | import com.taoke.autopay.entity.*; |
| | | |
| | | import com.taoke.autopay.exception.KeyOrderException; |
| | | import com.taoke.autopay.exception.KeyVerifyException; |
| | | import com.taoke.autopay.exception.WxOrderCountException; |
| | | import com.taoke.autopay.factory.OrderFactory; |
| | | import com.taoke.autopay.service.ClientInfoService; |
| | | import com.taoke.autopay.service.KeyOrderService; |
| | | import com.taoke.autopay.service.WxUserOrderCountService; |
| | | import com.taoke.autopay.service.WxUserSettingService; |
| | | import com.taoke.autopay.utils.JsonUtil; |
| | | import com.taoke.autopay.utils.StringUtil; |
| | | import com.taoke.autopay.utils.TimeUtil; |
| | | import com.taoke.autopay.manager.OrderPayFailProcessor; |
| | | import com.taoke.autopay.service.*; |
| | | import com.taoke.autopay.utils.*; |
| | | import com.taoke.autopay.utils.order.DYOrderApi; |
| | | import com.taoke.autopay.vo.AcceptData; |
| | | import com.taoke.autopay.vo.KeyOrderVO; |
| | | import com.taoke.autopay.vo.OrderFilter; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * @author hxh |
| | |
| | | |
| | | @Resource |
| | | private WxUserSettingService wxUserSettingService; |
| | | |
| | | @Resource |
| | | private SystemConfigService systemConfigService; |
| | | |
| | | @Resource |
| | | private OrderPayFailProcessor orderPayFailProcessor; |
| | | |
| | | |
| | | @ResponseBody |
| | |
| | | orderUpdate.setOrderState(dto.getOrder_status()); |
| | | orderUpdate.setOrderType(1); |
| | | orderUpdate.setOrderNo(orderNo); |
| | | orderUpdate.setOrderChannel(dto.getOrderChannel()); |
| | | orderUpdate.setPayType(Constant.PAY_TYPE_WITH_ORDER_NO); |
| | | if (order.getState() == KeyOrder.STATE_NOT_PROCESS) { |
| | | if (dto.getOrder_status() == DYOrderDto.ORDER_STATUS_CANCELED) { |
| | | orderUpdate.setState(KeyOrder.STATE_PAY); |
| | |
| | | if (order.getUid() != null) { |
| | | WxUserOrderCount countInfo = wxUserOrderCountService.get(order.getUid(), OrderCountTypeEnum.DY_ORDER_PAY, TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd")); |
| | | if (countInfo != null) { |
| | | WxUserSettings settings = wxUserSettingService.selectByUid(order.getUid()); |
| | | WxUserSettings settings = wxUserSettingService.getUserSettings(order.getUid()); |
| | | if (settings.getDyOrderCountPerDay() <= countInfo.getOrderCount()) { |
| | | throw new Exception("今日已达支付次数上限:" + settings.getDyOrderCountPerDay()); |
| | | } |
| | |
| | | orderUpdate.setOrderType(1); |
| | | orderUpdate.setOrderState(dto.getOrder_status()); |
| | | orderUpdate.setOrderNo(orderNo); |
| | | orderUpdate.setOrderChannel(dto.getOrderChannel()); |
| | | orderUpdate.setPayType(Constant.PAY_TYPE_WITH_ORDER_NO); |
| | | orderUpdate.setExcutePayTime(new Date()); |
| | | keyOrderService.update(orderUpdate); |
| | | order = keyOrderService.selectById(id); |
| | |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("setOrderNoV2") |
| | | public String setOrderNoV2(AcceptData acceptData, String id, String orderNoDesc, String orderStatus, String money) { |
| | | loggerPay.info("setOrderNo: {}-{}-{}-{}", id, orderNoDesc, orderStatus, money); |
| | | if (StringUtil.isNullOrEmpty(id)) { |
| | | return JsonUtil.loadFalseResult("请上传id"); |
| | | } |
| | | if (StringUtil.isNullOrEmpty(money)) { |
| | | return JsonUtil.loadFalseResult("请上传money"); |
| | | } |
| | | |
| | | KeyOrder order = keyOrderService.selectById(id); |
| | | if (order == null) { |
| | | return JsonUtil.loadFalseResult("口令不存在"); |
| | | } |
| | | |
| | | money = money.replace("¥",""); |
| | | |
| | | int orderType=Constant.ORDER_TYPE_UNKNOWN; |
| | | |
| | | if(orderNoDesc.contains("抖音")||orderNoDesc.contains("上海格物致品")){ |
| | | orderType = Constant.ORDER_TYPE_DY; |
| | | }else if(orderNoDesc.contains("快手")){ |
| | | orderType = Constant.ORDER_TYPE_KS; |
| | | } |
| | | |
| | | String orderNo= ""; |
| | | try { |
| | | if(orderType==Constant.ORDER_TYPE_UNKNOWN){ |
| | | throw new KeyOrderException("未定义的订单类型"); |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(orderStatus)) { |
| | | throw new KeyOrderException(orderStatus); |
| | | } |
| | | |
| | | DYOrderDto dyOrderDto =null; |
| | | try { |
| | | dyOrderDto = keyOrderService.verifyKey(orderNoDesc, orderStatus, money); |
| | | }catch(KeyVerifyException ve){ |
| | | throw new KeyOrderException("口令验证失败:" + ve.getMessage()); |
| | | } |
| | | // if(dyOrderDto!=null&&order.getOrderMoney()!=null){ |
| | | // // 判断订单支付金额与用户提交的金额是否匹配 |
| | | // if(dyOrderDto.getPay_amount()!=order.getOrderMoney().multiply(new BigDecimal(100)).setScale(0, RoundingMode.FLOOR).intValue()){ |
| | | // throw new KeyOrderException(String.format("订单接口金额不匹配:%s-%s",dyOrderDto.getPay_amount(),MoneyUtil.getMoneyStr(order.getOrderMoney()))); |
| | | // } |
| | | // } |
| | | if(dyOrderDto!=null){ |
| | | orderNo = dyOrderDto.getOrder_id(); |
| | | } |
| | | |
| | | |
| | | if (order.getUid() != null) { |
| | | OrderCountTypeEnum orderCountType=null; |
| | | switch (orderType){ |
| | | case Constant.ORDER_TYPE_DY: |
| | | orderCountType= OrderCountTypeEnum.DY_ORDER_PAY; |
| | | break; |
| | | case Constant.ORDER_TYPE_KS: |
| | | orderCountType= OrderCountTypeEnum.KS_ORDER_PAY; |
| | | break; |
| | | } |
| | | |
| | | WxUserOrderCount countInfo = wxUserOrderCountService.get(order.getUid(), orderCountType, TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd")); |
| | | if (countInfo != null) { |
| | | WxUserSettings settings = wxUserSettingService.getUserSettings(order.getUid()); |
| | | int maxOrderCount = settings.getDyOrderCountPerDay(); |
| | | if(orderCountType == OrderCountTypeEnum.KS_ORDER_PAY){ |
| | | maxOrderCount = settings.getKsOrderCountPerDay(); |
| | | } |
| | | if (maxOrderCount <= countInfo.getOrderCount()) { |
| | | throw new Exception("老铁今日已达支付次数上限:" + settings.getDyOrderCountPerDay()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 设置进入 |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setOrderType(orderType); |
| | | orderUpdate.setOrderNo(orderNo); |
| | | orderUpdate.setOrderMoney(new BigDecimal(money)); |
| | | if(dyOrderDto!=null){ |
| | | orderUpdate.setOrderState(dyOrderDto.getOrder_status()); |
| | | orderUpdate.setOrderChannel(dyOrderDto.getOrderChannel()); |
| | | orderUpdate.setPayType(Constant.PAY_TYPE_WITH_ORDER_NO); |
| | | }else{ |
| | | orderUpdate.setPayType(Constant.PAY_TYPE_WITH_MONEY); |
| | | } |
| | | orderUpdate.setExcutePayTime(new Date()); |
| | | keyOrderService.update(orderUpdate); |
| | | order = keyOrderService.selectById(id); |
| | | return JsonUtil.loadTrueResult(gson.toJson(OrderFactory.create(order))); |
| | | } catch (KeyOrderException e) { |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setOrderType(orderType); |
| | | orderUpdate.setOrderNo(orderNo); |
| | | orderUpdate.setOrderMoney(new BigDecimal(money)); |
| | | orderUpdate.setOrderState(0); |
| | | orderUpdate.setState(KeyOrder.STATE_REJECT_PAY); |
| | | if (order.getExcutePayTime() == null) { |
| | | orderUpdate.setExcutePayTime(new Date()); |
| | | } |
| | | orderUpdate.setStateDesc(e.getMessage()); |
| | | keyOrderService.update(orderUpdate); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("setPayResult") |
| | | public String setPayResult(AcceptData acceptData, String id, boolean paySuccess, String msg) { |
| | | loggerPay.info("setPayResult: {}-{}", id, paySuccess); |
| | | loggerPay.info("setPayResult: {}-{}-{}", id, paySuccess, msg); |
| | | if (StringUtil.isNullOrEmpty(id)) { |
| | | return JsonUtil.loadFalseResult("请上传id"); |
| | | } |
| | |
| | | if (order == null) { |
| | | return JsonUtil.loadFalseResult("口令不存在"); |
| | | } |
| | | if (StringUtil.isNullOrEmpty(order.getOrderNo())) { |
| | | return JsonUtil.loadFalseResult("没有匹配到订单号"); |
| | | } |
| | | // if (StringUtil.isNullOrEmpty(order.getOrderNo())) { |
| | | // return JsonUtil.loadFalseResult("没有匹配到订单号"); |
| | | // } |
| | | |
| | | if (order.getState() == KeyOrder.STATE_NOT_PROCESS) { |
| | | if (!paySuccess) { |
| | | // 支付失败 |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setState(KeyOrder.STATE_NOT_PAY); |
| | | orderUpdate.setStateDesc("支付失败"); |
| | | keyOrderService.update(orderUpdate); |
| | | } else { |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setState(KeyOrder.STATE_PAY); |
| | | if (order.getPayTime() == null) { |
| | | orderUpdate.setPayTime(new Date()); |
| | | if(msg!=null&&msg.contains("超时")) |
| | | { |
| | | loggerPay.info(String.format("因为超时支付失败不处理:%s-%s", order.getId(), msg)); |
| | | orderPayFailProcessor.processPayFail(order.getId(), msg); |
| | | }else { |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setState(KeyOrder.STATE_NOT_PAY); |
| | | orderUpdate.setStateDesc("支付失败"); |
| | | keyOrderService.update(orderUpdate); |
| | | } |
| | | orderUpdate.setStateDesc("支付成功"); |
| | | loggerPay.info("处理支付失败完成"); |
| | | } else { |
| | | try { |
| | | keyOrderService.paySuccess(id, "支付成功", TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd")); |
| | | loggerPay.info("处理支付成功完成"); |
| | | } catch (WxOrderCountException e) { |
| | | loggerPay.error(e.getMessage()); |
| | | e.printStackTrace(); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } |