|
@ -127,9 +127,9 @@ func (s *sCouponUsers) InsertJwcodeByExcel(file multipart.File) (jwcodes []int, |
|
|
return nil, errors.New("没有工作表") |
|
|
return nil, errors.New("没有工作表") |
|
|
} |
|
|
} |
|
|
// 读取第一个工作表
|
|
|
// 读取第一个工作表
|
|
|
sheetName := GetSheetMap[1] |
|
|
|
|
|
|
|
|
//sheetName := GetSheetMap[1]
|
|
|
//rows, err := f.GetRows(f.GetSheetName(1))
|
|
|
//rows, err := f.GetRows(f.GetSheetName(1))
|
|
|
rows, err := f.GetRows(sheetName) |
|
|
|
|
|
|
|
|
rows, err := f.GetRows("Sheet1") |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
@ -222,10 +222,11 @@ func (s *sCouponUsers) InsertJwcodesToRedisByExcel(file multipart.File) (err err |
|
|
if len(GetSheetMap) == 0 { |
|
|
if len(GetSheetMap) == 0 { |
|
|
return errors.New("没有工作表") |
|
|
return errors.New("没有工作表") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 读取第一个工作表
|
|
|
// 读取第一个工作表
|
|
|
sheetName := GetSheetMap[1] |
|
|
|
|
|
|
|
|
//sheetName := GetSheetMap[1]
|
|
|
//rows, err := f.GetRows(f.GetSheetName(1))
|
|
|
//rows, err := f.GetRows(f.GetSheetName(1))
|
|
|
rows, err := f.GetRows(sheetName) |
|
|
|
|
|
|
|
|
rows, err := f.GetRows("Sheet1") |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
@ -267,6 +268,46 @@ func (s *sCouponUsers) InsertJwcodesToRedisByExcel(file multipart.File) (err err |
|
|
return //返回nil表示成功
|
|
|
return //返回nil表示成功
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 判断某用户能否抽到卡券
|
|
|
|
|
|
func (s *sCouponUsers) IsEligibleUser(ctx context.Context, jwcode int, couponIds []int) (img string, err error) { |
|
|
|
|
|
/*从redis中获取符合条件的精网号EligibleJwcodes*/ |
|
|
|
|
|
redisResult, err := g.Redis().Get(ctx, "EligibleJwcodes") |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return "", errors.New("从redis中获取数据失败") |
|
|
|
|
|
} |
|
|
|
|
|
var EligibleJwcodes []int |
|
|
|
|
|
err = json.Unmarshal(redisResult.Bytes(), &EligibleJwcodes) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return "", errors.New("redis中数据解析失败") |
|
|
|
|
|
} |
|
|
|
|
|
if len(EligibleJwcodes) == 0 { |
|
|
|
|
|
return "", errors.New("redis中数据为空") |
|
|
|
|
|
} |
|
|
|
|
|
/*从redis中获取符合条件的精网号EligibleJwcodes*/ |
|
|
|
|
|
|
|
|
|
|
|
//检查jwcode是否在EligibleJwcodes中
|
|
|
|
|
|
for _, EligibleJwcode := range EligibleJwcodes { |
|
|
|
|
|
if EligibleJwcode == jwcode { |
|
|
|
|
|
//存在,有资格,判断是否抽取过
|
|
|
|
|
|
for _, couponId := range couponIds { |
|
|
|
|
|
count, err := dao.CouponUsers.Ctx(ctx).Where("jwcode = ?", jwcode).Where("coupon_id = ?", couponId).Count() |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return "", errors.New("检索数据库中是否已存在数据失败") |
|
|
|
|
|
} |
|
|
|
|
|
//有记录,抽取过
|
|
|
|
|
|
if count > 0 { |
|
|
|
|
|
err = dao.CouponUsers.Ctx(ctx).Fields("img_url").Where("jwcode = ?", jwcode).Where("coupon_id = ?", couponId).Scan(&img) |
|
|
|
|
|
return img, errors.New("该用户已领取过该卡券") |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//所有的都没有记录,没有抽取过
|
|
|
|
|
|
return "", nil |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return "", errors.New("该用户不满足领取条件") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 给单个用户发放卡券
|
|
|
// 给单个用户发放卡券
|
|
|
func (s *sCouponUsers) IssueCouponToUser(ctx context.Context, jwcode, couponId int) (err error) { |
|
|
func (s *sCouponUsers) IssueCouponToUser(ctx context.Context, jwcode, couponId int) (err error) { |
|
|
//查看库中是否已经存在
|
|
|
//查看库中是否已经存在
|
|
@ -290,6 +331,9 @@ func (s *sCouponUsers) IssueCouponToUser(ctx context.Context, jwcode, couponId i |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return errors.New("redis中数据解析失败") |
|
|
return errors.New("redis中数据解析失败") |
|
|
} |
|
|
} |
|
|
|
|
|
if len(EligibleJwcodes) == 0 { |
|
|
|
|
|
return errors.New("redis中数据为空") |
|
|
|
|
|
} |
|
|
/*从redis中获取符合条件的精网号EligibleJwcodes*/ |
|
|
/*从redis中获取符合条件的精网号EligibleJwcodes*/ |
|
|
|
|
|
|
|
|
//检查jwcode是否在EligibleJwcodes中
|
|
|
//检查jwcode是否在EligibleJwcodes中
|
|
|