|
|
@@ -146,7 +146,6 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func handelWatering(engine *xorm.Engine, req md.DealUserWatersKindForWateringReq, basicSetting models.HappyOrchardBasicSetting) (err error) { |
|
|
|
session := engine.NewSession() |
|
|
|
session.Begin() |
|
|
@@ -156,22 +155,17 @@ func handelWatering(engine *xorm.Engine, req md.DealUserWatersKindForWateringReq |
|
|
|
_ = zhios_order_relate_logx.Error(err) |
|
|
|
} |
|
|
|
}() |
|
|
|
err = CommWatering(engine, session, req, basicSetting) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return |
|
|
|
} |
|
|
|
return session.Commit() |
|
|
|
} |
|
|
|
func CommWatering(engine *xorm.Engine, session *xorm.Session, req md.DealUserWatersKindForWateringReq, basicSetting models.HappyOrchardBasicSetting) (err error) { |
|
|
|
now := time.Now() |
|
|
|
|
|
|
|
//1、查找 happy_orchard_user_waters 数据 |
|
|
|
happyOrchardUserWatersSess := implement.NewHappyOrchardUserWatersSess(session) |
|
|
|
happyOrchardUserWaters, err := happyOrchardUserWatersSess.GetHappyOrchardUserWatersSess(req.Uid) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return |
|
|
|
} |
|
|
|
if happyOrchardUserWaters == nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return errors.New("用户数据不存在") |
|
|
|
} |
|
|
|
|
|
|
@@ -179,14 +173,17 @@ func CommWatering(engine *xorm.Engine, session *xorm.Session, req md.DealUserWat |
|
|
|
beforeWaterNums := happyOrchardUserWaters.WaterNums |
|
|
|
happyOrchardUserWaters.WaterNums -= basicSetting.WateringEveryTimeWaterDroplet |
|
|
|
if happyOrchardUserWaters.WaterNums < 0 { |
|
|
|
_ = session.Rollback() |
|
|
|
return errors.New("用户水滴不够") |
|
|
|
} |
|
|
|
|
|
|
|
//3、更新 happy_orchard_user_waters 数据 |
|
|
|
_, err = happyOrchardUserWatersSess.UpdateHappyOrchardUserWatersBySess(req.Uid, happyOrchardUserWaters, "water_nums") |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
//4、新增 happy_orchard_user_waters_log 数据 |
|
|
|
happyOrchardUserWatersLogDb := implement.NewHappyOrchardUserWatersLogDb(engine) |
|
|
|
_, err = happyOrchardUserWatersLogDb.InsertHappyOrchardUserWatersLogBySess(session, &models.HappyOrchardUserWatersLog{ |
|
|
@@ -200,9 +197,11 @@ func CommWatering(engine *xorm.Engine, session *xorm.Session, req md.DealUserWat |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return err |
|
|
|
} |
|
|
|
return nil |
|
|
|
|
|
|
|
return session.Commit() |
|
|
|
} |
|
|
|
|
|
|
|
func handelSevenDaysSign(engine *xorm.Engine, req md.DealUserWatersKindForSevenDaysSignReq, basicSetting models.HappyOrchardBasicSetting) (err error) { |
|
|
@@ -910,3 +909,59 @@ func generateRandomInt(min, max int) int { |
|
|
|
rand.Seed(time.Now().UnixNano()) // 初始化随机种子 |
|
|
|
return rand.Intn(max-min+1) + min // 生成[min,max]范围内的随机整数 |
|
|
|
} |
|
|
|
func CommWatering(engine *xorm.Engine, session *xorm.Session, req md.DealUserWatersKindForWateringReq) (err error) { |
|
|
|
now := time.Now() |
|
|
|
//1、查找 happy_orchard_user_waters 数据 |
|
|
|
happyOrchardUserWatersSess := implement.NewHappyOrchardUserWatersSess(session) |
|
|
|
happyOrchardUserWaters, err := happyOrchardUserWatersSess.GetHappyOrchardUserWatersSess(req.Uid) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
if happyOrchardUserWaters == nil { |
|
|
|
if req.Kind == 1 { |
|
|
|
happyOrchardUserWaters = &models.HappyOrchardUserWaters{ |
|
|
|
Uid: req.Uid, |
|
|
|
CreateAt: time.Now().Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: time.Now().Format("2006-01-02 15:04:05"), |
|
|
|
} |
|
|
|
_, err = session.Insert(happyOrchardUserWaters) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
} else { |
|
|
|
return errors.New("用户数据不存在") |
|
|
|
} |
|
|
|
} |
|
|
|
//2、判断用户水滴是否足够 |
|
|
|
beforeWaterNums := happyOrchardUserWaters.WaterNums |
|
|
|
if req.Kind == 1 { |
|
|
|
happyOrchardUserWaters.WaterNums += req.RewardWatersValue |
|
|
|
} else { |
|
|
|
happyOrchardUserWaters.WaterNums -= req.RewardWatersValue |
|
|
|
if happyOrchardUserWaters.WaterNums < 0 { |
|
|
|
return errors.New("用户水滴不够") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//3、更新 happy_orchard_user_waters 数据 |
|
|
|
_, err = happyOrchardUserWatersSess.UpdateHappyOrchardUserWatersBySess(req.Uid, happyOrchardUserWaters, "water_nums") |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
//4、新增 happy_orchard_user_waters_log 数据 |
|
|
|
happyOrchardUserWatersLogDb := implement.NewHappyOrchardUserWatersLogDb(engine) |
|
|
|
_, err = happyOrchardUserWatersLogDb.InsertHappyOrchardUserWatersLogBySess(session, &models.HappyOrchardUserWatersLog{ |
|
|
|
Uid: req.Uid, |
|
|
|
WaterNums: req.RewardWatersValue, |
|
|
|
Title: enum.DealUserWatersKind(req.KindType).String(), |
|
|
|
Kind: req.Kind, |
|
|
|
BeforeWaterNums: beforeWaterNums, |
|
|
|
AfterWaterNums: happyOrchardUserWaters.WaterNums, |
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |