diff --git a/api/controller/export.go b/api/controller/export.go index d666d9d..596d292 100644 --- a/api/controller/export.go +++ b/api/controller/export.go @@ -28,6 +28,7 @@ func (r *Export) DoctorWithdrawal(c *gin.Context) { return } + // 获取数据 doctorWithdrawalDao := dao.DoctorWithdrawalDao{} doctorWithdrawals, err := doctorWithdrawalDao.GetDoctorWithdrawalExportListSearch(req) if err != nil { @@ -45,3 +46,37 @@ func (r *Export) DoctorWithdrawal(c *gin.Context) { responses.OkWithData(ossAddress, c) } + +// DoctorWithdrawalOrder 提现记录-关联订单 +func (r *Export) DoctorWithdrawalOrder(c *gin.Context) { + doctorWithdrawalRequest := requests.DoctorWithdrawalRequest{} + req := doctorWithdrawalRequest.DoctorWithdrawalOrderExportList + 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 + } + + // 获取数据 + doctorWithdrawalOrderDao := dao.DoctorWithdrawalOrderDao{} + doctorWithdrawalOrders, err := doctorWithdrawalOrderDao.GetDoctorWithdrawalOrderExportListSearch(req) + if err != nil { + responses.FailWithMessage(err.Error(), c) + return + } + + // 业务处理 + exportService := service.ExportService{} + ossAddress, err := exportService.DoctorWithdrawalOrder(doctorWithdrawalOrders) + if err != nil { + responses.FailWithMessage(err.Error(), c) + return + } + + responses.OkWithData(ossAddress, c) +} diff --git a/api/dao/doctorWithdrawalOrder.go b/api/dao/doctorWithdrawalOrder.go index 6c61e1c..2a4978a 100644 --- a/api/dao/doctorWithdrawalOrder.go +++ b/api/dao/doctorWithdrawalOrder.go @@ -1,10 +1,12 @@ package dao import ( + "errors" "gorm.io/gorm" "hospital-admin-api/api/model" "hospital-admin-api/api/requests" "hospital-admin-api/global" + "strings" ) type DoctorWithdrawalOrderDao struct { @@ -28,7 +30,7 @@ func (r *DoctorWithdrawalOrderDao) GetDoctorWithdrawalOrderByWithdrawalId(withdr return m, nil } -// GetDoctorWithdrawalOrderPageSearch 获取医生提现列表-分页 +// GetDoctorWithdrawalOrderPageSearch 获取医生提现关联订单列表-分页 func (r *DoctorWithdrawalOrderDao) GetDoctorWithdrawalOrderPageSearch(req requests.GetDoctorWithdrawalOrderPage, page, pageSize int) (m []*model.DoctorWithdrawalOrder, total int64, err error) { var totalRecords int64 @@ -64,3 +66,43 @@ func (r *DoctorWithdrawalOrderDao) GetDoctorWithdrawalOrderPageSearch(req reques } return m, totalRecords, nil } + +// GetDoctorWithdrawalOrderExportListSearch 获取医生提现关联订单列表-导出 +func (r *DoctorWithdrawalOrderDao) GetDoctorWithdrawalOrderExportListSearch(req requests.DoctorWithdrawalOrderExportList) (m []*model.DoctorWithdrawalOrder, err error) { + // 构建查询条件 + query := global.Db.Model(&model.DoctorWithdrawalOrder{}) + + if req.WithdrawalId != "" { + query = query.Where("withdrawal_id = ?", req.WithdrawalId) + } + + // 医生 + query = query.Preload("UserDoctor", func(db *gorm.DB) *gorm.DB { + return db.Omit("open_id", "union_id", "wx_session_key") + }) + + // 订单 + query = query.Preload("OrderInquiry") + + // 患者 + query = query.Preload("OrderInquiry.User") + + // 排序 + query = query.Order("created_at desc") + + // 当前选择数据 + if req.Type == 2 { + if req.Id == "" { + return nil, errors.New("未提供需导出数据编号") + } + + id := strings.Split(req.Id, ",") + query = query.Where("withdrawal_order_id IN (?)", id) + } + + err = query.Find(&m).Error + if err != nil { + return nil, err + } + return m, nil +} diff --git a/api/requests/doctorWithdrawal.go b/api/requests/doctorWithdrawal.go index 4e6f0fb..f52cafd 100644 --- a/api/requests/doctorWithdrawal.go +++ b/api/requests/doctorWithdrawal.go @@ -1,11 +1,12 @@ package requests type DoctorWithdrawalRequest struct { - GetDoctorWithdrawalPage // 获取医生提现列表-分页 - GetDoctorWithdrawalOrderPage // 提现详情-关联订单列表-分页 - PutDoctorWithdrawalIncome // 修改提现个人所得税 - PutDoctorWithdrawalExamine // 修改提现审核状态 - DoctorWithdrawalExportList // 提现记录列表-导出 + GetDoctorWithdrawalPage // 获取医生提现列表-分页 + GetDoctorWithdrawalOrderPage // 提现详情-关联订单列表-分页 + PutDoctorWithdrawalIncome // 修改提现个人所得税 + PutDoctorWithdrawalExamine // 修改提现审核状态 + DoctorWithdrawalExportList // 提现记录列表-导出 + DoctorWithdrawalOrderExportList // 提现详情-关联订单-导出 } // GetDoctorWithdrawalPage 获取医生提现列表-分页 @@ -22,7 +23,7 @@ type GetDoctorWithdrawalPage struct { // GetDoctorWithdrawalOrderPage 提现详情-关联订单列表-分页 type GetDoctorWithdrawalOrderPage struct { - WithdrawalId string `json:"withdrawal_id" form:"withdrawal_id" validate:"required" label:"id"` + WithdrawalId string `json:"withdrawal_id" form:"withdrawal_id" validate:"required" label:"withdrawal_id"` Page int `json:"page" form:"page" label:"页码"` PageSize int `json:"page_size" form:"page_size" label:"每页个数"` } @@ -49,3 +50,10 @@ type DoctorWithdrawalExportList struct { ExamineStatus *int `json:"examine_status" form:"examine_status" label:"审核状态"` // (1:审核中 2:审核通过 3:审核未通过) PaymentStatus *int `json:"payment_status" form:"payment_status" label:"打款状态"` // 财务打款状态(0:否 1:是) } + +// DoctorWithdrawalOrderExportList 提现详情-关联订单-导出 +type DoctorWithdrawalOrderExportList struct { + Type int `json:"type" form:"type" label:"类型" validate:"required,oneof=1 2 3"` // 1:当前搜索数据 2:当前选择数据 3:全部数据 + Id string `json:"id" form:"id" label:"id"` // 选择数据的id,逗号分隔,当type为2时必填 + WithdrawalId string `json:"withdrawal_id" form:"withdrawal_id" validate:"required" label:"withdrawal_id"` +} diff --git a/api/router/router.go b/api/router/router.go index c5a23d8..3f5abed 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -602,7 +602,7 @@ func privateRouter(r *gin.Engine, api controller.Api) { withdrawalGroup.POST("", api.Export.DoctorWithdrawal) // 提现记录-关联订单 - withdrawalGroup.POST("/order", api.UserCaCert.RenewUserCloudCert) + withdrawalGroup.POST("/order", api.Export.DoctorWithdrawalOrder) } // 医生 diff --git a/api/service/export.go b/api/service/export.go index 00c2964..8b4aa5b 100644 --- a/api/service/export.go +++ b/api/service/export.go @@ -2,6 +2,7 @@ package service import ( "fmt" + "github.com/shopspring/decimal" "hospital-admin-api/api/dao" "hospital-admin-api/api/model" "hospital-admin-api/extend/aliyun" @@ -36,6 +37,24 @@ type DoctorWithdrawalData struct { CreatedAt time.Time // 创建时间 } +type DoctorWithdrawalOrderData struct { + DoctorName string // 医生姓名 + PatientName string // 患者姓名-就诊人 + PatientSex string // 患者性别-就诊人(0:未知 1:男 2:女) + PatientAge string // 患者年龄-就诊人 + PatientMobile string // 患者电话 + PayChannel string // 支付渠道(1:小程序支付 2:微信扫码支付 3:模拟支付) + PayTime time.Time // 支付时间 + InquiryNo string // 系统订单编号 + EscrowTradeNo string // 第三方支付流水号 + InquiryStatus string // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消) + AmountTotal float64 // 订单金额 + CouponAmountTotal float64 // 优惠卷金额 + PaymentAmountTotal float64 // 实际付款金额 + DoctorAmount float64 // 医生收益 + +} + // DoctorWithdrawal 提现记录 func (r *ExportService) DoctorWithdrawal(doctorWithdrawals []*model.DoctorWithdrawal) (string, error) { header := []utils.HeaderCellData{ @@ -186,3 +205,145 @@ func (r *ExportService) DoctorWithdrawal(doctorWithdrawals []*model.DoctorWithdr ossPath = utils.AddOssDomain("/" + ossPath) return ossPath, nil } + +// DoctorWithdrawalOrder 提现记录-关联订单 +func (r *ExportService) DoctorWithdrawalOrder(doctorWithdrawalOrders []*model.DoctorWithdrawalOrder) (string, error) { + header := []utils.HeaderCellData{ + {Value: "医生姓名", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "就诊人姓名", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "就诊人性别", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "就诊人年龄", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "患者电话", CellType: "string", NumberFmt: "", ColWidth: 20}, + {Value: "支付渠道", CellType: "float", NumberFmt: "", ColWidth: 18}, + {Value: "支付时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30}, + {Value: "系统订单编号", CellType: "string", NumberFmt: "", ColWidth: 30}, + {Value: "第三方支付流水号", CellType: "string", NumberFmt: "", ColWidth: 30}, + {Value: "订单状态", CellType: "string", NumberFmt: "", ColWidth: 18}, + {Value: "订单金额", CellType: "float", NumberFmt: "0.0000", ColWidth: 18}, + {Value: "优惠卷金额", CellType: "float", NumberFmt: "0.0000", ColWidth: 18}, + {Value: "付款金额", CellType: "float", NumberFmt: "0.0000", ColWidth: 18}, + {Value: "医生收益", CellType: "float", NumberFmt: "0.0000", ColWidth: 18}, + } + + var interfaceSlice []interface{} + for _, v := range doctorWithdrawalOrders { + // 医生姓名 + doctorName := "" + if v.UserDoctor != nil { + doctorName = v.UserDoctor.UserName + } + + // 就诊人数据 + patientName := "未知" + patientSex := "" + patientAge := "" + patientMobile := "" + payChannel := "未知" + inquiryNo := "未知" + escrowTradeNo := "未知" + inquiryStatus := "未知" + var amountTotal float64 + var couponAmountTotal float64 + var paymentAmountTotal float64 + var doctorAmount float64 + var payTime time.Time + if v.OrderInquiry != nil { + patientName = v.OrderInquiry.PatientName + + if v.OrderInquiry.PatientSex == 1 { + patientSex = "男" + } else if v.OrderInquiry.PatientSex == 2 { + patientSex = "女" + } + + // 患者年龄 + patientAge = fmt.Sprintf("%d", v.OrderInquiry.PatientAge) + + // 患者电话 + if v.OrderInquiry.User != nil { + patientMobile = v.OrderInquiry.User.Mobile + } + + // 支付渠道 + if v.OrderInquiry.InquiryPayChannel == 1 { + payChannel = "小程序支付" + } else if v.OrderInquiry.InquiryPayChannel == 2 { + payChannel = "微信扫码支付" + } else if v.OrderInquiry.InquiryPayChannel == 3 { + payChannel = "模拟支付" + } + + inquiryNo = v.OrderInquiry.InquiryNo + escrowTradeNo = v.OrderInquiry.EscrowTradeNo + + if v.OrderInquiry.InquiryStatus == 1 { + inquiryStatus = "待支付" + } else if v.OrderInquiry.InquiryStatus == 2 { + inquiryStatus = "待分配" + } else if v.OrderInquiry.InquiryStatus == 3 { + inquiryStatus = "待接诊" + } else if v.OrderInquiry.InquiryStatus == 4 { + inquiryStatus = "已接诊" + } else if v.OrderInquiry.InquiryStatus == 5 { + inquiryStatus = "已完成" + } else if v.OrderInquiry.InquiryStatus == 6 { + inquiryStatus = "已结束" + } else if v.OrderInquiry.InquiryStatus == 7 { + inquiryStatus = "已取消" + } + + amountTotal = v.OrderInquiry.AmountTotal + couponAmountTotal = v.OrderInquiry.CouponAmountTotal + paymentAmountTotal = v.OrderInquiry.PaymentAmountTotal + + // 医生收益 + doctorAmount, _ = decimal.NewFromFloat(v.OrderInquiry.AmountTotal).Mul(decimal.NewFromFloat(0.75)).Round(2).Float64() + + // 时间处理 + + if v.OrderInquiry.PayTime != (model.LocalTime{}) { + t := time.Time(v.OrderInquiry.PayTime) + payTime = t + } + } + + doctorWithdrawalOrderData := DoctorWithdrawalOrderData{ + DoctorName: doctorName, + PatientName: patientName, + PatientSex: patientSex, + PatientAge: patientAge, + PatientMobile: patientMobile, + PayChannel: payChannel, + PayTime: payTime, + InquiryNo: inquiryNo, + EscrowTradeNo: escrowTradeNo, + InquiryStatus: inquiryStatus, + AmountTotal: amountTotal, + CouponAmountTotal: couponAmountTotal, + PaymentAmountTotal: paymentAmountTotal, + DoctorAmount: doctorAmount, + } + + interfaceSlice = append(interfaceSlice, doctorWithdrawalOrderData) + } + + file, err := utils.Export(header, interfaceSlice) + if err != nil { + return "", err + } + + // 设置文件名字 + now := time.Now() + dateTimeString := now.Format("20060102150405") // 当前时间字符串 + rand.Seed(time.Now().UnixNano()) // 设置随机数 + ossPath := "admin/export/output" + dateTimeString + fmt.Sprintf("%d", rand.Intn(9000)+1000) + ".xlsx" + + // 上传oss + _, err = aliyun.PutObjectByte(ossPath, file.Bytes()) + if err != nil { + return "", err + } + + ossPath = utils.AddOssDomain("/" + ossPath) + return ossPath, nil +}