| | |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.entity.SystemPIDInfo; |
| | | import com.yeshi.fanli.service.manger.PIDManager; |
| | | import com.yeshi.fanli.service.manger.order.TeamRewardManager; |
| | | import com.yeshi.fanli.util.pinduoduo.PinDuoDuoUtil; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | @Resource |
| | | private TeamRewardManager teamRewardManager; |
| | | |
| | | @Resource |
| | | private PIDManager pidManager; |
| | | |
| | | /** |
| | | * 是否是分享订单 |
| | | * |
| | | * @param order |
| | | * @return |
| | | */ |
| | | private boolean isShareOrder(TaoBaoOrder order) { |
| | | private boolean isShareOrder(SystemEnum system, TaoBaoOrder order) { |
| | | |
| | | String specialRelationId = pidManager.getPidCache(system, Constant.SOURCE_TYPE_TAOBAO, SystemPIDInfo.PidType.fanliChannel); |
| | | |
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID); |
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(), order.getSourceMediaId(), |
| | | order.getAdPositionId()); |
| | | if (!StringUtil.isNullOrEmpty(order.getSpecialId()) |
| | | || pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)) {// 设置渠道ID当做会员运营ID的位置ID |
| | | || pid.equalsIgnoreCase(specialRelationId)) {// 设置渠道ID当做会员运营ID的位置ID |
| | | return false; |
| | | } else if (!StringUtil.isNullOrEmpty(order.getRelationId())) { |
| | | return true; |
| | |
| | | } |
| | | } |
| | | |
| | | //获取推广位类型 |
| | | private SystemPIDInfo.PidType getPidType(int sourceType, String pid) { |
| | | List<SystemPIDInfo> pidInfoList = pidManager.listPidInfoByPidCache(pid, sourceType); |
| | | if ((pidInfoList == null || pidInfoList.size() == 0) && sourceType == Constant.SOURCE_TYPE_TAOBAO) { |
| | | pidInfoList = pidManager.listPidInfoByPidCache(pid, Constant.SOURCE_TYPE_ELME); |
| | | } |
| | | |
| | | SystemPIDInfo.PidType pidType = null; |
| | | if (pidInfoList != null && pidInfoList.size() > 0) { |
| | | pidType = pidInfoList.get(0).getPidType(); |
| | | } |
| | | return pidType; |
| | | } |
| | | |
| | | //根据PID获取系统 |
| | | private List<SystemEnum> getPidSystems(String pid) { |
| | | List<SystemEnum> systemList = new ArrayList<>(); |
| | | List<SystemPIDInfo> pidInfoList = pidManager.listPidInfoByPidCache(pid, null); |
| | | |
| | | if (pidInfoList != null) { |
| | | for (SystemPIDInfo pidInfo : pidInfoList) { |
| | | systemList.add(pidInfo.getSystem()); |
| | | } |
| | | } |
| | | return systemList; |
| | | } |
| | | |
| | | private Set<Integer> getPidSourceTypes(String pid) { |
| | | Set<Integer> sourceTypes = new HashSet<>(); |
| | | List<SystemPIDInfo> pidInfoList = pidManager.listPidInfoByPidCache(pid, null); |
| | | if (pidInfoList != null) { |
| | | for (SystemPIDInfo pidInfo : pidInfoList) { |
| | | sourceTypes.add(pidInfo.getSourceType()); |
| | | } |
| | | } |
| | | return sourceTypes; |
| | | } |
| | | |
| | | @Override |
| | | public synchronized void processOrder(Map<String, List<TaoBaoOrder>> orders) { |
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID); |
| | |
| | | List<TaoBaoOrder> list = orders.get(orderId); |
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(), |
| | | list.get(0).getSourceMediaId(), list.get(0).getAdPositionId()); |
| | | if ("饿了么".equalsIgnoreCase(list.get(0).getOrderType()) |
| | | && !pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_PID_DEFAULT)) { |
| | | // 饿了么订单开始归入到淘宝订单 |
| | | if (TimeUtil.convertToTimeTemp(list.get(0).getCreateTime(), |
| | | "yyyy-MM-dd HH:mm:ss") >= Constant.NEW_ORDER_FANLI_RULE_TIME) { |
| | | fanliOrderMap.put(orderId, list); |
| | | } else { |
| | | elmeOrderMap.put(orderId, list); |
| | | } |
| | | } else if ("口碑".equalsIgnoreCase(list.get(0).getOrderType()) |
| | | && pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_KOUBEI_PID)) {// 口碑自购 |
| | | fanliOrderMap.put(orderId, list); |
| | | } else { |
| | | if (!StringUtil.isNullOrEmpty(list.get(0).getSpecialId()) |
| | | || pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID)) {// 设置渠道ID当做会员运营ID的位置ID |
| | | fanliOrderMap.put(orderId, list); |
| | | } else if (!StringUtil.isNullOrEmpty(list.get(0).getRelationId())) { |
| | | shareOrderMap.put(orderId, list); |
| | | } else { |
| | | // 通过红包查询 |
| | | CommonOrder commonOrder = commonOrderService |
| | | .selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, list.get(0).getTradeId()); |
| | | |
| | | if (commonOrder != null) { |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); |
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null |
| | | && hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) { |
| | | shareOrderMap.put(orderId, list); |
| | | continue; |
| | | } |
| | | |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_TAOBAO, pid); |
| | | |
| | | //--------分离自购,分享,饿了么订单类型------- |
| | | if (pidType != null) { |
| | | if ("饿了么".equalsIgnoreCase(list.get(0).getOrderType()) |
| | | && pidType != SystemPIDInfo.PidType.share) { |
| | | // 饿了么订单开始归入到淘宝订单 |
| | | if (TimeUtil.convertToTimeTemp(list.get(0).getCreateTime(), |
| | | "yyyy-MM-dd HH:mm:ss") >= Constant.NEW_ORDER_FANLI_RULE_TIME) { |
| | | fanliOrderMap.put(orderId, list); |
| | | } else { |
| | | elmeOrderMap.put(orderId, list); |
| | | } |
| | | } else { |
| | | if (!StringUtil.isNullOrEmpty(list.get(0).getSpecialId()) |
| | | || pidType == SystemPIDInfo.PidType.fanliChannel) {// 设置渠道ID当做会员运营ID的位置ID |
| | | fanliOrderMap.put(orderId, list); |
| | | } else if (!StringUtil.isNullOrEmpty(list.get(0).getRelationId())) { |
| | | shareOrderMap.put(orderId, list); |
| | | } else { |
| | | // 通过红包查询 |
| | | CommonOrder commonOrder = commonOrderService |
| | | .selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO, list.get(0).getTradeId()); |
| | | |
| | | if (commonOrder != null) { |
| | | HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); |
| | | if (hongBaoOrder != null && hongBaoOrder.getHongBaoV2() != null |
| | | && hongBaoOrder.getHongBaoV2().getType() == HongBaoV2.TYPE_SHARE_GOODS) { |
| | | shareOrderMap.put(orderId, list); |
| | | continue; |
| | | } |
| | | } |
| | | fanliOrderMap.put(orderId, list); |
| | | } |
| | | } |
| | | } else { |
| | | if ("口碑".equalsIgnoreCase(list.get(0).getOrderType()) |
| | | && pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_KOUBEI_PID)) {// 口碑自购 |
| | | fanliOrderMap.put(orderId, list); |
| | | } else { |
| | | fanliOrderMap.put(orderId, list); |
| | | } |
| | | } |
| | |
| | | String pid = String.format("mm_%s_%s_%s", configList.get(0).getAccountId(), |
| | | orderList.get(0).getSourceMediaId(), orderList.get(0).getAdPositionId()); |
| | | |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_TAOBAO, pid); |
| | | List<SystemEnum> systemList = getPidSystems(pid); |
| | | Set<Integer> sourceTypes = getPidSourceTypes(pid); |
| | | |
| | | Order oldOrder = orderMapper.selectOrderByOrderIdAndOrderType(orderId, Constant.SOURCE_TYPE_TAOBAO); |
| | | // 原来不存在订单 |
| | | Long uid = null; |
| | | if (oldOrder == null) { |
| | | Long targetUid = null; |
| | | if (pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_RELATION_AS_SPECIAL_PID) |
| | | if (pidType != null && pidType == SystemPIDInfo.PidType.fanliChannel |
| | | && !StringUtil.isNullOrEmpty(orderList.get(0).getRelationId())) {// 处理非返利商品库的商品 |
| | | targetUid = taoBaoBuyRelationMapService.selectUidByRelationId(orderList.get(0).getRelationId()); |
| | | |
| | | } else if ((pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_ELEME_PID) |
| | | } else if ((sourceTypes.contains(Constant.SOURCE_TYPE_ELME) |
| | | || pid.equalsIgnoreCase(TaoBaoConstant.TAOBAO_KOUBEI_PID)) |
| | | && !StringUtil.isNullOrEmpty(orderList.get(0).getRelationId())) {// 处理饿了么,口碑的订单 |
| | | UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService |
| | | .getByRelationId(orderList.get(0).getRelationId(), null); |
| | | .getByRelationId(orderList.get(0).getRelationId(), systemList); |
| | | if (extraInfo != null) { |
| | | targetUid = extraInfo.getUser().getId(); |
| | | } |
| | | } else if (!StringUtil.isNullOrEmpty(orderList.get(0).getSpecialId())) { |
| | | UserExtraTaoBaoInfo info = userExtraTaoBaoInfoService |
| | | .getBySpecialId(orderList.get(0).getSpecialId(), null); |
| | | .getBySpecialId(orderList.get(0).getSpecialId(), systemList); |
| | | if (info != null && info.getUser() != null) |
| | | targetUid = info.getUser().getId(); |
| | | } |
| | |
| | | if (order == null || order.getOrderItemList() == null || order.getOrderItemList().size() == 0) |
| | | return false; |
| | | Long positionId = order.getOrderItemList().get(0).getPositionId(); |
| | | if (positionId == JDApiUtil.POSITION_SHARE) {// 分享订单 |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_JD, positionId + ""); |
| | | if (pidType != null && pidType == SystemPIDInfo.PidType.share) {// 分享订单 |
| | | return true; |
| | | } |
| | | return false; |
| | |
| | | if (!StringUtil.isNullOrEmpty(uidStr) && NumberUtil.isNumeric(uidStr)) |
| | | uid = Long.parseLong(uidStr); |
| | | Long positionId = order.getOrderItemList().get(0).getPositionId(); |
| | | if (positionId == JDApiUtil.POSITION_FANLI)// 返利订单 |
| | | { |
| | | processFanLiJDOrder(order, uid); |
| | | lostOrderService.processSuceess(order.getOrderId() + "", Constant.SOURCE_TYPE_JD); |
| | | } else if (positionId == JDApiUtil.POSITION_SHARE) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processShareJDOrder(order, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_JD, positionId + ""); |
| | | |
| | | if (pidType != null) { |
| | | if (pidType == SystemPIDInfo.PidType.fanli)// 返利订单 |
| | | { |
| | | processFanLiJDOrder(order, uid); |
| | | lostOrderService.processSuceess(order.getOrderId() + "", Constant.SOURCE_TYPE_JD); |
| | | } else if (pidType == SystemPIDInfo.PidType.share) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processShareJDOrder(order, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | processFanLiJDOrder(order, null); |
| | | } |
| | | } else { |
| | | processFanLiJDOrder(order, null); |
| | | } |
| | | } |
| | |
| | | */ |
| | | private boolean isShareOrder(PDDOrder pddOrder) { |
| | | String positionId = pddOrder.getpId(); |
| | | if (PinDuoDuoApiUtil.PID_SHARE.equalsIgnoreCase(positionId)) |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_PDD, positionId); |
| | | |
| | | if (pidType != null && pidType == SystemPIDInfo.PidType.share) |
| | | return true; |
| | | else |
| | | return false; |
| | |
| | | if (!StringUtil.isNullOrEmpty(customParameters)) |
| | | uid = Long.parseLong(PinDuoDuoUtil.getUidFromCustomParams(customParameters)); |
| | | String positionId = pddOrder.getpId(); |
| | | if (PinDuoDuoApiUtil.PID_FANLI.equalsIgnoreCase(positionId))// 返利订单 |
| | | { |
| | | processFanLiPDDOrder(pddOrder, uid); |
| | | lostOrderService.processSuceess(pddOrder.getOrderSn(), Constant.SOURCE_TYPE_PDD); |
| | | } else if (PinDuoDuoApiUtil.PID_SHARE.equalsIgnoreCase(positionId)) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processSharePDDOrder(pddOrder, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_PDD, positionId); |
| | | if (pidType != null) { |
| | | if (pidType == SystemPIDInfo.PidType.fanli)// 返利订单 |
| | | { |
| | | processFanLiPDDOrder(pddOrder, uid); |
| | | lostOrderService.processSuceess(pddOrder.getOrderSn(), Constant.SOURCE_TYPE_PDD); |
| | | } else if (pidType == SystemPIDInfo.PidType.share) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processSharePDDOrder(pddOrder, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | processFanLiPDDOrder(pddOrder, null); |
| | | } |
| | | } else { |
| | | processFanLiPDDOrder(pddOrder, null); |
| | | } |
| | | } |
| | |
| | | if (!StringUtil.isNullOrEmpty(uidStr)) |
| | | uid = Long.parseLong(uidStr); |
| | | String positionId = suningOrder.getPositionId(); |
| | | if (SuningApiUtil.PID_BUY.equalsIgnoreCase(positionId))// 返利订单 |
| | | { |
| | | processFanLiSuningOrder(suningOrder, uid); |
| | | lostOrderService.processSuceess(suningOrder.getOrderCode(), Constant.SOURCE_TYPE_SUNING); |
| | | } else if (PinDuoDuoApiUtil.PID_SHARE.equalsIgnoreCase(positionId)) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processShareSuningOrder(suningOrder, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | |
| | | SystemPIDInfo.PidType pidType = getPidType(Constant.SOURCE_TYPE_SUNING, positionId); |
| | | |
| | | if (pidType != null) { |
| | | if (pidType == SystemPIDInfo.PidType.fanli)// 返利订单 |
| | | { |
| | | processFanLiSuningOrder(suningOrder, uid); |
| | | lostOrderService.processSuceess(suningOrder.getOrderCode(), Constant.SOURCE_TYPE_SUNING); |
| | | } else if (pidType == SystemPIDInfo.PidType.share) {// 分享订单 |
| | | if (uid == null)// 分享订单不允许找回 |
| | | return; |
| | | processShareSuningOrder(suningOrder, uid); |
| | | } else {// 处理是否有订单找回的状态 |
| | | processFanLiSuningOrder(suningOrder, null); |
| | | } |
| | | } else { |
| | | processFanLiSuningOrder(suningOrder, null); |
| | | } |
| | | } |
| | |
| | | |
| | | @Override |
| | | public boolean isShareOrder(CommonOrder commonOrder) { |
| | | //获取系统 |
| | | UserInfo user = userInfoMapper.selectByPrimaryKey(commonOrder.getUserInfo().getId()); |
| | | SystemEnum system = user.getSystem(); |
| | | switch (commonOrder.getSourceType()) { |
| | | case Constant.SOURCE_TYPE_TAOBAO: |
| | | return isShareOrder(taoBaoOrderService.selectByTradeId(commonOrder.getTradeId())); |
| | | return isShareOrder(system, taoBaoOrderService.selectByTradeId(commonOrder.getTradeId())); |
| | | case Constant.SOURCE_TYPE_JD: |
| | | return isShareOrder(jdOrderService.selectDetailByOrderId(Long.parseLong(commonOrder.getOrderNo()))); |
| | | case Constant.SOURCE_TYPE_PDD: |