1
This commit is contained in:
parent
859c9f56d0
commit
035676ba57
@ -11,8 +11,8 @@ type CouponGrantDao struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetCouponGrantById 获取数据-id
|
// GetCouponGrantById 获取数据-id
|
||||||
func (r *CouponGrantDao) GetCouponGrantById(orderServiceId int64) (m *model.CouponGrant, err error) {
|
func (r *CouponGrantDao) GetCouponGrantById(couponId int64) (m *model.CouponGrant, err error) {
|
||||||
err = global.Db.First(&m, orderServiceId).Error
|
err = global.Db.First(&m, couponId).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -20,8 +20,17 @@ func (r *CouponGrantDao) GetCouponGrantById(orderServiceId int64) (m *model.Coup
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetCouponGrantPreloadById 获取数据-加载全部关联-id
|
// GetCouponGrantPreloadById 获取数据-加载全部关联-id
|
||||||
func (r *CouponGrantDao) GetCouponGrantPreloadById(orderServiceId int64) (m *model.CouponGrant, err error) {
|
func (r *CouponGrantDao) GetCouponGrantPreloadById(couponId int64) (m *model.CouponGrant, err error) {
|
||||||
err = global.Db.Preload(clause.Associations).First(&m, orderServiceId).Error
|
err = global.Db.Preload(clause.Associations).First(&m, couponId).Error
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCouponGrantListPreloadByCouponId 获取数据-加载全部关联-id
|
||||||
|
func (r *CouponGrantDao) GetCouponGrantListPreloadByCouponId(couponId int64) (m []*model.CouponGrant, err error) {
|
||||||
|
err = global.Db.Preload(clause.Associations).Where("coupon_id = ?", couponId).Find(&m).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package dto
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"hospital-admin-api/api/dao"
|
||||||
"hospital-admin-api/api/model"
|
"hospital-admin-api/api/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,6 +19,8 @@ type CouponGrantDto struct {
|
|||||||
AdminUserId string `json:"admin_user_id"` // 后台操作用户id
|
AdminUserId string `json:"admin_user_id"` // 后台操作用户id
|
||||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||||
|
UserName string `json:"user_name"` // 用户名称
|
||||||
|
AdminUserName string `json:"admin_user_name"` // 操作人名称
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCouponGrantDto 优惠卷详情
|
// GetCouponGrantDto 优惠卷详情
|
||||||
@ -58,6 +61,14 @@ func GetCouponGrantListDto(m []*model.CouponGrant) []*CouponGrantDto {
|
|||||||
UpdatedAt: v.UpdatedAt,
|
UpdatedAt: v.UpdatedAt,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v.User != nil {
|
||||||
|
response.LoadUserAttr(v.User)
|
||||||
|
}
|
||||||
|
|
||||||
|
if v.AdminUserId != 0 {
|
||||||
|
response.LoadAdminUserName(v.AdminUserId)
|
||||||
|
}
|
||||||
|
|
||||||
// 将转换后的结构体添加到新切片中
|
// 将转换后的结构体添加到新切片中
|
||||||
responses[i] = response
|
responses[i] = response
|
||||||
}
|
}
|
||||||
@ -65,3 +76,24 @@ func GetCouponGrantListDto(m []*model.CouponGrant) []*CouponGrantDto {
|
|||||||
|
|
||||||
return responses
|
return responses
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LoadUserAttr 加载用户属性
|
||||||
|
func (r *CouponGrantDto) LoadUserAttr(m *model.User) *CouponGrantDto {
|
||||||
|
if m != nil {
|
||||||
|
r.UserName = m.UserName
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
// LoadAdminUserName 加载后台用户属性
|
||||||
|
func (r *CouponGrantDto) LoadAdminUserName(adminUserId int64) *CouponGrantDto {
|
||||||
|
if adminUserId != 0 {
|
||||||
|
// 获取后台操作人记录
|
||||||
|
adminUserDao := dao.AdminUserDao{}
|
||||||
|
adminUser, _ := adminUserDao.GetAdminUserFirstById(adminUserId)
|
||||||
|
if adminUser != nil {
|
||||||
|
r.AdminUserName = adminUser.NickName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@ type CouponGrant struct {
|
|||||||
StopReason string `gorm:"column:stop_reason;type:varchar(255);comment:停止原因" json:"stop_reason"`
|
StopReason string `gorm:"column:stop_reason;type:varchar(255);comment:停止原因" json:"stop_reason"`
|
||||||
AdminUserId int64 `gorm:"column:admin_user_id;type:bigint(19);comment:后台操作用户id" json:"admin_user_id"`
|
AdminUserId int64 `gorm:"column:admin_user_id;type:bigint(19);comment:后台操作用户id" json:"admin_user_id"`
|
||||||
Model
|
Model
|
||||||
|
User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"` // 用户
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *CouponGrant) TableName() string {
|
func (m *CouponGrant) TableName() string {
|
||||||
|
|||||||
@ -22,17 +22,21 @@ type CouponService struct {
|
|||||||
// GetSystemCoupon 系统优惠卷详情
|
// GetSystemCoupon 系统优惠卷详情
|
||||||
func (r *CouponService) GetSystemCoupon(couponId int64) (g *dto.CouponDto, err error) {
|
func (r *CouponService) GetSystemCoupon(couponId int64) (g *dto.CouponDto, err error) {
|
||||||
couponDao := dao.CouponDao{}
|
couponDao := dao.CouponDao{}
|
||||||
coupon, err := couponDao.GetCouponPreloadById(couponId)
|
coupon, err := couponDao.GetCouponById(couponId)
|
||||||
if err != nil || coupon == nil {
|
if err != nil || coupon == nil {
|
||||||
return nil, errors.New(err.Error())
|
return nil, errors.New(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取优惠卷发放数据
|
||||||
|
couponGrantDao := dao.CouponGrantDao{}
|
||||||
|
couponGrants, err := couponGrantDao.GetCouponGrantListPreloadByCouponId(coupon.CouponId)
|
||||||
|
|
||||||
// 处理返回值
|
// 处理返回值
|
||||||
g = dto.GetCouponDto(coupon)
|
g = dto.GetCouponDto(coupon)
|
||||||
|
|
||||||
// 加载发放优惠卷数据
|
// 加载发放优惠卷数据
|
||||||
if len(coupon.CouponGrant) > 0 {
|
if len(couponGrants) > 0 {
|
||||||
g = g.LoadCouponGrant(coupon.CouponGrant)
|
g = g.LoadCouponGrant(couponGrants)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载关联问诊类型
|
// 加载关联问诊类型
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user