package backstage_api

import (
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"net/http"
	"youngmini_server/app/model/backstage_model"
	"youngmini_server/app/service/backstage_service"
	"youngmini_server/library/response"
)

var Product = productApi{}

type productApi struct {
}

// CreatProduct  创建商品信息接口
func (brand *productApi) CreatProduct(r *ghttp.Request) {
	var apiReq *backstage_model.ProductReq
	if err := r.ParseForm(&apiReq); err != nil {
		response.JsonExit(r, http.StatusBadRequest, err.Error())
	}
	err := backstage_service.Product.CreatProduct(apiReq)
	if err != nil {
		response.JsonExit(r, http.StatusInternalServerError, err.Error())
	}
	response.JsonExit(r, http.StatusOK, "创建成功")
}

// DeleteProduct 删除商品接口
func (brand *productApi) DeleteProduct(r *ghttp.Request) {
	//var apiReq *backstage_model.ProductDelete
	//if err := r.ParseForm(&apiReq); err != nil {
	//	response.JsonExit(r, http.StatusBadRequest, err.Error())
	//}
	var photos []*backstage_model.ProductPhotoReq
	g.DB().Model("product_photo").Where("product_id", 9).Scan(&photos)
	response.JsonExit(r, http.StatusBadRequest, "err.Error()", g.Map{
		"photos": photos,
	})
}
