350 lines
12 KiB
Go
350 lines
12 KiB
Go
package service
|
||
|
||
import (
|
||
"fmt"
|
||
"github.com/shopspring/decimal"
|
||
"hospital-admin-api/api/dao"
|
||
"hospital-admin-api/api/model"
|
||
"hospital-admin-api/extend/aliyun"
|
||
"hospital-admin-api/utils"
|
||
"math/rand"
|
||
"time"
|
||
)
|
||
|
||
// ExportService 导出
|
||
type ExportService struct {
|
||
}
|
||
|
||
// DoctorWithdrawalData 提现记录数据
|
||
type DoctorWithdrawalData struct {
|
||
WithdrawalId string // 提现编号
|
||
DoctorName string // 医生姓名
|
||
Mobile string // 医生手机号
|
||
DoctorCardNum string // 医生证件号码
|
||
AppliedWithdrawalAmount float64 // 提现金额
|
||
ActualWithdrawalAmount float64 // 实际提现金额
|
||
IncomeTax float64 // 提现所得税金额
|
||
BankName string // 提现银行名称
|
||
BankCardCode string // 银行卡号
|
||
BankCardAddress string // 银行地址
|
||
ExamineStatus string // 审核状态(1:审核中 2:审核通过 3:审核未通过)
|
||
ExamineFailReason string // 审核失败原因
|
||
ExamineTime time.Time // 审核日期
|
||
ExamineBy string // 审核人员名称
|
||
PaymentStatus string // 财务打款状态(0:否 1:是)
|
||
PaymentTime time.Time // 财务打款时间
|
||
PaymentBy string // 财务打款人员id(后台用户id)
|
||
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{
|
||
{Value: "提现编号", CellType: "string", NumberFmt: "", ColWidth: 25},
|
||
{Value: "医生姓名", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||
{Value: "医生手机号", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||
{Value: "医生证件号码", CellType: "string", NumberFmt: "", ColWidth: 25},
|
||
{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: "string", NumberFmt: "", ColWidth: 25},
|
||
{Value: "银行卡号", CellType: "string", NumberFmt: "", ColWidth: 27},
|
||
{Value: "银行地址", CellType: "string", NumberFmt: "", ColWidth: 46},
|
||
{Value: "审核状态", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||
{Value: "审核失败原因", CellType: "string", NumberFmt: "", ColWidth: 33},
|
||
{Value: "审核日期", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30},
|
||
{Value: "审核人员", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||
{Value: "打款状态", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||
{Value: "打款时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30},
|
||
{Value: "打款人员", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||
{Value: "申请时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30},
|
||
}
|
||
|
||
var interfaceSlice []interface{}
|
||
for _, v := range doctorWithdrawals {
|
||
// 审核状态
|
||
examineStatus := "未知"
|
||
if v.ExamineStatus == 1 {
|
||
examineStatus = "审核中"
|
||
} else if v.ExamineStatus == 2 {
|
||
examineStatus = "审核通过"
|
||
} else if v.ExamineStatus == 3 {
|
||
examineStatus = "审核未通过"
|
||
}
|
||
|
||
// 审核人员
|
||
examineBy := ""
|
||
if v.ExamineBy != 0 {
|
||
adminUserDao := dao.AdminUserDao{}
|
||
adminUser, err := adminUserDao.GetAdminUserFirstById(v.ExamineBy)
|
||
if err == nil && adminUser != nil {
|
||
examineBy = adminUser.NickName
|
||
}
|
||
}
|
||
|
||
// 打款状态
|
||
paymentStatus := "未知"
|
||
if v.PaymentStatus == 0 {
|
||
paymentStatus = "未打款"
|
||
} else if v.ExamineStatus == 1 {
|
||
paymentStatus = "已打款"
|
||
}
|
||
|
||
// 打款人员
|
||
paymentBy := ""
|
||
if v.PaymentBy != 0 {
|
||
adminUserDao := dao.AdminUserDao{}
|
||
adminUser, err := adminUserDao.GetAdminUserFirstById(v.PaymentBy)
|
||
if err == nil && adminUser != nil {
|
||
paymentBy = adminUser.NickName
|
||
}
|
||
}
|
||
|
||
// 银行名称
|
||
bankName := "未知"
|
||
if v.DoctorWithdrawalBank != nil {
|
||
if v.DoctorWithdrawalBank.BasicBank != nil {
|
||
if v.DoctorWithdrawalBank.BasicBank.BankName != "" {
|
||
bankName = v.DoctorWithdrawalBank.BasicBank.BankName
|
||
}
|
||
}
|
||
}
|
||
|
||
// 银行卡号
|
||
bankCardCode := "未知"
|
||
|
||
// 开户行地址
|
||
bankCardAddress := ""
|
||
|
||
if v.DoctorWithdrawalBank != nil {
|
||
if v.DoctorWithdrawalBank.BankCardCode != "" {
|
||
bankCardCode = v.DoctorWithdrawalBank.BankCardCode
|
||
}
|
||
|
||
bankCardAddress = v.DoctorWithdrawalBank.Province + v.DoctorWithdrawalBank.City + v.DoctorWithdrawalBank.County
|
||
}
|
||
|
||
// 时间处理
|
||
var examineTime time.Time
|
||
if v.ExamineTime != (model.LocalTime{}) {
|
||
t := time.Time(v.ExamineTime)
|
||
examineTime = t
|
||
}
|
||
|
||
var paymentTime time.Time
|
||
if v.PaymentTime != (model.LocalTime{}) {
|
||
t := time.Time(v.PaymentTime)
|
||
paymentTime = t
|
||
}
|
||
|
||
var createdAt time.Time
|
||
if v.CreatedAt != (model.LocalTime{}) {
|
||
t := time.Time(v.CreatedAt)
|
||
createdAt = t
|
||
}
|
||
|
||
doctorWithdrawalData := DoctorWithdrawalData{
|
||
WithdrawalId: fmt.Sprintf("%d", v.WithdrawalId),
|
||
DoctorName: v.UserDoctor.UserName,
|
||
Mobile: v.UserDoctor.User.Mobile,
|
||
DoctorCardNum: v.UserDoctor.UserDoctorInfo.CardNum,
|
||
AppliedWithdrawalAmount: v.AppliedWithdrawalAmount,
|
||
ActualWithdrawalAmount: v.ActualWithdrawalAmount,
|
||
IncomeTax: v.IncomeTax,
|
||
BankName: bankName,
|
||
BankCardCode: bankCardCode,
|
||
BankCardAddress: bankCardAddress,
|
||
ExamineStatus: examineStatus,
|
||
ExamineFailReason: v.ExamineFailReason,
|
||
ExamineTime: examineTime,
|
||
ExamineBy: examineBy,
|
||
PaymentStatus: paymentStatus,
|
||
PaymentTime: paymentTime,
|
||
PaymentBy: paymentBy,
|
||
CreatedAt: createdAt,
|
||
}
|
||
|
||
interfaceSlice = append(interfaceSlice, doctorWithdrawalData)
|
||
}
|
||
|
||
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
|
||
}
|
||
|
||
// 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
|
||
}
|