|  | @@ -1,47 +1,34 @@
 | 
	
		
			
				|  |  |  package com.zanxiang.game.back.serve.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -import cn.hutool.http.HttpStatus;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.metadata.IPage;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 | 
	
		
			
				|  |  |  import com.zanxiang.advertising.tencent.base.AdvertisingTencentServer;
 | 
	
		
			
				|  |  | -import com.zanxiang.advertising.tencent.base.pojo.dto.DataReportOfAppIdRpcDTO;
 | 
	
		
			
				|  |  | -import com.zanxiang.advertising.tencent.base.pojo.dto.UserActionRpcDTO;
 | 
	
		
			
				|  |  |  import com.zanxiang.advertising.tencent.base.rpc.IUserActionSetRpc;
 | 
	
		
			
				|  |  |  import com.zanxiang.erp.base.ErpServer;
 | 
	
		
			
				|  |  |  import com.zanxiang.erp.base.rpc.ISysUserRpc;
 | 
	
		
			
				|  |  |  import com.zanxiang.erp.security.util.SecurityUtil;
 | 
	
		
			
				|  |  | -import com.zanxiang.game.back.base.tencent.pojo.dto.TencentOrderDTO;
 | 
	
		
			
				|  |  | -import com.zanxiang.game.back.base.tencent.pojo.dto.TencentUserDTO;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.serve.dao.mapper.GameBackPolicyMapper;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.serve.pojo.dto.GameBackPolicyDTO;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.serve.pojo.dto.GameBackPolicyListDTO;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.serve.pojo.entity.*;
 | 
	
		
			
				|  |  | -import com.zanxiang.game.back.serve.pojo.enums.ActionTypeEnum;
 | 
	
		
			
				|  |  | -import com.zanxiang.game.back.serve.pojo.enums.BackStatusEnum;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.serve.pojo.vo.GameBackPolicyVO;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.serve.service.IGameBackPolicyService;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.serve.service.IGameTencentBackLogService;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.serve.service.IGameTencentOrderService;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.back.serve.service.IGameTencentUserService;
 | 
	
		
			
				|  |  | -import com.zanxiang.game.back.serve.utils.BackPolicyUtil;
 | 
	
		
			
				|  |  | -import com.zanxiang.module.util.JsonUtil;
 | 
	
		
			
				|  |  |  import com.zanxiang.module.util.NumberUtil;
 | 
	
		
			
				|  |  |  import com.zanxiang.module.util.bean.BeanUtil;
 | 
	
		
			
				|  |  |  import com.zanxiang.module.util.exception.BaseException;
 | 
	
		
			
				|  |  | -import com.zanxiang.module.util.pojo.ResultVO;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.apache.dubbo.config.annotation.DubboReference;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | -import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.math.BigDecimal;
 | 
	
		
			
				|  |  |  import java.time.LocalDateTime;
 | 
	
		
			
				|  |  | -import java.util.HashMap;
 | 
	
		
			
				|  |  |  import java.util.List;
 | 
	
		
			
				|  |  | -import java.util.Map;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
	
		
			
				|  | @@ -67,193 +54,6 @@ public class GameBackPolicyServiceImpl extends ServiceImpl<GameBackPolicyMapper,
 | 
	
		
			
				|  |  |      private IUserActionSetRpc userActionSetRpc;
 | 
	
		
			
				|  |  |      @DubboReference(providedBy = ErpServer.SERVER_DUBBO_NAME)
 | 
	
		
			
				|  |  |      private ISysUserRpc sysUserRpc;
 | 
	
		
			
				|  |  | -    /**
 | 
	
		
			
				|  |  | -     * 支付状态,0 : 预下单, 1 : 待支付,2 : 支付成功,-1 : 已取消
 | 
	
		
			
				|  |  | -     */
 | 
	
		
			
				|  |  | -    private static final Integer COMPLETE_ORDER = 0;
 | 
	
		
			
				|  |  | -    private static final Integer PURCHASE = 2;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @Override
 | 
	
		
			
				|  |  | -    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | -    public boolean tencentOrderBack(TencentOrderDTO dto) {
 | 
	
		
			
				|  |  | -        log.error("回传腾讯订单开始,dto:{}", JsonUtil.toString(dto));
 | 
	
		
			
				|  |  | -        //订单保存
 | 
	
		
			
				|  |  | -        GameTencentOrder gameTencentOrder = GameTencentOrder.builder()
 | 
	
		
			
				|  |  | -                .adAccountId(dto.getAdAccountId())
 | 
	
		
			
				|  |  | -                .gameId(dto.getGameId())
 | 
	
		
			
				|  |  | -                .orderId(dto.getOrderId())
 | 
	
		
			
				|  |  | -                .channel(dto.getChannel())
 | 
	
		
			
				|  |  | -                .rechargeMoney(dto.getRechargeMoney())
 | 
	
		
			
				|  |  | -                .rechargeTime(dto.getRechargeTime())
 | 
	
		
			
				|  |  | -                .subscribeTime(dto.getSubscribeTime())
 | 
	
		
			
				|  |  | -                .registerTime(dto.getRegisterTime())
 | 
	
		
			
				|  |  | -                .wechatAppId(dto.getWechatAppId())
 | 
	
		
			
				|  |  | -                .wechatOpenid(dto.getWechatOpenid())
 | 
	
		
			
				|  |  | -                .orderStatus(dto.getOrderStatus())
 | 
	
		
			
				|  |  | -                .payTime(dto.getPayTime())
 | 
	
		
			
				|  |  | -                .createTime(LocalDateTime.now())
 | 
	
		
			
				|  |  | -                .isBack(BackStatusEnum.NO.getBackStatus())
 | 
	
		
			
				|  |  | -                .backPolicyId(dto.getBackPolicyId())
 | 
	
		
			
				|  |  | -                .userActionSetId(dto.getUserActionSetId())
 | 
	
		
			
				|  |  | -                .build();
 | 
	
		
			
				|  |  | -        gameTencentOrderService.save(gameTencentOrder);
 | 
	
		
			
				|  |  | -        if (!dto.getOrderStatus().equals(COMPLETE_ORDER) && !dto.getOrderStatus().equals(PURCHASE)) {
 | 
	
		
			
				|  |  | -            return true;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        String actionType = gameTencentOrder.getOrderStatus().equals(PURCHASE) ?
 | 
	
		
			
				|  |  | -                ActionTypeEnum.PURCHASE.getActionType() : ActionTypeEnum.COMPLETE_ORDER.getActionType();
 | 
	
		
			
				|  |  | -        Map<String, Object> actionParam = new HashMap<>(2);
 | 
	
		
			
				|  |  | -        actionParam.put("claim_type", 0);
 | 
	
		
			
				|  |  | -        actionParam.put("value", dto.getRechargeMoney());
 | 
	
		
			
				|  |  | -        DataReportOfAppIdRpcDTO dataReportOfAppIdRpcDTO = DataReportOfAppIdRpcDTO.builder()
 | 
	
		
			
				|  |  | -                .appId(dto.getWechatAppId())
 | 
	
		
			
				|  |  | -                .userActionSetId(dto.getUserActionSetId())
 | 
	
		
			
				|  |  | -                .action(UserActionRpcDTO.builder()
 | 
	
		
			
				|  |  | -                        .actionTime(dto.getOrderStatus().equals(PURCHASE) ? dto.getPayTime() : dto.getRechargeTime())
 | 
	
		
			
				|  |  | -                        .actionType(actionType)
 | 
	
		
			
				|  |  | -                        .userId(UserActionRpcDTO.UserIdRpcDTO.builder()
 | 
	
		
			
				|  |  | -                                .wechatAppId(dto.getWechatAppId())
 | 
	
		
			
				|  |  | -                                .wechatOpenid(dto.getWechatOpenid())
 | 
	
		
			
				|  |  | -                                .build())
 | 
	
		
			
				|  |  | -                        .actionParam(actionParam)
 | 
	
		
			
				|  |  | -                        .build())
 | 
	
		
			
				|  |  | -                .build();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        GameTencentBackLog gameTencentBackLog = GameTencentBackLog.builder()
 | 
	
		
			
				|  |  | -                .gameId(dto.getGameId())
 | 
	
		
			
				|  |  | -                .adAccountId(dto.getAdAccountId())
 | 
	
		
			
				|  |  | -                .actionTime(dto.getOrderStatus().equals(PURCHASE) ? dto.getPayTime() : dto.getRechargeTime())
 | 
	
		
			
				|  |  | -                .createTime(LocalDateTime.now())
 | 
	
		
			
				|  |  | -                .actionType(actionType)
 | 
	
		
			
				|  |  | -                .orderId(dto.getOrderId())
 | 
	
		
			
				|  |  | -                .wechatAppId(dto.getWechatAppId())
 | 
	
		
			
				|  |  | -                .wechatOpenid(dto.getWechatOpenid())
 | 
	
		
			
				|  |  | -                .userActionSetId(dto.getUserActionSetId())
 | 
	
		
			
				|  |  | -                .actionParam(actionParam.toString())
 | 
	
		
			
				|  |  | -                .build();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        boolean doBack;
 | 
	
		
			
				|  |  | -        if (null == dto.getBackPolicyId()) {
 | 
	
		
			
				|  |  | -            doBack = true;
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            GameBackPolicy gameBackPolicy = gameBackPolicyService.getById(dto.getBackPolicyId());
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            doBack = BackPolicyUtil.backOrder(gameBackPolicy, dto.getRechargeMoney(),
 | 
	
		
			
				|  |  | -                    () -> gameTencentOrderService.count(new LambdaQueryWrapper<GameTencentOrder>()
 | 
	
		
			
				|  |  | -                            .eq(GameTencentOrder::getGameId, dto.getGameId())
 | 
	
		
			
				|  |  | -                            .eq(GameTencentOrder::getWechatAppId, dto.getWechatAppId())
 | 
	
		
			
				|  |  | -                            .eq(GameTencentOrder::getAdAccountId, dto.getAdAccountId())
 | 
	
		
			
				|  |  | -                            .eq(GameTencentOrder::getOrderStatus, 2)
 | 
	
		
			
				|  |  | -                            .eq(GameTencentOrder::getWechatOpenid, dto.getWechatOpenid())
 | 
	
		
			
				|  |  | -                            .last("limit 1")
 | 
	
		
			
				|  |  | -                    ) < 1, backUnit -> Long.valueOf(gameTencentOrderService.count(new LambdaQueryWrapper<GameTencentOrder>()
 | 
	
		
			
				|  |  | -                            .eq(GameTencentOrder::getGameId, dto.getGameId())
 | 
	
		
			
				|  |  | -                            .eq(GameTencentOrder::getWechatAppId, dto.getWechatAppId())
 | 
	
		
			
				|  |  | -                            .eq(GameTencentOrder::getAdAccountId, dto.getAdAccountId())
 | 
	
		
			
				|  |  | -                            .eq(GameTencentOrder::getOrderStatus, 2)
 | 
	
		
			
				|  |  | -                            .orderByDesc(GameTencentOrder::getCreateTime)
 | 
	
		
			
				|  |  | -                            .last("limit " + backUnit)
 | 
	
		
			
				|  |  | -                    )).intValue());
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if (dto.getOrderStatus().equals(COMPLETE_ORDER) || doBack) {
 | 
	
		
			
				|  |  | -            ResultVO<Boolean> result = userActionSetRpc.reportByAppId(dataReportOfAppIdRpcDTO);
 | 
	
		
			
				|  |  | -            if (result.getCode() == HttpStatus.HTTP_OK) {
 | 
	
		
			
				|  |  | -                gameTencentOrder.setIsBack(BackStatusEnum.SUCCESS.getBackStatus());
 | 
	
		
			
				|  |  | -                gameTencentOrder.setBackLog("回传成功");
 | 
	
		
			
				|  |  | -                gameTencentOrderService.updateById(gameTencentOrder);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                gameTencentBackLog.setBackLog("回传成功");
 | 
	
		
			
				|  |  | -                gameTencentBackLogService.save(gameTencentBackLog);
 | 
	
		
			
				|  |  | -            } else {
 | 
	
		
			
				|  |  | -                log.error("回传腾讯订单失败,失败原因:{}", result.getMsg());
 | 
	
		
			
				|  |  | -                gameTencentOrder.setBackLog(result.getMsg());
 | 
	
		
			
				|  |  | -                gameTencentOrder.setIsBack(BackStatusEnum.FAILED.getBackStatus());
 | 
	
		
			
				|  |  | -                gameTencentOrderService.updateById(gameTencentOrder);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -                gameTencentBackLog.setBackLog(result.getMsg());
 | 
	
		
			
				|  |  | -                gameTencentBackLogService.saveOrUpdate(gameTencentBackLog);
 | 
	
		
			
				|  |  | -                return false;
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        return true;
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    @Override
 | 
	
		
			
				|  |  | -    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | -    public boolean tencentUserBack(TencentUserDTO dto) {
 | 
	
		
			
				|  |  | -        log.error("回传腾讯用户开始,dto:{}", JsonUtil.toString(dto));
 | 
	
		
			
				|  |  | -        GameTencentUser gameTencentUser = gameTencentUserService.getOne(new LambdaQueryWrapper<GameTencentUser>()
 | 
	
		
			
				|  |  | -                .eq(GameTencentUser::getWechatOpenid, dto.getWechatOpenid())
 | 
	
		
			
				|  |  | -                .eq(GameTencentUser::getGameId, dto.getGameId())
 | 
	
		
			
				|  |  | -                .eq(GameTencentUser::getWechatAppId, dto.getWechatAppId())
 | 
	
		
			
				|  |  | -                .eq(GameTencentUser::getAdAccountId, dto.getAdAccountId())
 | 
	
		
			
				|  |  | -                .eq(GameTencentUser::getIsBack, BackStatusEnum.SUCCESS.getBackStatus())
 | 
	
		
			
				|  |  | -        );
 | 
	
		
			
				|  |  | -        if (null == gameTencentUser) {
 | 
	
		
			
				|  |  | -            //用户保存
 | 
	
		
			
				|  |  | -            gameTencentUser = GameTencentUser.builder()
 | 
	
		
			
				|  |  | -                    .adAccountId(dto.getAdAccountId())
 | 
	
		
			
				|  |  | -                    .gameId(dto.getGameId())
 | 
	
		
			
				|  |  | -                    .channel(dto.getChannel())
 | 
	
		
			
				|  |  | -                    .subscribeTime(dto.getSubscribeTime())
 | 
	
		
			
				|  |  | -                    .registerTime(dto.getRegisterTime())
 | 
	
		
			
				|  |  | -                    .wechatAppId(dto.getWechatAppId())
 | 
	
		
			
				|  |  | -                    .wechatOpenid(dto.getWechatOpenid())
 | 
	
		
			
				|  |  | -                    .isBack(BackStatusEnum.NO.getBackStatus())
 | 
	
		
			
				|  |  | -                    .userActionSetId(dto.getUserActionSetId())
 | 
	
		
			
				|  |  | -                    .createTime(LocalDateTime.now())
 | 
	
		
			
				|  |  | -                    .build();
 | 
	
		
			
				|  |  | -            gameTencentUserService.save(gameTencentUser);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        Map<String, Object> actionParam = new HashMap<>(2);
 | 
	
		
			
				|  |  | -        actionParam.put("claim_type", 0);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        DataReportOfAppIdRpcDTO dataReportOfAppIdRpcDTO = DataReportOfAppIdRpcDTO.builder()
 | 
	
		
			
				|  |  | -                .appId(dto.getWechatAppId())
 | 
	
		
			
				|  |  | -                .userActionSetId(dto.getUserActionSetId())
 | 
	
		
			
				|  |  | -                .action(UserActionRpcDTO.builder()
 | 
	
		
			
				|  |  | -                        .actionTime(dto.getRegisterTime())
 | 
	
		
			
				|  |  | -                        .actionType(ActionTypeEnum.REGISTER.getActionType())
 | 
	
		
			
				|  |  | -                        .userId(UserActionRpcDTO.UserIdRpcDTO.builder()
 | 
	
		
			
				|  |  | -                                .wechatAppId(dto.getWechatAppId())
 | 
	
		
			
				|  |  | -                                .wechatOpenid(dto.getWechatOpenid())
 | 
	
		
			
				|  |  | -                                .build())
 | 
	
		
			
				|  |  | -                        .actionParam(actionParam)
 | 
	
		
			
				|  |  | -                        .build())
 | 
	
		
			
				|  |  | -                .build();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        GameTencentBackLog gameTencentBackLog = GameTencentBackLog.builder()
 | 
	
		
			
				|  |  | -                .gameId(dto.getGameId())
 | 
	
		
			
				|  |  | -                .adAccountId(dto.getAdAccountId())
 | 
	
		
			
				|  |  | -                .actionTime(dto.getRegisterTime())
 | 
	
		
			
				|  |  | -                .createTime(LocalDateTime.now())
 | 
	
		
			
				|  |  | -                .actionType(ActionTypeEnum.REGISTER.getActionType())
 | 
	
		
			
				|  |  | -                .wechatAppId(dto.getWechatAppId())
 | 
	
		
			
				|  |  | -                .wechatOpenid(dto.getWechatOpenid())
 | 
	
		
			
				|  |  | -                .userActionSetId(dto.getUserActionSetId())
 | 
	
		
			
				|  |  | -                .actionParam(actionParam.toString())
 | 
	
		
			
				|  |  | -                .build();
 | 
	
		
			
				|  |  | -        ResultVO<Boolean> result = userActionSetRpc.reportByAppId(dataReportOfAppIdRpcDTO);
 | 
	
		
			
				|  |  | -        if (result.getCode() == HttpStatus.HTTP_OK) {
 | 
	
		
			
				|  |  | -            gameTencentUser.setIsBack(BackStatusEnum.SUCCESS.getBackStatus());
 | 
	
		
			
				|  |  | -            gameTencentUser.setBackLog("回传成功");
 | 
	
		
			
				|  |  | -            gameTencentUserService.updateById(gameTencentUser);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            gameTencentBackLog.setBackLog("回传成功");
 | 
	
		
			
				|  |  | -            gameTencentBackLogService.save(gameTencentBackLog);
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            log.error("回传腾讯用户失败,失败原因:{}", result.getMsg());
 | 
	
		
			
				|  |  | -            gameTencentUser.setBackLog(result.getMsg());
 | 
	
		
			
				|  |  | -            gameTencentUser.setIsBack(BackStatusEnum.FAILED.getBackStatus());
 | 
	
		
			
				|  |  | -            gameTencentUserService.updateById(gameTencentUser);
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            gameTencentBackLog.setBackLog(result.getMsg());
 | 
	
		
			
				|  |  | -            gameTencentBackLogService.saveOrUpdate(gameTencentBackLog);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        return true;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public IPage<GameBackPolicyVO> policyList(GameBackPolicyListDTO dto) {
 |