package logic import ( "app.yhyue.com/moapp/jybase/common" "context" "jyBXBase/rpc/bxcollection/model" "strings" "jyBXBase/rpc/bxcollection/bxcol" "jyBXBase/rpc/bxcollection/internal/svc" "github.com/zeromicro/go-zero/core/logx" ) type CheckSearchLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewCheckSearchLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckSearchLogic { return &CheckSearchLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } // 修改筛选列表 func (l *CheckSearchLogic) CheckSearch(in *bxcol.AddSearchReq) (res *bxcol.CommonRes, err error) { // todo: add your logic here and delete this line res = new(bxcol.CommonRes) if in.UserId == "" { res.ErrCode = 1 res.ErrMsg = "用户未登录" return } if in.Keywords == "" { res.ErrCode = 1 res.ErrMsg = "请先输入关键词" return } in.NotKey = strings.Replace(in.NotKey, " ", ",", -1) in.Keywords = strings.Replace(in.Keywords, " ", ",", -1) query := map[string]interface{}{ "user_id": in.UserId, } allData, b := model.Mgo.Find("search_condition", query, "", "", false, -1, -1) if !b { res.ErrCode = 1 res.ErrMsg = "查询失败" return } if allData != nil { if len(*allData) >= 10 { res.ErrCode = 1 res.ErrMsg = "对不起,最多可保存10个筛选条件。" return } //判重 for _, vlu := range *allData { if in.Keywords == common.InterfaceToStr(vlu["keywords"]) && in.Type == common.InterfaceToStr(vlu["type"]) && in.PublishTime == common.InterfaceToStr(vlu["publish_time"]) && in.Area == common.InterfaceToStr(vlu["area"]) && in.City == common.InterfaceToStr(vlu["city"]) && in.Subtype == common.InterfaceToStr(vlu["subtype"]) && in.MinPrice == common.InterfaceToStr(vlu["min_price"]) && in.MaxPrice == common.InterfaceToStr(vlu["max_price"]) && in.Industry == common.InterfaceToStr(vlu["industry"]) && in.SelectType == common.InterfaceToStr(vlu["select_type"]) && in.BuyerClass == common.InterfaceToStr(vlu["buyer_class"]) && in.HasBuyerTel == common.InterfaceToStr(vlu["buyer_tel"]) && in.HasWinnerTel == common.InterfaceToStr(vlu["winner_tel"]) && in.FileExists == common.InterfaceToStr(vlu["file_exists"]) && in.NotKey == common.InterfaceToStr(vlu["not_key"]) && in.TabularFlag == common.InterfaceToStr(vlu["tabular_flag"]) { res.ErrCode = 1 res.ErrMsg = "该条件已保存,无需重复添加。" return } } } return }