新增平台商品
This commit is contained in:
@@ -15,6 +15,7 @@ type Api struct {
|
||||
caManage // ca管理
|
||||
financeManage // 财务管理
|
||||
exportManage // 导出管理
|
||||
productManage // 商品管理
|
||||
}
|
||||
|
||||
// SysSetting 系统设置
|
||||
@@ -84,3 +85,8 @@ type financeManage struct {
|
||||
type exportManage struct {
|
||||
Export
|
||||
}
|
||||
|
||||
// 商品管理
|
||||
type productManage struct {
|
||||
Product
|
||||
}
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/dto"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/api/responses"
|
||||
"hospital-admin-api/api/service"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Product struct{}
|
||||
|
||||
// GetPlatformProductPage 获取平台商品列表-分页
|
||||
func (r *Product) GetPlatformProductPage(c *gin.Context) {
|
||||
productRequest := requests.ProductRequest{}
|
||||
req := productRequest.GetPlatformProductPage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
productPlatformDao := dao.ProductPlatformDao{}
|
||||
productPlatform, total, err := productPlatformDao.GetPlatformProductPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
GetProductPlatformPageResponses := dto.GetProductPlatformListDto(productPlatform)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = GetProductPlatformPageResponses
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
|
||||
// GetPlatformProduct 平台商品详情
|
||||
func (r *Product) GetPlatformProduct(c *gin.Context) {
|
||||
id := c.Param("product_platform_id")
|
||||
if id == "" {
|
||||
responses.FailWithMessage("缺少参数", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将 id 转换为 int64 类型
|
||||
productPlatformId, err := strconv.ParseInt(id, 10, 64)
|
||||
if err != nil {
|
||||
responses.Fail(c)
|
||||
return
|
||||
}
|
||||
|
||||
// 业务处理
|
||||
productService := service.ProductService{}
|
||||
getPlatformProductResponses, err := productService.GetPlatformProduct(productPlatformId)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
responses.OkWithData(getPlatformProductResponses, c)
|
||||
}
|
||||
|
||||
// GetSystemProductPage 获取系统商品列表-分页
|
||||
func (r *Product) GetSystemProductPage(c *gin.Context) {
|
||||
productRequest := requests.ProductRequest{}
|
||||
req := productRequest.GetPlatformProductPage
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
productPlatformDao := dao.ProductPlatformDao{}
|
||||
productPlatform, total, err := productPlatformDao.GetPlatformProductPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
GetProductPlatformPageResponses := dto.GetProductPlatformListDto(productPlatform)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = GetProductPlatformPageResponses
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
Reference in New Issue
Block a user