新增:获取系统优惠卷列表-分页
This commit is contained in:
parent
0bae6f821f
commit
061c91c686
@ -16,6 +16,7 @@ type Api struct {
|
||||
financeManage // 财务管理
|
||||
exportManage // 导出管理
|
||||
productManage // 商品管理
|
||||
couponManage // 优惠卷管理
|
||||
}
|
||||
|
||||
// SysSetting 系统设置
|
||||
@ -91,3 +92,8 @@ type exportManage struct {
|
||||
type productManage struct {
|
||||
Product
|
||||
}
|
||||
|
||||
// 优惠卷管理
|
||||
type couponManage struct {
|
||||
Coupon
|
||||
}
|
||||
|
||||
58
api/controller/coupon.go
Normal file
58
api/controller/coupon.go
Normal file
@ -0,0 +1,58 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/dto"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/api/responses"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
)
|
||||
|
||||
type Coupon struct{}
|
||||
|
||||
// GetSystemCouponPage 获取系统优惠卷列表-分页
|
||||
func (r *Coupon) GetSystemCouponPage(c *gin.Context) {
|
||||
couponRequest := requests.CouponRequest{}
|
||||
req := couponRequest.GetSystemCouponPage
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 参数验证
|
||||
if err := global.Validate.Struct(req); err != nil {
|
||||
responses.FailWithMessage(utils.Translate(err), c)
|
||||
return
|
||||
}
|
||||
|
||||
if req.Page == 0 {
|
||||
req.Page = 1
|
||||
}
|
||||
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 20
|
||||
}
|
||||
|
||||
couponDao := dao.CouponDao{}
|
||||
coupon, total, err := couponDao.GetCouponPageSearch(req, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
GetProductPlatformPageResponses := dto.GetCouponListDto(coupon)
|
||||
if err != nil {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result["page"] = req.Page
|
||||
result["page_size"] = req.PageSize
|
||||
result["total"] = total
|
||||
result["data"] = GetProductPlatformPageResponses
|
||||
responses.OkWithData(result, c)
|
||||
}
|
||||
167
api/dao/coupon.go
Normal file
167
api/dao/coupon.go
Normal file
@ -0,0 +1,167 @@
|
||||
package dao
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"hospital-admin-api/api/model"
|
||||
"hospital-admin-api/api/requests"
|
||||
"hospital-admin-api/global"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CouponDao struct {
|
||||
}
|
||||
|
||||
// GetCouponById 获取数据-id
|
||||
func (r *CouponDao) GetCouponById(couponId int64) (m *model.Coupon, err error) {
|
||||
err = global.Db.First(&m, couponId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetCouponPreloadById 获取数据-加载全部关联-id
|
||||
func (r *CouponDao) GetCouponPreloadById(couponId int64) (m *model.Coupon, err error) {
|
||||
err = global.Db.Preload(clause.Associations).First(&m, couponId).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// EditCoupon 修改
|
||||
func (r *CouponDao) EditCoupon(tx *gorm.DB, maps interface{}, data interface{}) error {
|
||||
err := tx.Model(&model.Coupon{}).Where(maps).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditCouponByOrderServicePackageId 修改-id
|
||||
func (r *CouponDao) EditCouponByOrderServicePackageId(tx *gorm.DB, couponId int64, data interface{}) error {
|
||||
err := tx.Model(&model.Coupon{}).Where("coupon_id = ?", couponId).Updates(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetCouponList 获取列表
|
||||
func (r *CouponDao) GetCouponList(maps interface{}) (m []*model.Coupon, err error) {
|
||||
err = global.Db.Where(maps).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddCoupon 新增
|
||||
func (r *CouponDao) AddCoupon(tx *gorm.DB, model *model.Coupon) (*model.Coupon, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// GetCouponPageSearch 获取列表-分页
|
||||
func (r *CouponDao) GetCouponPageSearch(req requests.GetSystemCouponPage, page, pageSize int) (m []*model.Coupon, total int64, err error) {
|
||||
var totalRecords int64
|
||||
|
||||
// 构建查询条件
|
||||
query := global.Db.Model(&model.Coupon{})
|
||||
|
||||
// 优惠卷名称
|
||||
if req.CouponName != "" {
|
||||
query = query.Where("coupon_name LIKE ?", "%"+req.CouponName+"%")
|
||||
}
|
||||
|
||||
// 使用平台(1:小程序)
|
||||
if req.CouponClient != nil {
|
||||
query = query.Where("coupon_client = ?", req.CouponClient)
|
||||
}
|
||||
|
||||
// 优惠卷类型(1:无门槛 2:满减 3:数量
|
||||
if req.CouponType != nil {
|
||||
query = query.Where("coupon_type = ?", req.CouponType)
|
||||
}
|
||||
|
||||
// 状态(1:正常 2:强制失效 3:结束 4:删除)
|
||||
if req.CouponStatus != nil {
|
||||
query = query.Where("coupon_status = ?", req.CouponStatus)
|
||||
}
|
||||
|
||||
// 发放对象(1:全部用户 2:新注册用户 3:会员 4:近期消费 5:近期购药 6:存量用户 7:健康包服务用户)
|
||||
if req.DistributionObject != nil {
|
||||
query = query.Where("distribution_object = ?", req.DistributionObject)
|
||||
}
|
||||
|
||||
// 适用范围(1:全场通用 2:问诊 3:按品牌适用 4:按类别适用 5:单品使用 6:全品类药品)
|
||||
if req.ApplicationScope != nil {
|
||||
query = query.Where("application_scope = ?", req.ApplicationScope)
|
||||
}
|
||||
|
||||
// 关联问诊类型,application_scope=问诊时存在生效,逗号分隔(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药 6:检测)
|
||||
if req.InquiryType != "" {
|
||||
query = query.Where("inquiry_type = ?", req.InquiryType)
|
||||
}
|
||||
|
||||
// 关联品牌id(如不限制品牌,此项为空)
|
||||
if req.BrandId != "" {
|
||||
query = query.Where("brand_id = ?", req.BrandId)
|
||||
}
|
||||
|
||||
// 是否互斥(0:否 1:是)互斥情况下无法和其他优惠卷同时使用
|
||||
if req.IsMutex != nil {
|
||||
query = query.Where("is_mutex = ?", req.IsMutex)
|
||||
}
|
||||
|
||||
// 是否展示(0:否 1:是)
|
||||
if req.IsDisplay != nil {
|
||||
query = query.Where("is_display = ?", req.IsDisplay)
|
||||
}
|
||||
|
||||
// 有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效)
|
||||
if req.ValidType != nil {
|
||||
query = query.Where("valid_type = ?", req.ValidType)
|
||||
}
|
||||
|
||||
// 过期之后是否允许再次发放(0:否 1:是)
|
||||
if req.IsReissuableAfterExpire != nil {
|
||||
query = query.Where("is_reissuable_after_expire = ?", req.IsReissuableAfterExpire)
|
||||
}
|
||||
|
||||
// 是否首页弹窗(0:否 1:是)
|
||||
if req.IsPopup != nil {
|
||||
query = query.Where("is_popup = ?", req.IsPopup)
|
||||
}
|
||||
|
||||
// 创建时间
|
||||
if req.CreatedAt != "" {
|
||||
createdAt := strings.Split(req.CreatedAt, "&")
|
||||
if len(createdAt) == 2 {
|
||||
startTime, _ := time.Parse("2006-01-02", createdAt[0])
|
||||
endTime, _ := time.Parse("2006-01-02", createdAt[1])
|
||||
|
||||
endTime = endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second)
|
||||
|
||||
query = query.Where("created_at BETWEEN ? AND ?", startTime, endTime)
|
||||
}
|
||||
}
|
||||
|
||||
// 排序
|
||||
query = query.Order("created_at desc")
|
||||
|
||||
// 查询总数量
|
||||
if err := query.Count(&totalRecords).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
err = query.Scopes(model.Paginate(page, pageSize)).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
@ -65,7 +65,7 @@ func GetCouponDto(m *model.Coupon) *CouponDto {
|
||||
ValidDays: m.ValidDays,
|
||||
ValidStartTime: m.ValidStartTime,
|
||||
ValidEndTime: m.ValidEndTime,
|
||||
ProductId: fmt.Sprintf("%d", m.ProductId),
|
||||
ProductId: m.ProductId,
|
||||
ReissueIntervalDays: m.ReissueIntervalDays,
|
||||
IsReissuableAfterExpire: m.IsReissuableAfterExpire,
|
||||
IsPopup: m.IsPopup,
|
||||
@ -106,7 +106,7 @@ func GetCouponListDto(m []*model.Coupon) []*CouponDto {
|
||||
ValidDays: v.ValidDays,
|
||||
ValidStartTime: v.ValidStartTime,
|
||||
ValidEndTime: v.ValidEndTime,
|
||||
ProductId: fmt.Sprintf("%d", v.ProductId),
|
||||
ProductId: v.ProductId,
|
||||
ReissueIntervalDays: v.ReissueIntervalDays,
|
||||
IsReissuableAfterExpire: v.IsReissuableAfterExpire,
|
||||
IsPopup: v.IsPopup,
|
||||
|
||||
26
api/requests/coupon.go
Normal file
26
api/requests/coupon.go
Normal file
@ -0,0 +1,26 @@
|
||||
package requests
|
||||
|
||||
type CouponRequest struct {
|
||||
GetSystemCouponPage // 获取系统优惠卷列表-分页
|
||||
}
|
||||
|
||||
// GetSystemCouponPage 获取系统优惠卷列表-分页
|
||||
type GetSystemCouponPage struct {
|
||||
Page int `json:"page" form:"page" label:"页码"`
|
||||
PageSize int `json:"page_size" form:"page_size" label:"每页个数"`
|
||||
CouponName string `json:"coupon_name" form:"coupon_name" label:"优惠卷名称"` // 优惠卷名称
|
||||
CouponClient *int `json:"coupon_client" form:"coupon_client" label:"使用平台(1:小程序)"` // 使用平台(1:小程序)
|
||||
CouponType *int `json:"coupon_type" form:"coupon_type" label:"优惠卷类型(1:无门槛 2:满减 3:数量)"` // 优惠卷类型(1:无门槛 2:满减 3:数量)
|
||||
CouponStatus *int `json:"coupon_status" form:"coupon_status" label:"状态(1:正常 2:强制失效 3:结束 4:删除)"` // 状态(1:正常 2:强制失效 3:结束 4:删除)
|
||||
DistributionObject *int `json:"distribution_object" form:"distribution_object" label:"发放对象(1:全部用户 2:新注册用户 3:会员 4:近期消费 5:近期购药 6:存量用户 7:健康包服务用户)"` // 发放对象(1:全部用户 2:新注册用户 3:会员 4:近期消费 5:近期购药 6:存量用户 7:健康包服务用户)
|
||||
ApplicationScope *int `json:"application_scope" form:"application_scope" label:"适用范围(1:全场通用 2:问诊 3:按品牌适用 4:按类别适用 5:单品使用 6:全品类药品)"` // 适用范围(1:全场通用 2:问诊 3:按品牌适用 4:按类别适用 5:单品使用 6:全品类药品)
|
||||
InquiryType string `json:"inquiry_type" form:"inquiry_type" label:"关联问诊类型,application_scope=问诊时存在生效,逗号分隔(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药 6:检测)"` // 关联问诊类型,application_scope=问诊时存在生效,逗号分隔(1:全部 2:快速问诊 3:专家问诊 4:公益问诊 5:问诊购药 6:检测)
|
||||
BrandId string `json:"brand_id" form:"brand_id" label:"关联品牌id(如不限制品牌,此项为空)"` // 关联品牌id(如不限制品牌,此项为空)
|
||||
IsMutex *int `json:"is_mutex" form:"is_mutex" label:"是否互斥(0:否 1:是)互斥情况下无法和其他优惠卷同时使用"` // 是否互斥(0:否 1:是)互斥情况下无法和其他优惠卷同时使用
|
||||
IsDisplay *int `json:"is_display" form:"is_display" label:"是否展示(0:否 1:是)"` // 是否展示(0:否 1:是)
|
||||
ValidType *int `json:"valid_type" form:"valid_type" label:"有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效)"` // 有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效)
|
||||
IsReissuableAfterExpire *int `json:"is_reissuable_after_expire" form:"is_reissuable_after_expire" label:"过期之后是否允许再次发放(0:否 1:是)"` // 过期之后是否允许再次发放(0:否 1:是)
|
||||
IsPopup *int `json:"is_popup" form:"is_popup" label:"是否首页弹窗(0:否 1:是)"` // 是否首页弹窗(0:否 1:是)
|
||||
CouponDesc string `json:"coupon_desc" form:"coupon_desc" label:"优惠卷描述"`
|
||||
CreatedAt string `json:"created_at" form:"created_at" label:"创建时间"` // 创建时间
|
||||
}
|
||||
@ -719,4 +719,46 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
||||
platformGroup.GET("/list", api.Product.GetPlatformProductList)
|
||||
}
|
||||
}
|
||||
|
||||
// 优惠卷管理
|
||||
couponGroup := adminGroup.Group("/coupon")
|
||||
{
|
||||
// 系统优惠卷管理
|
||||
systemGroup := couponGroup.Group("/system")
|
||||
{
|
||||
// 获取系统优惠卷列表-分页
|
||||
systemGroup.POST("/page", api.Coupon.GetSystemCouponPage)
|
||||
|
||||
// 系统优惠卷详情
|
||||
systemGroup.GET("/:product_id", api.Product.GetProduct)
|
||||
|
||||
// 新增系统优惠卷
|
||||
systemGroup.POST("", api.Product.AddProduct)
|
||||
|
||||
// 修改系统优惠卷
|
||||
systemGroup.PUT("/:product_id", api.Product.PutProduct)
|
||||
|
||||
// 修改系统优惠卷状态
|
||||
systemGroup.PUT("/status/:product_id", api.Product.PutProductStatus)
|
||||
}
|
||||
|
||||
// 用户优惠卷管理
|
||||
userGroup := couponGroup.Group("/user")
|
||||
{
|
||||
// 获取用户优惠卷列表-分页
|
||||
userGroup.POST("/page", api.Product.GetProductPage)
|
||||
|
||||
// 系统用户优惠卷详情
|
||||
userGroup.GET("/:product_id", api.Product.GetProduct)
|
||||
|
||||
// 新增用户优惠卷
|
||||
userGroup.POST("", api.Product.AddProduct)
|
||||
|
||||
// 修改用户优惠卷
|
||||
userGroup.PUT("/:product_id", api.Product.PutProduct)
|
||||
|
||||
// 修改用户优惠卷状态
|
||||
userGroup.PUT("/status/:product_id", api.Product.PutProductStatus)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user