From e19316cfc3983e80df03d13a0a4f8cf5520e6935 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Tue, 21 May 2024 10:49:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E8=8D=AF=E5=93=81?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E8=AF=A6=E6=83=85=E7=9A=84=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=8D=B7=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/dao/orderProductCoupon.go | 82 +++++++++++++++++++++++++++++++++ api/dto/OrderProduct.go | 11 +++++ api/dto/OrderProductCoupon.go | 52 +++++++++++++++++++++ api/model/orderProductCoupon.go | 35 ++++++++++++++ api/service/OrderInquiry.go | 8 ++-- api/service/orderProduct.go | 7 +++ 6 files changed, 191 insertions(+), 4 deletions(-) create mode 100644 api/dao/orderProductCoupon.go create mode 100644 api/dto/OrderProductCoupon.go create mode 100644 api/model/orderProductCoupon.go diff --git a/api/dao/orderProductCoupon.go b/api/dao/orderProductCoupon.go new file mode 100644 index 0000000..9db0efb --- /dev/null +++ b/api/dao/orderProductCoupon.go @@ -0,0 +1,82 @@ +package dao + +import ( + "gorm.io/gorm" + "gorm.io/gorm/clause" + "hospital-admin-api/api/model" + "hospital-admin-api/global" +) + +type OrderProductCouponDao struct { +} + +// GetOrderProductCouponById 获取药品订单优惠卷数据-药品订单优惠卷id +func (r *OrderProductCouponDao) GetOrderProductCouponById(orderCouponId int64) (m *model.OrderProductCoupon, err error) { + err = global.Db.First(&m, orderCouponId).Error + if err != nil { + return nil, err + } + return m, nil +} + +func (r *OrderProductCouponDao) GetOrderProductCouponByOrderProductId(orderProductId int64) (m *model. + OrderProductCoupon, err error) { + err = global.Db.Where("order_product_id = ?", orderProductId).First(&m).Error + if err != nil { + return nil, err + } + return m, nil +} + +// GetOrderProductCouponPreloadById 获取药品订单优惠卷数据-加载全部关联-药品订单优惠卷id +func (r *OrderProductCouponDao) GetOrderProductCouponPreloadById(orderCouponId int64) (m *model.OrderProductCoupon, err error) { + err = global.Db.Preload(clause.Associations).First(&m, orderCouponId).Error + if err != nil { + return nil, err + } + return m, nil +} + +// DeleteOrderProductCoupon 删除药品订单优惠卷 +func (r *OrderProductCouponDao) DeleteOrderProductCoupon(tx *gorm.DB, maps interface{}) error { + err := tx.Where(maps).Delete(&model.OrderProductCoupon{}).Error + if err != nil { + return err + } + return nil +} + +// EditOrderProductCoupon 修改药品订单优惠卷 +func (r *OrderProductCouponDao) EditOrderProductCoupon(tx *gorm.DB, maps interface{}, data interface{}) error { + err := tx.Model(&model.OrderProductCoupon{}).Where(maps).Updates(data).Error + if err != nil { + return err + } + return nil +} + +// EditOrderProductCouponById 修改药品订单优惠卷-药品订单优惠卷id +func (r *OrderProductCouponDao) EditOrderProductCouponById(tx *gorm.DB, orderCouponId int64, data interface{}) error { + err := tx.Model(&model.OrderProductCoupon{}).Where("order_coupon_id = ?", orderCouponId).Updates(data).Error + if err != nil { + return err + } + return nil +} + +// GetOrderProductCouponList 获取药品订单优惠卷列表 +func (r *OrderProductCouponDao) GetOrderProductCouponList(maps interface{}) (m []*model.OrderProductCoupon, err error) { + err = global.Db.Where(maps).Find(&m).Error + if err != nil { + return nil, err + } + return m, nil +} + +// AddOrderProductCoupon 新增药品订单优惠卷 +func (r *OrderProductCouponDao) AddOrderProductCoupon(tx *gorm.DB, model *model.OrderProductCoupon) (*model.OrderProductCoupon, error) { + if err := tx.Create(model).Error; err != nil { + return nil, err + } + return model, nil +} diff --git a/api/dto/OrderProduct.go b/api/dto/OrderProduct.go index 125b7b0..313f297 100644 --- a/api/dto/OrderProduct.go +++ b/api/dto/OrderProduct.go @@ -57,6 +57,7 @@ type OrderProductDto struct { UserDoctor *UserDoctorDto `json:"user_doctor"` // 医生数据 OrderPrescription *OrderPrescriptionDto `json:"order_prescription"` // 处方数据 OrderInquiryCase *OrderInquiryCaseDto `json:"order_inquiry_case"` // 问诊病例 + OrderProductCoupon *OrderProductCouponDto `json:"order_product_coupon"` // 优惠卷 } // OrderProductConsigneeDto 药品订单收货人数据 @@ -263,3 +264,13 @@ func (r *OrderProductDto) LoadOrderProductRefund(m *model.OrderProductRefund) *O } return r } + +// LoadOrderProductCoupon 加载药品订单优惠卷数据 +func (r *OrderProductDto) LoadOrderProductCoupon(m *model.OrderProductCoupon) *OrderProductDto { + if m != nil { + d := GetOrderProductCouponDto(m) + + r.OrderProductCoupon = d + } + return r +} diff --git a/api/dto/OrderProductCoupon.go b/api/dto/OrderProductCoupon.go new file mode 100644 index 0000000..dd54eef --- /dev/null +++ b/api/dto/OrderProductCoupon.go @@ -0,0 +1,52 @@ +package dto + +import ( + "fmt" + "hospital-admin-api/api/model" +) + +type OrderProductCouponDto struct { + OrderCouponId string `json:"order_coupon_id"` // 主键id + OrderProductId string `json:"order_product_id"` // 订单-商品id + UserCouponId string `json:"user_coupon_id"` // 用户优惠卷表id + CouponName string `json:"coupon_name"` // 优惠卷名称 + CouponUsePrice float64 `json:"coupon_use_price"` // 优惠卷使用金额 + CreatedAt model.LocalTime `json:"created_at"` // 创建时间 + UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间 +} + +func GetOrderProductCouponDto(m *model.OrderProductCoupon) *OrderProductCouponDto { + return &OrderProductCouponDto{ + OrderCouponId: fmt.Sprintf("%d", m.OrderCouponId), + OrderProductId: fmt.Sprintf("%d", m.OrderProductId), + UserCouponId: fmt.Sprintf("%d", m.UserCouponId), + CouponName: m.CouponName, + CouponUsePrice: m.CouponUsePrice, + CreatedAt: m.CreatedAt, + UpdatedAt: m.UpdatedAt, + } +} + +func GetOrderProductCouponListDto(m []*model.OrderProductCoupon) []OrderProductCouponDto { + // 处理返回值 + responses := make([]OrderProductCouponDto, len(m)) + + if len(m) > 0 { + for i, v := range m { + response := OrderProductCouponDto{ + OrderCouponId: fmt.Sprintf("%d", v.OrderCouponId), + OrderProductId: fmt.Sprintf("%d", v.OrderProductId), + UserCouponId: fmt.Sprintf("%d", v.UserCouponId), + CouponName: v.CouponName, + CouponUsePrice: v.CouponUsePrice, + CreatedAt: v.CreatedAt, + UpdatedAt: v.UpdatedAt, + } + + // 将转换后的结构体添加到新切片中 + responses[i] = response + } + } + + return responses +} diff --git a/api/model/orderProductCoupon.go b/api/model/orderProductCoupon.go new file mode 100644 index 0000000..2396132 --- /dev/null +++ b/api/model/orderProductCoupon.go @@ -0,0 +1,35 @@ +package model + +import ( + "gorm.io/gorm" + "hospital-admin-api/global" + "time" +) + +// OrderProductCoupon 订单-商品-优惠卷表 +type OrderProductCoupon struct { + OrderCouponId int64 `gorm:"column:order_coupon_id;type:bigint(19);primary_key;comment:主键id" json:"order_coupon_id"` + OrderProductId int64 `gorm:"column:order_product_id;type:bigint(19);comment:订单-商品id" json:"order_product_id"` + UserCouponId int64 `gorm:"column:user_coupon_id;type:bigint(19);comment:用户优惠卷表id" json:"user_coupon_id"` + CouponName string `gorm:"column:coupon_name;type:varchar(255);comment:优惠卷名称" json:"coupon_name"` + CouponUsePrice float64 `gorm:"column:coupon_use_price;type:decimal(10,2);default:0.00;comment:优惠卷使用金额" json:"coupon_use_price"` + Model +} + +func (m *OrderProductCoupon) TableName() string { + return "gdxz_order_product_coupon" +} + +func (m *OrderProductCoupon) BeforeCreate(tx *gorm.DB) error { + if m.OrderCouponId == 0 { + m.OrderCouponId = global.Snowflake.Generate().Int64() + } + + m.CreatedAt = LocalTime(time.Now()) + tx.Statement.SetColumn("CreatedAt", m.CreatedAt) + + m.UpdatedAt = LocalTime(time.Now()) + tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt) + + return nil +} diff --git a/api/service/OrderInquiry.go b/api/service/OrderInquiry.go index 2057b1e..b57d500 100644 --- a/api/service/OrderInquiry.go +++ b/api/service/OrderInquiry.go @@ -76,7 +76,7 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry } // 检测退款金额 - if req.RefundAmount > orderInquiry.PaymentAmountTotal { + if *req.RefundAmount > orderInquiry.PaymentAmountTotal { return false, errors.New("退款金额不可超过实付金额") } @@ -120,7 +120,7 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry OutTradeNo: orderInquiry.InquiryNo, OutRefundNo: refundNo, Reason: "客服取消", - RefundAmount: int64(req.RefundAmount * 100), + RefundAmount: int64(*req.RefundAmount * 100), PaymentAmountTotal: int64(orderInquiry.PaymentAmountTotal * 100), NotifyUrl: config.C.Wechat.RefundNotifyDomain + config.C.Wechat.PatientInquiryRefundNotifyUrl, } @@ -218,7 +218,7 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry RefundNo: refundNo, RefundId: refundId, RefundStatus: refundStatus, - RefundTotal: req.RefundAmount, + RefundTotal: *req.RefundAmount, RefundReason: req.CancelRemarks, } @@ -241,7 +241,7 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry InquiryRefundNo: refundNo, RefundId: refundId, InquiryRefundStatus: refundStatus, - RefundTotal: req.RefundAmount, + RefundTotal: *req.RefundAmount, RefundReason: req.CancelRemarks, SuccessTime: model.LocalTime(successTime), } diff --git a/api/service/orderProduct.go b/api/service/orderProduct.go index bc4c160..5783684 100644 --- a/api/service/orderProduct.go +++ b/api/service/orderProduct.go @@ -58,6 +58,10 @@ func (r *OrderProductService) GetOrderProduct(orderProductId int64) (g *dto.Orde return nil, errors.New(err.Error()) } + // 获取药品订单优惠卷 + orderProductCouponDao := dao.OrderProductCouponDao{} + orderProductCoupon, err := orderProductCouponDao.GetOrderProductCouponByOrderProductId(orderProduct.OrderProductId) + // 处理返回值 g = dto.GetOrderProductDto(orderProduct) @@ -79,6 +83,9 @@ func (r *OrderProductService) GetOrderProduct(orderProductId int64) (g *dto.Orde // 加载退款数据 g.LoadOrderProductRefund(orderProductRefund) + // 加载药品订单优惠卷数据 + g.LoadOrderProductCoupon(orderProductCoupon) + return g, nil }