Browse Source

Merge remote-tracking branch 'origin/master'

master
dengbiao 7 months ago
parent
commit
13904817c0
4 changed files with 84 additions and 13 deletions
  1. +13
    -2
      rule/consume_integral_settlement.go
  2. +1
    -0
      rule/micro_applications/happy_orchard_user_seed_record.go
  3. +65
    -10
      rule/micro_applications/happy_orchard_user_waters.go
  4. +5
    -1
      rule/micro_applications/md/happy_orchard.go

+ 13
- 2
rule/consume_integral_settlement.go View File

@@ -371,8 +371,13 @@ func DealUserConsumeIntegral(session *xorm.Session, subsidyWithUser *model.Subsi
afterAmount = 0
subsidyWithUser.State = 3 //补贴完
}
balanceAmount1, _ := decimal.NewFromString(subsidyWithUser.BalanceAmount)
afterAmount1, _ := balanceAmount1.Sub(decimal.NewFromFloat(consumeIntegralValue)).Float64()
if afterAmount1 <= 0 {
}
subsidyWithUser.BalanceAmount = zhios_order_relate_utils.Float64ToStr(afterAmount1)
subsidyWithUser.LeaveDay = afterAmount
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "leave_day", "state")
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "leave_day", "state", "balance_amount")
if err != nil {
return err
}
@@ -450,8 +455,14 @@ func DealUserExperienceIntegral(session *xorm.Session, subsidyWithUser *model.Su
afterAmount = 0
subsidyWithUser.State = 3 //补贴完
}
balanceAmount1, _ := decimal.NewFromString(subsidyWithUser.BalanceAmount)
afterAmount1, _ := balanceAmount1.Sub(decimal.NewFromFloat(experienceIntegralValue)).Float64()
if afterAmount1 <= 0 {
}
subsidyWithUser.BalanceAmount = zhios_order_relate_utils.Float64ToStr(afterAmount1)

subsidyWithUser.LeaveDay = afterAmount
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "leave_day", "state")
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "leave_day", "state", "balance_amount")
if err != nil {
return err
}


+ 1
- 0
rule/micro_applications/happy_orchard_user_seed_record.go View File

@@ -50,6 +50,7 @@ func GetHappyOrchardUserSeedRecordData(engine *xorm.Engine, record models.HappyO
resp.RecordPlantingNextStage = resp.RecordPlantingStage + 1
resp.RecordPlantingNextStageZh = stageNameCustomData[resp.RecordPlantingNextStage]
resp.RecordPlantingNextStageNeedWaterNums = nextSeedStateWaters / happyOrchardBasicSetting.WateringEveryTimeWaterDroplet
resp.RecordPlantingNextStageNeedWater = nextSeedStateWaters
}
resp.RecordId = record.Id
resp.RecordName = happyOrchardSeed.Name


+ 65
- 10
rule/micro_applications/happy_orchard_user_waters.go View File

@@ -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
}

+ 5
- 1
rule/micro_applications/md/happy_orchard.go View File

@@ -36,13 +36,17 @@ type GetHappyOrchardUserSeedRecordDataResp struct {
RecordPlantingNextStage int `json:"record_planting_next_stage"` //种子种植下一阶段
RecordPlantingNextStageZh string `json:"record_planting_next_stage_zh"`
RecordPlantingNextStageNeedWaterNums int `json:"record_planting_next_stage_need_water_nums"` //种子种植下一阶段需浇水次数
RecordPlantingNextStageNeedWater int `json:"record_planting_next_stage_need_water"` //种子种植下一阶段水滴数
NowRecordWaters int `json:"now_record_waters"` //当前种子水滴数
TotalNeedWaters int `json:"total_need_waters"` //总计需要水滴数
PlantingRate float64 `json:"planting_rate"` //种植进度百分比
}

type DealUserWatersKindForWateringReq struct {
Uid int `json:"uid"` //用户id
Uid int `json:"uid"` //用户id
KindType string `json:"kind_type"`
Kind int `json:"kind"`
RewardWatersValue int `json:"reward_waters_value"`
}
type DealUserWatersKindForSevenDaysSignReq struct {
Uid int `json:"uid"` //用户id


Loading…
Cancel
Save