// @Description 订阅设置相关 package service import ( "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/mongodb" "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy" "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/entity" IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/init" "errors" "fmt" "github.com/gogf/gf/v2/util/gconv" "github.com/zeromicro/go-zero/core/logx" "strconv" "strings" "time" ) type SubseribeService struct { Mgo mongodb.MongodbSim UserId string //mongodb 的用户id Types string //订阅信息产品类型 超级订阅、大会员、商机管理、免费订阅... PositionType int64 *entity.SubscribeUpdate PositionId int64 BaseUserId int64 MgoLog mongodb.MongodbSim UserType string } // @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) } //查询条件 //查询字段 fields := `` key := "" status := "" switch this.UserType { //fType:普通用户;vType:超级订阅用户;mType:大会员用户;eType:商机管理用户 case "fType": fields = `{"o_jy":1}` key = "o_jy" case "vType": key = "o_vipjy" status = "i_vip_status" fields = `{"i_vip_status":1,"o_vipjy":1}` case "mType": key = "o_member_jy" status = "i_member_status" fields = `{"i_member_status":1,"o_member_jy":1}` } //查询用户信息 r := IC.Compatible.Select(this.UserId, fields) if r == nil || len(*r) == 0 { logx.Error("未找到用户") return -1, errors.New(entity.UPDATE_ERROR_MSG) } //判断用户权益 vip_status := int64(1) if key != "o_jy" { vip_status = common.Int64All((*r)[status]) } if vip_status <= 0 { logx.Error("用户暂无权益") return -1, errors.New(entity.UPDATE_ERROR_MSG) } o_vipjy := common.ObjToMap((*r)[key]) //权益通过,获取要修改的参数 setMap := map[string]interface{}{} if this.Area != nil { setMap[KeyHandle(key, "o_area")] = this.Area } //区县 if this.District != nil { setMap[KeyHandle(key, "o_district")] = this.District } if this.Buyerclass != nil { setMap[KeyHandle(key, "a_buyerclass")] = this.Buyerclass } if this.Amount != "" { setMap[KeyHandle(key, "amount")] = this.Amount } if this.UserType != "vType" { this.ISwitch = 1 } setMap[KeyHandle(key, "i_switch")] = this.ISwitch if this.Items != nil { if this.UserType == "fType" { if len(this.Items) > 0 { setMap[KeyHandle(key, "a_key")] = gconv.Maps(this.Items[0]["a_key"]) } } else { if this.UserType == "vType" { //判断是否新增 keyLen := 0 if (*o_vipjy)["a_items"] != nil { aitems, _ := (*o_vipjy)["a_items"].([]interface{}) a_items := common.ObjArrToMapArr(aitems) keyLen = GetKeyWordLen(a_items) } newKeyLen := GetKeyWordLen(this.Items) if newKeyLen > keyLen { jy.Publish(this.MgoLog, IC.C.Nsq, IC.C.NsqTopic, "task", this.UserId, jy.Jyweb_node2, map[string]interface{}{ "code": 1015, //首次订阅 "types": "subscribeKeyWords", "num": 50, "baseUserId": this.BaseUserId, "positionId": this.PositionId, }) } } //大会员 setMap[KeyHandle(key, "a_items")] = this.Items } } if this.Infotype != nil { setMap[KeyHandle(key, "a_infotype")] = this.Infotype } if this.Matchmode != "" { setMap[KeyHandle(key, "i_matchmode")] = strings.Split(this.Matchmode, ",") } if this.Matchway != "" { i_matchway, _ := strconv.Atoi(this.Matchway) setMap[KeyHandle(key, "i_matchway")] = i_matchway } if this.Projectmatch != "" { i_projectmatch, _ := strconv.Atoi(this.Projectmatch) setMap[KeyHandle(key, "i_projectmatch")] = i_projectmatch } if this.Ratemode != "" { i_ratemode, _ := strconv.Atoi(this.Ratemode) setMap[KeyHandle(key, "i_ratemode")] = i_ratemode } if this.Apppush != "" { i_apppush, _ := strconv.Atoi(this.Apppush) setMap[KeyHandle(key, "i_apppush")] = i_apppush } if this.Mailpush != "" { i_mailpush, _ := strconv.Atoi(this.Mailpush) setMap[KeyHandle(key, "i_mailpush")] = i_mailpush } if this.Mail != "" { setMap[KeyHandle(key, "s_email")] = this.Mail } if this.Otherbuyerclass != "" { i_otherbuyerclass, _ := strconv.Atoi(this.Otherbuyerclass) setMap[KeyHandle(key, "i_matchbuyerclass_other")] = i_otherbuyerclass } if ok := IC.Compatible.Update(this.UserId, map[string]interface{}{ "$set": setMap, }); ok { data := IC.Compatible.Select(this.UserId, `{"o_vipjy":1,"o_member_jy":1,"o_jy":"1"}`) if data != nil && len(*data) > 0 { (*data)["userid"] = this.UserId (*data)["type"] = key (*data)["createtime"] = time.Now().Unix() IC.MgoLog.Save("ovipjy_log", data) } return 1, nil } //日志保存 return -1, errors.New(entity.UPDATE_ERROR_MSG) } func KeyHandle(k, v string) string { return fmt.Sprintf("%s.%s", k, v) } func GetKeyWordLen(a_items []map[string]interface{}) (count int) { if len(a_items) == 0 { return } for _, v := range a_items { a_key, _ := v["a_key"].([]interface{}) count += len(a_key) } return }