Ver Fonte

feat:返回字段格式修改

duxin há 2 anos atrás
pai
commit
6515e099a3

+ 9 - 1
jyBXSubscribe/api/internal/logic/distributorlogic.go

@@ -40,10 +40,18 @@ func (l *DistributorLogic) Distributor(req *types.DistributorReq) (resp *types.C
 			Data:     nil,
 		}, nil
 	}
+	var data []map[string]interface{}
+	for _, v := range res.Items {
+		_d := make(map[string]interface{})
+		_d["name"] = v.Name
+		_d["id"] = v.Id
+		_d["phone"] = v.Phone
+		data = append(data, _d)
+	}
 	return &types.CommonResp{
 		Err_code: res.ErrCode,
 		Err_msg:  res.ErrMsg,
-		Data:     res.Items,
+		Data:     data,
 	}, nil
 	return
 }

+ 15 - 1
jyBXSubscribe/api/internal/logic/viewStatusLogic.go

@@ -3,6 +3,7 @@ package logic
 import (
 	"context"
 	"jyBXSubscribe/rpc/type/bxsubscribe"
+	"time"
 
 	"jyBXSubscribe/api/internal/svc"
 	"jyBXSubscribe/api/internal/types"
@@ -39,10 +40,23 @@ func (l *ViewStatusLogic) ViewStatus(req *types.ViewStatusReq) (resp *types.Comm
 			Data:     nil,
 		}, nil
 	}
+	var data []map[string]interface{}
+	for _, v := range res.Items {
+		_d := make(map[string]interface{})
+		_d["name"] = v.Name
+		_d["id"] = v.Id
+		var visittime string
+		if v.Visittime > 0 {
+			visittime = time.Unix(v.Visittime, 0).Format("2006/01/02")
+		}
+		_d["visittime"] = visittime
+		_d["isvisit"] = v.Isvisit
+		data = append(data, _d)
+	}
 	return &types.CommonResp{
 		Err_code: res.ErrCode,
 		Err_msg:  res.ErrMsg,
-		Data:     res.Items,
+		Data:     data,
 	}, nil
 	return
 }

+ 15 - 5
jyBXSubscribe/rpc/internal/logic/getviewstatuslogic.go

@@ -42,7 +42,7 @@ func (l *GetViewStatusLogic) GetViewStatus(in *bxsubscribe.GetViewStatusReq) (*b
 	in.InfoId = util.DecodeId(in.InfoId)
 	log.Println("查看状态参数", in)
 	res := new(bxsubscribe.ViewStatusResp)
-	finsql = `SELECT userid,isvisit,visittime,date FROM pushentniche where  infoid =? and source in (2,3) order By date asc`
+	finsql = `SELECT userid,isvisit,visittime,date FROM pushentniche where  infoid =? and source in (2,3) order By date desc`
 	if user.Role_admin_department {
 		users = model.GetDisUsers(common.IntAll(in.EntId), user.Dept.Id)
 		if users != nil && len(*users) > 0 {
@@ -59,7 +59,7 @@ func (l *GetViewStatusLogic) GetViewStatus(in *bxsubscribe.GetViewStatusReq) (*b
 		users = model.GetEntUsers(common.IntAll(in.EntId))
 	}
 	if len(ss) > 0 {
-		finsql = fmt.Sprintf(`SELECT userid,isvisit,visittime,date FROM pushentniche where  infoid =? and source in (2,3) %s order By date asc`, fmt.Sprintf(`and userid in (%s)`, strings.Join(ss, ",")))
+		finsql = fmt.Sprintf(`SELECT userid,isvisit,visittime,date FROM pushentniche where  infoid =? and source in (2,3) %s order By date desc`, fmt.Sprintf(`and userid in (%s)`, strings.Join(ss, ",")))
 	}
 	data := IC.BaseServiceMysql.SelectBySql(finsql, in.InfoId)
 	userMap := make(map[int]string)
@@ -76,14 +76,24 @@ func (l *GetViewStatusLogic) GetViewStatus(in *bxsubscribe.GetViewStatusReq) (*b
 				da.Isvisit = common.Int64All(v["isvisit"])
 				da.Visittime = common.Int64All(v["visittime"])
 				da.Id = common.Int64All(userid)
-				if v2, ok1 := d[common.InterfaceToStr(userid)]; !ok1 {
+				if _, ok1 := d[common.InterfaceToStr(userid)]; !ok1 {
 					res.Items = append(res.Items, &da)
 					d[common.InterfaceToStr(userid)] = len(res.Items) - 1
-				} else {
-					res.Items[v2] = &da
 				}
 			}
 		}
 	}
+	Reverse(&res.Items)
 	return res, nil
 }
+
+// 数组倒序函数
+func Reverse(arr *[]*bxsubscribe.UserStatus) {
+	var temp *bxsubscribe.UserStatus
+	length := len(*arr)
+	for i := 0; i < length/2; i++ {
+		temp = (*arr)[i]
+		(*arr)[i] = (*arr)[length-1-i]
+		(*arr)[length-1-i] = temp
+	}
+}