|
|
@@ -1,6 +1,7 @@ |
|
|
|
package one_circles |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" |
|
|
|
"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/md" |
|
|
@@ -12,12 +13,55 @@ import ( |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"github.com/shopspring/decimal" |
|
|
|
"math/rand" |
|
|
|
"time" |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
// SettlementSignInGreenEnergy 计算签到得到绿色能量 |
|
|
|
func SettlementSignInGreenEnergy(engine *xorm.Engine, masterId string) (err error) { |
|
|
|
func SettlementSignInGreenEnergy(engine *xorm.Engine, masterId string, ch *rabbit.Channel) (err error) { |
|
|
|
defer ch.Release() |
|
|
|
//1、查找 `one_circles_green_energy_basic_setting` 基础设置 |
|
|
|
oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ |
|
|
|
"key": "is_open", |
|
|
|
"value": 1, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
if oneCirclesGreenEnergyBasicSetting == nil { |
|
|
|
return errors.New("开关未开!!") |
|
|
|
} |
|
|
|
//3、统计签到结束的用户数据 |
|
|
|
now := time.Now() |
|
|
|
var page = 1 |
|
|
|
var pageSize = 100 |
|
|
|
for { |
|
|
|
var list []model.OneCirclesGreenEnergySignIn |
|
|
|
err = engine.Where("end_time <= ?", now.Format("2006-01-02 15:04:05")).And("is_completed =?", 0).Limit(pageSize, (page-1)*pageSize).Asc("id").Find(&list) |
|
|
|
if err != nil { |
|
|
|
fmt.Println("err:::::1111", err) |
|
|
|
return |
|
|
|
} |
|
|
|
if len(list) <= 0 { |
|
|
|
break |
|
|
|
} |
|
|
|
|
|
|
|
for _, v := range list { |
|
|
|
//TODO::推入rabbitmq 异步处理 |
|
|
|
ch.Publish(md.OneCirclesExchange, md.OneCirclesStructForSignIn{ |
|
|
|
MasterId: masterId, |
|
|
|
Uid: v.Uid, |
|
|
|
Id: v.Id, |
|
|
|
}, md.OneCirclesRoutKeyForSignIn) |
|
|
|
} |
|
|
|
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) |
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func HandleSettlementSignInGreenEnergy(engine *xorm.Engine, masterId string, id int64, uid int) (err error) { |
|
|
|
//1、查找 `one_circles_green_energy_basic_setting` 基础设置 |
|
|
|
oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ |
|
|
|
"key": "is_open", |
|
|
@@ -49,15 +93,6 @@ func SettlementSignInGreenEnergy(engine *xorm.Engine, masterId string) (err erro |
|
|
|
rewardValue := zhios_order_relate_utils.Float64ToStrPrec8(zhios_order_relate_utils.StrToFloat64(reward) * float64(oneRoundDuration) * 60 * 60) |
|
|
|
|
|
|
|
//3、统计签到结束的用户数据 |
|
|
|
now := time.Now() |
|
|
|
startTime := now.Add(-time.Hour * time.Duration(oneRoundDuration)).Format("2006-01-02 15:04:05") |
|
|
|
var list []model.OneCirclesGreenEnergySignIn |
|
|
|
err = engine.Where("start_time <= ?", startTime).And("is_completed =?", 0).Find(&list) |
|
|
|
if err != nil { |
|
|
|
fmt.Println("err:::::1111", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
session := engine.NewSession() |
|
|
|
defer func() { |
|
|
|
session.Close() |
|
|
@@ -68,68 +103,66 @@ func SettlementSignInGreenEnergy(engine *xorm.Engine, masterId string) (err erro |
|
|
|
session.Begin() |
|
|
|
|
|
|
|
var reduceTotalGreenEnergy float64 |
|
|
|
for _, v := range list { |
|
|
|
//4.2给相应的用户加上个人的绿色积分(可用数量) |
|
|
|
err = DealUserCoin(session, md.DealUserCoinReq{ |
|
|
|
Kind: "add", |
|
|
|
Mid: masterId, |
|
|
|
Title: md.OneCirclesGreenEnergySignInSettlementPersonalReward, |
|
|
|
TransferType: md.OneCirclesGreenEnergySignInSettlementPersonalRewardForUserVirtualCoinFlow, |
|
|
|
OrdId: "", |
|
|
|
CoinId: oneCirclesGreenEnergyBasicSetting.PersonGreenEnergyCoinId, |
|
|
|
Uid: v.Uid, |
|
|
|
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) |
|
|
|
//4.2给相应的用户加上个人的绿色积分(可用数量) |
|
|
|
err = DealUserCoin(session, md.DealUserCoinReq{ |
|
|
|
Kind: "add", |
|
|
|
Mid: masterId, |
|
|
|
Title: md.OneCirclesGreenEnergySignInSettlementPersonalReward, |
|
|
|
TransferType: md.OneCirclesGreenEnergySignInSettlementPersonalRewardForUserVirtualCoinFlow, |
|
|
|
OrdId: "", |
|
|
|
CoinId: oneCirclesGreenEnergyBasicSetting.PersonGreenEnergyCoinId, |
|
|
|
Uid: uid, |
|
|
|
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) |
|
|
|
|
|
|
|
//4.2给相应的上级用户加上团队奖励的绿色积分(结算数量) |
|
|
|
relates, err1 := db.DbsUserRelate(engine, v.Uid, 0) |
|
|
|
if err1 != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
fmt.Println("err:::::3333", err1) |
|
|
|
return err1 |
|
|
|
} |
|
|
|
var parentRewardValue = zhios_order_relate_utils.StrToFloat64(rewardValue) |
|
|
|
if relates != nil { |
|
|
|
for _, relate := range *relates { |
|
|
|
if parentRewardValue <= rewardEndValue { |
|
|
|
break |
|
|
|
} |
|
|
|
parentRewardValue = parentRewardValue * rewardDecrement |
|
|
|
//TODO::判断是否活跃 |
|
|
|
var m model.OneCirclesGreenEnergySignIn |
|
|
|
has, err3333333 := engine.Where("uid =?", relate.ParentUid).And("start_time >=?", time.Now().Format("2006-01-02")+" 00:00:00").Get(&m) |
|
|
|
if err3333333 != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
fmt.Println("err:::::3333333", err3333333) |
|
|
|
return err3333333 |
|
|
|
} |
|
|
|
if !has { |
|
|
|
//不活跃不需要奖励 |
|
|
|
continue |
|
|
|
} |
|
|
|
err = DealUserCoin(session, md.DealUserCoinReq{ |
|
|
|
Kind: "add", |
|
|
|
Mid: masterId, |
|
|
|
Title: md.OneCirclesGreenEnergySignInSettlementTeamReward, |
|
|
|
TransferType: md.OneCirclesGreenEnergySignInSettlementTeamRewardForUserVirtualCoinFlow, |
|
|
|
OrdId: "", |
|
|
|
CoinId: oneCirclesGreenEnergyBasicSetting.TeamGreenEnergyCoinId, |
|
|
|
Uid: relate.ParentUid, |
|
|
|
Amount: parentRewardValue, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
fmt.Println("err:::::44444", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
reduceTotalGreenEnergy += parentRewardValue |
|
|
|
//4.2给相应的上级用户加上团队奖励的绿色积分(结算数量) |
|
|
|
relates, err1 := db.DbsUserRelate(engine, uid, 0) |
|
|
|
if err1 != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
fmt.Println("err:::::3333", err1) |
|
|
|
return err1 |
|
|
|
} |
|
|
|
var parentRewardValue = zhios_order_relate_utils.StrToFloat64(rewardValue) |
|
|
|
if relates != nil { |
|
|
|
for _, relate := range *relates { |
|
|
|
if parentRewardValue <= rewardEndValue { |
|
|
|
break |
|
|
|
} |
|
|
|
parentRewardValue = parentRewardValue * rewardDecrement |
|
|
|
//TODO::判断是否活跃 |
|
|
|
var m model.OneCirclesGreenEnergySignIn |
|
|
|
has, err3333333 := engine.Where("uid =?", relate.ParentUid).And("start_time >=?", time.Now().Format("2006-01-02")+" 00:00:00").Get(&m) |
|
|
|
if err3333333 != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
fmt.Println("err:::::3333333", err3333333) |
|
|
|
return err3333333 |
|
|
|
} |
|
|
|
if !has { |
|
|
|
//不活跃不需要奖励 |
|
|
|
continue |
|
|
|
} |
|
|
|
err = DealUserCoin(session, md.DealUserCoinReq{ |
|
|
|
Kind: "add", |
|
|
|
Mid: masterId, |
|
|
|
Title: md.OneCirclesGreenEnergySignInSettlementTeamReward, |
|
|
|
TransferType: md.OneCirclesGreenEnergySignInSettlementTeamRewardForUserVirtualCoinFlow, |
|
|
|
OrdId: "", |
|
|
|
CoinId: oneCirclesGreenEnergyBasicSetting.TeamGreenEnergyCoinId, |
|
|
|
Uid: relate.ParentUid, |
|
|
|
Amount: parentRewardValue, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
fmt.Println("err:::::44444", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
reduceTotalGreenEnergy += parentRewardValue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -144,18 +177,21 @@ func SettlementSignInGreenEnergy(engine *xorm.Engine, masterId string) (err erro |
|
|
|
} |
|
|
|
|
|
|
|
//6、更新 `one_circles_green_energy_sign_in` 中的 is_completed 状态 |
|
|
|
_, err = engine.Where("start_time <= ?", startTime).And("is_completed =?", 0).Update(&model.OneCirclesGreenEnergySignIn{ |
|
|
|
_, err = engine.Where("id = ?", id).Update(&model.OneCirclesGreenEnergySignIn{ |
|
|
|
IsCompleted: 1, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
fmt.Println("err:::::1111", err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
err = session.Commit() |
|
|
|
if err != nil { |
|
|
|
_ = session.Rollback() |
|
|
|
return errors.New("事务提交失败") |
|
|
|
} |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|