package user import ( "strings" "yunyan/comm" "yunyan/pb" ) // @Summary 获取渠道包信息 // @Description 获取渠道包信息并校验升级:传了 version 时返回 needupdate/forceupdate/reviewing 三个判定结果 // @Tags User // @Accept json // @Produce json // @Param user body pb.UserGetChannelAppReq true "获取渠道包信息" // @Success 200 {object} comm.HttpResult{data=pb.UserGetChannelAppResp} "成功返回" // @Router /api/home/user_getchannelapp [post] // // 升级判定一律由服务端算:版本号比较要逐段按整数比("1.10.0" > "1.9.0",按字符串比会判反), // 各客户端各写一遍必然有实现不一致,故统一收敛到 comm.CompareVersion / NeedForceUpdate。 func (this *apiComp) GetChannelApp(session comm.IUserSession, req *pb.UserGetChannelAppReq) (resp *pb.UserGetChannelAppResp, errdata *pb.ErrorData) { cfg, err := this.module.model.getChannelAppCfg(req.Channel) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Message: err.Error(), } return } resp = &pb.UserGetChannelAppResp{App: toPbChannelApp(cfg, req.Version)} resp.Needupdate, resp.Forceupdate, resp.Reviewing = evalChannelUpgrade(cfg, req.Version) return } // evalChannelUpgrade 由渠道配置与客户端版本算出三个升级判定。 // 渠道未配置或客户端没上报版本时全部为 false —— 客户端照旧走「无更新」分支, // 绝不能因为拿不到版本就判成强更,那会把所有老客户端挡在门外。 func evalChannelUpgrade(cfg *comm.ChannelApp, clientVer string) (need, force, reviewing bool) { if cfg == nil || strings.TrimSpace(clientVer) == "" { return false, false, false } if strings.TrimSpace(cfg.Version) != "" { need = comm.CompareVersion(clientVer, cfg.Version) < 0 } force = cfg.NeedForceUpdate(clientVer) // 强更必然意味着有更新可用:即便运营忘了把线上版本填得比最低支持版本高,也不该出现 // 「必须更新但没有更新」这种客户端无法处理的组合。 if force { need = true } reviewing = cfg.IsReviewing(clientVer) return }