diff --git a/api/v1/couponusers/couponUsers.go b/api/v1/couponusers/couponUsers.go index cb92860..d205dcd 100644 --- a/api/v1/couponusers/couponUsers.go +++ b/api/v1/couponusers/couponUsers.go @@ -32,3 +32,7 @@ type IssueCouponUserReq struct { type IsEligibleUserReq struct { CouponIds []int `json:"couponIds" v:"required#用于检测是否已抽取,不能为空" dc:"能抽出的卡券id"` } + +type InsertCouponUserRes struct { + Jwcode int `json:"jwcode" dc:"精网号"` +} diff --git a/hack/config.yaml b/hack/config.yaml index 03b6e23..e977e0f 100644 --- a/hack/config.yaml +++ b/hack/config.yaml @@ -6,7 +6,7 @@ gfcli: dao: - link: "mysql:live:p4jMAMShNM8HTrbX@tcp(39.101.133.168:3306)/live?charset=utf8mb4&parseTime=True&loc=Local" group: "default" - tables: "coupon, coupon_users, member_info" + tables: "coupon, coupon_users, member_info, coupon_qualified_users" descriptionTag: true docker: diff --git a/internal/dao/coupon_qualified_users.go b/internal/dao/coupon_qualified_users.go new file mode 100644 index 0000000..6dc9dec --- /dev/null +++ b/internal/dao/coupon_qualified_users.go @@ -0,0 +1,27 @@ +// ================================================================================= +// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish. +// ================================================================================= + +package dao + +import ( + "CouponBackendGo/internal/dao/internal" +) + +// internalCouponQualifiedUsersDao is internal type for wrapping internal DAO implements. +type internalCouponQualifiedUsersDao = *internal.CouponQualifiedUsersDao + +// couponQualifiedUsersDao is the data access object for table coupon_qualified_users. +// You can define custom methods on it to extend its functionality as you wish. +type couponQualifiedUsersDao struct { + internalCouponQualifiedUsersDao +} + +var ( + // CouponQualifiedUsers is globally public accessible object for table coupon_qualified_users operations. + CouponQualifiedUsers = couponQualifiedUsersDao{ + internal.NewCouponQualifiedUsersDao(), + } +) + +// Fill with you ideas below. diff --git a/internal/dao/internal/coupon_qualified_users.go b/internal/dao/internal/coupon_qualified_users.go new file mode 100644 index 0000000..687b206 --- /dev/null +++ b/internal/dao/internal/coupon_qualified_users.go @@ -0,0 +1,75 @@ +// ========================================================================== +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ========================================================================== + +package internal + +import ( + "context" + + "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/frame/g" +) + +// CouponQualifiedUsersDao is the data access object for table coupon_qualified_users. +type CouponQualifiedUsersDao struct { + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of current DAO. + columns CouponQualifiedUsersColumns // columns contains all the column names of Table for convenient usage. +} + +// CouponQualifiedUsersColumns defines and stores column names for table coupon_qualified_users. +type CouponQualifiedUsersColumns struct { + Id string // + Jwcode string // +} + +// couponQualifiedUsersColumns holds the columns for table coupon_qualified_users. +var couponQualifiedUsersColumns = CouponQualifiedUsersColumns{ + Id: "id", + Jwcode: "jwcode", +} + +// NewCouponQualifiedUsersDao creates and returns a new DAO object for table data access. +func NewCouponQualifiedUsersDao() *CouponQualifiedUsersDao { + return &CouponQualifiedUsersDao{ + group: "default", + table: "coupon_qualified_users", + columns: couponQualifiedUsersColumns, + } +} + +// DB retrieves and returns the underlying raw database management object of current DAO. +func (dao *CouponQualifiedUsersDao) DB() gdb.DB { + return g.DB(dao.group) +} + +// Table returns the table name of current dao. +func (dao *CouponQualifiedUsersDao) Table() string { + return dao.table +} + +// Columns returns all column names of current dao. +func (dao *CouponQualifiedUsersDao) Columns() CouponQualifiedUsersColumns { + return dao.columns +} + +// Group returns the configuration group name of database of current dao. +func (dao *CouponQualifiedUsersDao) Group() string { + return dao.group +} + +// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +func (dao *CouponQualifiedUsersDao) Ctx(ctx context.Context) *gdb.Model { + return dao.DB().Model(dao.table).Safe().Ctx(ctx) +} + +// Transaction wraps the transaction logic using function f. +// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It commits the transaction and returns nil if function f returns nil. +// +// Note that, you should not Commit or Rollback the transaction in function f +// as it is automatically handled by this function. +func (dao *CouponQualifiedUsersDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { + return dao.Ctx(ctx).Transaction(ctx, f) +} diff --git a/internal/logic/couponusers/couponUsers.go b/internal/logic/couponusers/couponUsers.go index 502adc5..35ca174 100644 --- a/internal/logic/couponusers/couponUsers.go +++ b/internal/logic/couponusers/couponUsers.go @@ -254,12 +254,12 @@ func (s *sCouponUsers) InsertJwcodesToRedisByExcel(file multipart.File) (err err } // 判断jwcode是否在表coupon_qualified_users中 - count, err := g.DB().Model(ctx, "coupon_qualified_users").Where("jwcode = ?", jwcode).Count() + count, err := dao.CouponQualifiedUsers.Ctx(ctx).Where("jwcode = ?", jwcode).Count() if err != nil { return errors.New("检索数据库中是否已存在数据失败") } if count == 0 { //不存在,插入 - _, err = g.DB().Model(ctx, "coupon_qualified_users").Insert(g.Map{ + _, err = dao.CouponQualifiedUsers.Ctx(ctx).Insert(g.Map{ "jwcode": jwcode, }) } @@ -274,19 +274,18 @@ func (s *sCouponUsers) InsertJwcodesToRedisByExcel(file multipart.File) (err err // 判断某用户能否抽到卡券 func (s *sCouponUsers) IsEligibleUser(ctx context.Context, jwcode int, couponIds []int) (img string, err error) { //从数据库中获取符合条件的精网号EligibleJwcodes - var EligibleJwcodes []int - err = g.DB().Model(ctx, "coupon_qualified_users").Fields("jwcode").Scan(&EligibleJwcodes) + var EligibleJwcodes []couponusers.InsertCouponUserRes + err = dao.CouponQualifiedUsers.Ctx(ctx).Fields("jwcode").Scan(&EligibleJwcodes) if err != nil { return "", errors.New("从数据库中获取符合条件的精网号失败") } if len(EligibleJwcodes) == 0 { return "", errors.New("核验数据库(满足条件)中数据为空") } - /*从redis中获取符合条件的精网号EligibleJwcodes*/ //检查jwcode是否在EligibleJwcodes中 for _, EligibleJwcode := range EligibleJwcodes { - if EligibleJwcode == jwcode { + if EligibleJwcode.Jwcode == jwcode { //存在,有资格,判断是否抽取过 for _, couponId := range couponIds { count, err := dao.CouponUsers.Ctx(ctx).Where("jwcode = ?", jwcode).Where("coupon_id = ?", couponId).Count() @@ -322,8 +321,8 @@ func (s *sCouponUsers) IssueCouponToUser(ctx context.Context, jwcode, couponId i //不存在 查看是否满足条件,满足就添加,不满足就返回 //从数据库中获取符合条件的精网号EligibleJwcodes - var EligibleJwcodes []int - err = g.DB().Model(ctx, "coupon_qualified_users").Fields("jwcode").Scan(&EligibleJwcodes) + var EligibleJwcodes []couponusers.InsertCouponUserRes + err = dao.CouponQualifiedUsers.Ctx(ctx).Fields("jwcode").Scan(&EligibleJwcodes) if err != nil { return errors.New("从数据库中获取符合条件的精网号失败") } @@ -333,7 +332,7 @@ func (s *sCouponUsers) IssueCouponToUser(ctx context.Context, jwcode, couponId i //检查jwcode是否在EligibleJwcodes中 for _, EligibleJwcode := range EligibleJwcodes { - if EligibleJwcode == jwcode { + if EligibleJwcode.Jwcode == jwcode { //存在,可以插入 _, err := dao.CouponUsers.Ctx(ctx).Insert(g.Map{ "jwcode": jwcode, diff --git a/internal/model/do/coupon_qualified_users.go b/internal/model/do/coupon_qualified_users.go new file mode 100644 index 0000000..cf7dec6 --- /dev/null +++ b/internal/model/do/coupon_qualified_users.go @@ -0,0 +1,16 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package do + +import ( + "github.com/gogf/gf/v2/frame/g" +) + +// CouponQualifiedUsers is the golang structure of table coupon_qualified_users for DAO operations like Where/Data. +type CouponQualifiedUsers struct { + g.Meta `orm:"table:coupon_qualified_users, do:true"` + Id interface{} // + Jwcode interface{} // +} diff --git a/internal/model/entity/coupon_qualified_users.go b/internal/model/entity/coupon_qualified_users.go new file mode 100644 index 0000000..2e37dc1 --- /dev/null +++ b/internal/model/entity/coupon_qualified_users.go @@ -0,0 +1,11 @@ +// ================================================================================= +// Code generated and maintained by GoFrame CLI tool. DO NOT EDIT. +// ================================================================================= + +package entity + +// CouponQualifiedUsers is the golang structure for table coupon_qualified_users. +type CouponQualifiedUsers struct { + Id uint `json:"id" orm:"id" description:""` // + Jwcode int `json:"jwcode" orm:"jwcode" description:""` // +}