医生账户-导出
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/dto"
|
||||
"hospital-admin-api/api/model"
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
@@ -105,72 +104,3 @@ func (r *DoctorAccountService) GetDoctorAccount(doctorId int64) (g *dto.DoctorAc
|
||||
|
||||
return g, nil
|
||||
}
|
||||
|
||||
// GetDoctorAccountPage 获取医生账户列表-分页
|
||||
func (r *DoctorAccountService) GetDoctorAccountPage(doctorAccounts []*model.DoctorAccount) (g []*dto.DoctorAccountDto, err error) {
|
||||
// 处理返回值
|
||||
res := dto.GetDoctorAccountListDto(doctorAccounts)
|
||||
|
||||
// 已完成待入账金额
|
||||
var completedWaitEntryAmount float64
|
||||
|
||||
// 今日预计收入
|
||||
var estimateIncome float64
|
||||
|
||||
for _, v := range res {
|
||||
// 获取医生全部已完成订单
|
||||
orderInquiryDao := dao.OrderInquiryDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["doctor_id"] = v.DoctorId
|
||||
maps["inquiry_status"] = 5 // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
maps["inquiry_refund_status"] = 0 // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
maps["inquiry_pay_status"] = 2 // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
maps["is_withdrawal"] = 0 // 是否提现(0:否 1:是 2:提现中)
|
||||
orderInquirys, err := orderInquiryDao.GetOrderInquiryList(maps)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(orderInquirys) > 0 {
|
||||
for _, inquiry := range orderInquirys {
|
||||
completedWaitEntryAmount = math.Floor((completedWaitEntryAmount+inquiry.AmountTotal)*0.75*100) / 100
|
||||
}
|
||||
}
|
||||
|
||||
// 获取医生当日接诊订单金额
|
||||
today := time.Now()
|
||||
|
||||
// 获取今天的开始时间
|
||||
startOfDay := time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, today.Location())
|
||||
|
||||
// 获取今天的结束时间
|
||||
endOfDay := time.Date(today.Year(), today.Month(), today.Day(), 23, 59, 59, 999999999, today.Location())
|
||||
|
||||
// 格式化为数据库的 datetime 格式
|
||||
startTime := startOfDay.Format("2006-01-02 15:04:05")
|
||||
endTime := endOfDay.Format("2006-01-02 15:04:05")
|
||||
|
||||
maps = make(map[string]interface{})
|
||||
maps["doctor_id"] = v.DoctorId
|
||||
maps["inquiry_refund_status"] = 0 // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
maps["inquiry_pay_status"] = 2 // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
maps["is_withdrawal"] = 0 // 是否提现(0:否 1:是 2:提现中)
|
||||
maps["inquiry_status"] = []int{4, 5} // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
orderInquirys, err = orderInquiryDao.GetOrderInquiryTimeList(maps, startTime, endTime)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(orderInquirys) > 0 {
|
||||
for _, inquiry := range orderInquirys {
|
||||
estimateIncome = math.Floor((estimateIncome+inquiry.AmountTotal)*0.75*100) / 100
|
||||
}
|
||||
}
|
||||
|
||||
v.CompletedWaitEntryAmount = completedWaitEntryAmount
|
||||
v.EstimateIncome = estimateIncome
|
||||
}
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -111,6 +111,7 @@ type UserDoctorData struct {
|
||||
BankCardAddress string // 开户银行地址
|
||||
}
|
||||
|
||||
// DoctorBankCardData 医生银行卡列表
|
||||
type DoctorBankCardData struct {
|
||||
DoctorName string // 医生姓名
|
||||
DoctorMobile string // 医生手机号
|
||||
@@ -122,6 +123,19 @@ type DoctorBankCardData struct {
|
||||
CreatedAt time.Time // 创建时间
|
||||
}
|
||||
|
||||
// DoctorAccountData 医生账户
|
||||
type DoctorAccountData struct {
|
||||
DoctorName string // 医生姓名
|
||||
DoctorMobile string // 医生手机号
|
||||
TotalAmount float64 // 总金额(已结束订单的总金额)
|
||||
BalanceAccount float64 // 账户余额
|
||||
AppliedWithdrawalAmount float64 // 提现金额
|
||||
IncomeTax float64 // 个人所得税
|
||||
ActualWithdrawalAmount float64 // 实际提现金额
|
||||
CompletedWaitEntryAmount float64 // 已完成待入账金额
|
||||
EstimateIncome float64 // 今日预计收入
|
||||
}
|
||||
|
||||
// DoctorWithdrawal 提现记录
|
||||
func (r *ExportService) DoctorWithdrawal(doctorWithdrawals []*model.DoctorWithdrawal) (string, error) {
|
||||
header := []utils.HeaderCellData{
|
||||
@@ -759,3 +773,69 @@ func (r *ExportService) UserDoctorBankCard(d []*model.DoctorBankCard) (string, e
|
||||
ossPath = utils.AddOssDomain("/" + ossPath)
|
||||
return ossPath, nil
|
||||
}
|
||||
|
||||
// DoctorAccount 医生账户
|
||||
func (r *ExportService) DoctorAccount(d []*model.DoctorAccount) (string, error) {
|
||||
header := []utils.HeaderCellData{
|
||||
{Value: "医生姓名", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "医生手机号", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "总金额", CellType: "float64", NumberFmt: "0.0000", ColWidth: 18},
|
||||
{Value: "账户余额", CellType: "float64", NumberFmt: "0.0000", ColWidth: 18},
|
||||
{Value: "提现金额", CellType: "float64", NumberFmt: "0.0000", ColWidth: 18},
|
||||
{Value: "个人所得税", CellType: "float64", NumberFmt: "0.0000", ColWidth: 18},
|
||||
{Value: "实际提现金额", CellType: "float64", NumberFmt: "0.0000", ColWidth: 18},
|
||||
{Value: "已完成待入账金额", CellType: "float64", NumberFmt: "0.0000", ColWidth: 22},
|
||||
{Value: "今日预计收入", CellType: "float64", NumberFmt: "0.0000", ColWidth: 18},
|
||||
}
|
||||
|
||||
var dataSlice []interface{}
|
||||
for _, v := range d {
|
||||
data := DoctorAccountData{
|
||||
TotalAmount: v.TotalAmount,
|
||||
BalanceAccount: v.BalanceAccount,
|
||||
AppliedWithdrawalAmount: v.AppliedWithdrawalAmount,
|
||||
ActualWithdrawalAmount: v.ActualWithdrawalAmount,
|
||||
IncomeTax: v.IncomeTax,
|
||||
}
|
||||
|
||||
if v.UserDoctor != nil {
|
||||
// 医生姓名
|
||||
data.DoctorName = v.UserDoctor.UserName
|
||||
|
||||
if v.UserDoctor.User != nil {
|
||||
// 手机号
|
||||
data.DoctorMobile = v.UserDoctor.User.Mobile
|
||||
}
|
||||
}
|
||||
|
||||
userDoctorService := UserDoctorService{}
|
||||
|
||||
// 获取医生已完成待入账金额
|
||||
data.CompletedWaitEntryAmount, _ = userDoctorService.GetDoctorCompletedWaitEntryAmount(v.DoctorId)
|
||||
|
||||
// 获取医生今日预计收入
|
||||
data.EstimateIncome, _ = userDoctorService.GetDoctorEstimateIncome(v.DoctorId)
|
||||
|
||||
dataSlice = append(dataSlice, data)
|
||||
}
|
||||
|
||||
file, err := utils.Export(header, dataSlice)
|
||||
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
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/shopspring/decimal"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/dto"
|
||||
"hospital-admin-api/api/model"
|
||||
@@ -1524,3 +1525,77 @@ func (r *UserDoctorService) GetUserDoctorById(doctorId int64) (g *dto.UserDoctor
|
||||
|
||||
return g, nil
|
||||
}
|
||||
|
||||
// GetDoctorCompletedWaitEntryAmount 获取医生已完成待入账金额
|
||||
func (r *UserDoctorService) GetDoctorCompletedWaitEntryAmount(doctorId int64) (g float64, err error) {
|
||||
// 已完成待入账金额
|
||||
var completedWaitEntryAmount = decimal.NewFromFloat(0)
|
||||
|
||||
// 获取医生全部已完成订单
|
||||
orderInquiryDao := dao.OrderInquiryDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["doctor_id"] = doctorId
|
||||
maps["inquiry_status"] = 5 // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
maps["inquiry_refund_status"] = 0 // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
maps["inquiry_pay_status"] = 2 // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
maps["is_withdrawal"] = 0 // 是否提现(0:否 1:是 2:提现中)
|
||||
orderInquirys, err := orderInquiryDao.GetOrderInquiryList(maps)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if len(orderInquirys) > 0 {
|
||||
for _, inquiry := range orderInquirys {
|
||||
// 等同于math.Floor((completedWaitEntryAmount+inquiry.AmountTotal)*0.75*100) / 100
|
||||
amountTotal := decimal.NewFromFloat(inquiry.AmountTotal)
|
||||
completedWaitEntryAmount = completedWaitEntryAmount.Add(amountTotal).Mul(decimal.NewFromFloat(0.75)).Mul(decimal.NewFromFloat(100)).Floor().Div(decimal.NewFromFloat(100))
|
||||
}
|
||||
}
|
||||
|
||||
result, _ := completedWaitEntryAmount.Float64()
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetDoctorEstimateIncome 获取医生今日预计收入
|
||||
func (r *UserDoctorService) GetDoctorEstimateIncome(doctorId int64) (g float64, err error) {
|
||||
// 今日预计收入
|
||||
var estimateIncome = decimal.NewFromFloat(0)
|
||||
|
||||
// 获取医生当日接诊订单金额
|
||||
today := time.Now()
|
||||
|
||||
// 获取今天的开始时间
|
||||
startOfDay := time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, today.Location())
|
||||
|
||||
// 获取今天的结束时间
|
||||
endOfDay := time.Date(today.Year(), today.Month(), today.Day(), 23, 59, 59, 999999999, today.Location())
|
||||
|
||||
// 格式化为数据库的 datetime 格式
|
||||
startTime := startOfDay.Format("2006-01-02 15:04:05")
|
||||
endTime := endOfDay.Format("2006-01-02 15:04:05")
|
||||
|
||||
orderInquiryDao := dao.OrderInquiryDao{}
|
||||
|
||||
maps := make(map[string]interface{})
|
||||
maps["doctor_id"] = doctorId
|
||||
maps["inquiry_refund_status"] = 0 // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭)
|
||||
maps["inquiry_pay_status"] = 2 // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
maps["is_withdrawal"] = 0 // 是否提现(0:否 1:是 2:提现中)
|
||||
maps["inquiry_status"] = []int{4, 5} // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
orderInquirys, err := orderInquiryDao.GetOrderInquiryTimeList(maps, startTime, endTime)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if len(orderInquirys) > 0 {
|
||||
for _, inquiry := range orderInquirys {
|
||||
// 等同于math.Floor((estimateIncome+inquiry.AmountTotal)*0.75*100) / 100
|
||||
amountTotal := decimal.NewFromFloat(inquiry.AmountTotal)
|
||||
estimateIncome = estimateIncome.Add(amountTotal).Mul(decimal.NewFromFloat(0.75)).Mul(decimal.NewFromFloat(100)).Floor().Div(decimal.NewFromFloat(100))
|
||||
}
|
||||
}
|
||||
|
||||
result, _ := estimateIncome.Float64()
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user