123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- // @Description 订阅设置相关
- package service
- import (
- "errors"
- "jyBXSubscribe/entity"
- IC "jyBXSubscribe/rpc/init"
- "strconv"
- "strings"
- "app.yhyue.com/moapp/jybase/common"
- "app.yhyue.com/moapp/jybase/mongodb"
- "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type SubseribeService struct {
- Mgo mongodb.MongodbSim
- UserId string //mongodb 的用户id
- Types string //订阅信息产品类型 超级订阅、大会员、商机管理、免费订阅...
- PositionType int64
- *entity.SubscribeUpdate
- PositionId int64
- BaseUserId int64
- MgoLog mongodb.MongodbSim
- }
- // @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 := `{"i_vip_status":1,"o_vipjy":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 := common.Int64All((*r)["i_vip_status"])
- if vip_status <= 0 {
- logx.Error("用户暂无权益")
- return -1, errors.New(entity.UPDATE_ERROR_MSG)
- }
- o_vipjy := common.ObjToMap((*r)["o_vipjy"])
- //权益通过,获取要修改的参数
- setMap := map[string]interface{}{}
- if this.Area != nil {
- setMap["o_vipjy.o_area"] = this.Area
- }
- //区县
- if this.District != nil {
- setMap["o_vipjy.o_district"] = this.District
- }
- if this.Buyerclass != nil {
- setMap["o_vipjy.a_buyerclass"] = this.Buyerclass
- }
- if this.Amount != "" {
- setMap["o_vipjy.amount"] = this.Amount
- }
- setMap["o_vipjy.i_switch"] = this.ISwitch
- if this.Items != nil {
- setMap["o_vipjy.a_items"] = this.Items
- //判断是否新增
- 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,
- })
- }
- }
- if this.Infotype != nil {
- setMap["o_vipjy.a_infotype"] = this.Infotype
- }
- if this.Matchmode != "" {
- setMap["o_vipjy.i_matchmode"] = strings.Split(this.Matchmode, ",")
- }
- 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 != "" {
- i_otherbuyerclass, _ := strconv.Atoi(this.Otherbuyerclass)
- setMap["o_vipjy.i_matchbuyerclass_other"] = i_otherbuyerclass
- }
- if ok := IC.Compatible.Update(this.UserId, map[string]interface{}{
- "$set": setMap,
- }); ok {
- return 1, nil
- }
- return -1, errors.New(entity.UPDATE_ERROR_MSG)
- }
- 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
- }
|