@@ -11,6 +11,8 @@ type OneCirclesAvailableGreenEnergyPointsFlow struct { | |||
Kind int `json:"kind" xorm:"not null default 1 comment('种类(1:个人活跃积分兑换 2:结算绿色能量释放 3:签到奖励 4:账户余额兑换 5:绿色能量兑换余额)') TINYINT(1)"` | |||
Title string `json:"title" xorm:"not null default '' comment('标题') VARCHAR(255)"` | |||
Amount string `json:"amount" xorm:"not null comment('变更数量') DECIMAL(28,10)"` | |||
BeforePrice string `json:"before_price" xorm:"not null default 0.0000000000 comment('变更前-价格') DECIMAL(28,10)"` | |||
AfterPrice string `json:"after_price" xorm:"not null default 0.0000000000 comment('变更后-价格') DECIMAL(28,10)"` | |||
BeforeEcologicalApplicationValues string `json:"before_ecological_application_values" xorm:"not null default 0.0000000000 comment('变更前-生态应用区块币数量') DECIMAL(28,10)"` | |||
AfterEcologicalApplicationValues string `json:"after_ecological_application_values" xorm:"not null default 0.0000000000 comment('变更后-生态应用区块币数量') DECIMAL(28,10)"` | |||
BeforeTechnicalTeamValues string `json:"before_technical_team_values" xorm:"not null default 0.0000000000 comment('变更前-技术团队区块币数量') DECIMAL(28,10)"` | |||
@@ -35,5 +37,7 @@ type OneCirclesAvailableGreenEnergyPointsFlow struct { | |||
AfterStarLevelDividendsValues string `json:"after_star_level_dividends_values" xorm:"not null default 0.0000000000 comment('变更后-星级分红区块币数量') DECIMAL(28,10)"` | |||
BeforeDestructionQuantityValues string `json:"before_destruction_quantity_values" xorm:"not null default 0.0000000000 comment('变更前-销毁区块币数量') DECIMAL(28,10)"` | |||
AfterDestructionQuantityValues string `json:"after_destruction_quantity_values" xorm:"not null default 0.0000000000 comment('变更后-销毁区块币数量') DECIMAL(28,10)"` | |||
BeforeCommunityDividends string `json:"before_community_dividends" xorm:"not null default 0.0000000000 comment('变更前-社区分红区块币数量') DECIMAL(28,10)"` | |||
AfterCommunityDividends string `json:"after_community_dividends" xorm:"not null default 0.0000000000 comment('变更后-社区分红区块币数量') DECIMAL(28,10)"` | |||
CreateTime time.Time `json:"create_time" xorm:"default 'CURRENT_TIMESTAMP' comment('创建时间') DATETIME"` | |||
} |
@@ -0,0 +1,12 @@ | |||
package model | |||
type OneCirclesCommunityDividends struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Nums int `json:"nums" xorm:"not null default 0 comment('分红数量') INT(11)"` | |||
Name string `json:"name" xorm:"not null default '' comment('名称') VARCHAR(255)"` | |||
CoinId int `json:"coin_id" xorm:"not null default 0 comment('虚拟币id') INT(11)"` | |||
PersonsNum int `json:"persons_num" xorm:"not null default 0 comment('分红人数') INT(11)"` | |||
IsOver int32 `json:"is_over" xorm:"not null default 0 comment('是否分红完毕') TINYINT(1)"` | |||
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||
} |
@@ -0,0 +1,9 @@ | |||
package model | |||
type OneCirclesCommunityDividendsWithUser struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"` | |||
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(255)"` | |||
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||
} |
@@ -0,0 +1,11 @@ | |||
package model | |||
type OneCirclesCommunityDividendsWithUserRecords struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"` | |||
Value string `json:"value" xorm:"not null default 0.0000000000 comment('数量') DECIMAL(28,10)"` | |||
RecordsId int `json:"records_id" xorm:"not null default 0 comment('记录id') INT(11)"` | |||
CoinId int `json:"coin_id" xorm:"not null default 0 comment('虚拟币id') INT(11)"` | |||
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||
} |
@@ -23,6 +23,7 @@ type OneCirclesGreenEnergyBasicSetting struct { | |||
DevelopmentCommittee string `json:"development_committee" xorm:"not null comment('发展委员会') DECIMAL(28,8)"` | |||
PublicWelfareAndCharity string `json:"public_welfare_and_charity" xorm:"not null comment('公益慈善') DECIMAL(28,8)"` | |||
StarLevelDividends string `json:"star_level_dividends" xorm:"not null comment('星级分红') DECIMAL(28,8)"` | |||
CommunityDividends string `json:"community_dividends" xorm:"not null comment('社区分红') DECIMAL(28,8)"` | |||
DestructionQuantityNums string `json:"destruction_quantity_nums" xorm:"not null comment('销毁数量') DECIMAL(28,8)"` | |||
DestructionSetting string `json:"destruction_setting" xorm:"not null comment('销毁设置') TEXT"` | |||
IsLimitDividend int `json:"is_limit_dividend" xorm:"not null default 1 comment('是否限制分红(会员本人不活跃,没有绿色能量分红)') TINYINT(1)"` | |||
@@ -35,4 +36,5 @@ type OneCirclesGreenEnergyBasicSetting struct { | |||
CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||
UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | |||
IsOpenWelfareOrders int `json:"is_open_welfare_orders" xorm:"not null default 0 comment('是否开启福利订单') TINYINT(1)"` | |||
CommunityDividendsCoinId int `json:"community_dividends_coin_id" xorm:"not null default 0 comment('社区分红对应虚拟币id') INT(11)"` | |||
} |
@@ -74,6 +74,7 @@ const ( | |||
OneCirclesTeamActiveCoinExchangeToBeGreenEnergy = "T兑换绿色能量" | |||
OneCirclesSettlementGreenEnergyExchangeTobeGreenEnergy = "绿色能量释放" | |||
OneCirclesSettlementStarLevelDividends = "绿色能量分红" | |||
OneCirclesCommunityDividends = "社区分红" | |||
GreenCoinDoubleChainExchangeByCoin1 = "绿色积分双链兑换账户余额-减少绿色积分" | |||
GreenCoinDoubleChainExchangeByCoin2 = "绿色积分双链兑换账户余额-减少贡献积分" | |||
@@ -149,6 +150,7 @@ const ( | |||
OneCirclesTeamActiveCoinExchangeToBeGreenEnergyForUserVirtualCoinFlow = 167 //T兑换绿色能量 | |||
OneCirclesSettlementGreenEnergyExchangeTobeGreenEnergyForUserVirtualCoinFlow = 168 //绿色能量释放 | |||
OneCirclesSettlementStarLevelDividendsForUserVirtualCoinFlow = 169 //绿色能量分红(结算星级分红-得到结算绿色能量) | |||
OneCirclesCommunityDividendsForUserVirtualCoinFlow = 172 //社区分红 | |||
GreenCoinDoubleChainExchangeByCoin1ForForUserVirtualCoinFlow = 170 //绿色积分双链兑换账户余额-减少绿色积分 | |||
GreenCoinDoubleChainExchangeByCoin2ForForUserVirtualCoinFlow = 171 //绿色积分双链兑换账户余额-减少贡献积分 | |||
@@ -13,6 +13,7 @@ const ( | |||
SettlementStarLevelDividends | |||
MarketplaceMerchantNumsAutoExchangeMarketplaceMerchantFunds | |||
MarketplaceMerchantFundsAutoExchangeMarketplaceMerchantNums | |||
CommunityDividends | |||
) | |||
func (kind OneCirclesAvailableGreenEnergyPointsFlowKind) String() string { | |||
@@ -35,6 +36,8 @@ func (kind OneCirclesAvailableGreenEnergyPointsFlowKind) String() string { | |||
return "市商数量自动兑换市商资金" | |||
case MarketplaceMerchantFundsAutoExchangeMarketplaceMerchantNums: | |||
return "市商资金自动兑换市商数量" | |||
case CommunityDividends: | |||
return "社区分红" | |||
default: | |||
return "未知状态" | |||
} | |||
@@ -32,6 +32,7 @@ type DestructionSettingStruct struct { | |||
DevelopmentCommittee string `json:"development_committee"` //发展委员会百分比 | |||
StarLevelDividends string `json:"star_level_dividends"` //星级分红百分比 | |||
MarketplaceMerchant string `json:"marketplace_merchant"` //市商数量百分比 | |||
CommunityDividends string `json:"community_dividends"` //社区分红百分比 | |||
} | |||
type WelfareOrdersLimit struct { | |||
@@ -48,84 +48,8 @@ func NewCalcPriceIncreaseFormula(userAmountValue string, oneCirclesGreenEnergyBa | |||
return | |||
} | |||
//// CalcPriceReductionFormula 计算降价公式(【用户需兑换绿能色量数量*{原始资金÷(用户需兑换绿色数量+原始数量}*(1 - 扣比例50% ~ 23%) = 用户获得钱) | |||
//func CalcPriceReductionFormula(engine *xorm.Engine, userExchangeNumsValue string, levelId string, uid int) (err error, values, greenEnergy, greenEnergyFee, nowPriceValue, afterPriceValue string) { | |||
// //1、查找 `one_circles_green_energy_basic_setting` 基础设置 | |||
// oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ | |||
// "key": "is_open", | |||
// "value": 1, | |||
// }) | |||
// if err != nil { | |||
// return | |||
// } | |||
// var vipEquitySetting []*md2.VipEquitySettingStruct | |||
// err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.VipEquitySetting), &vipEquitySetting) | |||
// if err != nil { | |||
// return | |||
// } | |||
// var exchangeAccountBalanceFeeValue string | |||
// for _, v := range vipEquitySetting { | |||
// if v.VipLevelId == levelId { | |||
// exchangeAccountBalanceFeeValue = v.ExchangeAccountBalanceFee | |||
// } | |||
// } | |||
// if exchangeAccountBalanceFeeValue == "" { | |||
// err = errors.New("未查询到当前会员等级兑换余额手续费") | |||
// return | |||
// } | |||
// decimalRate := decimal.NewFromInt(100) //百分比 | |||
// exchangeAccountBalanceFee, _ := decimal.NewFromString(exchangeAccountBalanceFeeValue) //兑换手续费 | |||
// //TODO::统计当前有多少直推用户昨天签到了 | |||
// userRelates, err := db.DbsUserRelateByParentUid(engine, uid, 1) | |||
// if err != nil { | |||
// return | |||
// } | |||
// var userRelatesUids []int | |||
// if userRelates != nil { | |||
// for _, userRelate := range *userRelates { | |||
// userRelatesUids = append(userRelatesUids, userRelate.Uid) | |||
// } | |||
// } | |||
// if len(userRelatesUids) > 0 { | |||
// now := time.Now() | |||
// startDate := now.AddDate(0, 0, -1).Format("2006-01-02") + " 00:00:00" | |||
// endDate := now.Format("2006-01-02") + " 00:00:00" | |||
// var oneCirclesGreenEnergySignIns []*model.OneCirclesGreenEnergySignIn | |||
// err = engine.Where("start_time >= ?", startDate).And("start_time <=?", endDate).In("uid", userRelatesUids).And("is_completed =?", 0).Find(&oneCirclesGreenEnergySignIns) | |||
// if err != nil { | |||
// return | |||
// } | |||
// | |||
// decimalRateV2 := decimal.NewFromInt(10) //百分比 | |||
// if len(oneCirclesGreenEnergySignIns) > 0 { | |||
// decimalBase := decimal.NewFromInt(1) //基数 | |||
// userRelatesUidsValue := decimal.NewFromInt(int64(len(userRelatesUids))) | |||
// oneCirclesGreenEnergySignInsValue := decimal.NewFromInt(int64(len(oneCirclesGreenEnergySignIns))) | |||
// exchangeAccountBalanceFee = exchangeAccountBalanceFee.Add(decimalBase.Sub(oneCirclesGreenEnergySignInsValue.Div(userRelatesUidsValue)).Mul(decimalRateV2)) | |||
// } else { | |||
// exchangeAccountBalanceFee = exchangeAccountBalanceFee.Add(decimalRateV2) | |||
// } | |||
// } | |||
// | |||
// userExchangeNums, _ := decimal.NewFromString(userExchangeNumsValue) //用户兑换绿色能量 | |||
// originalQuantityNums, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.OriginalQuantityNums) //原始数量 | |||
// nowPrice, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.NowPrice) //当前价格 | |||
// originalQuantityFunds, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.OriginalFunds) //原始资金 | |||
// afterPrice := originalQuantityFunds.Div(userExchangeNums.Add(originalQuantityNums)) //降价后的价格 | |||
// | |||
// greenEnergyValues := userExchangeNums.Mul(afterPrice) //绿色能量个数 | |||
// greenEnergyFeeValues := greenEnergyValues.Mul(exchangeAccountBalanceFee.Div(decimalRate)) //绿色能量个数扣除手续费价值 | |||
// | |||
// values = greenEnergyValues.Sub(greenEnergyFeeValues).Truncate(8).String() //用户实际得到的钱 | |||
// greenEnergy = greenEnergyValues.Truncate(8).String() //原本兑换到的钱 | |||
// greenEnergyFee = userExchangeNums.Mul(exchangeAccountBalanceFee.Div(decimalRate)).Truncate(8).String() //绿色能量手续费 | |||
// nowPriceValue = nowPrice.String() | |||
// afterPriceValue = afterPrice.String() | |||
// return | |||
//} | |||
// CalcPriceReductionFormula 计算降价公式(【用户需兑换绿能色量数量*{原始资金÷(用户需兑换绿色数量+原始数量}*(1 - 扣比例50% ~ 23%) = 用户获得钱) | |||
func CalcPriceReductionFormula(engine *xorm.Engine, userExchangeNumsValue string, levelId string) (err error, values, greenEnergy, greenEnergyFee, nowPriceValue, afterPriceValue string) { | |||
func CalcPriceReductionFormula(engine *xorm.Engine, userExchangeNumsValue string, levelId string, uid int) (err error, values, greenEnergy, greenEnergyFee, nowPriceValue, afterPriceValue string) { | |||
//1、查找 `one_circles_green_energy_basic_setting` 基础设置 | |||
oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ | |||
"key": "is_open", | |||
@@ -149,8 +73,40 @@ func CalcPriceReductionFormula(engine *xorm.Engine, userExchangeNumsValue string | |||
err = errors.New("未查询到当前会员等级兑换余额手续费") | |||
return | |||
} | |||
decimalRate := decimal.NewFromInt(100) //百分比 | |||
exchangeAccountBalanceFee, _ := decimal.NewFromString(exchangeAccountBalanceFeeValue) //兑换手续费 | |||
decimalRate := decimal.NewFromInt(100) //百分比 | |||
exchangeAccountBalanceFee, _ := decimal.NewFromString(exchangeAccountBalanceFeeValue) //兑换手续费 | |||
//TODO::统计当前有多少直推用户昨天签到了 | |||
userRelates, err := db.DbsUserRelateByParentUid(engine, uid, 1) | |||
if err != nil { | |||
return | |||
} | |||
var userRelatesUids []int | |||
if userRelates != nil { | |||
for _, userRelate := range *userRelates { | |||
userRelatesUids = append(userRelatesUids, userRelate.Uid) | |||
} | |||
} | |||
if len(userRelatesUids) > 0 { | |||
now := time.Now() | |||
startDate := now.AddDate(0, 0, -1).Format("2006-01-02") + " 00:00:00" | |||
endDate := now.Format("2006-01-02") + " 00:00:00" | |||
var oneCirclesGreenEnergySignIns []*model.OneCirclesGreenEnergySignIn | |||
err = engine.Where("start_time >= ?", startDate).And("start_time <=?", endDate).In("uid", userRelatesUids).And("is_completed =?", 0).Find(&oneCirclesGreenEnergySignIns) | |||
if err != nil { | |||
return | |||
} | |||
decimalRateV2 := decimal.NewFromInt(10) //百分比 | |||
if len(oneCirclesGreenEnergySignIns) > 0 { | |||
decimalBase := decimal.NewFromInt(1) //基数 | |||
userRelatesUidsValue := decimal.NewFromInt(int64(len(userRelatesUids))) | |||
oneCirclesGreenEnergySignInsValue := decimal.NewFromInt(int64(len(oneCirclesGreenEnergySignIns))) | |||
exchangeAccountBalanceFee = exchangeAccountBalanceFee.Add(decimalBase.Sub(oneCirclesGreenEnergySignInsValue.Div(userRelatesUidsValue)).Mul(decimalRateV2)) | |||
} else { | |||
exchangeAccountBalanceFee = exchangeAccountBalanceFee.Add(decimalRateV2) | |||
} | |||
} | |||
userExchangeNums, _ := decimal.NewFromString(userExchangeNumsValue) //用户兑换绿色能量 | |||
originalQuantityNums, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.OriginalQuantityNums) //原始数量 | |||
nowPrice, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.NowPrice) //当前价格 | |||
@@ -168,6 +124,50 @@ func CalcPriceReductionFormula(engine *xorm.Engine, userExchangeNumsValue string | |||
return | |||
} | |||
// CalcPriceReductionFormula 计算降价公式(【用户需兑换绿能色量数量*{原始资金÷(用户需兑换绿色数量+原始数量}*(1 - 扣比例50% ~ 23%) = 用户获得钱) | |||
//func CalcPriceReductionFormula(engine *xorm.Engine, userExchangeNumsValue string, levelId string) (err error, values, greenEnergy, greenEnergyFee, nowPriceValue, afterPriceValue string) { | |||
// //1、查找 `one_circles_green_energy_basic_setting` 基础设置 | |||
// oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ | |||
// "key": "is_open", | |||
// "value": 1, | |||
// }) | |||
// if err != nil { | |||
// return | |||
// } | |||
// var vipEquitySetting []*md2.VipEquitySettingStruct | |||
// err = json.Unmarshal([]byte(oneCirclesGreenEnergyBasicSetting.VipEquitySetting), &vipEquitySetting) | |||
// if err != nil { | |||
// return | |||
// } | |||
// var exchangeAccountBalanceFeeValue string | |||
// for _, v := range vipEquitySetting { | |||
// if v.VipLevelId == levelId { | |||
// exchangeAccountBalanceFeeValue = v.ExchangeAccountBalanceFee | |||
// } | |||
// } | |||
// if exchangeAccountBalanceFeeValue == "" { | |||
// err = errors.New("未查询到当前会员等级兑换余额手续费") | |||
// return | |||
// } | |||
// decimalRate := decimal.NewFromInt(100) //百分比 | |||
// exchangeAccountBalanceFee, _ := decimal.NewFromString(exchangeAccountBalanceFeeValue) //兑换手续费 | |||
// userExchangeNums, _ := decimal.NewFromString(userExchangeNumsValue) //用户兑换绿色能量 | |||
// originalQuantityNums, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.OriginalQuantityNums) //原始数量 | |||
// nowPrice, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.NowPrice) //当前价格 | |||
// originalQuantityFunds, _ := decimal.NewFromString(oneCirclesGreenEnergyBasicSetting.OriginalFunds) //原始资金 | |||
// afterPrice := originalQuantityFunds.Div(userExchangeNums.Add(originalQuantityNums)) //降价后的价格 | |||
// | |||
// greenEnergyValues := userExchangeNums.Mul(afterPrice) //绿色能量个数 | |||
// greenEnergyFeeValues := greenEnergyValues.Mul(exchangeAccountBalanceFee.Div(decimalRate)) //绿色能量个数扣除手续费价值 | |||
// | |||
// values = greenEnergyValues.Sub(greenEnergyFeeValues).Truncate(8).String() //用户实际得到的钱 | |||
// greenEnergy = greenEnergyValues.Truncate(8).String() //原本兑换到的钱 | |||
// greenEnergyFee = userExchangeNums.Mul(exchangeAccountBalanceFee.Div(decimalRate)).Truncate(8).String() //绿色能量手续费 | |||
// nowPriceValue = nowPrice.String() | |||
// afterPriceValue = afterPrice.String() | |||
// return | |||
//} | |||
// NewCalcPriceReductionFormula 计算降价公式(【用户需兑换绿能色量数量*{原始资金÷(用户需兑换绿色数量+原始数量}*(1 - 扣比例50% ~ 23%) = 用户获得钱) | |||
func NewCalcPriceReductionFormula(userExchangeNumsValue string, oneCirclesGreenEnergyBasicSetting *model.OneCirclesGreenEnergyBasicSetting) (err error, greenEnergy, nowPriceValue, afterPriceValue string) { | |||
userExchangeNums, _ := decimal.NewFromString(userExchangeNumsValue) //用户兑换绿色能量 | |||
@@ -0,0 +1,116 @@ | |||
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" | |||
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" | |||
"github.com/shopspring/decimal" | |||
"time" | |||
"xorm.io/xorm" | |||
) | |||
// CommunityDividends 社区分红 | |||
func CommunityDividends(engine *xorm.Engine, masterId string) (err error) { | |||
//1、查找 `one_circles_green_energy_basic_setting` 基础设置 && `one_circles_public_platoon_basic_setting` 基础设置 | |||
oneCirclesGreenEnergyBasicSetting, err := db.OneCirclesGreenEnergyBasicSettingGetOneByParams(engine, map[string]interface{}{ | |||
"key": "is_open", | |||
"value": 1, | |||
}) | |||
if err != nil { | |||
return | |||
} | |||
//2、查找当前是否有待分红的记录 "个人活跃积分"可以自动兑换的用户数据 && "团队活跃积分"可以自动兑换的用户数据 | |||
var m model.OneCirclesCommunityDividends | |||
has, err := engine.Where("is_over = 0").Get(&m) | |||
if err != nil { | |||
fmt.Println("err::::::2222", err.Error()) | |||
return | |||
} | |||
if has { | |||
//3、查找 `one_circles_community_dividends_with_user` 数据 | |||
var list []model.OneCirclesCommunityDividendsWithUser | |||
err = engine.Where("1 = 1").Find(&list) | |||
totalValue := decimal.NewFromInt(int64(m.Nums)) | |||
singleValue, _ := totalValue.Div(decimal.NewFromInt(int64(len(list)))).Float64() | |||
session := engine.NewSession() | |||
defer func() { | |||
session.Close() | |||
if err := recover(); err != nil { | |||
_ = zhios_order_relate_logx.Error(err) | |||
} | |||
}() | |||
session.Begin() | |||
now := time.Now() | |||
for _, v := range list { | |||
//4、 给相应的用户加上分红权益 | |||
err = DealUserCoin(session, md.DealUserCoinReq{ | |||
Kind: "add", | |||
Mid: masterId, | |||
Title: md.OneCirclesCommunityDividends, | |||
TransferType: md.OneCirclesCommunityDividendsForUserVirtualCoinFlow, | |||
OrdId: "", | |||
CoinId: m.CoinId, | |||
Uid: v.Uid, | |||
Amount: singleValue, | |||
}) | |||
if err != nil { | |||
_ = session.Rollback() | |||
fmt.Println("err:::::33333", err) | |||
return err | |||
} | |||
//5、增加 one_circles_community_dividends_with_user_records 记录 | |||
_, err = session.InsertOne(&model.OneCirclesCommunityDividendsWithUserRecords{ | |||
Uid: v.Uid, | |||
Value: zhios_order_relate_utils.Float64ToStr(singleValue), | |||
RecordsId: m.Id, | |||
CoinId: m.CoinId, | |||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||
}) | |||
if err != nil { | |||
_ = session.Rollback() | |||
fmt.Println("err:::::insert", err) | |||
return err | |||
} | |||
} | |||
//6、 减少“社区分红”钱包中的值 | |||
totalDividend, _ := totalValue.Float64() | |||
err = DealAvailableGreenEnergyCoin(session, int(enum.CommunityDividends), totalDividend, 0, enum.CommunityDividends.String(), oneCirclesGreenEnergyBasicSetting, oneCirclesGreenEnergyBasicSetting.NowPrice) | |||
if err != nil { | |||
_ = session.Rollback() | |||
fmt.Println("err:::::444444", err) | |||
return err | |||
} | |||
//7、修改 one_circles_community_dividends 记录 | |||
m.IsOver = 1 | |||
m.PersonsNum = len(list) | |||
affected, err := session.Where("id=?", m.Id).Cols("is_over", "persons_num").Update(m) | |||
if err != nil { | |||
_ = session.Rollback() | |||
fmt.Println("err:::::5555555", err) | |||
return err | |||
} | |||
if affected == 0 { | |||
_ = session.Rollback() | |||
fmt.Println("err:::::6666666", errors.New("更新 one_circles_community_dividends 记录失败")) | |||
return err | |||
} | |||
err = session.Commit() | |||
if err != nil { | |||
_ = session.Rollback() | |||
return errors.New("事务提交失败") | |||
} | |||
} | |||
return | |||
} |
@@ -79,6 +79,8 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues = chain.PublicWelfareAndCharity | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeCommunityDividends = chain.CommunityDividends //社区分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterCommunityDividends = chain.CommunityDividends | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | |||
@@ -111,6 +113,8 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues = chain.PublicWelfareAndCharity | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeCommunityDividends = chain.CommunityDividends //社区分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterCommunityDividends = chain.CommunityDividends | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityFundValues = chain.OriginalFunds //原始资金 | |||
@@ -139,6 +143,8 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues = chain.PublicWelfareAndCharity | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeCommunityDividends = chain.CommunityDividends //社区分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterCommunityDividends = chain.CommunityDividends | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds //市商资金 | |||
@@ -169,6 +175,8 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues = chain.PublicWelfareAndCharity | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeCommunityDividends = chain.CommunityDividends //社区分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterCommunityDividends = chain.CommunityDividends | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | |||
@@ -206,6 +214,13 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||
starLevelDividends, _ := decimal.NewFromString(destructionSetting.StarLevelDividends) //星级分红百分比 | |||
afterStarLevelDividendsValues := starLevelDividendsNums.Add(amountFeeValue.Mul(starLevelDividends.Div(decimalRate))).RoundFloor(8).String() | |||
var afterCommunityDividendsValues = chain.CommunityDividends | |||
if chain.CommunityDividends != "" { | |||
communityDividendsNums, _ := decimal.NewFromString(chain.CommunityDividends) | |||
communityDividends, _ := decimal.NewFromString(destructionSetting.CommunityDividends) //社区分红百分比 | |||
afterCommunityDividendsValues = communityDividendsNums.Add(amountFeeValue.Mul(communityDividends.Div(decimalRate))).RoundFloor(8).String() | |||
} | |||
destructionQuantityNums, _ := decimal.NewFromString(chain.DestructionQuantityNums) | |||
destructionQuantity, _ := decimal.NewFromString(destructionSetting.DestructionQuantity) //销毁百分比 | |||
afterDestructionQuantityValues := destructionQuantityNums.Add(amountFeeValue.Mul(destructionQuantity.Div(decimalRate))).RoundFloor(8).String() | |||
@@ -236,6 +251,8 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues = afterPublicWelfareAndCharityValues | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = afterStarLevelDividendsValues | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeCommunityDividends = chain.CommunityDividends //社区分红百分比 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterCommunityDividends = afterCommunityDividendsValues | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = afterDestructionQuantityValues | |||
@@ -294,6 +311,8 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues = chain.PublicWelfareAndCharity | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = beforeStarLevelDividends.Sub(amountValue).RoundFloor(8).String() | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeCommunityDividends = chain.CommunityDividends //社区分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterCommunityDividends = chain.CommunityDividends | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | |||
@@ -326,8 +345,10 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDevelopmentCommitteeValues = chain.DevelopmentCommittee | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforePublicWelfareAndCharityValues = chain.PublicWelfareAndCharity //公益慈善 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues = chain.PublicWelfareAndCharity | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeCommunityDividends = chain.CommunityDividends //社区分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterCommunityDividends = chain.CommunityDividends | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | |||
@@ -361,8 +382,10 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDevelopmentCommitteeValues = chain.DevelopmentCommittee | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforePublicWelfareAndCharityValues = chain.PublicWelfareAndCharity //公益慈善 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues = chain.PublicWelfareAndCharity | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeCommunityDividends = chain.CommunityDividends //社区分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterCommunityDividends = chain.CommunityDividends | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | |||
@@ -373,6 +396,38 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds //市商资金 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantFundValues = beforeMarketplaceMerchantFunds.Sub(amountFeeValue).String() | |||
break | |||
case int(enum.CommunityDividends): //社区分红 | |||
beforeCommunityDividends, _ := decimal.NewFromString(chain.CommunityDividends) | |||
oneCirclesAvailableGreenEnergyPointsFlow.Direction = 2 | |||
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 = chain.StarLevelDividends //星级分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityFundValues = chain.OriginalFunds //原始资金 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityFundValues = chain.OriginalFunds | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds //市商资金 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeCommunityDividends = chain.CommunityDividends //社区分红 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterCommunityDividends = beforeCommunityDividends.Sub(amountValue).RoundFloor(8).String() | |||
break | |||
} | |||
chain.EcologicalApplication = oneCirclesAvailableGreenEnergyPointsFlow.AfterEcologicalApplicationValues //生态应用 | |||
@@ -384,10 +439,15 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||
chain.DevelopmentCommittee = oneCirclesAvailableGreenEnergyPointsFlow.AfterDevelopmentCommitteeValues //发展委员会 | |||
chain.PublicWelfareAndCharity = oneCirclesAvailableGreenEnergyPointsFlow.AfterPublicWelfareAndCharityValues //公益慈善 | |||
chain.StarLevelDividends = oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues //星级分红 | |||
chain.CommunityDividends = oneCirclesAvailableGreenEnergyPointsFlow.AfterCommunityDividends //社区分红 | |||
chain.DestructionQuantityNums = oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues //销毁数量 | |||
chain.OriginalFunds = oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityFundValues //原始资金 | |||
chain.MarketplaceMerchantFunds = oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantFundValues //市商资金 | |||
oneCirclesAvailableGreenEnergyPointsFlow.BeforePrice = chain.NowPrice //价格 | |||
oneCirclesAvailableGreenEnergyPointsFlow.AfterPrice = nowPriceValue | |||
//更新 `one_circles_green_energy_basic_setting` 表 | |||
if chain.NowPrice != nowPriceValue { | |||
chain.NowPrice = nowPriceValue | |||
@@ -46,6 +46,17 @@ func AddSmallPublicPlatoonRelateCommission(engine *xorm.Engine, AddSmallPublicPl | |||
return nil, err | |||
} | |||
for _, param := range AddSmallPublicPlatoonRelateCommissionReqList { | |||
isHasPublicPlatoonUserRelation, err11 := db.UserSmallPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{ | |||
"key": "uid", | |||
"value": param.Uid, | |||
}) | |||
if err11 != nil { | |||
return nil, err11 | |||
} | |||
if isHasPublicPlatoonUserRelation != nil { | |||
return nil, errors.New("当前用户已加入公排") | |||
} | |||
//1、判断是否有推荐人 | |||
if param.RecommendUid != "" { | |||
//2、有推荐人 | |||
@@ -915,7 +926,7 @@ func SmallDealCommonWealthPunish(engine *xorm.Engine, uid int, reason string) (e | |||
return | |||
} | |||
//2、查询出 `user_public_platoon_relation` 中相关记录 && 将该记录的uid置为 -1 | |||
//2、查询出 `user_small_public_platoon_relation` 中相关记录 && 将该记录的uid置为 -1 | |||
params, err := db.UserSmallPublicPlatoonRelationGetOneByParams(engine, map[string]interface{}{ | |||
"key": "uid", | |||
"value": uid, | |||
@@ -925,15 +936,15 @@ func SmallDealCommonWealthPunish(engine *xorm.Engine, uid int, reason string) (e | |||
return | |||
} | |||
if params == nil { | |||
err = errors.New("未查询到公排关系记录") | |||
fmt.Println("未查询到公排关系记录!!!!!!!", uid) | |||
_ = session.Rollback() | |||
} | |||
//TODO::判断是否为推荐用户 | |||
if params.RecommendUid == 0 { | |||
params.Uid = params.Uid - 2147483648 | |||
params.Uid = params.Uid - int(time.Now().Unix()) | |||
} else { | |||
params.Uid = params.Uid - 2147483648 | |||
params.Uid = params.Uid - int(time.Now().Unix()) | |||
} | |||
for n := 1; n <= 9; n++ { | |||