Commit 0ad91afc authored by hujiebin's avatar hujiebin

feat: 处理并发

parent 898a0b58
......@@ -22,6 +22,12 @@ func (ub *UserNoble) UpdateEndTime(db *gorm.DB, endTime time.Time) (int64, error
return r.RowsAffected, r.Error
}
// 延长贵族
func (ub *UserNoble) ExtenedEndTime(db *gorm.DB, day int) (int64, error) {
r := db.Model(&UserNoble{}).Where(ub).Update("end_time", gorm.Expr("DATE_ADD(end_time,INTERVAL ? day)", day))
return r.RowsAffected, r.Error
}
// 查询用户未过期的贵族
func (ub *UserNoble) Find(db *gorm.DB) ([]UserNoble, error) {
rows := make([]UserNoble, 0)
......
......@@ -41,7 +41,7 @@ func ats32(a interface{}) string {
}
func main() {
url := "https://apiv2.faceline.live/v1/fruitMachine/rank/award?lang=zh-cn&pageIndex=1&pageSize=5000&beginDate=2023-08-30&endDate=2023-08-30&userCode=&timezone=1"
url := "https://apiv2.faceline.live/v1/fruitMachine/rank/award?lang=zh-cn&pageIndex=1&pageSize=5000&beginDate=2023-08-31&endDate=2023-08-31&userCode=&timezone=1"
method := "GET"
client := &http.Client{}
......@@ -95,7 +95,7 @@ func main() {
for _, v := range svips {
svipMap[v.Code] = v.Level
}
excelFileName := fmt.Sprintf("./0830水果机中奖榜.xlsx")
excelFileName := fmt.Sprintf("./0831水果机中奖榜.xlsx")
xlFile := xlsx.NewFile()
sheet, _ := xlFile.AddSheet("charge")
row := sheet.AddRow()
......
......@@ -21,7 +21,7 @@ func SendNoble(model *domain.Model, receiverUserId mysql.ID, level uint16, days
return fmt.Errorf("level is 0")
}
cfg, err := noble_m.GetConfigByLevel(model.Db, level)
cfg, err := noble_m.GetConfigByLevel(model.DB(), level)
if err != nil {
return err
}
......@@ -29,7 +29,7 @@ func SendNoble(model *domain.Model, receiverUserId mysql.ID, level uint16, days
return fmt.Errorf("level is 0")
}
n := noble_m.UserNoble{UserId: receiverUserId, Level: level}
records, err := n.FindAll(model.Db)
records, err := n.FindAll(model.DB())
if err != nil {
return err
}
......@@ -42,7 +42,7 @@ func SendNoble(model *domain.Model, receiverUserId mysql.ID, level uint16, days
// 新增贵族
endTime := time.Now().AddDate(0, 0, int(days))
n = noble_m.UserNoble{UserId: receiverUserId, Level: level, EndTime: endTime}
err = n.Create(model.Db)
err = n.Create(model.DB())
if err != nil {
return err
}
......@@ -55,7 +55,7 @@ func SendNoble(model *domain.Model, receiverUserId mysql.ID, level uint16, days
SrcType: noble_m.SRC_APP,
NewEndTime: endTime,
}
err = nbl.Create(model.Db)
err = nbl.Create(model.DB())
if err != nil {
return err
}
......@@ -71,12 +71,16 @@ func SendNoble(model *domain.Model, receiverUserId mysql.ID, level uint16, days
Entity: mysql.Entity{ID: n.ID, UpdatedTime: n.UpdatedTime},
}
af, err := nn.UpdateEndTime(model.Db, endTime)
af, err := nn.UpdateEndTime(model.DB(), endTime)
if err != nil {
return err
}
if af <= 0 {
return fmt.Errorf("bizerr.TransactionFailed")
if af2, err := nn.ExtenedEndTime(model.DB(), days); err != nil {
return err
} else if af2 <= 0 {
return fmt.Errorf("bizerr.TransactionFailed rows 0")
}
}
nbl := noble_m.UserNobleLog{
......@@ -88,7 +92,7 @@ func SendNoble(model *domain.Model, receiverUserId mysql.ID, level uint16, days
OldEndTime: n.EndTime,
NewEndTime: endTime,
}
err = nbl.Create(model.Db)
err = nbl.Create(model.DB())
if err != nil {
return err
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment