| | |
| | | package com.taoke.autopay.service.impl; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.taoke.autopay.dao.KeyOrderMapper; |
| | | import com.taoke.autopay.dao.WxUserSettingsMapper; |
| | | import com.taoke.autopay.dto.ChannelOrderStatistic; |
| | |
| | | import com.taoke.autopay.entity.agent.ChannelAgentSettings; |
| | | import com.taoke.autopay.exception.KeyOrderException; |
| | | import com.taoke.autopay.exception.KeyVerifyException; |
| | | import com.taoke.autopay.exception.UserCreditException; |
| | | import com.taoke.autopay.exception.WxOrderCountException; |
| | | import com.taoke.autopay.factory.OrderFactory; |
| | | import com.taoke.autopay.manager.UserCreditManager; |
| | | import com.taoke.autopay.service.*; |
| | | import com.taoke.autopay.service.agent.ChannelAgentService; |
| | | import com.taoke.autopay.service.agent.ChannelAgentSettingService; |
| | |
| | | import com.taoke.autopay.utils.order.DYOrderApi; |
| | | import com.taoke.autopay.utils.order.OrderChannelUtil; |
| | | import com.taoke.autopay.vo.SubmitKeyInfo; |
| | | import com.taoke.autopay.vo.admin.IgnoreAgentOrderSettingVO; |
| | | import net.sf.json.JSONArray; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | */ |
| | | @Service |
| | | public class KeyOrderServiceImpl implements KeyOrderService { |
| | | |
| | | private Logger loggerDebug= LoggerFactory.getLogger("debugLogger"); |
| | | |
| | | @Resource |
| | | private KeyOrderMapper keyOrderMapper; |
| | |
| | | @Resource |
| | | private PayMoneySettingService payMoneySettingService; |
| | | |
| | | @Resource |
| | | private WxUserService wxUserService; |
| | | |
| | | @Resource |
| | | private UserCreditManager userCreditManager; |
| | | |
| | | |
| | | @Override |
| | | public KeyOrder selectById(String id) { |
| | |
| | | if (uid != null) { |
| | | WxUserSettings settings = wxUserSettingService.getUserSettings(uid); |
| | | OrderCountTypeEnum countType = OrderCountTypeEnum.SUBMIT_TOKEN_COUNT; |
| | | wxUserOrderCountService.addOrderCount(uid, countType,null, day, 1, settings.getTotalOrderCountPerDay()); |
| | | wxUserOrderCountService.addOrderCount(uid, countType, null, day, 1, settings.getTotalOrderCountPerDay()); |
| | | wxUserService.setLatestInfoInfo(uid, keyInfo.getIp(), keyInfo.getIpInfo()); |
| | | } |
| | | String id = OrderFactory.createId(keyInfo.getKey()); |
| | | KeyOrder order = keyOrderMapper.selectById(id); |
| | |
| | | } |
| | | // 验证渠道时间 |
| | | ChannelAgentSettings settings = channelAgentSettingService.selectByAgentId(agent.getId()); |
| | | if(settings!=null&&!StringUtil.isNullOrEmpty(settings.getStartSubmitTime())&&!StringUtil.isNullOrEmpty(settings.getEndSubmitTime())){ |
| | | 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(":",""); |
| | | 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())); |
| | | throw new KeyOrderException(String.format("口令提交时间段为:%s-%s", settings.getStartSubmitTime(), settings.getEndSubmitTime())); |
| | | } |
| | | } |
| | | |
| | | // 获取渠道忽略订单的配置 |
| | | String config = systemConfigService.getValueCache(SystemConfigKeyEnum.IGNORE_AGENT_ORDER_SETTING); |
| | | if (!StringUtil.isNullOrEmpty(config)) { |
| | | IgnoreAgentOrderSettingVO ignore = JsonUtil.getSimpleGson().fromJson(config, IgnoreAgentOrderSettingVO.class); |
| | | if (ignore.getPercent() > 0) { |
| | | // 获取当前代理今日的订单数量 |
| | | KeyOrderMapper.DaoQuery daoQuery = new KeyOrderMapper.DaoQuery(); |
| | | daoQuery.agentId = agent.getId(); |
| | | daoQuery.minCreateTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"), "yyyyMMdd")); |
| | | long keyCount = count(daoQuery); |
| | | if (keyCount > ignore.getBeginCount()) { |
| | | if ((keyCount - ignore.getBeginCount()) % (100 / ignore.getPercent()) == 0) { |
| | | order.setIgnore(true); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | order.setAgentId(agent.getId()); |
| | | } |
| | | } |
| | |
| | | order.setState(KeyOrder.STATE_NOT_PROCESS); |
| | | order.setStateDesc("尚未处理"); |
| | | order.setCreateTime(new Date()); |
| | | if(orderType!=Constant.ORDER_TYPE_UNKNOWN){ |
| | | if (orderType != Constant.ORDER_TYPE_UNKNOWN) { |
| | | order.setOrderType(orderType); |
| | | } |
| | | if (orderDto != null) { |
| | | order.setOrderNo(orderDto.getOrder_id()); |
| | | } |
| | | |
| | | order.setIp(keyInfo.getIp()); |
| | | if (keyInfo.getIpInfo() != null) { |
| | | order.setIpInfo(new Gson().toJson(keyInfo.getIpInfo())); |
| | | } |
| | | keyOrderMapper.insertSelective(order); |
| | | |
| | | |
| | | return order; |
| | | } |
| | | |
| | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void paySuccess(String id, String stateDesc, String day,String payMerchant) 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, OrderChannelUtil.getChannelByKey( old.getOrderChannel()), 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.setPayTime(new Date()); |
| | | } |
| | | update(orderUpdate); |
| | | // 增加积分 |
| | | try { |
| | | boolean creditEnable = true; |
| | | // 判断代理是否允许增加积分 |
| | | Long agengId = old.getAgentId(); |
| | | if(agengId!=null) { |
| | | ChannelAgentSettings agentSettings = channelAgentSettingService.selectByAgentId(agengId); |
| | | if(agentSettings!=null&&agentSettings.getCreditEnable()!=null) { |
| | | creditEnable =agentSettings.getCreditEnable(); |
| | | } |
| | | } |
| | | if(creditEnable) { |
| | | if (old.getOrderType() == Constant.ORDER_TYPE_DY) { |
| | | userCreditManager.addDYOrderPayRecord(old.getUid(), id); |
| | | } else if (old.getOrderType() == Constant.ORDER_TYPE_KS) { |
| | | userCreditManager.addKSOrderPayRecord(old.getUid(), id); |
| | | } |
| | | } |
| | | |
| | | } catch (UserCreditException e) { |
| | | loggerDebug.error("增加积分出错:"+id, e); |
| | | } |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | 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<>(); |
| | | 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<>(); |
| | | |
| | | Set<String> orderIds=new HashSet<>(); |
| | | for(KeyOrder order:orderList){ |
| | | String orderId=order.getOrderType()+"#"+ order.getOrderNo(); |
| | | if(!StringUtil.isNullOrEmpty(order.getOrderNo())){ |
| | | if(orderIds.contains(orderId)){ |
| | | 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)){ |
| | | if (!uidsMap.containsKey(orderChannel)) { |
| | | uidsMap.put(orderChannel, new HashSet<>()); |
| | | } |
| | | uidsMap.get(orderChannel).add(order.getUid()); |
| | | |
| | | if(!countMap.containsKey(orderChannel)){ |
| | | countMap.put(orderChannel,0); |
| | | if (!countMap.containsKey(orderChannel)) { |
| | | countMap.put(orderChannel, 0); |
| | | } |
| | | countMap.put(orderChannel, countMap.get(orderChannel)+1); |
| | | countMap.put(orderChannel, countMap.get(orderChannel) + 1); |
| | | |
| | | |
| | | if(!moneyMap.containsKey(orderChannel)){ |
| | | 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(); |
| | | 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()); |
| | |
| | | } catch (KeyOrderException e) { |
| | | // 抖音订单未验证通过,匹配金额 |
| | | // 验证提交的金额是否正确 |
| | | Set<String> moneySet =payMoneySettingService.listAllMoneyAsStr(); |
| | | Set<String> moneySet = payMoneySettingService.listAllMoneyAsStr(); |
| | | // 匹配金额 |
| | | if (!moneySet.contains(money)) { |
| | | throw new KeyVerifyException(KeyVerifyException.CODE_KEY_MONEY_NOT_MATCH, String.format("金额未在系统设置中:%s", money)); |
| | |
| | | |
| | | @Override |
| | | public long countUserNotDoOrder(Long uid, Date minCreateTime) { |
| | | KeyOrderMapper.DaoQuery daoQuery=new KeyOrderMapper.DaoQuery(); |
| | | KeyOrderMapper.DaoQuery daoQuery = new KeyOrderMapper.DaoQuery(); |
| | | daoQuery.uid = uid; |
| | | daoQuery.stateList=Arrays.asList(new Integer[]{KeyOrder.STATE_NOT_PROCESS,KeyOrder.STATE_NOT_PAY}); |
| | | daoQuery.stateList = Arrays.asList(new Integer[]{KeyOrder.STATE_NOT_PROCESS, KeyOrder.STATE_NOT_PAY}); |
| | | daoQuery.minCreateTime = minCreateTime; |
| | | return keyOrderMapper.count(daoQuery); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void rejectPay(String id, String rejectMsg) { |
| | | KeyOrder keyOrder = new KeyOrder(); |
| | | keyOrder.setId(id); |
| | | keyOrder.setState(KeyOrder.STATE_REJECT_PAY); |
| | | keyOrder.setStateDesc(rejectMsg); |
| | | update(keyOrder); |
| | | } |
| | | } |