From f5f06603002b3f3570e58b922a1d8a2bb2f50e03 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Wed, 22 May 2024 16:29:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../happy_orchard_user_waters.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/rule/micro_applications/happy_orchard_user_waters.go b/rule/micro_applications/happy_orchard_user_waters.go index 69746ed..69625cd 100644 --- a/rule/micro_applications/happy_orchard_user_waters.go +++ b/rule/micro_applications/happy_orchard_user_waters.go @@ -156,17 +156,22 @@ 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("用户数据不存在") } @@ -174,17 +179,14 @@ func handelWatering(engine *xorm.Engine, req md.DealUserWatersKindForWateringReq 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{ @@ -198,11 +200,9 @@ func handelWatering(engine *xorm.Engine, req md.DealUserWatersKindForWateringReq UpdateAt: now.Format("2006-01-02 15:04:05"), }) if err != nil { - _ = session.Rollback() return err } - - return session.Commit() + return nil } func handelSevenDaysSign(engine *xorm.Engine, req md.DealUserWatersKindForSevenDaysSignReq, basicSetting models.HappyOrchardBasicSetting) (err error) {