package svc import ( "applet/app/db" "applet/app/e" "applet/app/md" "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "encoding/json" "github.com/gin-gonic/gin" "time" ) func UserFeedbackCate(c *gin.Context) { NewUserFeedbackCateDb := implement.NewUserFeedbackCateDb(db.Db) cate, _ := NewUserFeedbackCateDb.FindUserFeedbackCate("1", "100") data := make([]map[string]string, 0) if cate != nil { for _, v := range *cate { tmp := map[string]string{ "id": utils.IntToStr(v.Id), "name": v.Name, } data = append(data, tmp) } } e.OutSuc(c, data, nil) return } func UserFeedbackList(c *gin.Context) { eg := db.Db var req md.UserFeedbackListReq err := c.ShouldBindJSON(&req) if err != nil { err = HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } user := GetUser(c) NewUserFeedbackDb := implement.NewUserFeedbackDb(eg) article, _ := NewUserFeedbackDb.FindUserFeedback(req.Page, req.Limit, utils.Int64ToStr(user.Id)) data := make([]md.UserFeedbackListResp, 0) if article != nil { for _, v := range *article { img := make([]string, 0) json.Unmarshal([]byte(v.Img), &img) tmp := md.UserFeedbackListResp{ Id: utils.IntToStr(v.Id), Title: v.Type, Img: img, Content: v.Content, State: "0", CreateAt: v.CreateAt.Format("2006-01-02"), } count, _ := eg.Where("uid=? and lid=?", 0, v.Id).Count(&model.UserFeedbackRecord{}) if count > 0 { tmp.State = "1" } data = append(data, tmp) } } e.OutSuc(c, data, nil) return } func UserFeedbackRecord(c *gin.Context) { eg := db.Db var req md.UserFeedbackRecordReq err := c.ShouldBindJSON(&req) if err != nil { err = HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } user := GetUser(c) NewUserFeedbackRecordDb := implement.NewUserFeedbackRecordDb(eg) article, _ := NewUserFeedbackRecordDb.FindUserFeedback(req.Page, "1000", req.Id) data := make([]md.UserFeedbackRecordResp, 0) if article != nil { for _, v := range *article { tmp := md.UserFeedbackRecordResp{ Content: v.Content, CreateAt: v.CreateAt.Format("2006-01-02"), Type: "official", } if v.Uid > 0 { tmp.Type = "user" tmp.Nickname = user.Nickname tmp.HeadImg = GetOssUrl(user.Avatar) } else { tmp.Nickname = GetSysCfgStr("app_name") tmp.HeadImg = GetOssUrl(GetSysCfgStr("app_logo")) } data = append(data, tmp) } } e.OutSuc(c, data, nil) return } func UserFeedbackSave(c *gin.Context) { eg := db.Db var req md.UserFeedbackSaveReq err := c.ShouldBindJSON(&req) if err != nil { err = HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } user := GetUser(c) data := model.UserFeedback{ Uid: int(user.Id), Type: req.Type, Title: req.Title, Extra: utils.SerializeStr(c.Request.Header), Content: req.Content, Img: utils.SerializeStr(req.Img), Idea: req.Idea, Phone: req.Phone, Cid: utils.StrToInt(req.Cid), Ip: c.ClientIP(), CreateAt: time.Now(), } eg.Insert(&data) e.OutSuc(c, "success", nil) return } func UserFeedbackSay(c *gin.Context) { eg := db.Db var req md.UserFeedbackSayReq err := c.ShouldBindJSON(&req) if err != nil { err = HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } user := GetUser(c) data := model.UserFeedbackRecord{ Uid: int(user.Id), Lid: utils.StrToInt(req.Id), Content: req.Content, CreateAt: time.Now(), } eg.Insert(&data) e.OutSuc(c, "success", nil) return }