| | |
| | | |
| | | import com.taoke.autopay.dao.KeyOrderMapper; |
| | | import com.taoke.autopay.dao.WxUserSettingsMapper; |
| | | import com.taoke.autopay.entity.KeyOrder; |
| | | import com.taoke.autopay.entity.OrderCountTypeEnum; |
| | | import com.taoke.autopay.entity.OrderDistributeCountInfo; |
| | | import com.taoke.autopay.entity.WxUserSettings; |
| | | import com.taoke.autopay.dto.DYOrderDto; |
| | | import com.taoke.autopay.entity.*; |
| | | 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.KeyOrderService; |
| | | import com.taoke.autopay.service.SystemConfigService; |
| | | import com.taoke.autopay.service.WxUserOrderCountService; |
| | | import com.taoke.autopay.service.WxUserSettingService; |
| | | import com.taoke.autopay.utils.StringUtil; |
| | | import com.taoke.autopay.utils.TimeUtil; |
| | | import com.taoke.autopay.utils.*; |
| | | import com.taoke.autopay.utils.order.DYOrderApi; |
| | | import com.taoke.autopay.vo.SubmitKeyInfo; |
| | | import net.sf.json.JSONArray; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | /** |
| | | * @author hxh |
| | |
| | | |
| | | @Resource |
| | | private WxUserOrderCountService wxUserOrderCountService; |
| | | |
| | | @Resource |
| | | private SystemConfigService systemConfigService; |
| | | |
| | | |
| | | @Override |
| | |
| | | public void deleteAll(Date maxCreateTime) { |
| | | keyOrderMapper.deleteAll(maxCreateTime); |
| | | } |
| | | |
| | | @Override |
| | | 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("快手")){ |
| | | orderType = Constant.ORDER_TYPE_KS; |
| | | } |
| | | |
| | | String orderNo= ""; |
| | | // 匹配连续的数字 |
| | | Pattern pattern = Pattern.compile("\\d+"); |
| | | Matcher matcher = pattern.matcher(orderNoDesc); |
| | | while (matcher.find()) { |
| | | // 获取匹配到的数字字符串 |
| | | String number = matcher.group(); |
| | | if (number.length() > 10) { |
| | | orderNo = number; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | 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() )); |
| | | } |
| | | } |
| | | }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; |
| | | } |
| | | |
| | | @Override |
| | | public void removeDistributedClient(String id) { |
| | | keyOrderMapper.removeDistributedClient(id); |
| | | } |
| | | } |