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