admin
2020-04-21 0b57cfd62e842b309d03467b96a331c673ecad7c
fanli/src/main/java/com/yeshi/fanli/controller/client/v1/ConfigController.java
@@ -2,6 +2,7 @@
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
@@ -17,7 +18,14 @@
import com.yeshi.fanli.entity.bus.homemodule.FloatAD.FloatADTypeEnum;
import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture;
import com.yeshi.fanli.entity.bus.msg.MsgDeviceReadState;
import com.yeshi.fanli.entity.bus.user.ThreeSale;
import com.yeshi.fanli.entity.bus.user.UserActiveLog;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelUpgradedNotify;
import com.yeshi.fanli.entity.bus.user.vip.UserVIPInfo;
import com.yeshi.fanli.entity.bus.user.vip.UserVIPPreInfo;
import com.yeshi.fanli.entity.common.JumpDetailV2;
import com.yeshi.fanli.entity.config.AppHomeFloatImg;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.entity.taobao.ClientTBPid;
@@ -31,10 +39,21 @@
import com.yeshi.fanli.service.inter.user.TBPidService;
import com.yeshi.fanli.service.inter.user.UserActiveLogService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.notify.UserActivedRecordService;
import com.yeshi.fanli.service.inter.user.vip.UserLevelUpgradedNotifyService;
import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
import com.yeshi.fanli.service.inter.user.vip.UserVIPPreInfoService;
import com.yeshi.fanli.service.inter.user.vip.UserVipConfigService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.ThreadUtil;
import com.yeshi.fanli.util.TimeUtil;
import com.yeshi.fanli.util.VersionUtil;
import com.yeshi.fanli.vo.user.UserDialogBtnVO;
import com.yeshi.fanli.vo.user.UserDialogVO;
import com.yeshi.fanli.vo.user.VIPUpgradedNotifyVO;
import net.sf.json.JSONObject;
@@ -74,10 +93,32 @@
   @Resource
   private UserActiveLogService userActiveLogService;
   @Resource
   private SwiperPictureService swiperPictureService;
   @Resource
   private UserActivedRecordService userActivedRecordService;
   @Resource
   private UserInfoService userInfoService;
   @Resource
   private UserVIPInfoService userVIPInfoService;
   @Resource
   private UserVIPPreInfoService userVIPPreInfoService;
   @Resource
   private UserLevelUpgradedNotifyService userLevelUpgradedNotifyService;
   @Resource
   private ThreeSaleSerivce threeSaleSerivce;
   @Resource
   private UserVipConfigService userVipConfigService;
   /**
    * s 首页配置信息
@@ -104,7 +145,6 @@
      if (!StringUtil.isNullOrEmpty(notifyImg)) {
         data.put("floatNotifyImg", notifyImg);
      }
      // 无新人弹框 则查询默认
      FloatAD floatAD = floatADService.getEffectiveFloatAD(FloatAD.POSITION_INDEX, 0);
@@ -138,8 +178,8 @@
      } else {// 老人
         data.put("userTimeType", 1);
      }
      data.put("hotFuctionLink",
            configService.getByVersion(ConfigKeyEnum.hotFunctionUrl.getKey(), platform, Integer.parseInt(acceptData.getVersion())));//
      data.put("hotFuctionLink", configService.getByVersion(ConfigKeyEnum.hotFunctionUrl.getKey(), platform,
            Integer.parseInt(acceptData.getVersion())));//
      out.print(JsonUtil.loadTrueResult(data));
   }
@@ -163,7 +203,8 @@
      }
      // 是否需要购物城转链
      boolean convert = "0".equalsIgnoreCase(configService.get(ConfigKeyEnum.showTaobaoCartConvert.getKey())) ? false : true;
      boolean convert = "0".equalsIgnoreCase(configService.get(ConfigKeyEnum.showTaobaoCartConvert.getKey())) ? false
            : true;
      if (!"cart".equalsIgnoreCase(position) && !convert) {
         out.print(JsonUtil.loadFalseResult(""));
@@ -238,8 +279,41 @@
      out.print(JsonUtil.loadTrueResult(data));
   }
   /**
    * 关闭提醒
    *
    * @param acceptData
    * @param uid
    * @param id
    * @param type
    *            0-关闭 1-点击右边按钮 2-点击左边按钮
    * @param out
    */
   @RequestMapping(value = "closeDialogNotify", method = RequestMethod.POST)
   public void closeDialogNotify(AcceptData acceptData, Long uid, String id, String sourceId, int type,
         PrintWriter out) {
      if (uid == null) {
         out.print(JsonUtil.loadFalseResult("用户未登录"));
         return;
      }
      if (StringUtil.isNullOrEmpty(id)) {
         out.print(JsonUtil.loadFalseResult("id为空"));
         return;
      }
      if (id.equalsIgnoreCase("tearcherNotify")) {
         userActivedRecordService.setTearcherNotified(uid);
         out.print(JsonUtil.loadTrueResult(""));
      } else if (id.equalsIgnoreCase("vipUpgradedNotify")) {
         userLevelUpgradedNotifyService.setNotified(sourceId);
         out.print(JsonUtil.loadTrueResult(""));
      } else {
         out.print(JsonUtil.loadFalseResult("id不存在"));
      }
   }
   @RequestMapping(value = "getUserConfig", method = RequestMethod.POST)
   public void getUserConfig(AcceptData acceptData, PrintWriter out) {
   public void getUserConfig(AcceptData acceptData, Long uid, PrintWriter out) {
      try {
         // 用户协议链接
         String serviceProtocol = configService.get(ConfigKeyEnum.serviceProtocolLink.getKey());
@@ -249,23 +323,138 @@
         data.put("serviceProtocolLink", serviceProtocol);
         data.put("privacyProtocolLink", privacyProtocol);
         // 购物车跳转方式(包含jumpDetail与params)
         JSONObject source = JSONObject.fromObject(configService.getByVersion(ConfigKeyEnum.taobaoCartJumpDetail.getKey(),
               acceptData.getPlatform(), Integer.parseInt(acceptData.getVersion())));
         JSONObject source = JSONObject
               .fromObject(configService.getByVersion(ConfigKeyEnum.taobaoCartJumpDetail.getKey(),
                     acceptData.getPlatform(), Integer.parseInt(acceptData.getVersion())));
         data.put("taoBaoCart", source);
         if (VersionUtil.greaterThan_2_0_2(acceptData.getPlatform(), acceptData.getVersion())) {
            // 我的界面banner
            List<SwiperPicture> banner = swiperPictureService.getByBannerCardAndVersion("my_interface_banner",acceptData.getPlatform(), Integer.parseInt(acceptData.getVersion()));
            List<SwiperPicture> banner = swiperPictureService.getByBannerCardAndVersion("my_interface_banner",
                  acceptData.getPlatform(), Integer.parseInt(acceptData.getVersion()));
            if (banner == null)
               banner = new ArrayList<SwiperPicture>();
            data.put("banner", JsonUtil.getApiCommonGson().toJson(banner));
         }
         }
         if (VersionUtil.greaterThan_2_0_7(acceptData.getPlatform(), acceptData.getVersion())) {
            // 转链的网页链接
            String convertLinkUrl = configService.get(ConfigKeyEnum.convertDocWebLink.getKey());
            data.put("convertLinkUrl", convertLinkUrl);
            if (uid != null) {
               String tearcherLink = configService.getByVersion(ConfigKeyEnum.tearcherLink.getKey(),
                     acceptData.getPlatform(), Integer.parseInt(acceptData.getVersion()));
               if (userActivedRecordService.canNotifyAddTearcher(uid) && !StringUtil.isNullOrEmpty(tearcherLink)) {
                  UserInfo userInfo = userInfoService.selectAvailableByPrimaryKey(uid);
                  if (userInfo != null) {
                     JumpDetailV2 jumpDetail = jumpDetailV2Service.getByTypeCache("web",
                           Constant.getPlatformCode(acceptData.getPlatform()),
                           Integer.parseInt(acceptData.getVersion()));
                     JSONObject negativeParams = new JSONObject();
                     negativeParams.put("url", configService.getByVersion(ConfigKeyEnum.newerGonglue.getKey(),
                           acceptData.getPlatform(), Integer.parseInt(acceptData.getVersion())));
                     JSONObject positiveParams = new JSONObject();
                     positiveParams.put("url", tearcherLink);
                     UserDialogVO dialog = new UserDialogVO("tearcherNotify", true,
                           "HI," + userInfo.getNickName(),
                           "我是你的导师,为你在省赚过程中解难答疑,对你一对一辅导,倾听你的需求总结并反馈给板栗快省官方运营团队,快来添加我吧。",
                           new UserDialogBtnVO("复制导师微信", jumpDetail, positiveParams),
                           new UserDialogBtnVO("去新手攻略", jumpDetail, negativeParams));
                     data.put("dialog", dialog);
                  }
               }
               data.put("tearcherLink", tearcherLink);
            }
         }
         if (VersionUtil.greaterThan_2_1(acceptData.getPlatform(), acceptData.getVersion())) {
            // TODO 验证是否是导师
            JSONObject inner = new JSONObject();
            inner.put("link", userVipConfigService.getValueByKey("vip_link"));
            inner.put("ion", "http://img.flqapp.com/resource/vip/icon_vip.png");
            inner.put("title", "免费升级 享会员权益");
            inner.put("btnName", "升级会员");
            if (uid != null) {
               // 是否导师 TODO
               if (userVIPInfoService.isVIP(uid)) {
                  inner.put("link", userVipConfigService.getValueByKey("vip_link"));
                  inner.put("ion", "http://img.flqapp.com/resource/vip/icon_tearcher.png");
                  inner.put("title", "拿五险与津贴 享导师权益");
                  inner.put("btnName", "升级会员");
               } else {
                  UserVIPPreInfo userVIPPreInfo = userVIPPreInfoService.getLatestProcessInfo(uid);
                  if (userVIPPreInfo != null) {
                     if (userVIPPreInfo.getProcess() == UserVIPPreInfo.PROCESS_1) {
                        inner.put("btnName", "升级高级会员");
                     } else if (userVIPPreInfo.getProcess() == UserVIPPreInfo.PROCESS_2) {
                        inner.put("btnName", "升级超级会员");
                     }
                  }
               }
            }
            data.put("vip", inner);
         }
         if (VersionUtil.greaterThan_2_1(acceptData.getPlatform(), acceptData.getVersion()) && uid != null) {
            UserLevelUpgradedNotify notify = userLevelUpgradedNotifyService.getNeedNotifyByUid(uid);
            if (notify != null) {
               Date endTime = getUpgradedTime(uid, notify.getToLevel());
               Date startTime = getUpgradedTime(uid, notify.getFromLevel());
               if (endTime != null && startTime != null) {
                  VIPUpgradedNotifyVO notifyVO = new VIPUpgradedNotifyVO();
                  notifyVO.setDay(TimeUtil.getDayDifferenceCount(startTime, endTime));
                  notifyVO.setDetailLink(notify.getToLevel().getDetailLink());
                  notifyVO.setFromLevelName(notify.getFromLevel().getName());
                  notifyVO.setId("vipUpgradedNotify");
                  notifyVO.setSourceId(notify.getId());
                  notifyVO.setToLevel(notify.getToLevel().getTag());
                  notifyVO.setToLevelName(notify.getToLevel().getName());
                  data.put("vipUpgradedNotify", notifyVO);
               }
            }
         }
         out.print(JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult("获取失败"));
         e.printStackTrace();
      }
   }
   // 获取升级时间
   private Date getUpgradedTime(Long uid, UserLevelEnum level) {
      Date time = null;
      if (level == UserLevelEnum.superVIP) {
         UserVIPInfo vipInfo = userVIPInfoService.selectByUid(uid);
         if (vipInfo != null && vipInfo.getState() == UserVIPInfo.STATE_SUCCESS)
            time = vipInfo.getSuccessTime();
      } else if (level == UserLevelEnum.highVIP) {
         UserVIPPreInfo info = userVIPPreInfoService.selectByUidAndProcess(uid, level.getLevel());
         if (info != null)
            time = info.getCreateTime();
      } else if (level == UserLevelEnum.daRen) {
         // 成为达人的时间,用户激活时间
         ThreeSale threeSale = threeSaleSerivce.getByWorkerId(uid);
         if (threeSale != null && threeSale.getState() == true && threeSale.getSucceedTime() != null) {
            time = new Date(threeSale.getSucceedTime());
         } else {// 取用户注册时间
            UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
            time = new Date(user.getCreatetime());
         }
      }
      return time;
   }
   /**
@@ -306,7 +495,8 @@
   public void getOrderConfig(AcceptData acceptData, PrintWriter out) {
      JSONObject data = new JSONObject();
      // 测试
      data.put("showTaoBaoOrder", "0".equalsIgnoreCase(configService.get(ConfigKeyEnum.showTaobaoOrder.getKey()).trim()) ? false : true);
      data.put("showTaoBaoOrder",
            "0".equalsIgnoreCase(configService.get(ConfigKeyEnum.showTaobaoOrder.getKey()).trim()) ? false : true);
      data.put("taoBaoOrderUrl", "https://main.m.taobao.com/olist/index.html");
      out.print(JsonUtil.loadTrueResult(data));
   }