|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- package user_feedback
-
- import (
- "applet/app/db"
- "applet/app/e"
- "applet/app/md"
- "applet/app/svc"
- "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"
- "github.com/tidwall/gjson"
- "strings"
- "time"
- )
-
- func List(c *gin.Context) {
- var req *md.UserFeedbackListReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- var resp md.UserFeedbackListResp
- noticeList := make([]md.UserFeedbackList, 0)
- NewUserFeedbackDb := implement.NewUserFeedbackDb(db.Db)
- uid := ""
- if req.Uid != "" {
- uid = req.Uid
- }
- if req.Phone != "" {
- uid = "-1"
- NewUserDb := implement.NewUserDb(db.Db)
- user, _ := NewUserDb.UserGetOneByParams(map[string]interface{}{
- "key": "phone",
- "value": req.Phone,
- })
- if user != nil {
- uid = utils.Int64ToStr(user.Id)
- }
- }
- notice, total, _ := NewUserFeedbackDb.FindUserFeedbackAndTotal(req.Page, req.Limit, uid, req.Cid, "")
- resp.Total = total
- resp.SelectData = make([]map[string]interface{}, 0)
- NewUserFeedbackCateDb := implement.NewUserFeedbackCateDb(db.Db)
- pid, _ := NewUserFeedbackCateDb.FindUserFeedbackCate("1", "100")
- if pid != nil {
- for _, v := range *pid {
- tmp := map[string]interface{}{
- "name": v.Name, "value": utils.IntToStr(v.Id),
- }
- resp.SelectData = append(resp.SelectData, tmp)
- }
- }
- if notice != nil {
- platformMap := map[string]string{
- "android": "安卓",
- "iOS": "iOS",
- "wx_applet": "小程序",
- }
- for _, v := range *notice {
- v.Extra = strings.ToLower(v.Extra)
- platform := gjson.Get(v.Extra, "platform").String()
- img := make([]string, 0)
- json.Unmarshal([]byte(v.Img), &img)
- if v.Phone == "" {
- NewUserDb := implement.NewUserDb(db.Db)
- user, _ := NewUserDb.UserGetOneByParams(map[string]interface{}{
- "key": "id",
- "value": v.Uid,
- })
- if user != nil {
- v.Phone = user.Phone
- }
- }
- for k1, v1 := range img {
- img[k1] = svc.GetOssUrl(v1)
- }
- tmp := md.UserFeedbackList{
- Id: utils.IntToStr(v.Id),
- Phone: v.Phone,
- Title: v.Title,
- Platform: platformMap[platform],
- Version: gjson.Get(v.Extra, "devicemodel").String() + " " + gjson.Get(v.Extra, "osversion").String() + " " + gjson.Get(v.Extra, "appversionname").String(),
- Type: v.Type,
- Img: img,
- Content: v.Content,
- CreateAt: v.CreateAt.Format("2006-01-02 15:04:05"),
- State: utils.IntToStr(v.State),
- }
- noticeList = append(noticeList, tmp)
- }
- }
- resp.List = noticeList
- e.OutSuc(c, resp, nil)
- return
- }
- func RecordList(c *gin.Context) {
- eg := db.Db
- var req md.UserFeedbackRecordListReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- NewUserFeedbackRecordDb := implement.NewUserFeedbackRecordDb(eg)
- article, _ := NewUserFeedbackRecordDb.FindUserFeedback(req.Page, "1000", req.Id)
- data := make([]md.UserFeedbackRecordListResp, 0)
- if article != nil {
- for _, v := range *article {
- tmp := md.UserFeedbackRecordListResp{
- Content: v.Content,
- CreateAt: v.CreateAt.Format("2006-01-02"),
- Type: "official",
- }
- if v.Uid > 0 {
- NewUserDb := implement.NewUserDb(eg)
- user, _ := NewUserDb.GetUser(int64(v.Uid))
- if user != nil {
- tmp.Nickname = user.Nickname
- tmp.HeadImg = svc.GetOssUrl(user.Avatar)
- }
- tmp.Type = "user"
- } else {
- tmp.Nickname = svc.GetSysCfgStr("app_name")
- tmp.HeadImg = svc.GetOssUrl(svc.GetSysCfgStr("app_logo"))
- }
- data = append(data, tmp)
- }
- }
- e.OutSuc(c, data, nil)
- return
- }
-
- func Say(c *gin.Context) {
- var req *md.UserFeedbackSayReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- data := model.UserFeedbackRecord{
- Lid: utils.StrToInt(req.Id),
- Content: req.Content,
- CreateAt: time.Now(),
- }
- db.Db.Insert(&data)
- e.OutSuc(c, "success", nil)
- return
- }
- func ChangeState(c *gin.Context) {
- var req *md.UserFeedbackChangeStateReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- NewUserFeedbackDb := implement.NewUserFeedbackDb(db.Db)
- notice, _ := NewUserFeedbackDb.GetUserFeedback(req.Id)
- if notice == nil {
- e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
- return
- }
- notice.State = utils.StrToInt(req.State)
- db.Db.Where("id=?", notice.Id).Cols("state").Update(notice)
- e.OutSuc(c, "success", nil)
- return
- }
-
- func Del(c *gin.Context) {
- var req *md.UserFeedbackDelReq
- if err := c.ShouldBindJSON(&req); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- db.Db.In("id", req.Id).Delete(&model.UserFeedback{})
- db.Db.In("lid", req.Id).Delete(&model.UserFeedbackRecord{})
- e.OutSuc(c, "success", nil)
- return
- }
|