From a053811c774ac07340e46561f5d2ab4d892282a0 Mon Sep 17 00:00:00 2001 From: Administrator <1101184511@qq.com> Date: 星期一, 29 七月 2024 02:38:40 +0800 Subject: [PATCH] 渠道功能完善 --- src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java | 186 ++++++++++++++++++++++++++++++++++------------ 1 files changed, 136 insertions(+), 50 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 7ef1ea8..0cea788 100644 --- a/src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java +++ b/src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java @@ -2,8 +2,10 @@ import com.taoke.autopay.dao.KeyOrderMapper; import com.taoke.autopay.dao.WxUserSettingsMapper; +import com.taoke.autopay.dto.ChannelOrderStatistic; import com.taoke.autopay.dto.DYOrderDto; import com.taoke.autopay.entity.*; +import com.taoke.autopay.entity.agent.ChannelAgent; import com.taoke.autopay.exception.KeyOrderException; import com.taoke.autopay.exception.KeyVerifyException; import com.taoke.autopay.exception.WxOrderCountException; @@ -12,6 +14,8 @@ import com.taoke.autopay.service.SystemConfigService; import com.taoke.autopay.service.WxUserOrderCountService; import com.taoke.autopay.service.WxUserSettingService; +import com.taoke.autopay.service.agent.ChannelAgentService; +import com.taoke.autopay.service.agent.ChannelAgentSharingRatioService; import com.taoke.autopay.utils.*; import com.taoke.autopay.utils.order.DYOrderApi; import com.taoke.autopay.vo.SubmitKeyInfo; @@ -21,6 +25,7 @@ import javax.annotation.Resource; import java.math.BigDecimal; +import java.net.URI; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -46,6 +51,12 @@ @Resource private SystemConfigService systemConfigService; + @Resource + private ChannelAgentService channelAgentService; + + @Resource + private ChannelAgentSharingRatioService channelAgentSharingRatioService; + @Override public KeyOrder selectById(String id) { @@ -66,9 +77,27 @@ throw new KeyOrderException("璇峰嬁閲嶅鎻愪氦鍙d护"); } order = new KeyOrder(); + // 瑙f瀽referer涓殑閾炬帴 + if (!StringUtil.isNullOrEmpty(keyInfo.getReferer())) { + Map<String, String> paramsMap = HttpUtil.getPramsFromUrl(keyInfo.getReferer()); + if (paramsMap.containsKey("a")) { + String alias = paramsMap.get("a"); + ChannelAgent agent = channelAgentService.selectByAlias(alias); + if (agent == null) { + throw new KeyOrderException("娓犻亾涓嶅瓨鍦�"); + } + + if (agent.getStatus() != ChannelAgent.STATUS_NOMAL) { + throw new KeyOrderException("娓犻亾鍙楅檺"); + } + order.setAgentId(agent.getId()); + } + } + + order.setId(id); order.setKey(keyInfo.getKey()); - if(!StringUtil.isNullOrEmpty(keyInfo.getMoney())){ + if (!StringUtil.isNullOrEmpty(keyInfo.getMoney())) { order.setOrderMoney(new BigDecimal(keyInfo.getMoney())); } order.setUid(uid); @@ -99,22 +128,22 @@ @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) throws WxOrderCountException { KeyOrder old = keyOrderMapper.selectByPrimaryKeyForUpdate(id); - if(old==null){ - return; - } - if(old.getState() == KeyOrder.STATE_PAY){ + if (old == null) { return; } - if(old.getUid()!=null) { - wxUserOrderCountService.addOrderCount(old.getUid(),OrderCountTypeEnum.DY_ORDER_PAY,day,1,null); + if (old.getState() == KeyOrder.STATE_PAY) { + return; + } + if (old.getUid() != null) { + wxUserOrderCountService.addOrderCount(old.getUid(), OrderCountTypeEnum.DY_ORDER_PAY, day, 1, null); } KeyOrder orderUpdate = new KeyOrder(); orderUpdate.setId(id); orderUpdate.setState(KeyOrder.STATE_PAY); orderUpdate.setStateDesc(stateDesc); - if(old.getPayTime()==null){ + if (old.getPayTime() == null) { orderUpdate.setPayTime(new Date()); } update(orderUpdate); @@ -150,9 +179,56 @@ } @Override + public List<KeyOrder> listWithUser(KeyOrderMapper.DaoQuery query) { + return keyOrderMapper.listWithUser(query); + } + + @Override + public long countWithUser(KeyOrderMapper.DaoQuery query) { + return keyOrderMapper.countWithUser(query); + } + + @Override + public ChannelOrderStatistic statisticWithUser(KeyOrderMapper.DaoQuery query) { + Map<OrderChannelEnum, BigDecimal> shareMoneyMap = channelAgentSharingRatioService.getShareMoneyMap(query.agentId); + List<ChannelOrderStatistic> channelOrderStatisticList = keyOrderMapper.statisticChannelOrders(query); + BigDecimal totalMoney = new BigDecimal(0); + for (ChannelOrderStatistic s : channelOrderStatisticList) { + + for (OrderChannelEnum channel : OrderChannelEnum.values()) { + if (channel.getKey().equalsIgnoreCase(s.getOrderChannel())) { + + if (shareMoneyMap.containsKey(channel)) { + totalMoney = totalMoney.add(shareMoneyMap.get(channel).multiply(new BigDecimal(s.getCount()))); + } + break; + } + } + } + long userCount = keyOrderMapper.countUser(query); + ChannelOrderStatistic statistic = new ChannelOrderStatistic(); + statistic.setCount(userCount); + statistic.setMoney(totalMoney); + return statistic; + } + + @Override + public List<ChannelOrderStatistic> statisticChannelOrders(Long agentId, Date startTime, Date endTime) { + KeyOrderMapper.DaoQuery daoQuery=new KeyOrderMapper.DaoQuery(); + daoQuery.oMinCreateTime=startTime; + daoQuery.oMaxCreateTime=endTime; + daoQuery.agentId = agentId; + daoQuery.state =KeyOrder.STATE_PAY; + daoQuery.hasPayTime=true; + + return keyOrderMapper.statisticChannelOrders(daoQuery); + } + + + @Override public Long getCanDistributeUid() { // 鏈�杩�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 * 60L), new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 12L)); if (list == null || list.size() == 0) { return null; } @@ -202,15 +278,15 @@ } @Override - public DYOrderDto verifyKey(String orderNoDesc, String orderStatus, String money) throws KeyVerifyException { - int orderType= Constant.ORDER_TYPE_UNKNOWN; - if(orderNoDesc.contains("鎶栭煶")){ + public DYOrderDto verifyKey(String orderNoDesc, String orderStatus, String money) throws KeyVerifyException { + int orderType = Constant.ORDER_TYPE_UNKNOWN; + if (orderNoDesc.contains("鎶栭煶")) { orderType = Constant.ORDER_TYPE_DY; - }else if(orderNoDesc.contains("蹇墜")){ + } else if (orderNoDesc.contains("蹇墜")) { orderType = Constant.ORDER_TYPE_KS; } - String orderNo= ""; + String orderNo = ""; // 鍖归厤杩炵画鐨勬暟瀛� Pattern pattern = Pattern.compile("\\d+"); Matcher matcher = pattern.matcher(orderNoDesc); @@ -223,50 +299,60 @@ } } - if(orderType==Constant.ORDER_TYPE_UNKNOWN){ - throw new KeyVerifyException(KeyVerifyException.CODE_ORDER_TYPE_ERROR, "鏈畾涔夌殑璁㈠崟绫诲瀷"); - } + if (orderType == Constant.ORDER_TYPE_UNKNOWN) { + throw new KeyVerifyException(KeyVerifyException.CODE_ORDER_TYPE_ERROR, "鏈畾涔夌殑璁㈠崟绫诲瀷"); + } - if (!StringUtil.isNullOrEmpty(orderStatus)&&!orderStatus.contains("鏈敮浠�")) { - throw new KeyVerifyException(KeyVerifyException.CODE_ORDER_STATUS_ERROR, "璁㈠崟鐘舵�侊細"+orderStatus); - } - DYOrderDto dyOrderDto=null; - // 鍏堝尮閰嶈鍗� - try { - if(orderType == Constant.ORDER_TYPE_DY&&!StringUtil.isNullOrEmpty(orderNo)){ - dyOrderDto = DYOrderApi.getOrderDetail(orderNo); - if(dyOrderDto!=null){ - // 楠岃瘉閲戦 - if( dyOrderDto.getPay_amount().intValue()!= new BigDecimal(money).multiply(new BigDecimal(100)).setScale(0).intValue()){ - throw new KeyVerifyException(KeyVerifyException.CODE_ORDER_MONEY_NOT_MATCH ,String.format("鏀粯閲戦涓庤鍗曢噾棰濅笉涓�鑷达細%s-%d",money,dyOrderDto.getPay_amount() )); - } + if (!StringUtil.isNullOrEmpty(orderStatus) && !orderStatus.contains("鏈敮浠�")) { + throw new KeyVerifyException(KeyVerifyException.CODE_ORDER_STATUS_ERROR, "璁㈠崟鐘舵�侊細" + orderStatus); + } + DYOrderDto dyOrderDto = null; + // 鍏堝尮閰嶈鍗� + try { + if (orderType == Constant.ORDER_TYPE_DY && !StringUtil.isNullOrEmpty(orderNo)) { + dyOrderDto = DYOrderApi.getOrderDetail(orderNo); + if (dyOrderDto != null) { + // 楠岃瘉閲戦 + if (dyOrderDto.getPay_amount().intValue() != new BigDecimal(money).multiply(new BigDecimal(100)).setScale(0).intValue()) { + throw new KeyVerifyException(KeyVerifyException.CODE_ORDER_MONEY_NOT_MATCH, String.format("鏀粯閲戦涓庤鍗曢噾棰濅笉涓�鑷达細%s-%d", money, dyOrderDto.getPay_amount())); } - }else{ - throw new KeyOrderException("鎶栭煶璁㈠崟鑾峰彇澶辫触"); } - }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)))); - } - // 鍖归厤閲戦 - if(!moneySet.contains(money)){ - throw new KeyVerifyException(KeyVerifyException.CODE_KEY_MONEY_NOT_MATCH, String.format("閲戦鏈湪绯荤粺璁剧疆涓細%s",money)); - } + } else { + throw new KeyOrderException("鎶栭煶璁㈠崟鑾峰彇澶辫触"); } + } 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)))); + } + // 鍖归厤閲戦 + if (!moneySet.contains(money)) { + throw new KeyVerifyException(KeyVerifyException.CODE_KEY_MONEY_NOT_MATCH, String.format("閲戦鏈湪绯荤粺璁剧疆涓細%s", money)); + } + } - return dyOrderDto; + return dyOrderDto; } @Override public void removeDistributedClient(String id) { keyOrderMapper.removeDistributedClient(id); } + + @Override + public List<Long> listAgentId(KeyOrderMapper.DaoQuery query) { + return keyOrderMapper.listAgentId(query); + } + + @Override + public long countAgentId(KeyOrderMapper.DaoQuery query) { + return keyOrderMapper.countAgentId(query); + } } -- Gitblit v1.8.0