|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- package hdl
-
- import (
- enum2 "applet/app/admin/enum"
- "applet/app/admin/lib/validate"
- "applet/app/admin/md"
- "applet/app/admin/svc"
- "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+"%")
- }
-
- admin := svc.GetUser(c)
- if admin.IsSuperAdministrator != enum2.IsSuperAdministratorTure {
- adminWithEnterpriseDb := db.AdminWithEnterpriseDb{}
- adminWithEnterpriseDb.Set()
- adminWithEnterprise, err1 := adminWithEnterpriseDb.FindAdminWithEnterprise(admin.AdmId)
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- var enterPriseIds []int
- for _, v1 := range *adminWithEnterprise {
- enterPriseIds = append(enterPriseIds, v1.EnterpriseId)
- }
- if len(enterPriseIds) == 0 {
- return
- }
- sess.In("suggested_feedback.enterprise_id", enterPriseIds)
- }
-
- 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{
- Id: v.SuggestedFeedback.Id,
- 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
- }
|