| | |
| | | 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 javax.annotation.Resource; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | |
| | | @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); |
| | | if (StringUtil.isNullOrEmpty(id)) { |
| | | return JsonUtil.loadFalseResult("请上传id"); |
| | | } |
| | | if (StringUtil.isNullOrEmpty(orderNo)) { |
| | | return JsonUtil.loadFalseResult("orderNo"); |
| | | } |
| | | |
| | | KeyOrder order = keyOrderService.selectById(id); |
| | | if (order == null) { |
| | | return JsonUtil.loadFalseResult("口令不存在"); |
| | | } |
| | | |
| | | try { |
| | | if (order.getOrderNo() != null && !order.getOrderNo().equalsIgnoreCase(orderNo)) { |
| | | throw new KeyOrderException("已经处理过,与之前处理的订单号不一致"); |
| | | } |
| | | } catch (KeyOrderException e) { |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } |
| | | |
| | | try { |
| | | 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); |
| | | 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); |
| | | 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("订单已支付"); |
| | | } |
| | | } |
| | | |
| | | 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.getUserSettings(order.getUid()); |
| | | if (settings.getDyOrderCountPerDay() <= countInfo.getOrderCount()) { |
| | | throw new Exception("今日已达支付次数上限:" + settings.getDyOrderCountPerDay()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 设置进入 |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | 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); |
| | | return JsonUtil.loadTrueResult(gson.toJson(OrderFactory.create(order))); |
| | | } catch (KeyOrderException e) { |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setOrderType(1); |
| | | orderUpdate.setOrderState(0); |
| | | orderUpdate.setOrderNo(orderNo); |
| | | 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("setOrderNoV2") |
| | | public String setOrderNoV2(AcceptData acceptData, String id, String orderNoDesc, String orderStatus, String money) { |
| | | loggerPay.info("setOrderNo: {}-{}-{}-{}", id, orderNoDesc, orderStatus, money); |
| | | loggerPay.info("setOrderNo[{}]: {}-{}-{}-{}", acceptData.getUid(), id, orderNoDesc, orderStatus, money); |
| | | if (StringUtil.isNullOrEmpty(id)) { |
| | | return JsonUtil.loadFalseResult("请上传id"); |
| | | } |
| | |
| | | return JsonUtil.loadFalseResult("口令不存在"); |
| | | } |
| | | |
| | | money = money.replace("¥",""); |
| | | money = money.replace("¥", ""); |
| | | |
| | | int orderType=Constant.ORDER_TYPE_UNKNOWN; |
| | | int orderType = Constant.ORDER_TYPE_UNKNOWN; |
| | | |
| | | if(orderNoDesc.contains("抖音")||orderNoDesc.contains("上海格物致品")){ |
| | | if (orderNoDesc.contains("抖音") || orderNoDesc.contains("上海格物致品")) { |
| | | orderType = Constant.ORDER_TYPE_DY; |
| | | }else if(orderNoDesc.contains("快手")){ |
| | | } else if (orderNoDesc.contains("快手")) { |
| | | orderType = Constant.ORDER_TYPE_KS; |
| | | } |
| | | |
| | | String orderNo= ""; |
| | | String orderNo = ""; |
| | | try { |
| | | if(orderType==Constant.ORDER_TYPE_UNKNOWN){ |
| | | if (orderType == Constant.ORDER_TYPE_UNKNOWN) { |
| | | throw new KeyOrderException("未定义的订单类型"); |
| | | } |
| | | |
| | |
| | | throw new KeyOrderException(orderStatus); |
| | | } |
| | | |
| | | DYOrderDto dyOrderDto =null; |
| | | DYOrderDto dyOrderDto = null; |
| | | try { |
| | | dyOrderDto = keyOrderService.verifyKey(orderNoDesc, orderStatus, money); |
| | | }catch(KeyVerifyException ve){ |
| | | // 验证订单是否可以支付 |
| | | dyOrderDto = keyOrderService.verifyKey(orderNoDesc, orderStatus, money, null, null); |
| | | } catch (KeyVerifyException ve) { |
| | | throw new KeyOrderException("口令验证失败:" + ve.getMessage()); |
| | | } |
| | | // if(dyOrderDto!=null&&order.getOrderMoney()!=null){ |
| | |
| | | // throw new KeyOrderException(String.format("订单接口金额不匹配:%s-%s",dyOrderDto.getPay_amount(),MoneyUtil.getMoneyStr(order.getOrderMoney()))); |
| | | // } |
| | | // } |
| | | if(dyOrderDto!=null){ |
| | | 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) { |
| | | 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; |
| | | if(orderType==Constant.ORDER_TYPE_DY){ |
| | | orderCountType=OrderCountTypeEnum.DY_ORDER_PAY; |
| | | }else if(orderType==Constant.ORDER_TYPE_KS){ |
| | | orderCountType=OrderCountTypeEnum.KS_ORDER_PAY; |
| | | } |
| | | |
| | | 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()); |
| | | } |
| | | long todayCount = wxUserOrderCountService.sum(order.getUid(), orderCountType, orderChannel, TimeUtil.getGernalTime(System.currentTimeMillis(), Constant.DB_DAY_FORMAT)); |
| | | long totalCount = wxUserOrderCountService.sum(order.getUid(), orderCountType, null, null); |
| | | int maxPayCount = userSettingService.getLimitCountByTotalCount(orderType, totalCount, orderChannel); |
| | | if (todayCount >= maxPayCount) { |
| | | throw new Exception(String.format("老铁今日已达支付次数(%s)上限:%s", orderChannel.getName(), maxPayCount)); |
| | | } |
| | | } |
| | | |
| | |
| | | orderUpdate.setOrderType(orderType); |
| | | orderUpdate.setOrderNo(orderNo); |
| | | orderUpdate.setOrderMoney(new BigDecimal(money)); |
| | | if(dyOrderDto!=null){ |
| | | if (dyOrderDto != null) { |
| | | orderUpdate.setOrderState(dyOrderDto.getOrder_status()); |
| | | orderUpdate.setOrderChannel(dyOrderDto.getOrderChannel()); |
| | | orderUpdate.setPayType(Constant.PAY_TYPE_WITH_ORDER_NO); |
| | | }else{ |
| | | } 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(orderType); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @author hxh |
| | | * @description 设置商家是否可支付 |
| | | * @date 1:26 2025/2/8 |
| | | * @param: acceptData |
| | | * @param: id |
| | | * @param: merchant |
| | | * @return java.lang.String |
| | | **/ |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("isMerchantCanPay") |
| | | public String isMerchantCanPay(AcceptData acceptData, String id, String merchant) { |
| | | loggerPay.info("isMerchantCanPay[{}]: {}-{}", acceptData.getUid(), 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, keyOrder.getOrderMoney()); |
| | | if (isCanPay) { |
| | | // 更新渠道 |
| | | |
| | | return JsonUtil.loadTrueResult(""); |
| | | } else { |
| | | return JsonUtil.loadFalseResult("商家校验未通过"); |
| | | } |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @return java.lang.String |
| | | * @author hxh |
| | | * @description 是否可以执行支付 |
| | | * @date 0:22 2024/12/28 |
| | | * @param: acceptData |
| | | * @param: id |
| | | **/ |
| | | @ResponseBody |
| | | @RequestMapping("canExcutePay") |
| | | public String canExcutePay(AcceptData acceptData, String id) { |
| | | try { |
| | | KeyOrder keyOrder = keyOrderService.selectByIdForUpdate(id); |
| | | if (keyOrder == null) { |
| | | throw new Exception("订单不存在"); |
| | | } |
| | | if (keyOrder.getState() == KeyOrder.STATE_PAY) { |
| | | throw new Exception("订单已支付"); |
| | | } |
| | | loggerPay.info("canExcutePay[{}]: {}-{}", acceptData.getUid(), id, "可以支付"); |
| | | return JsonUtil.loadTrueResult(""); |
| | | } catch (Exception e) { |
| | | loggerPay.error("canExcutePay[{}]: {}-{}", acceptData.getUid(), id, "不可以支付:" + e.getMessage()); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("setPayResult") |
| | | public String setPayResult(AcceptData acceptData, String id, boolean paySuccess, String msg) { |
| | | loggerPay.info("setPayResult: {}-{}-{}", id, paySuccess, msg); |
| | | public String setPayResult(AcceptData acceptData, String id, boolean paySuccess, String msg, String payMerchant) { |
| | | loggerPay.info("setPayResult[{}]: {}-{}-{}-{}", acceptData.getUid(), id, paySuccess, msg, payMerchant); |
| | | if (StringUtil.isNullOrEmpty(id)) { |
| | | return JsonUtil.loadFalseResult("请上传id"); |
| | | } |
| | |
| | | if (order.getState() == KeyOrder.STATE_NOT_PROCESS) { |
| | | if (!paySuccess) { |
| | | // 支付失败 |
| | | if(msg!=null&&msg.contains("超时")) |
| | | { |
| | | if (msg != null && msg.contains("超时")) { |
| | | loggerPay.info(String.format("因为超时支付失败不处理:%s-%s", order.getId(), msg)); |
| | | orderPayFailProcessor.processPayFail(order.getId(), msg); |
| | | }else { |
| | | } else { |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(id); |
| | | orderUpdate.setState(KeyOrder.STATE_NOT_PAY); |
| | | orderUpdate.setStateDesc("支付失败"); |
| | | orderUpdate.setStateDesc("支付失败:" + msg); |
| | | orderUpdate.setPayMerchant(payMerchant); |
| | | keyOrderService.update(orderUpdate); |
| | | } |
| | | 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()); |
| | |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("rejectPay") |
| | | public String rejectPay(AcceptData acceptData, Long uid, String id) { |
| | | loggerPay.info("rejectPay: {}-{}", uid, id); |
| | | public String rejectPay(AcceptData acceptData, String id) { |
| | | loggerPay.info("rejectPay: {}-{}", acceptData.getUid(), id); |
| | | if (StringUtil.isNullOrEmpty(id)) { |
| | | return JsonUtil.loadFalseResult("请上传id"); |
| | | } |
| | |
| | | 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(""); |
| | | } |