From eab70a7103c6f16091b99302637142622c8ba071 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Tue, 21 May 2024 20:35:55 +0800 Subject: [PATCH] update --- .../happy_orchard_reward_exchange_records.go | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 rule/micro_applications/happy_orchard_reward_exchange_records.go diff --git a/rule/micro_applications/happy_orchard_reward_exchange_records.go b/rule/micro_applications/happy_orchard_reward_exchange_records.go new file mode 100644 index 0000000..d58b677 --- /dev/null +++ b/rule/micro_applications/happy_orchard_reward_exchange_records.go @@ -0,0 +1,74 @@ +package micro_applications + +import ( + enum2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/micro_applications/enum" + "code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/implement" + "code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/models" + "errors" + "time" + "xorm.io/xorm" +) + +//HappyOrchardUserSeedExchangeReward 用户种子兑换礼品 +//TODO::调用此方法前注意开启session、关闭session 会话 +func HappyOrchardUserSeedExchangeReward(session *xorm.Session, records models.HappyOrchardUserSeedRecord, rewardId int, masterId string) error { + now := time.Now() + + //1、获取奖品数据 、 种子数据 + db := implement.NewHappyOrchardRewardDb(session.Engine()) + happyOrchardReward, err := db.GetHappyOrchardReward(rewardId) + if err != nil { + return err + } + if happyOrchardReward == nil { + return errors.New("未查询到奖品记录") + } + + seedDb := implement.NewHappyOrchardSeedDb(session.Engine()) + seed, err := seedDb.GetHappyOrchardSeed(records.SeedId) + if err != nil { + return err + } + if seed == nil { + return errors.New("未查询到种子记录") + } + + //2、新增 happy_orchard_reward_exchange_records 记录 + happyOrchardRewardExchangeRecordsDb := implement.NewHappyOrchardRewardExchangeRecordsDb(nil) + happyOrchardRewardExchangeRecords := models.HappyOrchardRewardExchangeRecords{ + Uid: records.Uid, + RewardId: happyOrchardReward.Id, + RewardName: happyOrchardReward.Name, + RewardKind: happyOrchardReward.Kind, + SeedId: records.SeedId, + SeedName: seed.Name, + WaterNums: seed.WaterNums, + State: 1, + RecordId: records.Id, + LogisticCompany: "", + LogisticCompanyCode: "", + LogisticNum: "", + DeliveryAt: "", + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + } + _, err = happyOrchardRewardExchangeRecordsDb.InsertHappyOrchardRewardExchangeRecordsBySess(session, &happyOrchardRewardExchangeRecords) + if err != nil { + return err + } + + //3、判断奖品类型 && 是否为自动发放 + if happyOrchardRewardExchangeRecords.RewardKind == int(enum2.RewardKindForVirtual) { + err = HappyOrchardGiveIntegral(session, happyOrchardRewardExchangeRecords, masterId) + if err != nil { + return err + } + happyOrchardRewardExchangeRecords.State = 2 + _, err = happyOrchardRewardExchangeRecordsDb.UpdateHappyOrchardRewardExchangeRecordsBySess(session, &happyOrchardRewardExchangeRecords, "state") + if err != nil { + return err + } + } + + return nil +}