shop.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package admin
  2. import (
  3. "zhiyuan/pkg/app"
  4. "zhiyuan/pkg/utils"
  5. "zhiyuan/services/form"
  6. "zhiyuan/services/shop"
  7. "github.com/gin-gonic/gin"
  8. )
  9. func ShopList(c *gin.Context) {
  10. type Shop struct {
  11. ID int `json:"id"`
  12. ShopName string `json:"shop_name"`
  13. CollectInfo string `json:"collect_info"`
  14. CreatedAt string `json:"created_at"`
  15. }
  16. shopList := make([]*Shop, 0)
  17. if _, err := shop.GetList(nil, nil, &shopList); err != nil {
  18. app.Error(c, err.Error())
  19. return
  20. }
  21. for k, v := range shopList {
  22. v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD")
  23. shopList[k] = v
  24. }
  25. app.Success(c, shopList)
  26. }
  27. func ShopAdd(c *gin.Context) {
  28. var form form.ShopAdd
  29. if app.Bind(c, &form) != nil {
  30. return
  31. }
  32. id, err := shop.Add(form)
  33. if err != nil {
  34. app.Error(c, err.Error())
  35. return
  36. }
  37. app.Success(c, gin.H{"id": id})
  38. }
  39. func ShopEdit(c *gin.Context) {
  40. id := utils.StrTo(c.Param("id")).MustInt()
  41. if id <= 0 {
  42. app.ErrorMsg(c, "门店id有误", nil)
  43. return
  44. }
  45. var form form.ShopAdd
  46. if app.Bind(c, &form) != nil {
  47. return
  48. }
  49. if _, err := shop.Edit(form, id); err != nil {
  50. app.Error(c, err.Error())
  51. return
  52. }
  53. app.Success(c, nil)
  54. }