package hdl import ( "applet/app/customer/lib/validate" "applet/app/customer/md" "applet/app/customer/svc" "applet/app/db" "applet/app/db/model" "applet/app/e" "fmt" "github.com/gin-gonic/gin" "github.com/jinzhu/copier" "time" ) func SuggestedFeedbackList(c *gin.Context) { var req md.SuggestedFeedbackListReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } if req.Limit == 0 { req.Limit = 10 } if req.Page == 0 { req.Page = 1 } var m []*model.SuggestedFeedback total, err := db.Db.Where("user_identity_id =?", req.UserIdentityId).Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) type respStruct struct { Id int `json:"id" xorm:"not null pk autoincr INT(11)"` Uid int `json:"uid" xorm:"not null comment('用户id') INT(11)"` UserIdentityId int `json:"user_identity_id" xorm:"not null comment('身份id') INT(11)"` EnterpriseId int `json:"enterprise_id" xorm:"not null comment('单位id') INT(11)"` Kind int `json:"kind" ` Content string `json:"content" xorm:"not null default '' comment('反馈内容') VARCHAR(255)"` ReplyContent string `json:"reply_content" xorm:"not null default '' comment('回复内容') VARCHAR(255)"` ReplyDate string `json:"reply_date" xorm:"not null default '' comment('回复时间') CHAR(50)"` CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` } var list []respStruct for _, v := range m { var tmp respStruct err = copier.Copy(&tmp, v) fmt.Println(err) kind := 2 if v.ReplyDate != "" { kind = 1 } tmp.Kind = kind list = append(list, tmp) } e.OutSuc(c, map[string]interface{}{ "list": list, "total": total, "kind_list": []map[string]interface{}{ { "name": "已回复", "value": 1, }, { "name": "未回复", "value": 2, }, }, }, nil) return } func SuggestedFeedbackAdd(c *gin.Context) { var req md.SuggestedFeedbackAddReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } suggestedFeedbackDb := db.SuggestedFeedbackDb{} suggestedFeedbackDb.Set() user := svc.GetUser(c) now := time.Now() insertAffected, err := suggestedFeedbackDb.SuggestedFeedbackInsert(&model.SuggestedFeedback{ Uid: user.Id, UserIdentityId: req.UserIdentityId, EnterpriseId: req.EnterpriseId, Content: req.Content, ReplyContent: "", ReplyDate: "", CreateAt: now.Format("2006-01-02 15:04:05"), UpdateAt: now.Format("2006-01-02 15:04:05"), }) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if insertAffected <= 0 { e.OutErr(c, e.ERR_DB_ORM, "新增数据失败") return } e.OutSuc(c, "success", nil) return }