hospital-admin-api/api/controller/doctorWithdrawal.go
2023-10-31 09:13:50 +08:00

84 lines
2.0 KiB
Go

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"
)
// DoctorWithdrawal 医生提现
type DoctorWithdrawal struct{}
// GetDoctorWithdrawalPage 获取医生提现列表-分页
func (r *DoctorWithdrawal) GetDoctorWithdrawalPage(c *gin.Context) {
doctorWithdrawalRequest := requests.DoctorWithdrawalRequest{}
req := doctorWithdrawalRequest.GetDoctorWithdrawalPage
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
}
doctorWithdrawalDao := dao.DoctorWithdrawalDao{}
doctorWithdrawal, total, err := doctorWithdrawalDao.GetDoctorWithdrawalPageSearch(req, req.Page, req.PageSize)
if err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
// 处理返回值
res := dto.GetDoctorWithdrawalListDto(doctorWithdrawal)
result := make(map[string]interface{})
result["page"] = req.Page
result["page_size"] = req.PageSize
result["total"] = total
result["data"] = res
responses.OkWithData(result, c)
}
// GetDoctorWithdrawal 提现详情
func (r *DoctorWithdrawal) GetDoctorWithdrawal(c *gin.Context) {
id := c.Param("withdrawal_id")
if id == "" {
responses.FailWithMessage("缺少参数", c)
return
}
// 将 id 转换为 int64 类型
withdrawalId, err := strconv.ParseInt(id, 10, 64)
if err != nil {
responses.Fail(c)
return
}
// 业务处理
doctorWithdrawaService := service.DoctorWithdrawaService{}
res, err := doctorWithdrawaService.GetDoctorWithdrawal(withdrawalId)
if err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
responses.OkWithData(res, c)
}