增加了药品订单详情的优惠卷数据
This commit is contained in:
parent
931d2def98
commit
e19316cfc3
82
api/dao/orderProductCoupon.go
Normal file
82
api/dao/orderProductCoupon.go
Normal file
@ -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
|
||||||
|
}
|
||||||
@ -57,6 +57,7 @@ type OrderProductDto struct {
|
|||||||
UserDoctor *UserDoctorDto `json:"user_doctor"` // 医生数据
|
UserDoctor *UserDoctorDto `json:"user_doctor"` // 医生数据
|
||||||
OrderPrescription *OrderPrescriptionDto `json:"order_prescription"` // 处方数据
|
OrderPrescription *OrderPrescriptionDto `json:"order_prescription"` // 处方数据
|
||||||
OrderInquiryCase *OrderInquiryCaseDto `json:"order_inquiry_case"` // 问诊病例
|
OrderInquiryCase *OrderInquiryCaseDto `json:"order_inquiry_case"` // 问诊病例
|
||||||
|
OrderProductCoupon *OrderProductCouponDto `json:"order_product_coupon"` // 优惠卷
|
||||||
}
|
}
|
||||||
|
|
||||||
// OrderProductConsigneeDto 药品订单收货人数据
|
// OrderProductConsigneeDto 药品订单收货人数据
|
||||||
@ -263,3 +264,13 @@ func (r *OrderProductDto) LoadOrderProductRefund(m *model.OrderProductRefund) *O
|
|||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadOrderProductCoupon 加载药品订单优惠卷数据
|
||||||
|
func (r *OrderProductDto) LoadOrderProductCoupon(m *model.OrderProductCoupon) *OrderProductDto {
|
||||||
|
if m != nil {
|
||||||
|
d := GetOrderProductCouponDto(m)
|
||||||
|
|
||||||
|
r.OrderProductCoupon = d
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|||||||
52
api/dto/OrderProductCoupon.go
Normal file
52
api/dto/OrderProductCoupon.go
Normal file
@ -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
|
||||||
|
}
|
||||||
35
api/model/orderProductCoupon.go
Normal file
35
api/model/orderProductCoupon.go
Normal file
@ -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
|
||||||
|
}
|
||||||
@ -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("退款金额不可超过实付金额")
|
return false, errors.New("退款金额不可超过实付金额")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry
|
|||||||
OutTradeNo: orderInquiry.InquiryNo,
|
OutTradeNo: orderInquiry.InquiryNo,
|
||||||
OutRefundNo: refundNo,
|
OutRefundNo: refundNo,
|
||||||
Reason: "客服取消",
|
Reason: "客服取消",
|
||||||
RefundAmount: int64(req.RefundAmount * 100),
|
RefundAmount: int64(*req.RefundAmount * 100),
|
||||||
PaymentAmountTotal: int64(orderInquiry.PaymentAmountTotal * 100),
|
PaymentAmountTotal: int64(orderInquiry.PaymentAmountTotal * 100),
|
||||||
NotifyUrl: config.C.Wechat.RefundNotifyDomain + config.C.Wechat.PatientInquiryRefundNotifyUrl,
|
NotifyUrl: config.C.Wechat.RefundNotifyDomain + config.C.Wechat.PatientInquiryRefundNotifyUrl,
|
||||||
}
|
}
|
||||||
@ -218,7 +218,7 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry
|
|||||||
RefundNo: refundNo,
|
RefundNo: refundNo,
|
||||||
RefundId: refundId,
|
RefundId: refundId,
|
||||||
RefundStatus: refundStatus,
|
RefundStatus: refundStatus,
|
||||||
RefundTotal: req.RefundAmount,
|
RefundTotal: *req.RefundAmount,
|
||||||
RefundReason: req.CancelRemarks,
|
RefundReason: req.CancelRemarks,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ func (r *OrderInquiryService) CancelOrderInquiry(req requests.CancelOrderInquiry
|
|||||||
InquiryRefundNo: refundNo,
|
InquiryRefundNo: refundNo,
|
||||||
RefundId: refundId,
|
RefundId: refundId,
|
||||||
InquiryRefundStatus: refundStatus,
|
InquiryRefundStatus: refundStatus,
|
||||||
RefundTotal: req.RefundAmount,
|
RefundTotal: *req.RefundAmount,
|
||||||
RefundReason: req.CancelRemarks,
|
RefundReason: req.CancelRemarks,
|
||||||
SuccessTime: model.LocalTime(successTime),
|
SuccessTime: model.LocalTime(successTime),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,6 +58,10 @@ func (r *OrderProductService) GetOrderProduct(orderProductId int64) (g *dto.Orde
|
|||||||
return nil, errors.New(err.Error())
|
return nil, errors.New(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取药品订单优惠卷
|
||||||
|
orderProductCouponDao := dao.OrderProductCouponDao{}
|
||||||
|
orderProductCoupon, err := orderProductCouponDao.GetOrderProductCouponByOrderProductId(orderProduct.OrderProductId)
|
||||||
|
|
||||||
// 处理返回值
|
// 处理返回值
|
||||||
g = dto.GetOrderProductDto(orderProduct)
|
g = dto.GetOrderProductDto(orderProduct)
|
||||||
|
|
||||||
@ -79,6 +83,9 @@ func (r *OrderProductService) GetOrderProduct(orderProductId int64) (g *dto.Orde
|
|||||||
// 加载退款数据
|
// 加载退款数据
|
||||||
g.LoadOrderProductRefund(orderProductRefund)
|
g.LoadOrderProductRefund(orderProductRefund)
|
||||||
|
|
||||||
|
// 加载药品订单优惠卷数据
|
||||||
|
g.LoadOrderProductCoupon(orderProductCoupon)
|
||||||
|
|
||||||
return g, nil
|
return g, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user