123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- package logic
- import (
- "app.yhyue.com/moapp/jybase/common"
- it "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/api/init"
- "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/api/internal/svc"
- "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/api/internal/types"
- . "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/entity"
- "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/bxsubscribe"
- "context"
- "encoding/json"
- "fmt"
- "github.com/zeromicro/go-zero/core/logx"
- "time"
- )
- type SubscribeUpdateLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewSubscribeUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SubscribeUpdateLogic {
- return &SubscribeUpdateLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx,
- }
- }
- func (l *SubscribeUpdateLogic) SubscribeUpdate(req *types.SubscribeUpdateReq) (resp *types.CommonResp, err error) {
- resp = &types.CommonResp{}
- if req.UserId == "" {
- return
- } else if KeyWordsRepeat(req.Items) {
- resp.Data = map[string]interface{}{
- "status": -1,
- }
- resp.Err_code, resp.Err_msg = -1, "关键词设置异常"
- return
- }
- su := &SubscribeUpdate{
- Area: req.Area,
- Buyerclass: req.Buyerclass,
- Items: req.Items,
- Infotype: req.Infotype,
- Matchway: req.Matchway,
- Projectmatch: req.Projectmatch,
- Ratemode: req.Ratemode,
- Apppush: req.Apppush,
- Mailpush: req.Mailpush,
- Mail: req.Mail,
- Otherbuyerclass: req.Otherbuyerclass,
- District: req.District,
- Amount: req.Amount,
- ISwitch: req.ISwitch,
- Matchmode: req.Matchmode,
- }
- fmt.Println("###")
- b, _ := json.Marshal(su)
- rp, err := l.svcCtx.Suscribe.UpdateSubScribeInfo(l.ctx, &bxsubscribe.UpdateSubScribeInfoReq{
- UserId: req.UserId,
- PositionType: req.PositionType,
- SubSet: b,
- BaseUserId: req.NewUserId,
- PositionId: req.PositionId,
- UserType: req.UserType,
- MgoUserId: req.MgoUserId,
- })
- if err != nil {
- resp.Err_code, resp.Err_msg = -1, "修改失败"
- l.Error(fmt.Sprintf("%+v", req), resp.Err_msg)
- } else {
- saveData := map[string]interface{}{
- "userid": req.UserId,
- "o_vipjy": req,
- "createtime": time.Now().Unix(),
- "type": "o_vipjy",
- }
- go it.SubscribeUpdateLog.SendLogs(saveData)
- resp.Data = map[string]interface{}{
- "status": rp.Status,
- }
- }
- return
- }
- // 判断关键词是否异常,
- func KeyWordsRepeat(aitems []map[string]interface{}) bool {
- m := map[string]bool{} //去重的数组
- // 录入的关键词
- i := 0
- for _, items := range aitems {
- for kk, vv := range items {
- if kk == "a_key" {
- for _, n := range common.ObjArrToMapArr(vv.([]interface{})) {
- db_not := []string{}
- db_key := []string{}
- db_append := []string{}
- matchway := 0
- if n["key"] != nil {
- db_key = common.ObjArrToStringArr(n["key"].([]interface{}))
- }
- if n["notkey"] != nil {
- db_not = common.ObjArrToStringArr(n["notkey"].([]interface{}))
- }
- if n["appendkey"] != nil {
- db_append = common.ObjArrToStringArr(n["appendkey"].([]interface{}))
- }
- if n["matchway"] != nil {
- matchway = common.IntAll(n["matchway"])
- if mn, ok := n["matchway"].(json.Number); matchway == 0 && ok {
- mi, _ := mn.Int64()
- matchway = int(mi)
- }
- }
- key := fmt.Sprintf("%v%v%v%d", db_key, db_append, db_not, matchway)
- if m[key] {
- return true //有重复 不可以提交
- }
- i++
- m[key] = true
- }
- }
- }
- }
- if i > 300 {
- //关键词大于300异常
- return true
- }
- return false
- }
|