|
@@ -5,13 +5,10 @@ import ( |
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db" |
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db" |
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" |
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" |
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" |
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" |
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule" |
|
|
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/enum" |
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/enum" |
|
|
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/md" |
|
|
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/md" |
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/svc" |
|
|
|
|
|
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" |
|
|
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" |
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/cache" |
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/cache" |
|
|
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" |
|
|
|
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
"errors" |
|
|
"errors" |
|
|
"fmt" |
|
|
"fmt" |
|
@@ -75,17 +72,18 @@ func SettlementSignInGreenEnergy(engine *xorm.Engine, masterId string, ch *rabbi |
|
|
|
|
|
|
|
|
func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine, masterId string, id int64, uid int, endTime string) (err error) { |
|
|
func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine, masterId string, id int64, uid int, endTime string) (err error) { |
|
|
//1、查找 `one_circles_green_energy_basic_setting` 基础设置 |
|
|
//1、查找 `one_circles_green_energy_basic_setting` 基础设置 |
|
|
//oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ |
|
|
|
|
|
// "key": "is_open", |
|
|
|
|
|
// "value": 1, |
|
|
|
|
|
//}) |
|
|
|
|
|
oneCirclesGreenEnergyBasicSetting, cb, err := svc.GetPrice(engine, masterId) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
if cb != nil { |
|
|
|
|
|
defer cb() // 释放锁 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//oneCirclesGreenEnergyBasicSetting, cb, err := svc.GetPrice(engine, masterId) |
|
|
|
|
|
//if err != nil { |
|
|
|
|
|
// return |
|
|
|
|
|
//} |
|
|
|
|
|
//if cb != nil { |
|
|
|
|
|
// defer cb() // 释放锁 |
|
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
|
|
oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ |
|
|
|
|
|
"key": "is_open", |
|
|
|
|
|
"value": 1, |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
var teamRewardSetting *md2.TeamRewardSettingStruct |
|
|
var teamRewardSetting *md2.TeamRewardSettingStruct |
|
|
err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.TeamReward), &teamRewardSetting) |
|
|
err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.TeamReward), &teamRewardSetting) |
|
@@ -110,18 +108,10 @@ func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine, |
|
|
rewardValue := zhios_order_relate_utils.Float64ToStrPrec8(zhios_order_relate_utils.StrToFloat64(reward) * float64(oneRoundDuration) * 60 * 60) |
|
|
rewardValue := zhios_order_relate_utils.Float64ToStrPrec8(zhios_order_relate_utils.StrToFloat64(reward) * float64(oneRoundDuration) * 60 * 60) |
|
|
|
|
|
|
|
|
//3、统计签到结束的用户数据 |
|
|
//3、统计签到结束的用户数据 |
|
|
session := engine.NewSession() |
|
|
|
|
|
defer func() { |
|
|
|
|
|
session.Close() |
|
|
|
|
|
if err := recover(); err != nil { |
|
|
|
|
|
_ = zhios_order_relate_logx.Error(err) |
|
|
|
|
|
} |
|
|
|
|
|
}() |
|
|
|
|
|
session.Begin() |
|
|
|
|
|
|
|
|
|
|
|
var reduceTotalGreenEnergy float64 |
|
|
var reduceTotalGreenEnergy float64 |
|
|
//4.2给相应的用户加上个人的绿色积分(可用数量) |
|
|
//4.2给相应的用户加上个人的绿色积分(可用数量) |
|
|
err = rule.DealUserCoin(session, md.DealUserCoinReq{ |
|
|
|
|
|
|
|
|
var oneCirclesDealUserCoinData = md.OneCirclesDealUserCoinStruct{ |
|
|
Kind: "add", |
|
|
Kind: "add", |
|
|
Mid: masterId, |
|
|
Mid: masterId, |
|
|
Title: md.OneCirclesGreenEnergySignInSettlementPersonalReward, |
|
|
Title: md.OneCirclesGreenEnergySignInSettlementPersonalReward, |
|
@@ -130,21 +120,16 @@ func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine, |
|
|
CoinId: oneCirclesGreenEnergyBasicSetting.PersonGreenEnergyCoinId, |
|
|
CoinId: oneCirclesGreenEnergyBasicSetting.PersonGreenEnergyCoinId, |
|
|
Uid: uid, |
|
|
Uid: uid, |
|
|
Amount: zhios_order_relate_utils.StrToFloat64(rewardValue), |
|
|
Amount: zhios_order_relate_utils.StrToFloat64(rewardValue), |
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
fmt.Println("err:::::2222", err) |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
} |
|
|
reduceTotalGreenEnergy += zhios_order_relate_utils.StrToFloat64(rewardValue) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reduceTotalGreenEnergy += zhios_order_relate_utils.StrToFloat64(rewardValue) |
|
|
//4.2给相应的上级用户加上团队奖励的绿色积分(结算数量) |
|
|
//4.2给相应的上级用户加上团队奖励的绿色积分(结算数量) |
|
|
relates, err1 := db.DbsUserRelate(engine, uid, 0) |
|
|
relates, err1 := db.DbsUserRelate(engine, uid, 0) |
|
|
if err1 != nil { |
|
|
if err1 != nil { |
|
|
_ = session.Rollback() |
|
|
|
|
|
fmt.Println("err:::::3333", err1) |
|
|
fmt.Println("err:::::3333", err1) |
|
|
return err1 |
|
|
return err1 |
|
|
} |
|
|
} |
|
|
|
|
|
var oneCirclesDealUserCoinDataForParents []md.OneCirclesDealUserCoinStruct |
|
|
var parentRewardValue = zhios_order_relate_utils.StrToFloat64(rewardValue) |
|
|
var parentRewardValue = zhios_order_relate_utils.StrToFloat64(rewardValue) |
|
|
if relates != nil { |
|
|
if relates != nil { |
|
|
for _, relate := range *relates { |
|
|
for _, relate := range *relates { |
|
@@ -157,7 +142,6 @@ func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine, |
|
|
if endTime != "" { |
|
|
if endTime != "" { |
|
|
has, err3333333 := engine.Where("uid =?", relate.ParentUid).And("end_time >=?", endTime).Get(&m) |
|
|
has, err3333333 := engine.Where("uid =?", relate.ParentUid).And("end_time >=?", endTime).Get(&m) |
|
|
if err3333333 != nil { |
|
|
if err3333333 != nil { |
|
|
_ = session.Rollback() |
|
|
|
|
|
fmt.Println("err:::::3333333", err3333333) |
|
|
fmt.Println("err:::::3333333", err3333333) |
|
|
return err3333333 |
|
|
return err3333333 |
|
|
} |
|
|
} |
|
@@ -168,7 +152,6 @@ func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine, |
|
|
} else { |
|
|
} else { |
|
|
has, err3333333 := engine.Where("uid =?", relate.ParentUid).And("end_time >=?", time.Now().Format("2006-01-02 15:04:05")).Get(&m) |
|
|
has, err3333333 := engine.Where("uid =?", relate.ParentUid).And("end_time >=?", time.Now().Format("2006-01-02 15:04:05")).Get(&m) |
|
|
if err3333333 != nil { |
|
|
if err3333333 != nil { |
|
|
_ = session.Rollback() |
|
|
|
|
|
fmt.Println("err:::::3333333", err3333333) |
|
|
fmt.Println("err:::::3333333", err3333333) |
|
|
return err3333333 |
|
|
return err3333333 |
|
|
} |
|
|
} |
|
@@ -178,7 +161,7 @@ func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine, |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
err = rule.DealUserCoin(session, md.DealUserCoinReq{ |
|
|
|
|
|
|
|
|
oneCirclesDealUserCoinDataForParents = append(oneCirclesDealUserCoinDataForParents, md.OneCirclesDealUserCoinStruct{ |
|
|
Kind: "add", |
|
|
Kind: "add", |
|
|
Mid: masterId, |
|
|
Mid: masterId, |
|
|
Title: md.OneCirclesGreenEnergySignInSettlementTeamReward, |
|
|
Title: md.OneCirclesGreenEnergySignInSettlementTeamReward, |
|
@@ -188,40 +171,32 @@ func HandleSettlementSignInGreenEnergy(ch *rabbit.Channel, engine *xorm.Engine, |
|
|
Uid: relate.ParentUid, |
|
|
Uid: relate.ParentUid, |
|
|
Amount: parentRewardValue, |
|
|
Amount: parentRewardValue, |
|
|
}) |
|
|
}) |
|
|
if err != nil { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
fmt.Println("err:::::44444", err) |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
reduceTotalGreenEnergy += parentRewardValue |
|
|
reduceTotalGreenEnergy += parentRewardValue |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//5、减少“活跃赠送” 中的绿色能量 |
|
|
//5、减少“活跃赠送” 中的绿色能量 |
|
|
if reduceTotalGreenEnergy > 0 { |
|
|
if reduceTotalGreenEnergy > 0 { |
|
|
err = DealAvailableGreenEnergyCoin(session, int(enum.SignInReward), reduceTotalGreenEnergy, 0, enum.SignInReward.String(), oneCirclesGreenEnergyBasicSetting, oneCirclesGreenEnergyBasicSetting.NowPrice, masterId) |
|
|
|
|
|
//err = DealAvailableGreenEnergyCoin(session, int(enum.SignInReward), reduceTotalGreenEnergy, 0, enum.SignInReward.String(), nil, "", masterId) |
|
|
|
|
|
|
|
|
err = DealAvailableGreenEnergyCoin(engine.NewSession(), int(enum.SignInReward), reduceTotalGreenEnergy, 0, enum.SignInReward.String(), oneCirclesGreenEnergyBasicSetting, oneCirclesGreenEnergyBasicSetting.NowPrice, masterId) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
_ = session.Rollback() |
|
|
|
|
|
fmt.Println("err:::::55555", err) |
|
|
fmt.Println("err:::::55555", err) |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//6、更新 `one_circles_green_energy_sign_in` 中的 is_completed 状态 |
|
|
//6、更新 `one_circles_green_energy_sign_in` 中的 is_completed 状态 |
|
|
//_, err = session.Where("id = ?", id).Update(&model.OneCirclesGreenEnergySignIn{ |
|
|
|
|
|
// IsCompleted: 1, |
|
|
|
|
|
//}) |
|
|
|
|
|
//TODO::推入rabbitmq 异步处理 |
|
|
|
|
|
ch.Publish(md.OneCirclesExchange, md.UpdateOneCirclesStructForSignInRecords{ |
|
|
|
|
|
Uid: uid, |
|
|
|
|
|
Id: id, |
|
|
|
|
|
}, md.OneCirclesRoutKeyForSignInUpdateRecords) |
|
|
|
|
|
|
|
|
|
|
|
err = session.Commit() |
|
|
|
|
|
|
|
|
_, err = engine.Where("id = ?", id).Update(&model.OneCirclesGreenEnergySignIn{ |
|
|
|
|
|
IsCompleted: 1, |
|
|
|
|
|
}) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
_ = session.Rollback() |
|
|
|
|
|
return errors.New("事务提交失败") |
|
|
|
|
|
|
|
|
fmt.Println("err:::::66666", err) |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
////TODO::推入rabbitmq 异步处理 |
|
|
|
|
|
ch.Publish(md.OneCirclesExchange, oneCirclesDealUserCoinData, md.OneCirclesRoutKeyForRewardUserCoin) //个人的奖励 |
|
|
|
|
|
for _, oneCirclesDealUserCoinDataForParent := range oneCirclesDealUserCoinDataForParents { |
|
|
|
|
|
ch.Publish(md.OneCirclesExchange, oneCirclesDealUserCoinDataForParent, md.OneCirclesRoutKeyForRewardUserCoin) //上级的奖励 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return |
|
|
return |
|
|