123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package admin
- import (
- "zhiyuan/pkg/app"
- "zhiyuan/pkg/utils"
- "zhiyuan/services/form"
- "zhiyuan/services/shop"
- "github.com/gin-gonic/gin"
- )
- func ShopList(c *gin.Context) {
- type Shop struct {
- ID int `json:"id"`
- ShopName string `json:"shop_name"`
- CollectInfo string `json:"collect_info"`
- CreatedAt string `json:"created_at"`
- }
- shopList := make([]*Shop, 0)
- if _, err := shop.GetList(nil, nil, &shopList); err != nil {
- app.Error(c, err.Error())
- return
- }
- for k, v := range shopList {
- v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD")
- shopList[k] = v
- }
- app.Success(c, shopList)
- }
- func ShopAdd(c *gin.Context) {
- var form form.ShopAdd
- if app.Bind(c, &form) != nil {
- return
- }
- id, err := shop.Add(form)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, gin.H{"id": id})
- }
- func ShopEdit(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.ErrorMsg(c, "门店id有误", nil)
- return
- }
- var form form.ShopAdd
- if app.Bind(c, &form) != nil {
- return
- }
- if _, err := shop.Edit(form, id); err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, nil)
- }
|