From 17caebabf7a6a529b7039c71e21e5a324e31ea20 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 27 九月 2024 16:23:42 +0800 Subject: [PATCH] 代理新功能完善 --- src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java | 96 ++++++++++++++++++++++++++++++++++++----------- 1 files changed, 73 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java b/src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java index 6ceb5fa..31dae68 100644 --- a/src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java +++ b/src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java @@ -6,15 +6,18 @@ import com.taoke.autopay.dto.DYOrderDto; import com.taoke.autopay.entity.*; import com.taoke.autopay.entity.agent.ChannelAgent; +import com.taoke.autopay.entity.agent.ChannelAgentSettings; 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.*; import com.taoke.autopay.service.agent.ChannelAgentService; +import com.taoke.autopay.service.agent.ChannelAgentSettingService; import com.taoke.autopay.service.agent.ChannelAgentSharingRatioService; import com.taoke.autopay.utils.*; import com.taoke.autopay.utils.order.DYOrderApi; +import com.taoke.autopay.utils.order.OrderChannelUtil; import com.taoke.autopay.vo.SubmitKeyInfo; import net.sf.json.JSONArray; import org.springframework.stereotype.Service; @@ -55,7 +58,13 @@ private ChannelAgentSharingRatioService channelAgentSharingRatioService; @Resource + private ChannelAgentSettingService channelAgentSettingService; + + @Resource private ClientInfoService clientInfoService; + + @Resource + private PayMoneySettingService payMoneySettingService; @Override @@ -70,7 +79,7 @@ if (uid != null) { WxUserSettings settings = wxUserSettingService.getUserSettings(uid); OrderCountTypeEnum countType = OrderCountTypeEnum.SUBMIT_TOKEN_COUNT; - wxUserOrderCountService.addOrderCount(uid, countType, day, 1, settings.getTotalOrderCountPerDay()); + wxUserOrderCountService.addOrderCount(uid, countType,null, day, 1, settings.getTotalOrderCountPerDay()); } String id = OrderFactory.createId(keyInfo.getKey()); KeyOrder order = keyOrderMapper.selectById(id); @@ -91,6 +100,17 @@ if (agent.getStatus() != ChannelAgent.STATUS_NOMAL) { throw new KeyOrderException("娓犻亾鍙楅檺"); } + // 楠岃瘉娓犻亾鏃堕棿 + ChannelAgentSettings settings = channelAgentSettingService.selectByAgentId(agent.getId()); + if(settings!=null&&!StringUtil.isNullOrEmpty(settings.getStartSubmitTime())&&!StringUtil.isNullOrEmpty(settings.getEndSubmitTime())){ + String now = TimeUtil.getGernalTime(System.currentTimeMillis(), "HHmmss"); + String startTime = settings.getStartSubmitTime().replace(":",""); + String endTime = settings.getEndSubmitTime().replace(":",""); + if (Integer.parseInt(now) < Integer.parseInt(startTime) || Integer.parseInt(now) > Integer.parseInt(endTime)) { + throw new KeyOrderException(String.format("鍙d护鎻愪氦鏃堕棿娈典负锛�%s-%s",settings.getStartSubmitTime(), settings.getEndSubmitTime())); + } + } + order.setAgentId(agent.getId()); } } @@ -136,7 +156,7 @@ @Transactional(rollbackFor = Exception.class) @Override - public void paySuccess(String id, String stateDesc, String day) throws WxOrderCountException { + public void paySuccess(String id, String stateDesc, String day,String payMerchant) throws WxOrderCountException { KeyOrder old = keyOrderMapper.selectByPrimaryKeyForUpdate(id); if (old == null) { return; @@ -146,12 +166,13 @@ } if (old.getUid() != null) { Integer orderType = old.getOrderType(); - wxUserOrderCountService.addOrderCount(old.getUid(), (orderType==null||orderType==Constant.ORDER_TYPE_DY)? OrderCountTypeEnum.DY_ORDER_PAY:OrderCountTypeEnum.KS_ORDER_PAY, day, 1, null); + wxUserOrderCountService.addOrderCount(old.getUid(), (orderType==null||orderType==Constant.ORDER_TYPE_DY)? OrderCountTypeEnum.DY_ORDER_PAY:OrderCountTypeEnum.KS_ORDER_PAY, OrderChannelUtil.getChannelByKey( old.getOrderChannel()), day, 1, null); } KeyOrder orderUpdate = new KeyOrder(); orderUpdate.setId(id); orderUpdate.setState(KeyOrder.STATE_PAY); orderUpdate.setStateDesc(stateDesc); + orderUpdate.setPayMerchant(payMerchant); if (old.getPayTime() == null) { orderUpdate.setPayTime(new Date()); } @@ -227,20 +248,64 @@ @Override public List<ChannelOrderStatistic> statisticChannelOrders(Long agentId, Date startTime, Date endTime) { KeyOrderMapper.DaoQuery daoQuery = new KeyOrderMapper.DaoQuery(); - daoQuery.oMinCreateTime = startTime; - daoQuery.oMaxCreateTime = endTime; + daoQuery.minCreateTime = startTime; + daoQuery.maxCreateTime = endTime; daoQuery.agentId = agentId; daoQuery.state = KeyOrder.STATE_PAY; daoQuery.hasPayTime = true; + // 灏嗘暟鎹媺鍑烘潵 + long count = keyOrderMapper.count(daoQuery); + daoQuery.count = (int)count; + List<KeyOrder> orderList = keyOrderMapper.list(daoQuery); + Map<String,Set<Long>> uidsMap = new HashMap<>(); + Map<String,Integer> countMap = new HashMap<>(); + Map<String,BigDecimal> moneyMap = new HashMap<>(); - return keyOrderMapper.statisticChannelOrders(daoQuery); + Set<String> orderIds=new HashSet<>(); + for(KeyOrder order:orderList){ + String orderId=order.getOrderType()+"#"+ order.getOrderNo(); + if(!StringUtil.isNullOrEmpty(order.getOrderNo())){ + if(orderIds.contains(orderId)){ + continue; + } + orderIds.add(orderId); + } + String orderChannel = order.getOrderChannel(); + + if(!uidsMap.containsKey(orderChannel)){ + uidsMap.put(orderChannel, new HashSet<>()); + } + uidsMap.get(orderChannel).add(order.getUid()); + + if(!countMap.containsKey(orderChannel)){ + countMap.put(orderChannel,0); + } + countMap.put(orderChannel, countMap.get(orderChannel)+1); + + + if(!moneyMap.containsKey(orderChannel)){ + moneyMap.put(orderChannel, new BigDecimal(0)); + } + moneyMap.put(orderChannel, moneyMap.get(orderChannel).add(order.getOrderMoney())); + } + + List<ChannelOrderStatistic> results=new ArrayList<>(); + for(String orderChannel: moneyMap.keySet()){ + ChannelOrderStatistic statistic=new ChannelOrderStatistic(); + statistic.setCount(countMap.get(orderChannel)); + statistic.setMoney(moneyMap.get(orderChannel)); + statistic.setUserCount(uidsMap.get(orderChannel).size()); + statistic.setOrderChannel(orderChannel); + results.add(statistic); + } + return results; } @Override public Long getCanDistributeUid(int maxQueueSize) { // 鏈�杩�1灏忔椂鏈夋椿璺�,涓斾笉绠�12浠ヤ笂鏈墽琛岀殑鏁版嵁 - List<OrderDistributeCountInfo> list = keyOrderMapper.listDistributeUids(new Date(System.currentTimeMillis() - 1000 * 60 * 60L), new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 12L)); + List<OrderDistributeCountInfo> list = keyOrderMapper.listDistributeUids(new Date(System.currentTimeMillis() - 1000 * 60 * 31L), new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 12L)); if (list == null || list.size() == 0) { return null; } @@ -294,13 +359,6 @@ maxCount = settings.getKsOrderCountPerDay(); break; } - - try { - wxUserOrderCountService.isOrderCountLimit(uid, orderCountType, TimeUtil.getGernalTime(System.currentTimeMillis(), Constant.DB_DAY_FORMAT), 1, maxCount); - } catch (WxOrderCountException e) { - e.printStackTrace(); - throw new KeyVerifyException(KeyVerifyException.CODE_COMMON, "浠婃棩鎻愪氦瓒呰繃" +maxCount + "娆�"); - } } @@ -348,15 +406,7 @@ } catch (KeyOrderException e) { // 鎶栭煶璁㈠崟鏈獙璇侀�氳繃锛屽尮閰嶉噾棰� // 楠岃瘉鎻愪氦鐨勯噾棰濇槸鍚︽纭� - String moneyStr = systemConfigService.getValueCache(SystemConfigKeyEnum.PAY_MONEY_LIST); - if (StringUtil.isNullOrEmpty(moneyStr)) { - throw new KeyVerifyException(KeyVerifyException.CODE_KEY_MONEY_NOT_MATCH, "灏氭湭閰嶇疆閲戦"); - } - JSONArray array = JSONArray.fromObject(moneyStr); - Set<String> moneySet = new HashSet<>(); - for (int i = 0; i < array.size(); i++) { - moneySet.add(MoneyUtil.getMoneyStr(new BigDecimal(array.optString(i)))); - } + Set<String> moneySet =payMoneySettingService.listAllMoneyAsStr(); // 鍖归厤閲戦 if (!moneySet.contains(money)) { throw new KeyVerifyException(KeyVerifyException.CODE_KEY_MONEY_NOT_MATCH, String.format("閲戦鏈湪绯荤粺璁剧疆涓細%s", money)); -- Gitblit v1.8.0