新增了 退还用户优惠卷、新增了处理用户处方图片
This commit is contained in:
@@ -3,8 +3,10 @@ package service
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/extend/aliyun"
|
||||
"hospital-admin-api/extend/prescription"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
@@ -310,3 +312,145 @@ func (r *OrderService) ReportPreProduct(orderProductId, adminUserId int64) (bool
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// 发起订单退款-未完成
|
||||
func (r *OrderService) orderRefund(orderNo string, refundReason string) (bool, error) {
|
||||
orderDao := dao.OrderDao{}
|
||||
|
||||
// 获取订单数据
|
||||
maps := make(map[string]interface{})
|
||||
maps["order_no"] = orderNo
|
||||
order, err := orderDao.GetOrder(maps)
|
||||
if err != nil || order == nil {
|
||||
return false, errors.New("订单数据错误")
|
||||
}
|
||||
|
||||
// 检测订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常)
|
||||
if order.RefundStatus == 2 {
|
||||
return false, errors.New("订单退款中")
|
||||
}
|
||||
|
||||
if order.RefundStatus == 3 {
|
||||
return false, errors.New("订单已退款成功")
|
||||
}
|
||||
|
||||
if order.RefundStatus == 5 {
|
||||
return false, errors.New("订单已退款关闭")
|
||||
}
|
||||
|
||||
// 检测支付状态 (1:未支付 2:已支付 3:支付中 4:支付失败 5:支付超时 6:支付关闭 7:已撤销 8:转入退款)
|
||||
if order.PayStatus != 2 {
|
||||
return false, errors.New("订单支付状态错误")
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// PdfToImg 处理pdf转图片
|
||||
func (r *OrderService) PdfToImg() (bool, error) {
|
||||
//orderPrescription := dao.OrderPrescriptionDao{}
|
||||
orderPrescriptionFileDao := dao.OrderPrescriptionFileDao{}
|
||||
|
||||
// 获取订单数据
|
||||
maps := make(map[string]interface{})
|
||||
orderPrescriptionFiles, err := orderPrescriptionFileDao.GetOrderPrescriptionFileList(maps)
|
||||
if err != nil {
|
||||
return false, errors.New("订单数据错误")
|
||||
}
|
||||
|
||||
for _, orderPrescriptionFile := range orderPrescriptionFiles {
|
||||
if orderPrescriptionFile.PrescriptionPdfOssPath == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
if orderPrescriptionFile.IsConvertedPdf != 1 {
|
||||
continue
|
||||
}
|
||||
|
||||
OrderPrescriptionId := fmt.Sprintf("%d", orderPrescriptionFile.OrderPrescriptionId)
|
||||
|
||||
PrescriptionImgOssPath := strings.TrimLeft(orderPrescriptionFile.PrescriptionImgOssPath, "/")
|
||||
|
||||
// 下载处方pdf到本地
|
||||
local, err := aliyun.GetObjectToLocal(PrescriptionImgOssPath,
|
||||
"/Users/wucongxing/Desktop/work/go/hospital-admin-api/data/bak/"+OrderPrescriptionId+".jpg")
|
||||
if err != nil || !local {
|
||||
return false, err
|
||||
}
|
||||
|
||||
//pdfPath := "/Users/wucongxing/Desktop/work/go/hospital-admin-api/data/" + OrderPrescriptionId + ".pdf"
|
||||
//outputDir := "/Users/wucongxing/Desktop/work/go/hospital-admin-api/data/img"
|
||||
//
|
||||
//if err := utils.ConvertPDFToImages(pdfPath, outputDir, OrderPrescriptionId+".jpg"); err != nil {
|
||||
// return false, err
|
||||
//}
|
||||
//
|
||||
//// 修改为已转换
|
||||
//// 开始事务
|
||||
//tx := global.Db.Begin()
|
||||
//defer func() {
|
||||
// if r := recover(); r != nil {
|
||||
// tx.Rollback()
|
||||
// }
|
||||
//}()
|
||||
//
|
||||
//data := make(map[string]interface{})
|
||||
//data["is_converted_pdf"] = 1
|
||||
//err = orderPrescriptionFileDao.EditOrderPrescriptionFileById(tx, orderPrescriptionFile.PrescriptionFileId, data)
|
||||
//if err != nil {
|
||||
// tx.Rollback()
|
||||
// return false, err
|
||||
//}
|
||||
//
|
||||
//tx.Commit()
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// ReturnOrderCoupon 退还用户优惠卷
|
||||
func (r *OrderService) ReturnOrderCoupon(orderNo string, tx *gorm.DB) (bool, error) {
|
||||
orderCouponDao := dao.OrderCouponDao{}
|
||||
userCouponDao := dao.UserCouponDao{}
|
||||
|
||||
// 获取该订单全部优惠卷数据
|
||||
maps := make(map[string]interface{})
|
||||
maps["order_no"] = orderNo
|
||||
orderCoupons, err := orderCouponDao.GetOrderCouponList(maps)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 无优惠卷数据
|
||||
if len(orderCoupons) == 0 {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
for _, coupon := range orderCoupons {
|
||||
// 获取用户优惠卷数据
|
||||
userCoupon, err := userCouponDao.GetUserCouponById(coupon.UserCouponId)
|
||||
if err != nil || userCoupon == nil {
|
||||
// 无该优惠卷数据,无需处理
|
||||
continue
|
||||
}
|
||||
|
||||
// 恢复优惠卷
|
||||
userCouponData := make(map[string]interface{})
|
||||
|
||||
// 检测优惠卷过期时间。判断是否需要退还
|
||||
if userCoupon.ValidEndTime.Before(time.Now()) {
|
||||
userCouponData["user_coupon_status"] = 3
|
||||
} else {
|
||||
userCouponData["user_coupon_status"] = 0
|
||||
userCouponData["coupon_use_date"] = nil
|
||||
}
|
||||
|
||||
err = userCouponDao.EditUserCouponById(tx, userCoupon.UserCouponId, userCouponData)
|
||||
if err != nil {
|
||||
// 恢复优惠卷失败
|
||||
return false, errors.New("恢复优惠卷失败")
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user