医生账户-关联订单-导出
This commit is contained in:
+33
-30
@@ -2,6 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/shopspring/decimal"
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/dto"
|
||||
@@ -363,44 +364,46 @@ func (r *OrderInquiryService) GetOrderInquiryRecord(orderInquiryId int64) (g *dt
|
||||
return g, nil
|
||||
}
|
||||
|
||||
// GetOrderInquiryRecord 问诊记录详情
|
||||
func (r *OrderInquiryService) GetDoctor(orderInquiryId int64) (g *dto.OrderInquiryDto, err error) {
|
||||
// 获取问诊订单数据
|
||||
orderInquiryDao := dao.OrderInquiryDao{}
|
||||
orderInquiry, err := orderInquiryDao.GetOrderInquiryPreloadById(orderInquiryId)
|
||||
if err != nil || orderInquiry == nil {
|
||||
return nil, errors.New(err.Error())
|
||||
// GetOrderInquiryEntryStatus 获取订单入账状态
|
||||
func (r *OrderInquiryService) GetOrderInquiryEntryStatus(inquiryStatus, statisticsStatus int) int {
|
||||
// entryStatus 入账状态(0:未入账 1:已入账 2:入账中 3:入账失败 4:入账取消)
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
var entryStatus int
|
||||
if inquiryStatus == 7 {
|
||||
entryStatus = 4
|
||||
}
|
||||
|
||||
// 获取问诊病例
|
||||
orderInquiryCaseDao := dao.OrderInquiryCaseDao{}
|
||||
orderInquiryCase, err := orderInquiryCaseDao.GetOrderInquiryCaseByOrderInquiryId(orderInquiryId)
|
||||
if orderInquiryCase == nil {
|
||||
return nil, errors.New("数据错误,无问诊病例")
|
||||
if inquiryStatus == 1 || inquiryStatus == 2 || inquiryStatus == 3 {
|
||||
entryStatus = 0
|
||||
}
|
||||
|
||||
// 获取医生数据
|
||||
userDoctorService := UserDoctorService{}
|
||||
userDoctor, err := userDoctorService.GetUserDoctorById(orderInquiry.DoctorId)
|
||||
if err != nil {
|
||||
return nil, errors.New(err.Error())
|
||||
if inquiryStatus == 4 || inquiryStatus == 5 {
|
||||
entryStatus = 2
|
||||
}
|
||||
|
||||
// 获取聊天记录
|
||||
messageImDao := dao.MessageImDao{}
|
||||
messageIms, err := messageImDao.GetMessageImByOrderInquiryId(orderInquiryId)
|
||||
if inquiryStatus == 6 {
|
||||
if statisticsStatus == 1 {
|
||||
entryStatus = 1
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
g = dto.GetOrderInquiryRecordDto(orderInquiry)
|
||||
// 统计失败/已结束未统计
|
||||
if inquiryStatus == 2 || inquiryStatus == 0 {
|
||||
entryStatus = 3
|
||||
}
|
||||
}
|
||||
|
||||
// 加载医生数据
|
||||
g.UserDoctor = userDoctor
|
||||
return entryStatus
|
||||
}
|
||||
|
||||
// 加载问诊病例
|
||||
g.LoadMaskOrderInquiryCase(orderInquiryCase)
|
||||
// GetOrderInquiryDoctorAmount 获取订单中医生收益
|
||||
func (r *OrderInquiryService) GetOrderInquiryDoctorAmount(inquiryStatus int, amountTotal float64) float64 {
|
||||
var doctorAmount float64
|
||||
if inquiryStatus == 4 || inquiryStatus == 5 || inquiryStatus == 6 {
|
||||
doctorAmount, _ = decimal.NewFromFloat(amountTotal).
|
||||
Mul(decimal.NewFromFloat(0.75)).
|
||||
Mul(decimal.NewFromFloat(100000)).Floor().
|
||||
Div(decimal.NewFromFloat(100000)).Float64()
|
||||
}
|
||||
|
||||
// 加载聊天记录
|
||||
g.LoadMessageIm(messageIms)
|
||||
|
||||
return g, nil
|
||||
return doctorAmount
|
||||
}
|
||||
|
||||
@@ -136,6 +136,42 @@ type DoctorAccountData struct {
|
||||
EstimateIncome float64 // 今日预计收入
|
||||
}
|
||||
|
||||
// OrderInquiryForAccount 医生账户-关联订单
|
||||
type OrderInquiryForAccount struct {
|
||||
InquiryNo string // 系统订单编号
|
||||
DoctorName string // 医生姓名
|
||||
UserName string // 用户姓名(患者)
|
||||
PatientName string // 患者姓名-就诊人
|
||||
PatientSex string // 患者性别-就诊人(0:未知 1:男 2:女)
|
||||
PatientAge string // 患者年龄-就诊人
|
||||
PatientMobile string // 患者电话
|
||||
InquiryType string // 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测)
|
||||
InquiryMode string // 订单问诊方式(1:图文 2:视频 3:语音 4:电话 5:会员)
|
||||
InquiryStatus string // 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
IsDelete string // 删除状态(0:否 1:是)
|
||||
InquiryRefundStatus string // 问诊订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
InquiryPayChannel string // 支付渠道(1:小程序支付 2:微信扫码支付 3:模拟支付)
|
||||
InquiryPayStatus string // 支付状态(1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
EscrowTradeNo string // 第三方支付流水号
|
||||
AmountTotal float64 // 订单金额
|
||||
CouponAmountTotal float64 // 优惠卷总金额
|
||||
PaymentAmountTotal float64 // 实际付款金额
|
||||
DoctorAmount float64 // 医生收益
|
||||
PayTime time.Time // 支付时间
|
||||
ReceptionTime time.Time // 接诊时间(已接诊)
|
||||
CompleteTime time.Time // 订单完成时间(问诊完成时间)
|
||||
FinishTime time.Time // 订单结束时间
|
||||
StatisticsStatus string // 订单统计状态(0:未统计 1:已统计 2:统计失败)
|
||||
StatisticsTime time.Time // 订单统计时间
|
||||
IsWithdrawal string // 是否提现(0:否 1:是 2:提现中)
|
||||
WithdrawalTime time.Time // 提现时间
|
||||
CancelTime time.Time // 订单取消时间
|
||||
CancelReason string // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
CancelRemarks string // 取消订单备注(自动添加)
|
||||
EntryStatus string // 入账状态(0:未入账 1:已入账 2:入账中 3:入账失败)
|
||||
CreatedAt time.Time // 创建时间
|
||||
}
|
||||
|
||||
// DoctorWithdrawal 提现记录
|
||||
func (r *ExportService) DoctorWithdrawal(doctorWithdrawals []*model.DoctorWithdrawal) (string, error) {
|
||||
header := []utils.HeaderCellData{
|
||||
@@ -839,3 +875,154 @@ func (r *ExportService) DoctorAccount(d []*model.DoctorAccount) (string, error)
|
||||
ossPath = utils.AddOssDomain("/" + ossPath)
|
||||
return ossPath, nil
|
||||
}
|
||||
|
||||
// OrderInquiryForAccount 医生账户-关联订单
|
||||
func (r *ExportService) OrderInquiryForAccount(d []*model.OrderInquiry) (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: 18},
|
||||
{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: 18},
|
||||
{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: 18},
|
||||
{Value: "第三方支付流水号", CellType: "string", NumberFmt: "", ColWidth: 25},
|
||||
{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: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30},
|
||||
{Value: "接诊时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30},
|
||||
{Value: "订单完成时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30},
|
||||
{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},
|
||||
{Value: "是否提现", CellType: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "提现时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30},
|
||||
{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: "string", NumberFmt: "", ColWidth: 18},
|
||||
{Value: "创建时间", CellType: "date", NumberFmt: "yyyy-mm-dd hh:mm:ss", ColWidth: 30},
|
||||
}
|
||||
|
||||
orderInquiryService := OrderInquiryService{}
|
||||
|
||||
var dataSlice []interface{}
|
||||
for _, v := range d {
|
||||
data := OrderInquiryForAccount{
|
||||
InquiryNo: v.InquiryNo,
|
||||
DoctorName: v.PatientName,
|
||||
PatientName: v.PatientName,
|
||||
PatientAge: fmt.Sprintf("%d", v.PatientAge),
|
||||
EscrowTradeNo: v.EscrowTradeNo,
|
||||
AmountTotal: v.AmountTotal,
|
||||
CouponAmountTotal: v.CouponAmountTotal,
|
||||
PaymentAmountTotal: v.PaymentAmountTotal,
|
||||
CancelRemarks: v.CancelRemarks,
|
||||
}
|
||||
|
||||
if v.UserDoctor != nil {
|
||||
// 医生姓名
|
||||
data.DoctorName = v.UserDoctor.UserName
|
||||
}
|
||||
|
||||
if v.User != nil {
|
||||
// 用户姓名(患者)
|
||||
data.UserName = v.User.UserName
|
||||
|
||||
// 患者电话
|
||||
data.PatientMobile = v.User.Mobile
|
||||
}
|
||||
|
||||
// 性别
|
||||
data.PatientSex = utils.SexToString(v.PatientSex)
|
||||
data.InquiryType = utils.InquiryTypeToString(v.InquiryType)
|
||||
data.InquiryMode = utils.InquiryModeToString(v.InquiryMode)
|
||||
data.InquiryStatus = utils.InquiryStatusToString(v.InquiryStatus)
|
||||
data.IsDelete = utils.IsDeleteToString(v.IsDelete)
|
||||
data.InquiryRefundStatus = utils.RefundStatusToString(v.InquiryRefundStatus)
|
||||
data.InquiryPayChannel = utils.PayChannelToString(v.InquiryPayChannel)
|
||||
data.InquiryPayStatus = utils.PayStatusToString(v.InquiryPayStatus)
|
||||
|
||||
if v.PayTime != (model.LocalTime{}) {
|
||||
t := time.Time(v.PayTime)
|
||||
data.PayTime = t
|
||||
}
|
||||
|
||||
if v.ReceptionTime != (model.LocalTime{}) {
|
||||
t := time.Time(v.ReceptionTime)
|
||||
data.ReceptionTime = t
|
||||
}
|
||||
|
||||
if v.CompleteTime != (model.LocalTime{}) {
|
||||
t := time.Time(v.CompleteTime)
|
||||
data.CompleteTime = t
|
||||
}
|
||||
|
||||
if v.FinishTime != (model.LocalTime{}) {
|
||||
t := time.Time(v.FinishTime)
|
||||
data.FinishTime = t
|
||||
}
|
||||
|
||||
if v.StatisticsTime != (model.LocalTime{}) {
|
||||
t := time.Time(v.StatisticsTime)
|
||||
data.StatisticsTime = t
|
||||
}
|
||||
|
||||
if v.WithdrawalTime != (model.LocalTime{}) {
|
||||
t := time.Time(v.WithdrawalTime)
|
||||
data.WithdrawalTime = t
|
||||
}
|
||||
|
||||
if v.CancelTime != (model.LocalTime{}) {
|
||||
t := time.Time(v.CancelTime)
|
||||
data.CancelTime = t
|
||||
}
|
||||
|
||||
if v.CreatedAt != (model.LocalTime{}) {
|
||||
t := time.Time(v.CreatedAt)
|
||||
data.CreatedAt = t
|
||||
}
|
||||
|
||||
data.StatisticsStatus = utils.StatisticsStatusToString(v.StatisticsStatus)
|
||||
data.IsWithdrawal = utils.IsWithdrawalToString(v.IsWithdrawal)
|
||||
data.CancelReason = utils.CancelReasonToString(v.CancelReason)
|
||||
|
||||
// 处理入账状态(0:未入账 1:已入账 2:入账中 3:入账失败 4:入账取消)
|
||||
entryStatus := orderInquiryService.GetOrderInquiryEntryStatus(v.InquiryStatus, v.StatisticsStatus)
|
||||
data.EntryStatus = utils.EntryStatusToString(entryStatus)
|
||||
|
||||
// 处理医生收益
|
||||
data.DoctorAmount = orderInquiryService.GetOrderInquiryDoctorAmount(v.InquiryStatus, v.AmountTotal)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user