telco_server/app/admin/apis/bus_apis/a_cooperative_manage.go

259 lines
6.6 KiB
Go

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
}
if resp.CooperativeNumber == "" {
app.Error(c, http.StatusInternalServerError, err, "新增失败")
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
}
// AdjustAccountHandler 账户调整接口
// @Summary 账户调整(加款/减款)
// @Tags 合作商管理-V1.0.0
// @Accept json
// @Produce json
// @Param request body bus_models.AdjustAccountReq true "账户调整请求"
// @Success 200 {object} app.Response
// @Router /api/v1/cooperative/adjust_account [post]
func (e CooperativeApi) AdjustAccountHandler(c *gin.Context) {
s := bus_service.CooperativeService{}
var req bus_models.AdjustAccountReq
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
}
// 调用服务层方法
if err := s.AdjustAccount(c.Request.Context(), req); err != nil {
app.Error(c, http.StatusInternalServerError, err, err.Error())
return
}
app.OK(c, nil, "账户调整成功")
}
// SetCooperativeStatus 设置合作商状态
// @Summary 设置合作商状态
// @Tags 合作商管理-V1.0.0
// @Produce json
// @Accept json
// @Param request body bus_models.SetCooperativeStatusReq true "设置合作商状态"
// @Success 200 {object} app.Response
// @Router /api/v1/cooperative/status [post]
func (e CooperativeApi) SetCooperativeStatus(c *gin.Context) {
s := bus_service.CooperativeService{}
var req bus_models.SetCooperativeStatusReq
if err := c.ShouldBindJSON(&req); err != nil {
app.Error(c, http.StatusBadRequest, err, "参数错误")
return
}
err := e.MakeContext(c).MakeOrm().MakeService(&s.Service).Errors
if err != nil {
e.Logger.Error(err)
app.Error(c, http.StatusInternalServerError, err, "内部错误")
return
}
if err := s.SetCooperativeStatus(req); err != nil {
app.Error(c, http.StatusInternalServerError, err, "更新失败")
return
}
app.OK(c, nil, "更新成功")
}