// @Description 订阅设置相关 package service import ( "errors" "jyBXSubscribe/entity" "log" "strconv" "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/mongodb" "github.com/zeromicro/go-zero/core/logx" ) // type SubseribeService struct { Mgo mongodb.MongodbSim UserId string //mongodb 的用户id Types string //订阅信息产品类型 超级订阅、大会员、商机管理、免费订阅... Area map[string]interface{} //地区 Buyerclass []string //采购单位类型 Items []map[string]interface{} //关键词 Infotype []string //信息类型 Matchway string //匹配方式 1标题 2正文 Projectmatch string //项目匹配 1开始 0关闭 Ratemode string // 1:实时推送,2:每天9点推送,3:每周推送,4:每月推送 5:每日推送两次 Apppush string //app推送 1开启 0关闭 Mailpush string //邮箱推送 1开启 0关闭 Mail string //邮箱 Otherbuyerclass string //匹配未分类类型 1匹配 0不匹配 } // @description 订阅设置相关修改 // @param SubseribeService 用户信息相关 // @return int64 是否成功 1成功 -1失败 // @return error 错误信息 //TODO 后期需要实现 查询各个身份的订阅设置修改[目前只实现了超级订阅] func (this *SubseribeService) Update() (int64, error) { if this.UserId == "" { return -1, errors.New(entity.UPDATE_ERROR_MSG) } //查询条件 query := map[string]interface{}{ "_id": mongodb.StringTOBsonId(this.UserId), } //查询字段 fields := `{"i_vip_status":1,"o_vipjy":1}` //查询用户信息 r, ok := this.Mgo.FindOneByField(entity.User, query, fields) if !ok || r == nil || len(*r) == 0 { logx.Error("未找到用户") return -1, errors.New(entity.UPDATE_ERROR_MSG) } //判断用户权益 vip_status := common.Int64All((*r)["i_vip_status"]) if vip_status <= 0 { logx.Error("用户暂无权益") return -1, errors.New(entity.UPDATE_ERROR_MSG) } //权益通过,获取要修改的参数 setMap := map[string]interface{}{} if this.Area != nil { setMap["o_vipjy.o_area"] = this.Area } if this.Buyerclass != nil { setMap["o_vipjy.a_buyerclass"] = this.Buyerclass } if this.Items != nil { setMap["o_vipjy.a_items"] = this.Items } if this.Infotype != nil { setMap["o_vipjy.a_infotype"] = this.Infotype } if this.Matchway != "" { i_matchway, _ := strconv.Atoi(this.Matchway) setMap["o_vipjy.i_matchway"] = i_matchway } if this.Projectmatch != "" { i_projectmatch, _ := strconv.Atoi(this.Projectmatch) setMap["o_vipjy.i_projectmatch"] = i_projectmatch } if this.Ratemode != "" { i_ratemode, _ := strconv.Atoi(this.Ratemode) setMap["o_vipjy.i_ratemode"] = i_ratemode } if this.Apppush != "" { i_apppush, _ := strconv.Atoi(this.Apppush) setMap["o_vipjy.i_apppush"] = i_apppush } if this.Mailpush != "" { i_mailpush, _ := strconv.Atoi(this.Mailpush) setMap["o_vipjy.i_mailpush"] = i_mailpush } if this.Mail != "" { setMap["o_vipjy.s_email"] = this.Mail } if this.Otherbuyerclass != "" { setMap["o_vipjy.i_matchbuyerclass_other"] = this.Otherbuyerclass } log.Println(setMap) if ok := this.Mgo.UpdateById(entity.User, this.UserId, map[string]interface{}{ "$set": setMap, }); ok { return 1, nil } return -1, errors.New(entity.UPDATE_ERROR_MSG) }