83 lines
2.5 KiB
Go
83 lines
2.5 KiB
Go
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
|
|
}
|