| | |
| | | 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; |
| | |
| | | private ChannelAgentSharingRatioService channelAgentSharingRatioService; |
| | | |
| | | @Resource |
| | | private ChannelAgentSettingService channelAgentSettingService; |
| | | |
| | | @Resource |
| | | private ClientInfoService clientInfoService; |
| | | |
| | | @Resource |
| | | private PayMoneySettingService payMoneySettingService; |
| | | |
| | | |
| | | @Override |
| | |
| | | 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); |
| | |
| | | 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("口令提交时间段为:%s-%s",settings.getStartSubmitTime(), settings.getEndSubmitTime())); |
| | | } |
| | | } |
| | | |
| | | order.setAgentId(agent.getId()); |
| | | } |
| | | } |
| | |
| | | |
| | | @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; |
| | |
| | | } |
| | | 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()); |
| | | } |
| | |
| | | @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; |
| | | } |
| | |
| | | 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 + "次"); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | } 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)); |