201 lines
6.9 KiB
Go
201 lines
6.9 KiB
Go
package service
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"hospital-admin-api/api/dao"
|
|
"hospital-admin-api/api/responses/orderProductResponse"
|
|
)
|
|
|
|
type OrderProductService struct {
|
|
}
|
|
|
|
// GetOrderProduct 药品订单详情
|
|
func (r *OrderProductService) GetOrderProduct(orderProductId int64) (getOrderProductResponse *orderProductResponse.GetOrderProduct, err error) {
|
|
// 获取药品订单数据
|
|
orderProductDao := dao.OrderProductDao{}
|
|
orderProduct, err := orderProductDao.GetOrderProductPreloadById(orderProductId)
|
|
if err != nil || orderProduct == nil {
|
|
return nil, errors.New(err.Error())
|
|
}
|
|
|
|
// 获取退款数据
|
|
orderProductRefundService := OrderProductRefundService{}
|
|
orderProductRefund, err := orderProductRefundService.GetOrderProductRefundByOrderProductId(orderProductId)
|
|
if err != nil {
|
|
return nil, errors.New(err.Error())
|
|
}
|
|
|
|
// 获取商品数据
|
|
orderProductItemService := OrderProductItemService{}
|
|
orderProductItem, err := orderProductItemService.GetOrderProductItemByOrderProductId(orderProductId)
|
|
if err != nil {
|
|
return nil, errors.New(err.Error())
|
|
}
|
|
|
|
// 获取物流数据
|
|
orderProductLogisticsService := OrderProductLogisticsService{}
|
|
orderProductLogistics, err := orderProductLogisticsService.GetOrderProductLogisticsByOrderProductId(orderProductId)
|
|
if err != nil {
|
|
return nil, errors.New(err.Error())
|
|
}
|
|
|
|
// 获取处方数据
|
|
orderPrescriptionService := OrderPrescriptionService{}
|
|
orderPrescription, err := orderPrescriptionService.GetOrderPrescriptionById(orderProduct.OrderPrescriptionId)
|
|
if err != nil {
|
|
return nil, errors.New(err.Error())
|
|
}
|
|
|
|
// 获取问诊病例
|
|
orderInquiryCaseService := OrderInquiryCaseService{}
|
|
orderInquiryCase, err := orderInquiryCaseService.GetOrderInquiryCaseByOrderInquiryId(orderProduct.OrderInquiryId)
|
|
if err != nil {
|
|
return nil, errors.New(err.Error())
|
|
}
|
|
|
|
// 医生数据
|
|
userDoctorService := UserDoctorService{}
|
|
userDoctor, err := userDoctorService.GetOrderInquiryUserDoctor(orderProduct.DoctorId)
|
|
if err != nil {
|
|
return nil, errors.New(err.Error())
|
|
}
|
|
|
|
// 处理返回值
|
|
getOrderProductResponse = &orderProductResponse.GetOrderProduct{
|
|
OrderProductId: fmt.Sprintf("%v", orderProduct.OrderProductId),
|
|
OrderInquiryId: fmt.Sprintf("%v", orderProduct.OrderInquiryId),
|
|
OrderPrescriptionId: fmt.Sprintf("%v", orderProduct.OrderPrescriptionId),
|
|
DoctorId: fmt.Sprintf("%v", orderProduct.DoctorId),
|
|
PatientId: fmt.Sprintf("%v", orderProduct.PatientId),
|
|
FamilyId: fmt.Sprintf("%v", orderProduct.FamilyId),
|
|
OrderProductNo: orderProduct.OrderProductNo,
|
|
EscrowTradeNo: orderProduct.EscrowTradeNo,
|
|
OrderProductStatus: orderProduct.OrderProductStatus,
|
|
PayChannel: orderProduct.PayChannel,
|
|
PayStatus: orderProduct.PayStatus,
|
|
CancelReason: orderProduct.CancelReason,
|
|
AmountTotal: orderProduct.AmountTotal,
|
|
PaymentAmountTotal: orderProduct.PaymentAmountTotal,
|
|
LogisticsFee: orderProduct.LogisticsFee,
|
|
LogisticsNo: orderProduct.LogisticsNo,
|
|
LogisticsCompanyCode: orderProduct.LogisticsCompanyCode,
|
|
DeliveryTime: orderProduct.DeliveryTime,
|
|
PayTime: orderProduct.PayTime,
|
|
Remarks: orderProduct.Remarks,
|
|
RefundStatus: orderProduct.RefundStatus,
|
|
CancelTime: orderProduct.CancelTime,
|
|
CancelRemarks: orderProduct.CancelRemarks,
|
|
ReportPreStatus: orderProduct.ReportPreStatus,
|
|
ProvinceId: orderProduct.ProvinceId,
|
|
Province: orderProduct.Province,
|
|
CityId: orderProduct.CityId,
|
|
City: orderProduct.City,
|
|
CountyId: orderProduct.CountyId,
|
|
County: orderProduct.County,
|
|
AddressMask: orderProduct.AddressMask,
|
|
ConsigneeNameMask: orderProduct.ConsigneeNameMask,
|
|
ConsigneeTelMask: orderProduct.ConsigneeTelMask,
|
|
CreatedAt: orderProduct.CreatedAt,
|
|
UpdatedAt: orderProduct.UpdatedAt,
|
|
OrderProductRefund: orderProductRefund,
|
|
OrderProductItem: orderProductItem,
|
|
OrderProductLogistics: orderProductLogistics,
|
|
UserDoctor: userDoctor,
|
|
OrderPrescription: orderPrescription,
|
|
OrderInquiryCase: orderInquiryCase,
|
|
}
|
|
|
|
return getOrderProductResponse, nil
|
|
}
|
|
|
|
// CancelOrderProduct 取消药品订单
|
|
func (r *OrderProductService) CancelOrderProduct(orderProductId int64) (bool, error) {
|
|
// // 获取药品订单详情
|
|
// orderProductDao := dao.OrderProductDao{}
|
|
// orderProduct, err := orderProductDao.GetOrderProductPreloadById(orderProductId)
|
|
// if err != nil || orderProduct == nil {
|
|
// return false, errors.New("订单数据错误")
|
|
// }
|
|
//
|
|
// // 检测订单状态
|
|
// if orderProduct.OrderProductStatus == 1 {
|
|
// return false, errors.New("订单处于待支付状态,无法取消")
|
|
// }
|
|
//
|
|
// if orderProduct.OrderProductStatus == 3 {
|
|
// return false, errors.New("订单已发货,无法取消")
|
|
// }
|
|
//
|
|
// if orderProduct.OrderProductStatus == 4 {
|
|
// return false, errors.New("订单已签收,无法取消")
|
|
// }
|
|
//
|
|
// if orderProduct.OrderProductStatus == 5 {
|
|
// return false, errors.New("订单已取消,无法取消")
|
|
// }
|
|
//
|
|
// // 检测订单退款状态
|
|
// if orderProduct.RefundStatus == 1 {
|
|
// return false, errors.New("订单申请退款中,无法取消")
|
|
// }
|
|
//
|
|
// if orderProduct.RefundStatus == 2 {
|
|
// return false, errors.New("订单正在退款中,无法取消")
|
|
// }
|
|
//
|
|
// if orderProduct.RefundStatus == 3 {
|
|
// return false, errors.New("订单已退款成功,无法取消")
|
|
// }
|
|
//
|
|
// if orderProduct.RefundStatus == 6 {
|
|
// return false, errors.New("订单退款异常,请联系技术人员")
|
|
// }
|
|
//
|
|
// // 检测订单支付状态
|
|
// if orderProduct.PayStatus != 2 {
|
|
// return false, errors.New("订单未支付,无需取消")
|
|
// }
|
|
//
|
|
// // 开始事务
|
|
// tx := global.Db.Begin()
|
|
// defer func() {
|
|
// if r := recover(); r != nil {
|
|
// tx.Rollback()
|
|
// }
|
|
// }()
|
|
//
|
|
// // 药品订单修改数据
|
|
// orderProductData := make(map[string]interface{})
|
|
//
|
|
// // 退款编号
|
|
// refundNo := strconv.FormatInt(global.Snowflake.Generate().Int64(), 10)
|
|
//
|
|
// // 退款状态转换
|
|
// var productRefundStatus int
|
|
// var successTime time.Time
|
|
// var refundId string
|
|
//
|
|
// refundRequest := weChat.RefundRequest{
|
|
// TransactionId: orderProduct.EscrowTradeNo,
|
|
// OutTradeNo: orderProduct.OrderProductNo,
|
|
// OutRefundNo: refundNo,
|
|
// Reason: "客服取消",
|
|
// PaymentAmountTotal: int64(orderProduct.PaymentAmountTotal * 100),
|
|
// NotifyUrl: config.C.Wechat.RefundNotifyDomain + config.C.Wechat.PatientProductRefundNotifyUrl,
|
|
// }
|
|
//
|
|
// refund, err := refundRequest.Refund()
|
|
// if err != nil {
|
|
// tx.Rollback()
|
|
// return false, errors.New(err.Error())
|
|
// }
|
|
//
|
|
// if refund.Status == nil {
|
|
// tx.Rollback()
|
|
// return false, errors.New("退款状态错误")
|
|
// }
|
|
|
|
return true, nil
|
|
}
|