1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package aftersale
- import (
- "github.com/gin-gonic/gin"
- "zhiyuan/pkg/app"
- "zhiyuan/pkg/utils"
- "zhiyuan/services/aftersale"
- "zhiyuan/services/form"
- )
- func QaList(c *gin.Context) {
- page := app.HandlePageNum(c)
- where := map[string]interface{}{"deleted_at": 0}
- title := c.Query("title")
- if title != "" {
- where["title like"] = "%" + title + "%"
- }
- total, err := aftersale.CountQa(where)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- type Qa struct {
- ID int `json:"id"`
- Title string `json:"title"`
- Content string `json:"content"`
- DeletedAt int `json:"deleted_at"`
- CreatedAt string `json:"created_at"`
- UpdatedAt string `json:"updated_at"`
- }
- qaList := make([]*Qa, 0)
- if _, err := aftersale.GetQaList(where, nil, page, &qaList); err != nil {
- app.Error(c, err.Error())
- return
- }
- for k, v := range qaList {
- v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD")
- v.UpdatedAt = utils.DateS(v.UpdatedAt, "YYYY-MM-DD")
- qaList[k] = v
- }
- data := gin.H{
- "list": qaList,
- "total": total,
- "limit": page.PageSize,
- }
- app.Success(c, data)
- }
- func QaAdd(c *gin.Context) {
- var form form.ASQaAdd
- if app.Bind(c, &form) != nil {
- return
- }
- if id, err := aftersale.AddQa(form); err != nil {
- app.Error(c, err.Error())
- return
- } else {
- app.Success(c, gin.H{"id": id})
- }
- }
- func QaEdit(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.Error(c, "类型id有误")
- return
- }
- var form form.ASQaAdd
- if app.Bind(c, &form) != nil {
- return
- }
- if _, err := aftersale.EditQa(form, id); err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, nil)
- }
- func QaDel(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.Error(c, "类型id有误")
- return
- }
- if _, err := aftersale.DelQa(id); err != nil {
- app.ErrorMsg(c, err.Error(), nil)
- return
- }
- app.Success(c, nil)
- }
|