智慧食堂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hdl_suggested_feed_back.go 3.0 KiB

10 kuukautta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package hdl
  2. import (
  3. "applet/app/customer/lib/validate"
  4. "applet/app/customer/md"
  5. "applet/app/customer/svc"
  6. "applet/app/db"
  7. "applet/app/db/model"
  8. "applet/app/e"
  9. "fmt"
  10. "github.com/gin-gonic/gin"
  11. "github.com/jinzhu/copier"
  12. "time"
  13. )
  14. func SuggestedFeedbackList(c *gin.Context) {
  15. var req md.SuggestedFeedbackListReq
  16. err := c.ShouldBindJSON(&req)
  17. if err != nil {
  18. err = validate.HandleValidateErr(err)
  19. err1 := err.(e.E)
  20. e.OutErr(c, err1.Code, err1.Error())
  21. return
  22. }
  23. if req.Limit == 0 {
  24. req.Limit = 10
  25. }
  26. if req.Page == 0 {
  27. req.Page = 1
  28. }
  29. var m []*model.SuggestedFeedback
  30. total, err := db.Db.Where("user_identity_id =?", req.UserIdentityId).Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&m)
  31. type respStruct struct {
  32. Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
  33. Uid int `json:"uid" xorm:"not null comment('用户id') INT(11)"`
  34. UserIdentityId int `json:"user_identity_id" xorm:"not null comment('身份id') INT(11)"`
  35. EnterpriseId int `json:"enterprise_id" xorm:"not null comment('单位id') INT(11)"`
  36. Kind int `json:"kind" `
  37. Content string `json:"content" xorm:"not null default '' comment('反馈内容') VARCHAR(255)"`
  38. ReplyContent string `json:"reply_content" xorm:"not null default '' comment('回复内容') VARCHAR(255)"`
  39. ReplyDate string `json:"reply_date" xorm:"not null default '' comment('回复时间') CHAR(50)"`
  40. CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
  41. UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"`
  42. }
  43. var list []respStruct
  44. for _, v := range m {
  45. var tmp respStruct
  46. err = copier.Copy(&tmp, v)
  47. fmt.Println(err)
  48. kind := 2
  49. if v.ReplyDate != "" {
  50. kind = 1
  51. }
  52. tmp.Kind = kind
  53. list = append(list, tmp)
  54. }
  55. e.OutSuc(c, map[string]interface{}{
  56. "list": list,
  57. "total": total,
  58. "kind_list": []map[string]interface{}{
  59. {
  60. "name": "已回复",
  61. "value": 1,
  62. },
  63. {
  64. "name": "未回复",
  65. "value": 2,
  66. },
  67. },
  68. }, nil)
  69. return
  70. }
  71. func SuggestedFeedbackAdd(c *gin.Context) {
  72. var req md.SuggestedFeedbackAddReq
  73. err := c.ShouldBindJSON(&req)
  74. if err != nil {
  75. err = validate.HandleValidateErr(err)
  76. err1 := err.(e.E)
  77. e.OutErr(c, err1.Code, err1.Error())
  78. return
  79. }
  80. suggestedFeedbackDb := db.SuggestedFeedbackDb{}
  81. suggestedFeedbackDb.Set()
  82. user := svc.GetUser(c)
  83. now := time.Now()
  84. insertAffected, err := suggestedFeedbackDb.SuggestedFeedbackInsert(&model.SuggestedFeedback{
  85. Uid: user.Id,
  86. UserIdentityId: req.UserIdentityId,
  87. EnterpriseId: req.EnterpriseId,
  88. Content: req.Content,
  89. ReplyContent: "",
  90. ReplyDate: "",
  91. CreateAt: now.Format("2006-01-02 15:04:05"),
  92. UpdateAt: now.Format("2006-01-02 15:04:05"),
  93. })
  94. if err != nil {
  95. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  96. return
  97. }
  98. if insertAffected <= 0 {
  99. e.OutErr(c, e.ERR_DB_ORM, "新增数据失败")
  100. return
  101. }
  102. e.OutSuc(c, "success", nil)
  103. return
  104. }