diff --git a/app/admin/hdl/hdl_suggested_feedback.go b/app/admin/hdl/hdl_suggested_feedback.go new file mode 100644 index 0000000..8b57686 --- /dev/null +++ b/app/admin/hdl/hdl_suggested_feedback.go @@ -0,0 +1,124 @@ +package hdl + +import ( + "applet/app/admin/lib/validate" + "applet/app/admin/md" + "applet/app/db" + "applet/app/e" + "github.com/gin-gonic/gin" + "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 + } + + sess := db.Db.Desc("suggested_feedback.id") + if req.StartCreateAt != "" { + sess.And("suggested_feedback.create_at >= ?", req.StartCreateAt) + } + if req.EndCreateAt != "" { + sess.And("suggested_feedback.create_at <= ?", req.EndCreateAt) + } + if req.State == 1 { + sess.And("suggested_feedback.reply_date !=\"\" ") + } + if req.State == 2 { + sess.And("suggested_feedback.reply_date =\"\" ") + } + if req.Name != "" { + sess.And("user_identity.name like ?", "%"+req.Name+"%") + } + if req.Phone != "" { + sess.And("user.phone like ?", "%"+req.Phone+"%") + } + + var m []*db.SuggestedFeedbackWithUserIdentity + count, err := sess. + Join("LEFT", "user_identity", "suggested_feedback.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + + var resp []md.SuggestedFeedbackListResp + for _, v := range m { + kind := 2 + if v.SuggestedFeedback.ReplyDate != "" { + kind = 1 + } + resp = append(resp, md.SuggestedFeedbackListResp{ + EnterpriseId: v.Enterprise.Id, + EnterpriseName: v.Enterprise.Name, + Uid: v.User.Id, + UserIdentityId: v.UserIdentity.Id, + UserIdentityKind: v.UserIdentity.Kind, + UserIdentityName: v.UserIdentity.Name, + Phone: v.User.Phone, + Nickname: v.User.Nickname, + Content: v.SuggestedFeedback.Content, + Kind: kind, + ReplyContent: v.SuggestedFeedback.ReplyContent, + ReplyDate: v.SuggestedFeedback.ReplyDate, + CreateAt: v.SuggestedFeedback.CreateAt, + UpdateAt: v.SuggestedFeedback.UpdateAt, + }) + } + e.OutSuc(c, map[string]interface{}{ + "list": resp, + "total": count, + "kind_list": []map[string]interface{}{ + { + "name": "已回复", + "value": 1, + }, + { + "name": "未回复", + "value": 2, + }, + }, + }, nil) + return +} + +func SuggestedFeedbackReply(c *gin.Context) { + var req md.ReplySuggestedFeedbackReq + 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() + suggestedFeedback, err := suggestedFeedbackDb.GetSuggestedFeedback(req.Id) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + if suggestedFeedback == nil { + e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") + return + } + now := time.Now() + suggestedFeedback.ReplyContent = req.ReplyContent + suggestedFeedback.ReplyDate = now.Format("2006-01-02 15:04:05") + suggestedFeedback.UpdateAt = now.Format("2006-01-02 15:04:05") + _, err = suggestedFeedbackDb.SuggestedFeedbackUpdate(suggestedFeedback, "reply_date", "reply_content", "update_at") + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + e.OutSuc(c, "success", nil) + return +} diff --git a/app/admin/md/md_suggested_feedback.go b/app/admin/md/md_suggested_feedback.go new file mode 100644 index 0000000..9c13785 --- /dev/null +++ b/app/admin/md/md_suggested_feedback.go @@ -0,0 +1,33 @@ +package md + +type SuggestedFeedbackListReq struct { + Name string `json:"name" label:"姓名"` + Phone string `json:"phone" label:"电话"` + State int `json:"state" label:"状态"` + StartCreateAt string `json:"start_create_at" label:"开始-创建时间"` + EndCreateAt string `json:"end_create_at" label:"截止-创建时间"` + Limit int `json:"limit" binding:"required"` + Page int `json:"page" binding:"required"` +} + +type SuggestedFeedbackListResp struct { + EnterpriseId int `json:"enterprise_id" ` + EnterpriseName string `json:"enterprise_name" ` + Uid int `json:"uid" ` + UserIdentityId int `json:"user_identity_id" ` + UserIdentityKind int `json:"user_identity_kind" ` + UserIdentityName string `json:"user_identity_name" ` + Phone string `json:"phone" label:"联系电话"` + Nickname string `json:"nickname" label:"姓名"` + Content string `json:"content" label:"建议内容"` + Kind int `json:"kind" label:"回复状态"` + ReplyContent string `json:"reply_content" label:"回复内容"` + ReplyDate string `json:"reply_date"` + CreateAt string `json:"create_at"` + UpdateAt string `json:"update_at"` +} + +type ReplySuggestedFeedbackReq struct { + Id int `json:"id" binding:"required" label:"公司id"` + ReplyContent string `json:"reply_content" label:"内容"` +} diff --git a/app/db/db_suggested_feedback.go b/app/db/db_suggested_feedback.go new file mode 100644 index 0000000..f5911aa --- /dev/null +++ b/app/db/db_suggested_feedback.go @@ -0,0 +1,97 @@ +package db + +import ( + "applet/app/db/model" + "applet/app/utils/logx" + "reflect" + "xorm.io/xorm" +) + +type SuggestedFeedbackDb struct { + Db *xorm.Engine `json:"db"` +} + +func (suggestedFeedbackDb *SuggestedFeedbackDb) Set() { // set方法 + suggestedFeedbackDb.Db = Db +} + +func (suggestedFeedbackDb *SuggestedFeedbackDb) GetSuggestedFeedback(id int) (m *model.SuggestedFeedback, err error) { + m = new(model.SuggestedFeedback) + has, err := suggestedFeedbackDb.Db.Where("id =?", id).Get(m) + if err != nil { + return nil, logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +} + +func (suggestedFeedbackDb *SuggestedFeedbackDb) FindSuggestedFeedbackById(ids interface{}) (*[]model.SuggestedFeedback, error) { + var m []model.SuggestedFeedback + if err := suggestedFeedbackDb.Db.In("id", ids).Desc("sort").Find(&m); err != nil { + return nil, logx.Error(err) + } + return &m, nil +} + +func (suggestedFeedbackDb *SuggestedFeedbackDb) FindSuggestedFeedback(limit, start int) (*[]model.SuggestedFeedback, error) { + var m []model.SuggestedFeedback + if limit == 0 || start == 0 { + if err := suggestedFeedbackDb.Db.Asc("sort").Find(&m); err != nil { + return nil, logx.Error(err) + } + } else { + if err := suggestedFeedbackDb.Db.Asc("sort").Limit(limit, start).Find(m); err != nil { + return nil, logx.Error(err) + } + } + return &m, nil +} + +func (suggestedFeedbackDb *SuggestedFeedbackDb) GetSuggestedFeedbackByName(name string) (m *model.SuggestedFeedback, err error) { + m = new(model.SuggestedFeedback) + has, err := suggestedFeedbackDb.Db.Where("name =?", name).Get(m) + if err != nil { + return nil, logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +} + +func (suggestedFeedbackDb *SuggestedFeedbackDb) SuggestedFeedbackInsert(m *model.SuggestedFeedback) (int, error) { + _, err := suggestedFeedbackDb.Db.InsertOne(m) + if err != nil { + return 0, err + } + return m.Id, nil +} + +func (suggestedFeedbackDb *SuggestedFeedbackDb) SuggestedFeedbackUpdate(m *model.SuggestedFeedback, columns ...string) (int64, error) { + affected, err := suggestedFeedbackDb.Db.Where("id =?", m.Id).Cols(columns...).Update(m) + if err != nil { + return 0, err + } + return affected, nil +} + +func (suggestedFeedbackDb *SuggestedFeedbackDb) SuggestedFeedbackDelete(id interface{}) (int64, error) { + if reflect.TypeOf(id).Kind() == reflect.Slice { + return Db.In("id", id).Delete(model.SuggestedFeedback{}) + } else { + return Db.Where("id = ?", id).Delete(model.SuggestedFeedback{}) + } +} + +type SuggestedFeedbackWithUserIdentity struct { + model.SuggestedFeedback `xorm:"extends"` + model.UserIdentity `xorm:"extends"` + model.Enterprise `xorm:"extends"` + model.User `xorm:"extends"` +} + +func (SuggestedFeedbackWithUserIdentity) TableName() string { + return "suggested_feedback" +} diff --git a/app/db/model/suggested_feedback.go b/app/db/model/suggested_feedback.go new file mode 100644 index 0000000..3cdcef7 --- /dev/null +++ b/app/db/model/suggested_feedback.go @@ -0,0 +1,13 @@ +package model + +type SuggestedFeedback 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)"` + 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"` +} diff --git a/app/router/admin_router.go b/app/router/admin_router.go index f9da74b..86d25db 100644 --- a/app/router/admin_router.go +++ b/app/router/admin_router.go @@ -61,6 +61,11 @@ func rNotice(r *gin.RouterGroup) { r.DELETE("/delete/:id", hdl2.NoticeDelete) } +func rSuggestedFeedback(r *gin.RouterGroup) { + r.POST("/list", hdl2.SuggestedFeedbackList) + r.POST("/reply", hdl2.SuggestedFeedbackReply) +} + func rBanner(r *gin.RouterGroup) { r.GET("/list", hdl2.BannerList) r.POST("/add", hdl2.BannerAdd) @@ -291,17 +296,18 @@ func AdminRoute(r *gin.RouterGroup) { r.Use(mw.CheckPermission) //检测权限 - rHomePage(r.Group("/homePage")) //首页 - rCompany(r.Group("/company")) //公司管理 - rNotice(r.Group("/notice")) //公告管理 - rBanner(r.Group("/banner")) //轮播图管理 - rEnterprise(r.Group("/enterprise")) //校企管理 - rEnterpriseManage(r.Group("/enterpriseManage")) //校企管理详情 - rRole(r.Group("/role")) //权限管理 - rSetCenter(r.Group("/setCenter")) //设置中心 - rUser(r.Group("/user")) //用户管理 - rAuditCenter(r.Group("/auditCenter")) //审核中心 - rFinanceManage(r.Group("/financeManage")) //财务管理 - rDeviceManage(r.Group("/deviceManage")) //设备管理 - rDataStatistics(r.Group("/dataStatistics")) //数据统计 + rHomePage(r.Group("/homePage")) //首页 + rCompany(r.Group("/company")) //公司管理 + rNotice(r.Group("/notice")) //公告管理 + rSuggestedFeedback(r.Group("/suggestedFeedback")) //反馈建议 + rBanner(r.Group("/banner")) //轮播图管理 + rEnterprise(r.Group("/enterprise")) //校企管理 + rEnterpriseManage(r.Group("/enterpriseManage")) //校企管理详情 + rRole(r.Group("/role")) //权限管理 + rSetCenter(r.Group("/setCenter")) //设置中心 + rUser(r.Group("/user")) //用户管理 + rAuditCenter(r.Group("/auditCenter")) //审核中心 + rFinanceManage(r.Group("/financeManage")) //财务管理 + rDeviceManage(r.Group("/deviceManage")) //设备管理 + rDataStatistics(r.Group("/dataStatistics")) //数据统计 }