@@ -0,0 +1,187 @@ | |||
package db | |||
import ( | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" | |||
zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" | |||
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" | |||
"errors" | |||
"fmt" | |||
"reflect" | |||
"xorm.io/xorm" | |||
) | |||
// BatchSelectOneCirclesStarLevelDividendsRecordss 批量查询数据 TODO::和下面的方法重复了,建议采用下面的 `OneCirclesStarLevelDividendsRecordsFindByParams` 方法 | |||
func BatchSelectOneCirclesStarLevelDividendsRecordss(Db *xorm.Engine, params map[string]interface{}) (*[]model.OneCirclesStarLevelDividendsRecords, error) { | |||
var OneCirclesStarLevelDividendsRecordsData []model.OneCirclesStarLevelDividendsRecords | |||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]). | |||
Find(&OneCirclesStarLevelDividendsRecordsData); err != nil { | |||
return nil, zhios_order_relate_logx.Warn(err) | |||
} | |||
return &OneCirclesStarLevelDividendsRecordsData, nil | |||
} | |||
// OneCirclesStarLevelDividendsRecordsInsert 插入单条数据 | |||
func OneCirclesStarLevelDividendsRecordsInsertBySession(session *xorm.Session, OneCirclesStarLevelDividendsRecords *model.OneCirclesStarLevelDividendsRecords) (int64, error) { | |||
_, err := session.InsertOne(OneCirclesStarLevelDividendsRecords) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return OneCirclesStarLevelDividendsRecords.Id, nil | |||
} | |||
// BatchAddOneCirclesStarLevelDividendsRecordss 批量新增数据 | |||
func BatchAddOneCirclesStarLevelDividendsRecordss(Db *xorm.Engine, OneCirclesStarLevelDividendsRecordsData []*model.OneCirclesStarLevelDividendsRecords) (int64, error) { | |||
affected, err := Db.Insert(OneCirclesStarLevelDividendsRecordsData) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} | |||
func GetOneCirclesStarLevelDividendsRecordsCount(Db *xorm.Engine) int { | |||
var OneCirclesStarLevelDividendsRecords model.OneCirclesStarLevelDividendsRecords | |||
session := Db.Where("") | |||
count, err := session.Count(&OneCirclesStarLevelDividendsRecords) | |||
if err != nil { | |||
return 0 | |||
} | |||
return int(count) | |||
} | |||
// OneCirclesStarLevelDividendsRecordsDelete 删除记录 | |||
func OneCirclesStarLevelDividendsRecordsDelete(Db *xorm.Engine, id interface{}) (int64, error) { | |||
if reflect.TypeOf(id).Kind() == reflect.Slice { | |||
return Db.In("id", id).Delete(model.OneCirclesStarLevelDividendsRecords{}) | |||
} else { | |||
return Db.Where("id = ?", id).Delete(model.OneCirclesStarLevelDividendsRecords{}) | |||
} | |||
} | |||
// OneCirclesStarLevelDividendsRecordsUpdate 更新记录 | |||
func OneCirclesStarLevelDividendsRecordsUpdate(Db *xorm.Engine, id interface{}, OneCirclesStarLevelDividendsRecords *model.OneCirclesStarLevelDividendsRecords, forceColums ...string) (int64, error) { | |||
var ( | |||
affected int64 | |||
err error | |||
) | |||
if forceColums != nil { | |||
affected, err = Db.Where("id=?", id).Cols(forceColums...).Update(OneCirclesStarLevelDividendsRecords) | |||
} else { | |||
affected, err = Db.Where("id=?", id).Update(OneCirclesStarLevelDividendsRecords) | |||
} | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} | |||
func OneCirclesStarLevelDividendsRecordsUpdateBySession(session *xorm.Session, id interface{}, OneCirclesStarLevelDividendsRecords *model.OneCirclesStarLevelDividendsRecords, forceColums ...string) (int64, error) { | |||
var ( | |||
affected int64 | |||
err error | |||
) | |||
if forceColums != nil { | |||
affected, err = session.Where("id=?", id).Cols(forceColums...).Update(OneCirclesStarLevelDividendsRecords) | |||
} else { | |||
affected, err = session.Where("id=?", id).Update(OneCirclesStarLevelDividendsRecords) | |||
} | |||
if err != nil { | |||
return 0, err | |||
} | |||
return affected, nil | |||
} | |||
// OneCirclesStarLevelDividendsRecordsGetOneByParamsBySession 通过传入的参数查询数据(单条) | |||
func OneCirclesStarLevelDividendsRecordsGetOneByParamsBySession(session *xorm.Session, params map[string]interface{}) (*model.OneCirclesStarLevelDividendsRecords, error) { | |||
var m model.OneCirclesStarLevelDividendsRecords | |||
var query = fmt.Sprintf("%s =?", params["key"]) | |||
has, err := session.Where(query, params["value"]).Get(&m) | |||
if err != nil { | |||
return nil, zhios_order_relate_logx.Error(err) | |||
} | |||
if has == false { | |||
return nil, nil | |||
} | |||
return &m, nil | |||
} | |||
// OneCirclesStarLevelDividendsRecordsGetOneByParams 通过传入的参数查询数据(单条) | |||
func OneCirclesStarLevelDividendsRecordsGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.OneCirclesStarLevelDividendsRecords, error) { | |||
var m model.OneCirclesStarLevelDividendsRecords | |||
var query = fmt.Sprintf("%s =?", params["key"]) | |||
has, err := Db.Where(query, params["value"]).Get(&m) | |||
if err != nil { | |||
return nil, zhios_order_relate_logx.Error(err) | |||
} | |||
if !has { | |||
return nil, nil | |||
} | |||
return &m, nil | |||
} | |||
// OneCirclesStarLevelDividendsRecordsFindByParams 通过传入的参数查询数据(多条) | |||
func OneCirclesStarLevelDividendsRecordsFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.OneCirclesStarLevelDividendsRecords, error) { | |||
var m []model.OneCirclesStarLevelDividendsRecords | |||
if params["value"] == nil { | |||
return nil, errors.New("参数有误") | |||
} | |||
if params["key"] == nil { | |||
//查询全部数据 | |||
err := Db.Find(&m) | |||
if err != nil { | |||
return nil, zhios_order_relate_logx.Error(err) | |||
} | |||
return &m, nil | |||
} else { | |||
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { | |||
//指定In查询 | |||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Find(&m); err != nil { | |||
return nil, zhios_order_relate_logx.Warn(err) | |||
} | |||
return &m, nil | |||
} else { | |||
var query = fmt.Sprintf("%s =?", params["key"]) | |||
err := Db.Where(query, params["value"]).Find(&m) | |||
if err != nil { | |||
return nil, zhios_order_relate_logx.Error(err) | |||
} | |||
return &m, nil | |||
} | |||
} | |||
} | |||
func OneCirclesStarLevelDividendsRecordsFindByParamsByPage(Db *xorm.Engine, params map[string]interface{}, page, pageSize int) (*[]model.OneCirclesStarLevelDividendsRecords, error) { | |||
var m []model.OneCirclesStarLevelDividendsRecords | |||
if params["value"] == nil { | |||
return nil, errors.New("参数有误") | |||
} | |||
if page == 0 && pageSize == 0 { | |||
page = 1 | |||
pageSize = 10 | |||
} | |||
if params["key"] == nil { | |||
//查询全部数据 | |||
err := Db.Limit(pageSize, (page-1)*pageSize).Find(&m) | |||
if err != nil { | |||
return nil, zhios_order_relate_logx.Error(err) | |||
} | |||
return &m, nil | |||
} else { | |||
if reflect.TypeOf(params["value"]).Kind() == reflect.Slice { | |||
//指定In查询 | |||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m); err != nil { | |||
return nil, zhios_order_relate_logx.Warn(err) | |||
} | |||
return &m, nil | |||
} else { | |||
var query = fmt.Sprintf("%s =?", params["key"]) | |||
err := Db.Where(query, params["value"]).Limit(pageSize, (page-1)*pageSize).Find(&m) | |||
if err != nil { | |||
return nil, zhios_order_relate_logx.Error(err) | |||
} | |||
return &m, nil | |||
} | |||
} | |||
} |
@@ -0,0 +1,9 @@ | |||
package model | |||
type OneCirclesStarLevelDividendsRecords struct { | |||
Id int64 `json:"id" xorm:"pk default 0 BIGINT(20)"` | |||
Amount string `json:"amount" xorm:"not null default 0.00000000 comment('分红值') DECIMAL(20,8)"` | |||
AlreadyDividendsAmount string `json:"already_dividends_amount" xorm:"not null default 0.00000000 comment('已分红值') DECIMAL(20,8)"` | |||
NotDividendsAmount string `json:"not_dividends_amount" xorm:"not null default 0.00000000 comment('未分红值') DECIMAL(20,8)"` | |||
Date string `json:"date" xorm:"not null default '0000-00-00' comment('日期') CHAR(50)"` | |||
} |
@@ -73,6 +73,7 @@ const ( | |||
OneCirclesPersonalActiveCoinExchangeToBeGreenEnergy = "个人活跃积分-兑换可用绿色能量" | |||
OneCirclesTeamActiveCoinExchangeToBeGreenEnergy = "团队活跃积分-结算绿色能量" | |||
OneCirclesSettlementGreenEnergyExchangeTobeGreenEnergy = "结算绿色能量-释放可用绿色能量" | |||
OneCirclesSettlementStarLevelDividends = "结算星级分红" | |||
) | |||
const ( | |||
@@ -144,6 +145,7 @@ const ( | |||
OneCirclesPersonalActiveCoinExchangeToBeGreenEnergyForUserVirtualCoinFlow = 165 //个人活跃积分-兑换可用绿色能量 | |||
OneCirclesTeamActiveCoinExchangeToBeGreenEnergyForUserVirtualCoinFlow = 166 //团队活跃积分-结算绿色能量 | |||
OneCirclesSettlementGreenEnergyExchangeTobeGreenEnergyForUserVirtualCoinFlow = 167 //结算绿色能量-释放可用绿色能量 | |||
OneCirclesSettlementStarLevelDividendsForUserVirtualCoinFlow = 168 //结算星级冯弘-得到结算绿色能量 | |||
) | |||
@@ -10,6 +10,7 @@ const ( | |||
AccountBalanceExchange | |||
GreenEnergyExchangeBalance | |||
TeamActivePointRedemption | |||
SettlementStarLevelDividends | |||
) | |||
func (kind OneCirclesAvailableGreenEnergyPointsFlowKind) String() string { | |||
@@ -26,6 +27,8 @@ func (kind OneCirclesAvailableGreenEnergyPointsFlowKind) String() string { | |||
return "绿色能量兑换余额" | |||
case TeamActivePointRedemption: | |||
return "团队活跃积分兑换" | |||
case SettlementStarLevelDividends: | |||
return "结算星级分红" | |||
default: | |||
return "未知状态" | |||
} | |||
@@ -243,6 +243,65 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityFundValues = chain.OriginalFunds //原始资金 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityFundValues = afterOriginalFundValues | |||
//TODO::新增 / 更新 one_circles_star_level_dividends_records 记录 | |||
oneCirclesStarLevelDividendsRecords, err := db.OneCirclesStarLevelDividendsRecordsGetOneByParamsBySession(session, map[string]interface{}{ | |||
"key": "date", | |||
"value": now.Format("2006-01-02"), | |||
}) | |||
if err != nil { | |||
return err | |||
} | |||
if oneCirclesStarLevelDividendsRecords == nil { | |||
oneCirclesStarLevelDividendsRecords = &model.OneCirclesStarLevelDividendsRecords{ | |||
Amount: amountFeeValue.Mul(starLevelDividends.Div(decimalRate)).String(), | |||
AlreadyDividendsAmount: "", | |||
NotDividendsAmount: "", | |||
Date: now.Format("2006-01-02"), | |||
} | |||
_, err = db.OneCirclesStarLevelDividendsRecordsInsertBySession(session, oneCirclesStarLevelDividendsRecords) | |||
if err != nil { | |||
return err | |||
} | |||
} else { | |||
oneCirclesStarLevelDividendsRecordsAmountValue, _ := decimal.NewFromString(oneCirclesStarLevelDividendsRecords.Amount) | |||
oneCirclesStarLevelDividendsRecordsAmountValue = oneCirclesStarLevelDividendsRecordsAmountValue.Add(amountFeeValue.Mul(starLevelDividends.Div(decimalRate))) | |||
oneCirclesStarLevelDividendsRecords.Amount = oneCirclesStarLevelDividendsRecordsAmountValue.String() | |||
_, err = db.OneCirclesStarLevelDividendsRecordsUpdateBySession(session, oneCirclesStarLevelDividendsRecords.Id, oneCirclesStarLevelDividendsRecords, "amount") | |||
if err != nil { | |||
return err | |||
} | |||
} | |||
break | |||
case int(enum.SettlementStarLevelDividends): //星级分红 | |||
beforeStarLevelDividends, _ := decimal.NewFromString(chain.StarLevelDividends) | |||
oneCirclesAvailableGreenEnergyPointsFlow.Direction = 1 | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeEcologicalApplicationValues = chain.EcologicalApplication //生态应用 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterEcologicalApplicationValues = chain.EcologicalApplication | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeTechnicalTeamValues = chain.TotalTechnologyTeam //技术团队 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterTechnicalTeamValues = chain.TotalTechnologyTeam | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOperateTeamValues = chain.TotalOperateTeam //运营团队 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOperateTeamValues = chain.TotalOperateTeam | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeActiveGiveawaysValues = chain.TotalActiveGiveaways //活跃赠送 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterActiveGiveawaysValues = chain.TotalActiveGiveaways | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityValues = chain.OriginalQuantityNums //原始数量 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityValues = chain.OriginalQuantityNums | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantValues = chain.MarketplaceMerchantNums //市商数量 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantValues = chain.MarketplaceMerchantNums | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDevelopmentCommitteeValues = chain.DevelopmentCommittee //发展委员会 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDevelopmentCommitteeValues = chain.DevelopmentCommittee | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforePublicWelfareAndCharityValues = chain.PublicWelfareAndCharity //公益慈善 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues = chain.PublicWelfareAndCharity | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = beforeStarLevelDividends.Sub(amountValue).RoundFloor(8).String() | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityFundValues = chain.OriginalFunds //原始资金 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityFundValues = chain.OriginalFunds | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds //市商资金 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds | |||
break | |||
} | |||
@@ -0,0 +1,198 @@ | |||
package one_circles | |||
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/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/rule/one_circles/enum" | |||
md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/md" | |||
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" | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
"github.com/shopspring/decimal" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
const SettlementStarLevelDividendsLockKey = "settlement_star_level_dividends_lock_key" | |||
// SettlementStarLevelDividends 结算星级分红 | |||
func SettlementStarLevelDividends(engine *xorm.Engine, masterId string) (err error) { | |||
now := time.Now() | |||
fmt.Println(now.Hour()) | |||
if !(now.Hour() > 2 && now.Hour() < 8) { | |||
//TODO::只在凌晨一点 ~ 凌晨 8 点运行 | |||
return errors.New("非运行时间") | |||
} | |||
//TODO::增加“悲观锁”防止串行 | |||
getString, _ := cache.GetString(SettlementStarLevelDividendsLockKey) | |||
//if err != nil { | |||
// return err | |||
//} | |||
if getString != "" { | |||
fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", "上一次结算未执行完") | |||
return errors.New("上一次结算未执行完") | |||
} | |||
cache.SetEx(SettlementStarLevelDividendsLockKey, "running", 3600*8) //8小时 | |||
//1、查找 `one_circles_green_energy_basic_setting` 基础设置 | |||
oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ | |||
"key": "is_open", | |||
"value": 1, | |||
}) | |||
if err != nil { | |||
return | |||
} | |||
isLimitDividend := oneCirclesGreenEnergyBasicSetting.IsLimitDividend | |||
if isLimitDividend != 1 { | |||
return errors.New("必须开启限制分红!") | |||
} | |||
startDate := now.AddDate(0, 0, -1).Format("2006-01-02") + " 00:00:00" | |||
endDate := now.Format("2006-01-02") + " 00:00:00" | |||
var list []model.OneCirclesGreenEnergySignIn | |||
err = engine.Where("start_time >= ?", startDate).And("start_time <=?", endDate).Find(&list) | |||
if err != nil { | |||
fmt.Println("err:::::1111", err) | |||
return | |||
} | |||
if len(list) <= 0 { | |||
return errors.New("无须参与星级分红用户!") | |||
} | |||
var userSignInMap = map[int]string{} | |||
var userSignInArr []int | |||
for _, v := range list { | |||
userSignInMap[v.Uid] = "true" | |||
userSignInArr = append(userSignInArr, v.Uid) | |||
} | |||
var vipEquitySetting []*md2.VipEquitySettingStruct | |||
err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.VipEquitySetting), &vipEquitySetting) | |||
if err != nil { | |||
fmt.Println("err:::::22222", err) | |||
return | |||
} | |||
allUserLevel, err := db.UserLevlEgAll(engine) | |||
if err != nil { | |||
return err | |||
} | |||
var allUserLevelMap = map[int]model.UserLevel{} | |||
for _, v := range allUserLevel { | |||
allUserLevelMap[v.Id] = *v | |||
} | |||
session := engine.NewSession() | |||
//2、查找 `one_circles_star_level_dividends_records` 基础设置 | |||
oneCirclesStarLevelDividendsRecords, err := db.OneCirclesStarLevelDividendsRecordsGetOneByParamsBySession(session, map[string]interface{}{ | |||
"key": "date", | |||
"value": now.AddDate(0, 0, -1).Format("2006-01-02"), | |||
}) | |||
if err != nil { | |||
fmt.Println("err:::::33333", err) | |||
return | |||
} | |||
if oneCirclesStarLevelDividendsRecords == nil { | |||
return errors.New("今日无分红积分!") | |||
} | |||
//3、统计各等级人数 | |||
dividendAmountValue, _ := decimal.NewFromString(oneCirclesStarLevelDividendsRecords.Amount) | |||
decimalRate := decimal.NewFromInt(100) //百分比 | |||
var vipLevelUserTotalMap = map[string]map[string]int64{} | |||
var vipEquitySettingMap = map[string]string{} | |||
for _, v := range vipEquitySetting { | |||
dividendRatioValue, _ := decimal.NewFromString(v.DividendRatio) | |||
dividendRatioValue = dividendRatioValue.Div(decimalRate) //分红比例 | |||
vipEquitySettingMap[v.VipLevelId] = dividendAmountValue.Mul(dividendRatioValue).String() //TODO::计算各会员等级能得到多少分红 | |||
userLevel, err1 := db.UserLevelByID(engine, v.VipLevelId) | |||
if err1 != nil { | |||
fmt.Println("err:::::444444", err1) | |||
return err1 | |||
} | |||
var ms []*model.UserLevel | |||
err1 = session.Where("is_use=1").Where("level_weight > ?", userLevel.LevelWeight).Find(&ms) | |||
if err1 != nil { | |||
fmt.Println("err:::::55555", err1) | |||
return err1 | |||
} | |||
var tmpVipLevelId = []string{v.VipLevelId} | |||
for _, m := range ms { | |||
tmpVipLevelId = append(tmpVipLevelId, zhios_order_relate_utils.IntToStr(m.Id)) | |||
} | |||
var users model.User | |||
count, err1 := session.In("level", tmpVipLevelId).Count(&users) | |||
if err1 != nil { | |||
fmt.Println("err:::::66666", err1) | |||
return err1 | |||
} | |||
vipLevelUserTotalMap[v.VipLevelId]["count"] = count | |||
vipLevelUserTotalMap[v.VipLevelId]["weight"] = int64(userLevel.LevelWeight) | |||
} | |||
//4、处理分红 | |||
var users []*model.User | |||
err = session.In("uid", userSignInArr).Find(&users) | |||
if err != nil { | |||
fmt.Println("err:::::7777777", err) | |||
return err | |||
} | |||
var totalDividendValue = decimal.Decimal{} | |||
for _, item := range users { | |||
var siginDividendValue = decimal.Decimal{} | |||
for _, v := range vipLevelUserTotalMap { | |||
if int(v["weight"]) < allUserLevelMap[item.Level].LevelWeight { | |||
continue | |||
} | |||
if vipEquitySettingMap[zhios_order_relate_utils.IntToStr(item.Level)] != "" && vipLevelUserTotalMap[zhios_order_relate_utils.IntToStr(item.Level)]["count"] > 0 { | |||
dividendValue, _ := decimal.NewFromString(vipEquitySettingMap[zhios_order_relate_utils.IntToStr(item.Level)]) | |||
userTotal := decimal.NewFromInt(vipLevelUserTotalMap[zhios_order_relate_utils.IntToStr(item.Level)]["count"]) | |||
siginDividendValue = siginDividendValue.Add(dividendValue.Div(userTotal)) | |||
} | |||
} | |||
siginDividend, _ := siginDividendValue.Float64() | |||
if siginDividend > 0 { | |||
//给相应的用户加上个人的绿色积分(结算数量) | |||
err = DealUserCoin(session, md.DealUserCoinReq{ | |||
Kind: "add", | |||
Mid: masterId, | |||
Title: md.OneCirclesSettlementStarLevelDividends, | |||
TransferType: md.OneCirclesSettlementStarLevelDividendsForUserVirtualCoinFlow, | |||
OrdId: "", | |||
CoinId: oneCirclesGreenEnergyBasicSetting.TeamGreenEnergyCoinId, | |||
Uid: item.Uid, | |||
Amount: siginDividend, | |||
}) | |||
} | |||
totalDividendValue = totalDividendValue.Add(siginDividendValue) | |||
} | |||
//5、更新 one_circles_star_level_dividends_records 记录 | |||
oneCirclesStarLevelDividendsRecords.AlreadyDividendsAmount = totalDividendValue.String() | |||
oneCirclesStarLevelDividendsRecords.NotDividendsAmount = dividendAmountValue.Sub(totalDividendValue).String() | |||
_, err = db.OneCirclesStarLevelDividendsRecordsUpdateBySession(session, oneCirclesStarLevelDividendsRecords.Id, oneCirclesStarLevelDividendsRecords, "already_dividends_amount", "not_dividends_amount") | |||
if err != nil { | |||
fmt.Println("err:::::8888888", err) | |||
return err | |||
} | |||
//6、 减少“星级分红”中的绿色能量 | |||
totalDividend, _ := totalDividendValue.Float64() | |||
err = DealAvailableGreenEnergyCoin(session, int(enum.SettlementStarLevelDividends), totalDividend, 0, enum.SettlementStarLevelDividends.String(), oneCirclesGreenEnergyBasicSetting, oneCirclesGreenEnergyBasicSetting.NowPrice) | |||
if err != nil { | |||
_ = session.Rollback() | |||
fmt.Println("err:::::9999999", err) | |||
return err | |||
} | |||
err = session.Commit() | |||
if err != nil { | |||
_ = session.Rollback() | |||
return errors.New("事务提交失败") | |||
} | |||
return | |||
} |