1
This commit is contained in:
parent
859c9f56d0
commit
035676ba57
@ -11,8 +11,8 @@ type CouponGrantDao struct {
|
||||
}
|
||||
|
||||
// GetCouponGrantById 获取数据-id
|
||||
func (r *CouponGrantDao) GetCouponGrantById(orderServiceId int64) (m *model.CouponGrant, err error) {
|
||||
err = global.Db.First(&m, orderServiceId).Error
|
||||
func (r *CouponGrantDao) GetCouponGrantById(couponId int64) (m *model.CouponGrant, err error) {
|
||||
err = global.Db.First(&m, couponId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -20,8 +20,17 @@ func (r *CouponGrantDao) GetCouponGrantById(orderServiceId int64) (m *model.Coup
|
||||
}
|
||||
|
||||
// GetCouponGrantPreloadById 获取数据-加载全部关联-id
|
||||
func (r *CouponGrantDao) GetCouponGrantPreloadById(orderServiceId int64) (m *model.CouponGrant, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, orderServiceId).Error
|
||||
func (r *CouponGrantDao) GetCouponGrantPreloadById(couponId int64) (m *model.CouponGrant, err 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 {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -2,22 +2,25 @@ package dto
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/model"
|
||||
)
|
||||
|
||||
// CouponGrantDto 发放优惠券表
|
||||
type CouponGrantDto struct {
|
||||
GrantId string `json:"grant_id"` // 主键id
|
||||
CouponId string `json:"coupon_id"` // 优惠卷id
|
||||
GrantType int `json:"grant_type"` // 发放类型(1:具体用户 2:未拥有用户)
|
||||
UserId string `json:"user_id"` // 用户id(发放类型为具体用户时存在)
|
||||
TotalQuantity int `json:"total_quantity"` // 目标发放数量
|
||||
GrantQuantity int `json:"grant_quantity"` // 已发放数量
|
||||
GrantResult int `json:"grant_result"` // 发放结果(1:成功 2:发放中 3:部分 4:失败)
|
||||
StopReason string `json:"stop_reason"` // 停止原因
|
||||
AdminUserId string `json:"admin_user_id"` // 后台操作用户id
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
GrantId string `json:"grant_id"` // 主键id
|
||||
CouponId string `json:"coupon_id"` // 优惠卷id
|
||||
GrantType int `json:"grant_type"` // 发放类型(1:具体用户 2:未拥有用户)
|
||||
UserId string `json:"user_id"` // 用户id(发放类型为具体用户时存在)
|
||||
TotalQuantity int `json:"total_quantity"` // 目标发放数量
|
||||
GrantQuantity int `json:"grant_quantity"` // 已发放数量
|
||||
GrantResult int `json:"grant_result"` // 发放结果(1:成功 2:发放中 3:部分 4:失败)
|
||||
StopReason string `json:"stop_reason"` // 停止原因
|
||||
AdminUserId string `json:"admin_user_id"` // 后台操作用户id
|
||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||
UpdatedAt model.LocalTime `json:"updated_at"` // 修改时间
|
||||
UserName string `json:"user_name"` // 用户名称
|
||||
AdminUserName string `json:"admin_user_name"` // 操作人名称
|
||||
}
|
||||
|
||||
// GetCouponGrantDto 优惠卷详情
|
||||
@ -58,6 +61,14 @@ func GetCouponGrantListDto(m []*model.CouponGrant) []*CouponGrantDto {
|
||||
UpdatedAt: v.UpdatedAt,
|
||||
}
|
||||
|
||||
if v.User != nil {
|
||||
response.LoadUserAttr(v.User)
|
||||
}
|
||||
|
||||
if v.AdminUserId != 0 {
|
||||
response.LoadAdminUserName(v.AdminUserId)
|
||||
}
|
||||
|
||||
// 将转换后的结构体添加到新切片中
|
||||
responses[i] = response
|
||||
}
|
||||
@ -65,3 +76,24 @@ func GetCouponGrantListDto(m []*model.CouponGrant) []*CouponGrantDto {
|
||||
|
||||
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"`
|
||||
AdminUserId int64 `gorm:"column:admin_user_id;type:bigint(19);comment:后台操作用户id" json:"admin_user_id"`
|
||||
Model
|
||||
User *User `gorm:"foreignKey:UserId;references:user_id" json:"user"` // 用户
|
||||
}
|
||||
|
||||
func (m *CouponGrant) TableName() string {
|
||||
|
||||
@ -22,17 +22,21 @@ type CouponService struct {
|
||||
// GetSystemCoupon 系统优惠卷详情
|
||||
func (r *CouponService) GetSystemCoupon(couponId int64) (g *dto.CouponDto, err error) {
|
||||
couponDao := dao.CouponDao{}
|
||||
coupon, err := couponDao.GetCouponPreloadById(couponId)
|
||||
coupon, err := couponDao.GetCouponById(couponId)
|
||||
if err != nil || coupon == nil {
|
||||
return nil, errors.New(err.Error())
|
||||
}
|
||||
|
||||
// 获取优惠卷发放数据
|
||||
couponGrantDao := dao.CouponGrantDao{}
|
||||
couponGrants, err := couponGrantDao.GetCouponGrantListPreloadByCouponId(coupon.CouponId)
|
||||
|
||||
// 处理返回值
|
||||
g = dto.GetCouponDto(coupon)
|
||||
|
||||
// 加载发放优惠卷数据
|
||||
if len(coupon.CouponGrant) > 0 {
|
||||
g = g.LoadCouponGrant(coupon.CouponGrant)
|
||||
if len(couponGrants) > 0 {
|
||||
g = g.LoadCouponGrant(couponGrants)
|
||||
}
|
||||
|
||||
// 加载关联问诊类型
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user