From df7076fc1111f2c6fcb14f492035f87d3e108d92 Mon Sep 17 00:00:00 2001 From: chenlin Date: Tue, 18 Mar 2025 19:45:22 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=96=B0=E5=A2=9E=E5=90=88=E4=BD=9C=E5=95=86?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apis/bus_apis/a_cooperative_manage.go | 190 ++++++ .../models/bus_models/m_cooperative_manage.go | 127 ++++ .../models/bus_models/m_product_manage.go | 7 +- app/admin/router/bus_cooperative_manage.go | 22 + app/admin/router/router.go | 3 + .../bus_service/s_cooperative_manage.go | 329 ++++++++++ .../service/bus_service/s_product_manage.go | 34 +- common/global/constant.go | 5 + docs/admin/admin_docs.go | 589 ++++++++++++++++++ docs/admin/admin_swagger.json | 589 ++++++++++++++++++ docs/admin/admin_swagger.yaml | 414 ++++++++++++ 11 files changed, 2304 insertions(+), 5 deletions(-) create mode 100644 app/admin/apis/bus_apis/a_cooperative_manage.go create mode 100644 app/admin/models/bus_models/m_cooperative_manage.go create mode 100644 app/admin/router/bus_cooperative_manage.go create mode 100644 app/admin/service/bus_service/s_cooperative_manage.go create mode 100644 common/global/constant.go diff --git a/app/admin/apis/bus_apis/a_cooperative_manage.go b/app/admin/apis/bus_apis/a_cooperative_manage.go new file mode 100644 index 0000000..50aa720 --- /dev/null +++ b/app/admin/apis/bus_apis/a_cooperative_manage.go @@ -0,0 +1,190 @@ +package bus_apis + +import ( + "github.com/gin-gonic/gin" + "github.com/gin-gonic/gin/binding" + "github.com/go-admin-team/go-admin-core/sdk/api" + "go-admin/app/admin/models/bus_models" + "go-admin/app/admin/service/bus_service" + "go-admin/tools/app" + "net/http" +) + +type CooperativeApi struct { + api.Api +} + +// CooperativeList 查询合作商列表 +// @Summary 查询合作商列表 +// @Tags 合作商管理-V1.0.0 +// @Produce json +// @Accept json +// @Param request body bus_models.CooperativeListReq true "查询合作商列表模型" +// @Success 200 {object} bus_models.CooperativeListResp +// @Router /api/v1/cooperative/list [post] +func (e CooperativeApi) CooperativeList(c *gin.Context) { + s := bus_service.CooperativeService{} + var req bus_models.CooperativeListReq + + err := e.MakeContext(c). + MakeOrm(). + Bind(&req, binding.JSON). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + + // 调用服务层的 GetCooperativeList 函数获取数据 + resp, err := s.GetCooperativeList(c.Request.Context(), req) + if err != nil { + app.Error(c, http.StatusInternalServerError, err, err.Error()) + return + } + + // 返回查询结果 + app.OK(c, resp, "查询成功") + return +} + +// CreateCooperative 新建合作商 +// @Summary 新建合作商 +// @Tags 合作商管理-V1.0.0 +// @Produce json +// @Accept json +// @Param request body bus_models.CreateCooperativeReq true "新建合作商模型" +// @Success 200 {object} bus_models.CreateCooperativeResp +// @Router /api/v1/cooperative/create [post] +func (e CooperativeApi) CreateCooperative(c *gin.Context) { + s := bus_service.CooperativeService{} + var req bus_models.CreateCooperativeReq + + err := e.MakeContext(c). + MakeOrm(). + Bind(&req, binding.JSON). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + + // 调用服务层的 CreateCooperative 函数来处理逻辑 + resp, err := s.CreateCooperative(req) + if err != nil { + app.Error(c, http.StatusInternalServerError, err, err.Error()) + return + } + + // 返回创建结果 + app.OK(c, resp, "新增成功") + return +} + +// EditCooperative 编辑合作商 +// @Summary 编辑合作商 +// @Tags 合作商管理-V1.0.0 +// @Produce json +// @Accept json +// @Param request body bus_models.EditCooperativeReq true "编辑合作商模型" +// @Success 200 {object} app.Response +// @Router /api/v1/cooperative/edit [post] +func (e CooperativeApi) EditCooperative(c *gin.Context) { + s := bus_service.CooperativeService{} + var req bus_models.EditCooperativeReq + + err := e.MakeContext(c). + MakeOrm(). + Bind(&req, binding.JSON). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + + // 调用服务层的 EditCooperative 函数来处理逻辑 + err = s.EditCooperative(req) + if err != nil { + app.Error(c, http.StatusInternalServerError, err, err.Error()) + return + } + + // 返回创建结果 + app.OK(c, nil, "编辑成功") + return +} + +// DeleteCooperative 删除合作商 +// @Summary 删除合作商 +// @Tags 合作商管理-V1.0.0 +// @Produce json +// @Accept json +// @Param request body bus_models.DeleteCooperativeReq true "删除合作商模型" +// @Success 200 {object} app.Response +// @Router /api/v1/cooperative/delete [post] +func (e CooperativeApi) DeleteCooperative(c *gin.Context) { + s := bus_service.CooperativeService{} + var req bus_models.DeleteCooperativeReq + + err := e.MakeContext(c). + MakeOrm(). + Bind(&req, binding.JSON). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + + // 调用服务层的 DeleteCooperative 函数来处理逻辑 + err = s.DeleteCooperative(req) + if err != nil { + app.Error(c, http.StatusInternalServerError, err, err.Error()) + return + } + + // 返回创建结果 + app.OK(c, nil, "删除成功") + return +} + +// CooperativeDetail 查询合作商详情 +// @Summary 查询合作商详情 +// @Tags 合作商管理-V1.0.0 +// @Produce json +// @Accept json +// @Param request body bus_models.CooperativeDetailReq true "查询合作商详情请求参数" +// @Success 200 {object} bus_models.CooperativeDetailResp +// @Router /api/v1/cooperative/detail [post] +func (e CooperativeApi) CooperativeDetail(c *gin.Context) { + s := bus_service.CooperativeService{} + var req bus_models.CooperativeDetailReq + + err := e.MakeContext(c). + MakeOrm(). + Bind(&req, binding.JSON). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + + // 调用服务层的 GetCooperativeDetail 函数获取数据 + resp, err := s.GetCooperativeDetail(c.Request.Context(), req) + if err != nil { + app.Error(c, http.StatusInternalServerError, err, err.Error()) + return + } + + // 返回查询结果 + app.OK(c, resp, "查询成功") + return +} diff --git a/app/admin/models/bus_models/m_cooperative_manage.go b/app/admin/models/bus_models/m_cooperative_manage.go new file mode 100644 index 0000000..7149e77 --- /dev/null +++ b/app/admin/models/bus_models/m_cooperative_manage.go @@ -0,0 +1,127 @@ +package bus_models + +import "go-admin/app/admin/models" + +type BusCooperative struct { + models.Model + + CooperativeNumber string `gorm:"type:varchar(32);not null" json:"cooperative_number"` // 合作商编号 + CooperativeName string `gorm:"type:varchar(64);not null" json:"cooperative_name"` // 合作商名称 + Contact string `gorm:"type:varchar(32);not null" json:"contact"` // 联系人 + Tel string `gorm:"type:varchar(20);not null" json:"tel"` // 手机号 + Status int8 `gorm:"type:tinyint(1);not null;default:1" json:"status"` // 账户状态(1启用 0禁用) + Account string `gorm:"type:varchar(32);not null;unique" json:"account"` // 账户 + Password string `gorm:"type:varchar(64);not null" json:"password"` // 密码(建议存储加密哈希值) + Balance float64 `gorm:"type:decimal(10,3);not null;default:0.000" json:"balance"` // 账户余额 + Free float64 `gorm:"type:decimal(10,2);not null;default:0.00" json:"free"` // 赠送余额 + Bond float64 `gorm:"type:decimal(10,2);not null;default:0.00" json:"bond"` // 保证金 + CardHolder string `gorm:"type:varchar(32)" json:"card_holder,omitempty"` // 开户人 + Bank string `gorm:"type:varchar(64)" json:"bank,omitempty"` // 开户行 + CardID string `gorm:"type:varchar(32)" json:"card_id,omitempty"` // 银行帐号 + TaxID string `gorm:"type:varchar(32)" json:"tax_id,omitempty"` // 税号 + Products []BusCooperativeProduct `json:"products" gorm:"-"` // 产品信息 +} + +// BusCooperativeProduct 合作商与产品关联表 +type BusCooperativeProduct struct { + models.Model + + CooperativeID uint64 `gorm:"not null" json:"cooperative_id"` // 合作商编号 + ProductID uint64 `gorm:"not null" json:"product_id"` // 产品ID + Discount float64 `gorm:"type:decimal(5,2);not null;default:0.00" json:"discount"` // 折扣(0-1) +} + +// CooperativeListReq 查询合作商列表请求 +type CooperativeListReq struct { + CooperativeNumber string `form:"cooperative_number,omitempty"` // 合作商编号(可选) + CooperativeName string `form:"cooperative_name,omitempty"` // 合作商名称(支持模糊查询) + Status int8 `form:"status,omitempty"` // 账户状态(1启用 0禁用) + Page int `form:"page" binding:"required,min=1"` // 页码 + PageSize int `form:"page_size" binding:"required,min=1,max=100"` // 每页条数 +} + +// CooperativeListResp 查询合作商列表响应 +type CooperativeListResp struct { + List []BusCooperative `json:"list"` // 合作商列表 + Total int `json:"total"` // 总记录数 + Page int `json:"page"` // 页码 + PageSize int `json:"page_size"` // 每页大小 +} + +// CreateCooperativeReq 创建合作商请求 +type CreateCooperativeReq struct { + CooperativeName string `json:"cooperative_name" binding:"required"` // 合作商名称 + Contact string `json:"contact" binding:"required"` // 联系人 + Tel string `json:"tel" binding:"required"` // 手机号 + Account string `json:"account" binding:"required"` // 账户 + Password string `json:"password" binding:"required"` // 密码(前端传输时应加密) + Balance float64 `json:"balance,omitempty"` // 账户余额(可选) + Free float64 `json:"free,omitempty"` // 赠送余额(可选) + Bond float64 `json:"bond,omitempty"` // 保证金(可选) + CardHolder string `json:"card_holder,omitempty"` // 开户人(可选) + Bank string `json:"bank,omitempty"` // 开户行(可选) + CardID string `json:"card_id,omitempty"` // 银行帐号(可选) + TaxID string `json:"tax_id,omitempty"` // 税号(可选) + Products []ProductDiscount `json:"products"` // 关联产品及折扣信息 +} + +// ProductDiscount 结构体用于存储产品ID及对应折扣 +type ProductDiscount struct { + ProductID uint64 `json:"product_id" binding:"required"` // 产品ID + Discount float64 `json:"discount" binding:"required"` // 折扣(0-1之间) +} + +// CreateCooperativeResp 创建合作商响应 +type CreateCooperativeResp struct { + CooperativeNumber string `form:"cooperative_number"` // 合作商编号 +} + +// EditCooperativeReq 编辑合作商请求 +type EditCooperativeReq struct { + CooperativeNumber string `form:"cooperative_number,required"` // 合作商编号 + CooperativeName string `json:"cooperative_name,omitempty"` // 合作商名称(可选) + Contact string `json:"contact,omitempty"` // 联系人(可选) + Tel string `json:"tel,omitempty"` // 手机号(可选) + Status int8 `json:"status,omitempty"` // 账户状态(可选) + Account string `json:"account,omitempty"` // 账户(可选) + Password string `json:"password,omitempty"` // 密码(可选,前端加密传输) + Balance float64 `json:"balance,omitempty"` // 账户余额(可选) + Free float64 `json:"free,omitempty"` // 赠送余额(可选) + Bond float64 `json:"bond,omitempty"` // 保证金(可选) + CardHolder string `json:"card_holder,omitempty"` // 开户人(可选) + Bank string `json:"bank,omitempty"` // 开户行(可选) + CardID string `json:"card_id,omitempty"` // 银行帐号(可选) + TaxID string `json:"tax_id,omitempty"` // 税号(可选) + Products []ProductDiscount `json:"products"` // 关联产品及折扣信息 +} + +// DeleteCooperativeReq 删除合作商请求 +type DeleteCooperativeReq struct { + CooperativeNumber string `form:"cooperative_number,required"` // 合作商编号 +} + +// CooperativeDetailReq 查询合作商详情请求参数 +type CooperativeDetailReq struct { + CooperativeID uint64 `json:"cooperative_id" binding:"required"` // 合作商ID +} + +// CooperativeDetailResp 查询合作商详情响应参数 +type CooperativeDetailResp struct { + CooperativeNumber string `json:"cooperative_number"` // 合作商编号 + CooperativeName string `json:"cooperative_name"` // 合作商名称 + Contact string `json:"contact"` // 联系人 + Tel string `json:"tel"` // 手机号 + Status int8 `json:"status"` // 账户状态(1启用 0禁用) + Account string `json:"account"` // 账户 + Balance float64 `json:"balance"` // 账户余额 + Free float64 `json:"free"` // 赠送余额 + Bond float64 `json:"bond"` // 保证金 + Products []ProductDetail `json:"products"` // 产品信息 +} + +// ProductDetail 产品信息 +type ProductDetail struct { + ProductCode string `json:"product_code"` // 产品编码 + ProductName string `json:"product_name"` // 产品名称 + Discount float64 `json:"discount"` // 折扣(0-1) +} diff --git a/app/admin/models/bus_models/m_product_manage.go b/app/admin/models/bus_models/m_product_manage.go index ec001fe..b236752 100644 --- a/app/admin/models/bus_models/m_product_manage.go +++ b/app/admin/models/bus_models/m_product_manage.go @@ -31,14 +31,17 @@ type ProductListReq struct { ProductType uint8 `json:"product_type,omitempty"` // 产品类型:1-短信 2-话费 3-流量(可选) Platform uint8 `json:"platform,omitempty"` // 运营商:1-移动 2-联通 3-电信(可选) Province string `json:"province,omitempty"` // 省份(可选) + City string `json:"city,omitempty"` // 城市(可选) Page int `json:"page"` // 页码 PageSize int `json:"page_size"` // 每页大小 } // ProductListResp 查询产品列表 - 出参 type ProductListResp struct { - Total int `json:"total"` // 总记录数 - List []BusProduct `json:"list"` // 产品列表 + List []BusProduct `json:"list"` // 产品列表 + Total int `json:"total"` // 总记录数 + Page int `json:"page"` // 页码 + PageSize int `json:"page_size"` // 每页大小 } // CreateProductReq 新建产品 - 入参 diff --git a/app/admin/router/bus_cooperative_manage.go b/app/admin/router/bus_cooperative_manage.go new file mode 100644 index 0000000..ae87686 --- /dev/null +++ b/app/admin/router/bus_cooperative_manage.go @@ -0,0 +1,22 @@ +package router + +import ( + "github.com/gin-gonic/gin" + jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth" + "go-admin/app/admin/apis/bus_apis" + "go-admin/common/middleware" +) + +// 需认证的路由代码 +func registerCooperativeManageRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { + api := bus_apis.CooperativeApi{} + + product := v1.Group("/cooperative").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole()) + { + product.POST("/list", api.CooperativeList) // 合作商列表 + product.POST("/detail", api.CooperativeDetail) // 合作商详情 + product.POST("/create", api.CreateCooperative) // 创建合作商 + product.POST("/edit", api.EditCooperative) // 编辑合作商 + product.POST("/delete", api.DeleteCooperative) // 删除合作商 + } +} diff --git a/app/admin/router/router.go b/app/admin/router/router.go index f4a4054..65d22ca 100644 --- a/app/admin/router/router.go +++ b/app/admin/router/router.go @@ -41,4 +41,7 @@ func businessCheckRoleRouter(r *gin.Engine, authMiddleware *jwtauth.GinJWTMiddle // 产品管理 registerProductManageRouter(v1, authMiddleware) + + // 合作商管理 + registerCooperativeManageRouter(v1, authMiddleware) } diff --git a/app/admin/service/bus_service/s_cooperative_manage.go b/app/admin/service/bus_service/s_cooperative_manage.go new file mode 100644 index 0000000..016df73 --- /dev/null +++ b/app/admin/service/bus_service/s_cooperative_manage.go @@ -0,0 +1,329 @@ +package bus_service + +import ( + "context" + "errors" + "fmt" + "github.com/go-admin-team/go-admin-core/sdk/service" + "go-admin/app/admin/models/bus_models" + "go-admin/common/global" + "gorm.io/gorm" + "math/rand" + "time" +) + +type CooperativeService struct { + service.Service +} + +// GetCooperativeList 获取合作商列表 +func (e *CooperativeService) GetCooperativeList(ctx context.Context, req bus_models.CooperativeListReq) ( + bus_models.CooperativeListResp, error) { + var cooperativeList []bus_models.BusCooperative + var resp bus_models.CooperativeListResp + page := req.Page - 1 + if page < 0 { + page = 0 + } + if req.PageSize == 0 { + req.PageSize = 10 + } + + // 构建查询条件,假设我们支持根据 product_code 查询 + db := e.Orm.WithContext(ctx) + + // 如果需要支持分页,可以根据请求条件调整查询 + if req.CooperativeNumber != "" { + db = db.Where("cooperative_number = ?", req.CooperativeNumber) + } + if req.CooperativeName != "" { + db = db.Where("cooperative_name LIKE ?", "%"+req.CooperativeName+"%") + } + if req.Status != 0 { + db = db.Where("status = ?", req.Status) + } + + // 查询数据库 + if err := db.Offset(page * req.Page).Limit(req.PageSize).Find(&cooperativeList).Error; err != nil { + return resp, errors.New("查询合作商列表失败") + } + + resp.List = cooperativeList + resp.Total = len(cooperativeList) + resp.Page = page + 1 + resp.PageSize = req.PageSize + + return resp, nil +} + +// CreateCooperative 新建合作商(使用事务) +func (e *CooperativeService) CreateCooperative(req bus_models.CreateCooperativeReq) (bus_models.CreateCooperativeResp, error) { + var resp bus_models.CreateCooperativeResp + + // 开启事务 + tx := e.Orm.Begin() + defer func() { + if r := recover(); r != nil { + tx.Rollback() + } + }() + + // 创建合作商 + cooperative := bus_models.BusCooperative{ + CooperativeName: req.CooperativeName, + Contact: req.Contact, + Tel: req.Tel, + Status: global.CooperativeStatusOnUse, + Account: req.Account, + Password: req.Password, + Balance: req.Balance, + Free: req.Free, + Bond: req.Bond, + CardHolder: req.CardHolder, + Bank: req.Bank, + CardID: req.CardID, + TaxID: req.TaxID, + } + var err error + cooperative.CooperativeNumber, err = GenerateCooperativeNumber(e.Orm) + if err != nil { + return resp, err + } + + if err := tx.Create(&cooperative).Error; err != nil { + tx.Rollback() + return resp, errors.New("创建合作商失败") + } + + // 插入合作商产品信息 + var cooperativeProducts []bus_models.BusCooperativeProduct + for _, product := range req.Products { + cooperativeProducts = append(cooperativeProducts, bus_models.BusCooperativeProduct{ + CooperativeID: cooperative.ID, + ProductID: product.ProductID, + Discount: product.Discount, + }) + } + if len(cooperativeProducts) > 0 { + if err := tx.Create(&cooperativeProducts).Error; err != nil { + tx.Rollback() + return resp, errors.New("创建合作商产品失败") + } + } + + // 提交事务 + if err := tx.Commit().Error; err != nil { + return resp, errors.New("提交事务失败") + } + + resp.CooperativeNumber = cooperative.CooperativeNumber + return resp, nil +} + +func (e *CooperativeService) EditCooperative(req bus_models.EditCooperativeReq) error { + // 开启事务 + tx := e.Orm.Begin() + defer func() { + if r := recover(); r != nil { + tx.Rollback() + } + }() + + // 查找合作商 + var cooperative bus_models.BusCooperative + if err := tx.Where("cooperative_number = ?", req.CooperativeNumber).First(&cooperative).Error; err != nil { + tx.Rollback() + return errors.New("合作商不存在") + } + + // 更新合作商信息 + updateData := map[string]interface{}{ + "cooperative_name": req.CooperativeName, + "contact": req.Contact, + "tel": req.Tel, + "status": req.Status, + "account": req.Account, + "balance": req.Balance, + "free": req.Free, + "bond": req.Bond, + "card_holder": req.CardHolder, + "bank": req.Bank, + "card_id": req.CardID, + "tax_id": req.TaxID, + } + + if req.Password != "" { + updateData["password"] = req.Password + } + + if err := tx.Model(&bus_models.BusCooperative{}).Where("cooperative_number = ?", req.CooperativeNumber). + Updates(updateData).Error; err != nil { + tx.Rollback() + return errors.New("更新合作商信息失败") + } + + // 获取数据库中的旧产品数据 + var existingProducts []bus_models.BusCooperativeProduct + tx.Where("cooperative_id = ?", cooperative.ID).Find(&existingProducts) + + // 旧数据转换为 map (ProductID => Discount) + existingMap := make(map[uint64]float64) + for _, p := range existingProducts { + existingMap[p.ProductID] = p.Discount + } + + // 计算需要更新、删除、插入的数据 + newProductMap := make(map[uint64]float64) // (ProductID => Discount) + var newProducts []bus_models.BusCooperativeProduct + for _, product := range req.Products { + newProductMap[product.ProductID] = product.Discount + + // 如果是新产品,或者折扣变化,则需要插入/更新 + if discount, exists := existingMap[product.ProductID]; !exists || discount != product.Discount { + newProducts = append(newProducts, bus_models.BusCooperativeProduct{ + CooperativeID: cooperative.ID, + ProductID: product.ProductID, + Discount: product.Discount, + }) + } + } + + // 删除不存在于新数据中的旧产品 + var productIDsToDelete []uint64 + for oldProductID := range existingMap { + if _, exists := newProductMap[oldProductID]; !exists { + productIDsToDelete = append(productIDsToDelete, oldProductID) + } + } + if len(productIDsToDelete) > 0 { + tx.Where("cooperative_id = ? AND product_id IN ?", cooperative.ID, productIDsToDelete).Delete(&bus_models.BusCooperativeProduct{}) + } + + // 插入新的或有折扣变化的产品 + if len(newProducts) > 0 { + if err := tx.Create(&newProducts).Error; err != nil { + tx.Rollback() + return errors.New("添加/更新合作商产品信息失败") + } + } + + // 提交事务 + if err := tx.Commit().Error; err != nil { + return errors.New("提交事务失败") + } + + return nil +} + +// DeleteCooperative 删除合作商 +func (e *CooperativeService) DeleteCooperative(req bus_models.DeleteCooperativeReq) error { + // 执行删除操作 + if err := e.Orm.Where("cooperative_number = ?", req.CooperativeNumber). + Delete(&bus_models.BusCooperative{}).Error; err != nil { + return errors.New("删除产品失败") + } + + return nil +} + +// GetCooperativeDetail 获取合作商详细信息,包括产品信息 +func (e *CooperativeService) GetCooperativeDetail(ctx context.Context, req bus_models.CooperativeDetailReq) ( + bus_models.CooperativeDetailResp, error) { + var resp bus_models.CooperativeDetailResp + var cooperative bus_models.BusCooperative + + // 查询合作商基本信息 + db := e.Orm.WithContext(ctx).Where("id = ?", req.CooperativeID) + + if err := db.First(&cooperative).Error; err != nil { + return resp, errors.New("查询合作商详情失败") + } + + // 查询该合作商的产品信息 + var cooperativeProducts []bus_models.BusCooperativeProduct + err := e.Orm.WithContext(ctx). + Where("cooperative_id = ?", req.CooperativeID). + Find(&cooperativeProducts).Error + + if err != nil { + return resp, errors.New("查询合作商产品信息失败") + } + + // 根据产品ID查询产品名称和编码 + var productIDs []uint64 + for _, cp := range cooperativeProducts { + productIDs = append(productIDs, cp.ProductID) + } + + // 查询产品详细信息 + var products []bus_models.BusProduct + if len(productIDs) > 0 { + err = e.Orm.WithContext(ctx). + Where("id IN (?)", productIDs). + Find(&products).Error + + if err != nil { + return resp, errors.New("查询产品信息失败") + } + } + + // 将产品信息填充到响应中 + var productDetails []bus_models.ProductDetail + for _, cp := range cooperativeProducts { + // 查找对应产品 + for _, p := range products { + if p.ID == cp.ProductID { // 确保ID匹配 + productDetails = append(productDetails, bus_models.ProductDetail{ + ProductCode: p.ProductCode, + ProductName: p.ProductName, + Discount: cp.Discount, + }) + break + } + } + } + + // 填充合作商信息 + resp.CooperativeNumber = cooperative.CooperativeNumber + resp.CooperativeName = cooperative.CooperativeName + resp.Contact = cooperative.Contact + resp.Tel = cooperative.Tel + resp.Status = cooperative.Status + resp.Account = cooperative.Account + resp.Balance = cooperative.Balance + resp.Free = cooperative.Free + resp.Bond = cooperative.Bond + resp.Products = productDetails + + return resp, nil +} + +// GenerateCooperativeNumber 生成唯一的合作商编号,日期 + 10位随机数 +func GenerateCooperativeNumber(db *gorm.DB) (string, error) { + // 获取当前日期(年月日) + dateStr := time.Now().Format("20060102") // 格式为:YYYYMMDD + + // 生成一个10位随机数 + rand.Seed(time.Now().UnixNano()) // 设置随机数种子 + randomNum := rand.Int63n(10000000000) // 生成一个0到9999999999之间的随机数 + + // 将随机数转为固定长度的字符串,确保10位 + randomNumStr := fmt.Sprintf("%010d", randomNum) // 确保为10位,不足补零 + + // 拼接日期和随机数 + cooperativeNumber := fmt.Sprintf("%s%s", dateStr, randomNumStr) + + // 检查生成的合作商编号是否已存在 + var count int64 + err := db.Model(&bus_models.BusCooperative{}).Where("cooperative_number = ?", cooperativeNumber).Count(&count).Error + if err != nil { + return "", err + } + + // 如果已存在,重新生成 + if count > 0 { + return GenerateCooperativeNumber(db) // 递归重新生成 + } + + return cooperativeNumber, nil +} diff --git a/app/admin/service/bus_service/s_product_manage.go b/app/admin/service/bus_service/s_product_manage.go index e84c2d5..ab82a4b 100644 --- a/app/admin/service/bus_service/s_product_manage.go +++ b/app/admin/service/bus_service/s_product_manage.go @@ -15,6 +15,13 @@ type ProductService struct { func (e *ProductService) GetProductList(ctx context.Context, req bus_models.ProductListReq) (bus_models.ProductListResp, error) { var products []bus_models.BusProduct var resp bus_models.ProductListResp + page := req.Page - 1 + if page < 0 { + page = 0 + } + if req.PageSize == 0 { + req.PageSize = 10 + } // 构建查询条件,假设我们支持根据 product_code 查询 db := e.Orm.WithContext(ctx) @@ -29,14 +36,25 @@ func (e *ProductService) GetProductList(ctx context.Context, req bus_models.Prod if req.ProductType != 0 { db = db.Where("product_type = ?", req.ProductType) } + if req.Province != "" { + db = db.Where("province = ?", req.Province) + } + if req.City != "" { + db = db.Where("city = ?", req.City) + } + if req.Platform != 0 { + db = db.Where("platform = ?", req.Platform) + } // 查询数据库 - if err := db.Find(&products).Error; err != nil { + if err := db.Offset(page * req.Page).Limit(req.PageSize).Find(&products).Error; err != nil { return resp, errors.New("查询产品列表失败") } resp.List = products resp.Total = len(products) + resp.Page = page + 1 + resp.PageSize = req.PageSize return resp, nil } @@ -46,14 +64,19 @@ func (e *ProductService) CreateProduct(req bus_models.CreateProductReq) (bus_mod var resp bus_models.CreateProductResp product := bus_models.BusProduct{ ProductCode: req.ProductCode, + ServiceCode: req.ServiceCode, ProductName: req.ProductName, + ProductAttr: req.ProductAttr, ProductType: req.ProductType, - Platform: req.Platform, + Type: req.Type, + Size: req.Size, Price: req.Price, Discount: req.Discount, RetailPrice: req.RetailPrice, + Description: req.Description, Province: req.Province, City: req.City, + Platform: req.Platform, } // 将产品插入数据库 @@ -71,14 +94,19 @@ func (e *ProductService) CreateProduct(req bus_models.CreateProductReq) (bus_mod func (e *ProductService) EditProduct(req bus_models.EditProductReq) error { product := bus_models.BusProduct{ ProductCode: req.ProductCode, + ServiceCode: req.ServiceCode, ProductName: req.ProductName, + ProductAttr: req.ProductAttr, ProductType: req.ProductType, - Platform: req.Platform, + Type: req.Type, + Size: req.Size, Price: req.Price, Discount: req.Discount, RetailPrice: req.RetailPrice, + Description: req.Description, Province: req.Province, City: req.City, + Platform: req.Platform, } // 更新产品信息 diff --git a/common/global/constant.go b/common/global/constant.go new file mode 100644 index 0000000..837010e --- /dev/null +++ b/common/global/constant.go @@ -0,0 +1,5 @@ +package global + +const ( + CooperativeStatusOnUse = 1 // 合作商状态-启用 +) diff --git a/docs/admin/admin_docs.go b/docs/admin/admin_docs.go index 614d40d..8bd2628 100644 --- a/docs/admin/admin_docs.go +++ b/docs/admin/admin_docs.go @@ -86,6 +86,171 @@ const docTemplateadmin = `{ } } }, + "/api/v1/cooperative/create": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "合作商管理-V1.0.0" + ], + "summary": "新建合作商", + "parameters": [ + { + "description": "新建合作商模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/bus_models.CreateCooperativeReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/bus_models.CreateCooperativeResp" + } + } + } + } + }, + "/api/v1/cooperative/delete": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "合作商管理-V1.0.0" + ], + "summary": "删除合作商", + "parameters": [ + { + "description": "删除合作商模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/bus_models.DeleteCooperativeReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, + "/api/v1/cooperative/detail": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "合作商管理-V1.0.0" + ], + "summary": "查询合作商详情", + "parameters": [ + { + "description": "查询合作商详情请求参数", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/bus_models.CooperativeDetailReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/bus_models.CooperativeDetailResp" + } + } + } + } + }, + "/api/v1/cooperative/edit": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "合作商管理-V1.0.0" + ], + "summary": "编辑合作商", + "parameters": [ + { + "description": "编辑合作商模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/bus_models.EditCooperativeReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, + "/api/v1/cooperative/list": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "合作商管理-V1.0.0" + ], + "summary": "查询合作商列表", + "parameters": [ + { + "description": "查询合作商列表模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/bus_models.CooperativeListReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/bus_models.CooperativeListResp" + } + } + } + } + }, "/api/v1/db/columns/page": { "get": { "description": "数据库表列分页列表 / database table column page list", @@ -2942,6 +3107,115 @@ const docTemplateadmin = `{ } } }, + "bus_models.BusCooperative": { + "type": "object", + "properties": { + "account": { + "description": "账户", + "type": "string" + }, + "balance": { + "description": "账户余额", + "type": "number" + }, + "bank": { + "description": "开户行", + "type": "string" + }, + "bond": { + "description": "保证金", + "type": "number" + }, + "card_holder": { + "description": "开户人", + "type": "string" + }, + "card_id": { + "description": "银行帐号", + "type": "string" + }, + "contact": { + "description": "联系人", + "type": "string" + }, + "cooperative_name": { + "description": "合作商名称", + "type": "string" + }, + "cooperative_number": { + "description": "合作商编号", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "free": { + "description": "赠送余额", + "type": "number" + }, + "id": { + "description": "数据库记录编号", + "type": "integer" + }, + "password": { + "description": "密码(建议存储加密哈希值)", + "type": "string" + }, + "products": { + "description": "产品信息", + "type": "array", + "items": { + "$ref": "#/definitions/bus_models.BusCooperativeProduct" + } + }, + "status": { + "description": "账户状态(1启用 0禁用)", + "type": "integer" + }, + "tax_id": { + "description": "税号", + "type": "string" + }, + "tel": { + "description": "手机号", + "type": "string" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, + "bus_models.BusCooperativeProduct": { + "type": "object", + "properties": { + "cooperative_id": { + "description": "合作商编号", + "type": "integer" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "discount": { + "description": "折扣(0-1)", + "type": "number" + }, + "id": { + "description": "数据库记录编号", + "type": "integer" + }, + "product_id": { + "description": "产品ID", + "type": "integer" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, "bus_models.BusProduct": { "type": "object", "properties": { @@ -3015,6 +3289,198 @@ const docTemplateadmin = `{ } } }, + "bus_models.CooperativeDetailReq": { + "type": "object", + "required": [ + "cooperative_id" + ], + "properties": { + "cooperative_id": { + "description": "合作商ID", + "type": "integer" + } + } + }, + "bus_models.CooperativeDetailResp": { + "type": "object", + "properties": { + "account": { + "description": "账户", + "type": "string" + }, + "balance": { + "description": "账户余额", + "type": "number" + }, + "bond": { + "description": "保证金", + "type": "number" + }, + "contact": { + "description": "联系人", + "type": "string" + }, + "cooperative_name": { + "description": "合作商名称", + "type": "string" + }, + "cooperative_number": { + "description": "合作商编号", + "type": "string" + }, + "free": { + "description": "赠送余额", + "type": "number" + }, + "products": { + "description": "产品信息", + "type": "array", + "items": { + "$ref": "#/definitions/bus_models.ProductDetail" + } + }, + "status": { + "description": "账户状态(1启用 0禁用)", + "type": "integer" + }, + "tel": { + "description": "手机号", + "type": "string" + } + } + }, + "bus_models.CooperativeListReq": { + "type": "object", + "required": [ + "page", + "page_size" + ], + "properties": { + "cooperative_name": { + "description": "合作商名称(支持模糊查询)", + "type": "string" + }, + "cooperative_number": { + "description": "合作商编号(可选)", + "type": "string" + }, + "page": { + "description": "页码", + "type": "integer", + "minimum": 1 + }, + "page_size": { + "description": "每页条数", + "type": "integer", + "maximum": 100, + "minimum": 1 + }, + "status": { + "description": "账户状态(1启用 0禁用)", + "type": "integer" + } + } + }, + "bus_models.CooperativeListResp": { + "type": "object", + "properties": { + "list": { + "description": "合作商列表", + "type": "array", + "items": { + "$ref": "#/definitions/bus_models.BusCooperative" + } + }, + "page": { + "description": "页码", + "type": "integer" + }, + "page_size": { + "description": "每页大小", + "type": "integer" + }, + "total": { + "description": "总记录数", + "type": "integer" + } + } + }, + "bus_models.CreateCooperativeReq": { + "type": "object", + "required": [ + "account", + "contact", + "cooperative_name", + "password", + "tel" + ], + "properties": { + "account": { + "description": "账户", + "type": "string" + }, + "balance": { + "description": "账户余额(可选)", + "type": "number" + }, + "bank": { + "description": "开户行(可选)", + "type": "string" + }, + "bond": { + "description": "保证金(可选)", + "type": "number" + }, + "card_holder": { + "description": "开户人(可选)", + "type": "string" + }, + "card_id": { + "description": "银行帐号(可选)", + "type": "string" + }, + "contact": { + "description": "联系人", + "type": "string" + }, + "cooperative_name": { + "description": "合作商名称", + "type": "string" + }, + "free": { + "description": "赠送余额(可选)", + "type": "number" + }, + "password": { + "description": "密码(前端传输时应加密)", + "type": "string" + }, + "products": { + "description": "关联产品及折扣信息", + "type": "array", + "items": { + "$ref": "#/definitions/bus_models.ProductDiscount" + } + }, + "tax_id": { + "description": "税号(可选)", + "type": "string" + }, + "tel": { + "description": "手机号", + "type": "string" + } + } + }, + "bus_models.CreateCooperativeResp": { + "type": "object", + "properties": { + "cooperative_number": { + "description": "合作商编号", + "type": "string" + } + } + }, "bus_models.CreateProductReq": { "type": "object", "required": [ @@ -3093,6 +3559,15 @@ const docTemplateadmin = `{ } } }, + "bus_models.DeleteCooperativeReq": { + "type": "object", + "properties": { + "cooperative_number": { + "description": "合作商编号", + "type": "string" + } + } + }, "bus_models.DeleteProductReq": { "type": "object", "required": [ @@ -3105,6 +3580,74 @@ const docTemplateadmin = `{ } } }, + "bus_models.EditCooperativeReq": { + "type": "object", + "properties": { + "account": { + "description": "账户(可选)", + "type": "string" + }, + "balance": { + "description": "账户余额(可选)", + "type": "number" + }, + "bank": { + "description": "开户行(可选)", + "type": "string" + }, + "bond": { + "description": "保证金(可选)", + "type": "number" + }, + "card_holder": { + "description": "开户人(可选)", + "type": "string" + }, + "card_id": { + "description": "银行帐号(可选)", + "type": "string" + }, + "contact": { + "description": "联系人(可选)", + "type": "string" + }, + "cooperative_name": { + "description": "合作商名称(可选)", + "type": "string" + }, + "cooperative_number": { + "description": "合作商编号", + "type": "string" + }, + "free": { + "description": "赠送余额(可选)", + "type": "number" + }, + "password": { + "description": "密码(可选,前端加密传输)", + "type": "string" + }, + "products": { + "description": "关联产品及折扣信息", + "type": "array", + "items": { + "$ref": "#/definitions/bus_models.ProductDiscount" + } + }, + "status": { + "description": "账户状态(可选)", + "type": "integer" + }, + "tax_id": { + "description": "税号(可选)", + "type": "string" + }, + "tel": { + "description": "手机号(可选)", + "type": "string" + } + } + }, "bus_models.EditProductReq": { "type": "object", "required": [ @@ -3175,9 +3718,47 @@ const docTemplateadmin = `{ } } }, + "bus_models.ProductDetail": { + "type": "object", + "properties": { + "discount": { + "description": "折扣(0-1)", + "type": "number" + }, + "product_code": { + "description": "产品编码", + "type": "string" + }, + "product_name": { + "description": "产品名称", + "type": "string" + } + } + }, + "bus_models.ProductDiscount": { + "type": "object", + "required": [ + "discount", + "product_id" + ], + "properties": { + "discount": { + "description": "折扣(0-1之间)", + "type": "number" + }, + "product_id": { + "description": "产品ID", + "type": "integer" + } + } + }, "bus_models.ProductListReq": { "type": "object", "properties": { + "city": { + "description": "城市(可选)", + "type": "string" + }, "page": { "description": "页码", "type": "integer" @@ -3218,6 +3799,14 @@ const docTemplateadmin = `{ "$ref": "#/definitions/bus_models.BusProduct" } }, + "page": { + "description": "页码", + "type": "integer" + }, + "page_size": { + "description": "每页大小", + "type": "integer" + }, "total": { "description": "总记录数", "type": "integer" diff --git a/docs/admin/admin_swagger.json b/docs/admin/admin_swagger.json index 713fe42..ec345aa 100644 --- a/docs/admin/admin_swagger.json +++ b/docs/admin/admin_swagger.json @@ -78,6 +78,171 @@ } } }, + "/api/v1/cooperative/create": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "合作商管理-V1.0.0" + ], + "summary": "新建合作商", + "parameters": [ + { + "description": "新建合作商模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/bus_models.CreateCooperativeReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/bus_models.CreateCooperativeResp" + } + } + } + } + }, + "/api/v1/cooperative/delete": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "合作商管理-V1.0.0" + ], + "summary": "删除合作商", + "parameters": [ + { + "description": "删除合作商模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/bus_models.DeleteCooperativeReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, + "/api/v1/cooperative/detail": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "合作商管理-V1.0.0" + ], + "summary": "查询合作商详情", + "parameters": [ + { + "description": "查询合作商详情请求参数", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/bus_models.CooperativeDetailReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/bus_models.CooperativeDetailResp" + } + } + } + } + }, + "/api/v1/cooperative/edit": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "合作商管理-V1.0.0" + ], + "summary": "编辑合作商", + "parameters": [ + { + "description": "编辑合作商模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/bus_models.EditCooperativeReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/app.Response" + } + } + } + } + }, + "/api/v1/cooperative/list": { + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "合作商管理-V1.0.0" + ], + "summary": "查询合作商列表", + "parameters": [ + { + "description": "查询合作商列表模型", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/bus_models.CooperativeListReq" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/bus_models.CooperativeListResp" + } + } + } + } + }, "/api/v1/db/columns/page": { "get": { "description": "数据库表列分页列表 / database table column page list", @@ -2934,6 +3099,115 @@ } } }, + "bus_models.BusCooperative": { + "type": "object", + "properties": { + "account": { + "description": "账户", + "type": "string" + }, + "balance": { + "description": "账户余额", + "type": "number" + }, + "bank": { + "description": "开户行", + "type": "string" + }, + "bond": { + "description": "保证金", + "type": "number" + }, + "card_holder": { + "description": "开户人", + "type": "string" + }, + "card_id": { + "description": "银行帐号", + "type": "string" + }, + "contact": { + "description": "联系人", + "type": "string" + }, + "cooperative_name": { + "description": "合作商名称", + "type": "string" + }, + "cooperative_number": { + "description": "合作商编号", + "type": "string" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "free": { + "description": "赠送余额", + "type": "number" + }, + "id": { + "description": "数据库记录编号", + "type": "integer" + }, + "password": { + "description": "密码(建议存储加密哈希值)", + "type": "string" + }, + "products": { + "description": "产品信息", + "type": "array", + "items": { + "$ref": "#/definitions/bus_models.BusCooperativeProduct" + } + }, + "status": { + "description": "账户状态(1启用 0禁用)", + "type": "integer" + }, + "tax_id": { + "description": "税号", + "type": "string" + }, + "tel": { + "description": "手机号", + "type": "string" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, + "bus_models.BusCooperativeProduct": { + "type": "object", + "properties": { + "cooperative_id": { + "description": "合作商编号", + "type": "integer" + }, + "createdAt": { + "description": "创建时间", + "type": "string" + }, + "discount": { + "description": "折扣(0-1)", + "type": "number" + }, + "id": { + "description": "数据库记录编号", + "type": "integer" + }, + "product_id": { + "description": "产品ID", + "type": "integer" + }, + "updatedAt": { + "description": "更新时间", + "type": "string" + } + } + }, "bus_models.BusProduct": { "type": "object", "properties": { @@ -3007,6 +3281,198 @@ } } }, + "bus_models.CooperativeDetailReq": { + "type": "object", + "required": [ + "cooperative_id" + ], + "properties": { + "cooperative_id": { + "description": "合作商ID", + "type": "integer" + } + } + }, + "bus_models.CooperativeDetailResp": { + "type": "object", + "properties": { + "account": { + "description": "账户", + "type": "string" + }, + "balance": { + "description": "账户余额", + "type": "number" + }, + "bond": { + "description": "保证金", + "type": "number" + }, + "contact": { + "description": "联系人", + "type": "string" + }, + "cooperative_name": { + "description": "合作商名称", + "type": "string" + }, + "cooperative_number": { + "description": "合作商编号", + "type": "string" + }, + "free": { + "description": "赠送余额", + "type": "number" + }, + "products": { + "description": "产品信息", + "type": "array", + "items": { + "$ref": "#/definitions/bus_models.ProductDetail" + } + }, + "status": { + "description": "账户状态(1启用 0禁用)", + "type": "integer" + }, + "tel": { + "description": "手机号", + "type": "string" + } + } + }, + "bus_models.CooperativeListReq": { + "type": "object", + "required": [ + "page", + "page_size" + ], + "properties": { + "cooperative_name": { + "description": "合作商名称(支持模糊查询)", + "type": "string" + }, + "cooperative_number": { + "description": "合作商编号(可选)", + "type": "string" + }, + "page": { + "description": "页码", + "type": "integer", + "minimum": 1 + }, + "page_size": { + "description": "每页条数", + "type": "integer", + "maximum": 100, + "minimum": 1 + }, + "status": { + "description": "账户状态(1启用 0禁用)", + "type": "integer" + } + } + }, + "bus_models.CooperativeListResp": { + "type": "object", + "properties": { + "list": { + "description": "合作商列表", + "type": "array", + "items": { + "$ref": "#/definitions/bus_models.BusCooperative" + } + }, + "page": { + "description": "页码", + "type": "integer" + }, + "page_size": { + "description": "每页大小", + "type": "integer" + }, + "total": { + "description": "总记录数", + "type": "integer" + } + } + }, + "bus_models.CreateCooperativeReq": { + "type": "object", + "required": [ + "account", + "contact", + "cooperative_name", + "password", + "tel" + ], + "properties": { + "account": { + "description": "账户", + "type": "string" + }, + "balance": { + "description": "账户余额(可选)", + "type": "number" + }, + "bank": { + "description": "开户行(可选)", + "type": "string" + }, + "bond": { + "description": "保证金(可选)", + "type": "number" + }, + "card_holder": { + "description": "开户人(可选)", + "type": "string" + }, + "card_id": { + "description": "银行帐号(可选)", + "type": "string" + }, + "contact": { + "description": "联系人", + "type": "string" + }, + "cooperative_name": { + "description": "合作商名称", + "type": "string" + }, + "free": { + "description": "赠送余额(可选)", + "type": "number" + }, + "password": { + "description": "密码(前端传输时应加密)", + "type": "string" + }, + "products": { + "description": "关联产品及折扣信息", + "type": "array", + "items": { + "$ref": "#/definitions/bus_models.ProductDiscount" + } + }, + "tax_id": { + "description": "税号(可选)", + "type": "string" + }, + "tel": { + "description": "手机号", + "type": "string" + } + } + }, + "bus_models.CreateCooperativeResp": { + "type": "object", + "properties": { + "cooperative_number": { + "description": "合作商编号", + "type": "string" + } + } + }, "bus_models.CreateProductReq": { "type": "object", "required": [ @@ -3085,6 +3551,15 @@ } } }, + "bus_models.DeleteCooperativeReq": { + "type": "object", + "properties": { + "cooperative_number": { + "description": "合作商编号", + "type": "string" + } + } + }, "bus_models.DeleteProductReq": { "type": "object", "required": [ @@ -3097,6 +3572,74 @@ } } }, + "bus_models.EditCooperativeReq": { + "type": "object", + "properties": { + "account": { + "description": "账户(可选)", + "type": "string" + }, + "balance": { + "description": "账户余额(可选)", + "type": "number" + }, + "bank": { + "description": "开户行(可选)", + "type": "string" + }, + "bond": { + "description": "保证金(可选)", + "type": "number" + }, + "card_holder": { + "description": "开户人(可选)", + "type": "string" + }, + "card_id": { + "description": "银行帐号(可选)", + "type": "string" + }, + "contact": { + "description": "联系人(可选)", + "type": "string" + }, + "cooperative_name": { + "description": "合作商名称(可选)", + "type": "string" + }, + "cooperative_number": { + "description": "合作商编号", + "type": "string" + }, + "free": { + "description": "赠送余额(可选)", + "type": "number" + }, + "password": { + "description": "密码(可选,前端加密传输)", + "type": "string" + }, + "products": { + "description": "关联产品及折扣信息", + "type": "array", + "items": { + "$ref": "#/definitions/bus_models.ProductDiscount" + } + }, + "status": { + "description": "账户状态(可选)", + "type": "integer" + }, + "tax_id": { + "description": "税号(可选)", + "type": "string" + }, + "tel": { + "description": "手机号(可选)", + "type": "string" + } + } + }, "bus_models.EditProductReq": { "type": "object", "required": [ @@ -3167,9 +3710,47 @@ } } }, + "bus_models.ProductDetail": { + "type": "object", + "properties": { + "discount": { + "description": "折扣(0-1)", + "type": "number" + }, + "product_code": { + "description": "产品编码", + "type": "string" + }, + "product_name": { + "description": "产品名称", + "type": "string" + } + } + }, + "bus_models.ProductDiscount": { + "type": "object", + "required": [ + "discount", + "product_id" + ], + "properties": { + "discount": { + "description": "折扣(0-1之间)", + "type": "number" + }, + "product_id": { + "description": "产品ID", + "type": "integer" + } + } + }, "bus_models.ProductListReq": { "type": "object", "properties": { + "city": { + "description": "城市(可选)", + "type": "string" + }, "page": { "description": "页码", "type": "integer" @@ -3210,6 +3791,14 @@ "$ref": "#/definitions/bus_models.BusProduct" } }, + "page": { + "description": "页码", + "type": "integer" + }, + "page_size": { + "description": "每页大小", + "type": "integer" + }, "total": { "description": "总记录数", "type": "integer" diff --git a/docs/admin/admin_swagger.yaml b/docs/admin/admin_swagger.yaml index 1e1eeb5..141a67e 100644 --- a/docs/admin/admin_swagger.yaml +++ b/docs/admin/admin_swagger.yaml @@ -14,6 +14,86 @@ definitions: description: 请求id type: string type: object + bus_models.BusCooperative: + properties: + account: + description: 账户 + type: string + balance: + description: 账户余额 + type: number + bank: + description: 开户行 + type: string + bond: + description: 保证金 + type: number + card_holder: + description: 开户人 + type: string + card_id: + description: 银行帐号 + type: string + contact: + description: 联系人 + type: string + cooperative_name: + description: 合作商名称 + type: string + cooperative_number: + description: 合作商编号 + type: string + createdAt: + description: 创建时间 + type: string + free: + description: 赠送余额 + type: number + id: + description: 数据库记录编号 + type: integer + password: + description: 密码(建议存储加密哈希值) + type: string + products: + description: 产品信息 + items: + $ref: '#/definitions/bus_models.BusCooperativeProduct' + type: array + status: + description: 账户状态(1启用 0禁用) + type: integer + tax_id: + description: 税号 + type: string + tel: + description: 手机号 + type: string + updatedAt: + description: 更新时间 + type: string + type: object + bus_models.BusCooperativeProduct: + properties: + cooperative_id: + description: 合作商编号 + type: integer + createdAt: + description: 创建时间 + type: string + discount: + description: 折扣(0-1) + type: number + id: + description: 数据库记录编号 + type: integer + product_id: + description: 产品ID + type: integer + updatedAt: + description: 更新时间 + type: string + type: object bus_models.BusProduct: properties: city: @@ -68,6 +148,146 @@ definitions: description: 更新时间 type: string type: object + bus_models.CooperativeDetailReq: + properties: + cooperative_id: + description: 合作商ID + type: integer + required: + - cooperative_id + type: object + bus_models.CooperativeDetailResp: + properties: + account: + description: 账户 + type: string + balance: + description: 账户余额 + type: number + bond: + description: 保证金 + type: number + contact: + description: 联系人 + type: string + cooperative_name: + description: 合作商名称 + type: string + cooperative_number: + description: 合作商编号 + type: string + free: + description: 赠送余额 + type: number + products: + description: 产品信息 + items: + $ref: '#/definitions/bus_models.ProductDetail' + type: array + status: + description: 账户状态(1启用 0禁用) + type: integer + tel: + description: 手机号 + type: string + type: object + bus_models.CooperativeListReq: + properties: + cooperative_name: + description: 合作商名称(支持模糊查询) + type: string + cooperative_number: + description: 合作商编号(可选) + type: string + page: + description: 页码 + minimum: 1 + type: integer + page_size: + description: 每页条数 + maximum: 100 + minimum: 1 + type: integer + status: + description: 账户状态(1启用 0禁用) + type: integer + required: + - page + - page_size + type: object + bus_models.CooperativeListResp: + properties: + list: + description: 合作商列表 + items: + $ref: '#/definitions/bus_models.BusCooperative' + type: array + page: + description: 页码 + type: integer + page_size: + description: 每页大小 + type: integer + total: + description: 总记录数 + type: integer + type: object + bus_models.CreateCooperativeReq: + properties: + account: + description: 账户 + type: string + balance: + description: 账户余额(可选) + type: number + bank: + description: 开户行(可选) + type: string + bond: + description: 保证金(可选) + type: number + card_holder: + description: 开户人(可选) + type: string + card_id: + description: 银行帐号(可选) + type: string + contact: + description: 联系人 + type: string + cooperative_name: + description: 合作商名称 + type: string + free: + description: 赠送余额(可选) + type: number + password: + description: 密码(前端传输时应加密) + type: string + products: + description: 关联产品及折扣信息 + items: + $ref: '#/definitions/bus_models.ProductDiscount' + type: array + tax_id: + description: 税号(可选) + type: string + tel: + description: 手机号 + type: string + required: + - account + - contact + - cooperative_name + - password + - tel + type: object + bus_models.CreateCooperativeResp: + properties: + cooperative_number: + description: 合作商编号 + type: string + type: object bus_models.CreateProductReq: properties: city: @@ -126,6 +346,12 @@ definitions: description: 新创建的产品ID type: integer type: object + bus_models.DeleteCooperativeReq: + properties: + cooperative_number: + description: 合作商编号 + type: string + type: object bus_models.DeleteProductReq: properties: id: @@ -134,6 +360,56 @@ definitions: required: - id type: object + bus_models.EditCooperativeReq: + properties: + account: + description: 账户(可选) + type: string + balance: + description: 账户余额(可选) + type: number + bank: + description: 开户行(可选) + type: string + bond: + description: 保证金(可选) + type: number + card_holder: + description: 开户人(可选) + type: string + card_id: + description: 银行帐号(可选) + type: string + contact: + description: 联系人(可选) + type: string + cooperative_name: + description: 合作商名称(可选) + type: string + cooperative_number: + description: 合作商编号 + type: string + free: + description: 赠送余额(可选) + type: number + password: + description: 密码(可选,前端加密传输) + type: string + products: + description: 关联产品及折扣信息 + items: + $ref: '#/definitions/bus_models.ProductDiscount' + type: array + status: + description: 账户状态(可选) + type: integer + tax_id: + description: 税号(可选) + type: string + tel: + description: 手机号(可选) + type: string + type: object bus_models.EditProductReq: properties: city: @@ -186,8 +462,35 @@ definitions: - product_code - product_name type: object + bus_models.ProductDetail: + properties: + discount: + description: 折扣(0-1) + type: number + product_code: + description: 产品编码 + type: string + product_name: + description: 产品名称 + type: string + type: object + bus_models.ProductDiscount: + properties: + discount: + description: 折扣(0-1之间) + type: number + product_id: + description: 产品ID + type: integer + required: + - discount + - product_id + type: object bus_models.ProductListReq: properties: + city: + description: 城市(可选) + type: string page: description: 页码 type: integer @@ -217,6 +520,12 @@ definitions: items: $ref: '#/definitions/bus_models.BusProduct' type: array + page: + description: 页码 + type: integer + page_size: + description: 每页大小 + type: integer total: description: 总记录数 type: integer @@ -1317,6 +1626,111 @@ paths: summary: 获取验证码 tags: - 登陆 + /api/v1/cooperative/create: + post: + consumes: + - application/json + parameters: + - description: 新建合作商模型 + in: body + name: request + required: true + schema: + $ref: '#/definitions/bus_models.CreateCooperativeReq' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/bus_models.CreateCooperativeResp' + summary: 新建合作商 + tags: + - 合作商管理-V1.0.0 + /api/v1/cooperative/delete: + post: + consumes: + - application/json + parameters: + - description: 删除合作商模型 + in: body + name: request + required: true + schema: + $ref: '#/definitions/bus_models.DeleteCooperativeReq' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/app.Response' + summary: 删除合作商 + tags: + - 合作商管理-V1.0.0 + /api/v1/cooperative/detail: + post: + consumes: + - application/json + parameters: + - description: 查询合作商详情请求参数 + in: body + name: request + required: true + schema: + $ref: '#/definitions/bus_models.CooperativeDetailReq' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/bus_models.CooperativeDetailResp' + summary: 查询合作商详情 + tags: + - 合作商管理-V1.0.0 + /api/v1/cooperative/edit: + post: + consumes: + - application/json + parameters: + - description: 编辑合作商模型 + in: body + name: request + required: true + schema: + $ref: '#/definitions/bus_models.EditCooperativeReq' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/app.Response' + summary: 编辑合作商 + tags: + - 合作商管理-V1.0.0 + /api/v1/cooperative/list: + post: + consumes: + - application/json + parameters: + - description: 查询合作商列表模型 + in: body + name: request + required: true + schema: + $ref: '#/definitions/bus_models.CooperativeListReq' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/bus_models.CooperativeListResp' + summary: 查询合作商列表 + tags: + - 合作商管理-V1.0.0 /api/v1/db/columns/page: get: description: 数据库表列分页列表 / database table column page list