| | |
| | | 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.utils.order.OrderChannelApiUtil; |
| | | import com.taoke.autopay.utils.order.OrderChannelUtil; |
| | | 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.io.UnsupportedEncodingException; |
| | | 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; |
| | | |
| | | @Resource |
| | | private PayMoneySettingService payMoneySettingService; |
| | | |
| | | @Resource |
| | | private UserSettingService userSettingService; |
| | | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("listOrder") |
| | |
| | | clientInfoService.setActiveTime(filter.getUid(), new Date()); |
| | | query.start = (filter.getPage() - 1) * filter.getPageSize(); |
| | | query.count = filter.getPageSize(); |
| | | query.minCreateTime = new Date(System.currentTimeMillis() - 1000 * 60 * 30L); |
| | | if (filter.getState() != null) { |
| | | switch (filter.getState()) { |
| | | case OrderFilter.STATE_NOT_PROCESS: |
| | |
| | | return JsonUtil.loadTrueResult(data); |
| | | } |
| | | |
| | | /** |
| | | * @return java.lang.String 返回是否可以去支付 |
| | | * @author hxh |
| | | * @description 设置订单号 |
| | | * @date 23:08 2024/6/24 |
| | | * @param: acceptData |
| | | * @param: id 订单ID |
| | | * @param: orderNo 订单号 |
| | | * @param: orderStatus 订单状态:订单已取消/已支付 |
| | | **/ |
| | | @ResponseBody |
| | | @RequestMapping("setOrderNo") |
| | | public String setOrderNo(AcceptData acceptData, String id, String orderNo, String orderStatus) { |
| | | loggerPay.info("setOrderNo: {}-{}-{}", id, orderNo, orderStatus); |
| | | @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(orderNo)) { |
| | | return JsonUtil.loadFalseResult("orderNo"); |
| | | if (StringUtil.isNullOrEmpty(money)) { |
| | | return JsonUtil.loadFalseResult("请上传money"); |
| | | } |
| | | |
| | | KeyOrder order = keyOrderService.selectById(id); |
| | |
| | | return JsonUtil.loadFalseResult("口令不存在"); |
| | | } |
| | | |
| | | try { |
| | | if (order.getOrderNo() != null && !order.getOrderNo().equalsIgnoreCase(orderNo)) { |
| | | throw new KeyOrderException("已经处理过,与之前处理的订单号不一致"); |
| | | } |
| | | } catch (KeyOrderException e) { |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | 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 dto = DYOrderApi.getOrderDetail(orderNo); |
| | | // dto.setOrder_status(1); |
| | | if (dto.getOrder_status() != DYOrderDto.ORDER_STATUS_NOT_PAY) { |
| | | // 订单不处于尚未付款状态 |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setOrderState(dto.getOrder_status()); |
| | | orderUpdate.setOrderType(1); |
| | | orderUpdate.setOrderNo(orderNo); |
| | | if (order.getState() == KeyOrder.STATE_NOT_PROCESS) { |
| | | if (dto.getOrder_status() == DYOrderDto.ORDER_STATUS_CANCELED) { |
| | | orderUpdate.setState(KeyOrder.STATE_PAY); |
| | | orderUpdate.setStateDesc(dto.getOrder_status_desc()); |
| | | } else { |
| | | orderUpdate.setState(KeyOrder.STATE_PAY); |
| | | orderUpdate.setStateDesc(dto.getOrder_status_desc()); |
| | | } |
| | | } |
| | | keyOrderService.update(orderUpdate); |
| | | if (dto.getOrder_status() == DYOrderDto.ORDER_STATUS_CANCELED) { |
| | | throw new Exception("订单已取消"); |
| | | } else { |
| | | throw new Exception("订单已支付"); |
| | | } |
| | | |
| | | DYOrderDto dyOrderDto = null; |
| | | try { |
| | | // 验证订单是否可以支付 |
| | | dyOrderDto = keyOrderService.verifyKey(orderNoDesc, orderStatus, money, null, null); |
| | | } 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(); |
| | | } |
| | | |
| | | OrderChannelEnum orderChannel = null; |
| | | if (dyOrderDto != null) { |
| | | orderChannel =OrderChannelUtil.getChannelByKey(dyOrderDto.getOrderChannel()); |
| | | }else{ |
| | | orderChannel = OrderChannelEnum.unknown; |
| | | } |
| | | |
| | | // 验证渠道支付次数是否达到上限 |
| | | 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()); |
| | | if (settings.getDyOrderCountPerDay() <= countInfo.getOrderCount()) { |
| | | throw new Exception("今日已达支付次数上限:" + settings.getDyOrderCountPerDay()); |
| | | long todayCount = wxUserOrderCountService.sum(order.getUid(), null,orderChannel, TimeUtil.getGernalTime(System.currentTimeMillis(), Constant.DB_DAY_FORMAT)); |
| | | long totalCount = wxUserOrderCountService.sum(order.getUid(), null,orderChannel,null); |
| | | int maxPayCount = userSettingService.getLimitCountByTotalCount(totalCount, orderChannel); |
| | | if(todayCount>=maxPayCount){ |
| | | throw new Exception( String.format("老铁今日已达支付次数(%s)上限:%s" ,orderChannel.getName(), maxPayCount)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 设置进入 |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setOrderType(1); |
| | | orderUpdate.setOrderState(dto.getOrder_status()); |
| | | 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.setOrderChannel(OrderChannelEnum.unknown.getKey()); |
| | | } |
| | | orderUpdate.setExcutePayTime(new Date()); |
| | | keyOrderService.update(orderUpdate); |
| | | order = keyOrderService.selectById(id); |
| | | order.setPayType(orderUpdate.getPayType()); |
| | | return JsonUtil.loadTrueResult(gson.toJson(OrderFactory.create(order))); |
| | | } catch (KeyOrderException e) { |
| | | loggerPay.info(String.format("设置订单号出错:%s-%s", id, e.getMessage())); |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setOrderType(1); |
| | | orderUpdate.setOrderState(0); |
| | | 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()); |
| | |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("isMerchantCanPay") |
| | | public String isMerchantCanPay(AcceptData acceptData, String id, String merchant) { |
| | | loggerPay.info("isMerchantCanPay: {}-{}", id, merchant); |
| | | // 判断是否为卡金额 |
| | | KeyOrder keyOrder = keyOrderService.selectById(id); |
| | | if (keyOrder == null) { |
| | | return JsonUtil.loadFalseResult("订单ID不存在"); |
| | | } |
| | | OrderChannelEnum orderChannel = OrderChannelUtil.getChannelByKey(keyOrder.getOrderChannel()); |
| | | if (orderChannel != OrderChannelEnum.unknown) { |
| | | // 不是卡金额的订单可直接支付 |
| | | return JsonUtil.loadTrueResult(""); |
| | | } |
| | | |
| | | // 获取卡金额的设置信息 |
| | | PayMoneySetting payMoneySetting = payMoneySettingService.getSettingByMoney(keyOrder.getOrderMoney()); |
| | | if(payMoneySetting == null){ |
| | | return JsonUtil.loadFalseResult("该金额不属于卡金额范围"); |
| | | } |
| | | if(payMoneySetting.getVerifyMerchantChannel()==null||payMoneySetting.getVerifyMerchantChannel()==OrderChannelEnum.unknown){ |
| | | // 没有设置校验渠道 |
| | | return JsonUtil.loadTrueResult(""); |
| | | } |
| | | |
| | | try { |
| | | // 目前只判断超享佣 |
| | | boolean isCanPay = OrderChannelApiUtil.isMerchantCanPay(payMoneySetting.getVerifyMerchantChannel(), merchant); |
| | | if(isCanPay){ |
| | | return JsonUtil.loadTrueResult(""); |
| | | }else{ |
| | | return JsonUtil.loadFalseResult("商家校验未通过"); |
| | | } |
| | | } catch (UnsupportedEncodingException 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); |
| | | public String setPayResult(AcceptData acceptData, String id, boolean paySuccess, String msg,String payMerchant) { |
| | | loggerPay.info("setPayResult: {}-{}-{}-{}", id, paySuccess, msg, payMerchant); |
| | | 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("支付失败:"+msg); |
| | | orderUpdate.setPayMerchant(payMerchant); |
| | | keyOrderService.update(orderUpdate); |
| | | } |
| | | orderUpdate.setStateDesc("支付成功"); |
| | | loggerPay.info("处理支付失败完成"); |
| | | } else { |
| | | try { |
| | | keyOrderService.paySuccess(id, "支付成功", TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd")); |
| | | keyOrderService.paySuccess(id, "支付成功", TimeUtil.getGernalTime(System.currentTimeMillis(), Constant.DB_DAY_FORMAT), payMerchant); |
| | | loggerPay.info("处理支付成功完成"); |
| | | } catch (WxOrderCountException e) { |
| | | loggerPay.error(e.getMessage()); |
| | | e.printStackTrace(); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } |
| | |
| | | return JsonUtil.loadFalseResult("只有管理员才能删除"); |
| | | } |
| | | |
| | | // 删除24小时之前的数据 |
| | | // keyOrderService.deleteAll(new Date(System.currentTimeMillis() - 24*60*60*1000L)); |
| | | keyOrderService.deleteAll(new Date(System.currentTimeMillis())); |
| | | // 删除10天之前的数据 |
| | | keyOrderService.deleteAll(new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000L * 10)); |
| | | // keyOrderService.deleteAll(new Date(System.currentTimeMillis())); |
| | | // 刪除所有數據 |
| | | return JsonUtil.loadTrueResult(""); |
| | | } |