@@ -0,0 +1,153 @@ | |||||
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" | |||||
) | |||||
// BatchSelectUserPublicPlatoonDoubleNetworkRelations 批量查询数据 TODO::和下面的方法重复了,建议采用下面的 `UserPublicPlatoonDoubleNetworkRelationFindByParams` 方法 | |||||
func BatchSelectUserPublicPlatoonDoubleNetworkRelations(Db *xorm.Engine, params map[string]interface{}) (*[]model.UserPublicPlatoonDoubleNetworkRelation, error) { | |||||
var UserPublicPlatoonDoubleNetworkRelationData []model.UserPublicPlatoonDoubleNetworkRelation | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]). | |||||
Find(&UserPublicPlatoonDoubleNetworkRelationData); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &UserPublicPlatoonDoubleNetworkRelationData, nil | |||||
} | |||||
// UserPublicPlatoonDoubleNetworkRelationInsert 插入单条数据 | |||||
func UserPublicPlatoonDoubleNetworkRelationInsert(Db *xorm.Engine, UserPublicPlatoonDoubleNetworkRelation *model.UserPublicPlatoonDoubleNetworkRelation) (int, error) { | |||||
_, err := Db.InsertOne(UserPublicPlatoonDoubleNetworkRelation) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return UserPublicPlatoonDoubleNetworkRelation.Id, nil | |||||
} | |||||
// BatchAddUserPublicPlatoonDoubleNetworkRelations 批量新增数据 | |||||
func BatchAddUserPublicPlatoonDoubleNetworkRelations(Db *xorm.Engine, UserPublicPlatoonDoubleNetworkRelationData []*model.UserPublicPlatoonDoubleNetworkRelation) (int64, error) { | |||||
affected, err := Db.Insert(UserPublicPlatoonDoubleNetworkRelationData) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
func GetUserPublicPlatoonDoubleNetworkRelationCount(Db *xorm.Engine) int { | |||||
var UserPublicPlatoonDoubleNetworkRelation model.UserPublicPlatoonDoubleNetworkRelation | |||||
session := Db.Where("") | |||||
count, err := session.Count(&UserPublicPlatoonDoubleNetworkRelation) | |||||
if err != nil { | |||||
return 0 | |||||
} | |||||
return int(count) | |||||
} | |||||
// UserPublicPlatoonDoubleNetworkRelationDelete 删除记录 | |||||
func UserPublicPlatoonDoubleNetworkRelationDelete(Db *xorm.Engine, id interface{}) (int64, error) { | |||||
if reflect.TypeOf(id).Kind() == reflect.Slice { | |||||
return Db.In("id", id).Delete(model.UserPublicPlatoonDoubleNetworkRelation{}) | |||||
} else { | |||||
return Db.Where("id = ?", id).Delete(model.UserPublicPlatoonDoubleNetworkRelation{}) | |||||
} | |||||
} | |||||
// UserPublicPlatoonDoubleNetworkRelationUpdate 更新记录 | |||||
func UserPublicPlatoonDoubleNetworkRelationUpdate(session *xorm.Session, id interface{}, UserPublicPlatoonDoubleNetworkRelation *model.UserPublicPlatoonDoubleNetworkRelation, forceColums ...string) (int64, error) { | |||||
var ( | |||||
affected int64 | |||||
err error | |||||
) | |||||
if forceColums != nil { | |||||
affected, err = session.Where("id=?", id).Cols(forceColums...).Update(UserPublicPlatoonDoubleNetworkRelation) | |||||
} else { | |||||
affected, err = session.Where("id=?", id).Update(UserPublicPlatoonDoubleNetworkRelation) | |||||
} | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
// UserPublicPlatoonDoubleNetworkRelationGetOneByParams 通过传入的参数查询数据(单条) | |||||
func UserPublicPlatoonDoubleNetworkRelationGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.UserPublicPlatoonDoubleNetworkRelation, error) { | |||||
var m model.UserPublicPlatoonDoubleNetworkRelation | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
if has, err := Db.Where(query, params["value"]).Get(&m); err != nil || has == false { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
// UserPublicPlatoonDoubleNetworkRelationFindByParams 通过传入的参数查询数据(多条) | |||||
func UserPublicPlatoonDoubleNetworkRelationFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.UserPublicPlatoonDoubleNetworkRelation, error) { | |||||
var m []model.UserPublicPlatoonDoubleNetworkRelation | |||||
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 UserPublicPlatoonDoubleNetworkRelationFindByParamsByPage(Db *xorm.Engine, params map[string]interface{}, page, pageSize int) (*[]model.UserPublicPlatoonDoubleNetworkRelation, error) { | |||||
var m []model.UserPublicPlatoonDoubleNetworkRelation | |||||
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,117 @@ | |||||
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" | |||||
) | |||||
// BatchSelectUserPublicPlatoonDoubleNetworkSettings 批量查询数据 TODO::和下面的方法重复了,建议采用下面的 `UserPublicPlatoonDoubleNetworkSettingFindByParams` 方法 | |||||
func BatchSelectUserPublicPlatoonDoubleNetworkSettings(Db *xorm.Engine, params map[string]interface{}) (*[]model.UserPublicPlatoonDoubleNetworkSetting, error) { | |||||
var UserPublicPlatoonDoubleNetworkSettingData []model.UserPublicPlatoonDoubleNetworkSetting | |||||
if err := Db.In(zhios_order_relate_utils.AnyToString(params["key"]), params["value"]). | |||||
Find(&UserPublicPlatoonDoubleNetworkSettingData); err != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err) | |||||
} | |||||
return &UserPublicPlatoonDoubleNetworkSettingData, nil | |||||
} | |||||
// UserPublicPlatoonDoubleNetworkSettingInsert 插入单条数据 | |||||
func UserPublicPlatoonDoubleNetworkSettingInsert(Db *xorm.Engine, UserPublicPlatoonDoubleNetworkSetting *model.UserPublicPlatoonDoubleNetworkSetting) (int, error) { | |||||
_, err := Db.InsertOne(UserPublicPlatoonDoubleNetworkSetting) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return UserPublicPlatoonDoubleNetworkSetting.Id, nil | |||||
} | |||||
// BatchAddUserPublicPlatoonDoubleNetworkSettings 批量新增数据 | |||||
func BatchAddUserPublicPlatoonDoubleNetworkSettings(Db *xorm.Engine, UserPublicPlatoonDoubleNetworkSettingData []*model.UserPublicPlatoonDoubleNetworkSetting) (int64, error) { | |||||
affected, err := Db.Insert(UserPublicPlatoonDoubleNetworkSettingData) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
func GetUserPublicPlatoonDoubleNetworkSettingCount(Db *xorm.Engine) int { | |||||
var UserPublicPlatoonDoubleNetworkSetting model.UserPublicPlatoonDoubleNetworkSetting | |||||
session := Db.Where("") | |||||
count, err := session.Count(&UserPublicPlatoonDoubleNetworkSetting) | |||||
if err != nil { | |||||
return 0 | |||||
} | |||||
return int(count) | |||||
} | |||||
// UserPublicPlatoonDoubleNetworkSettingDelete 删除记录 | |||||
func UserPublicPlatoonDoubleNetworkSettingDelete(Db *xorm.Engine, id interface{}) (int64, error) { | |||||
if reflect.TypeOf(id).Kind() == reflect.Slice { | |||||
return Db.In("id", id).Delete(model.UserPublicPlatoonDoubleNetworkSetting{}) | |||||
} else { | |||||
return Db.Where("id = ?", id).Delete(model.UserPublicPlatoonDoubleNetworkSetting{}) | |||||
} | |||||
} | |||||
// UserPublicPlatoonDoubleNetworkSettingUpdate 更新记录 | |||||
func UserPublicPlatoonDoubleNetworkSettingUpdate(Db *xorm.Engine, id interface{}, UserPublicPlatoonDoubleNetworkSetting *model.UserPublicPlatoonDoubleNetworkSetting, forceColums ...string) (int64, error) { | |||||
var ( | |||||
affected int64 | |||||
err error | |||||
) | |||||
if forceColums != nil { | |||||
affected, err = Db.Where("id=?", id).Cols(forceColums...).Update(UserPublicPlatoonDoubleNetworkSetting) | |||||
} else { | |||||
affected, err = Db.Where("id=?", id).Update(UserPublicPlatoonDoubleNetworkSetting) | |||||
} | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} | |||||
// UserPublicPlatoonDoubleNetworkSettingGetOneByParams 通过传入的参数查询数据(单条) | |||||
func UserPublicPlatoonDoubleNetworkSettingGetOneByParams(Db *xorm.Engine, params map[string]interface{}) (*model.UserPublicPlatoonDoubleNetworkSetting, error) { | |||||
var m model.UserPublicPlatoonDoubleNetworkSetting | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
if has, err := Db.Where(query, params["value"]).Get(&m); err != nil || has == false { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} | |||||
// UserPublicPlatoonDoubleNetworkSettingFindByParams 通过传入的参数查询数据(多条) | |||||
func UserPublicPlatoonDoubleNetworkSettingFindByParams(Db *xorm.Engine, params map[string]interface{}) (*[]model.UserPublicPlatoonDoubleNetworkSetting, error) { | |||||
var m []model.UserPublicPlatoonDoubleNetworkSetting | |||||
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 | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,20 @@ | |||||
package model | |||||
import ( | |||||
"time" | |||||
) | |||||
type UserPublicPlatoonDoubleNetworkRelation struct { | |||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||||
Uid int `json:"uid" xorm:"not null default 0 comment('用户id(若为-1,则代表等待新用户填充)') index INT(11)"` | |||||
FatherUid string `json:"father_uid" xorm:"not null default '' comment('父级id(123456-563464-438384)') index VARCHAR(100)"` | |||||
Pid int `json:"pid" xorm:"not null default 0 comment('父级id') INT(11)"` | |||||
RecommendUid int `json:"recommend_uid" xorm:"not null default 0 comment('推荐人id') INT(11)"` | |||||
Level int `json:"level" xorm:"not null default 1 comment('等级(整个系统)') INT(11)"` | |||||
Position int `json:"position" xorm:"not null default 1 comment('位置') unique INT(11)"` | |||||
UniqueIdentifier string `json:"unique_identifier" xorm:"not null default '' comment('唯一标识符(父级id-uid-等级-位置)') unique CHAR(100)"` | |||||
ReturnCommissionNum int `json:"return_commission_num" xorm:"not null default 0 comment('返佣次数') INT(11)"` | |||||
JoinAt time.Time `json:"join_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('加入公排时间') DATETIME"` | |||||
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"` | |||||
} |
@@ -0,0 +1,17 @@ | |||||
package model | |||||
import ( | |||||
"time" | |||||
) | |||||
type UserPublicPlatoonDoubleNetworkSetting struct { | |||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||||
IsOpen int `json:"is_open" xorm:"not null default 0 comment('是否开启(0:关闭 1:开启)') TINYINT(1)"` | |||||
SeveralTimes int `json:"several_times" xorm:"not null default 0 comment('几乘') TINYINT(3)"` | |||||
SeveralRows int `json:"several_rows" xorm:"not null default 0 comment('几排') TINYINT(3)"` | |||||
OriginatorUid int `json:"originator_uid" xorm:"not null default -1 comment('创始人uid') INT(11)"` | |||||
SettlementDate string `json:"settlement_date" xorm:"not null default '0000-00-00 00:00:00' comment('结算日期') CHAR(50)"` | |||||
Ext string `json:"ext" xorm:"comment('拓展字段(json存储)') TEXT"` | |||||
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"` | |||||
} |
@@ -0,0 +1,25 @@ | |||||
package md | |||||
// 公排结构 | |||||
type DoubleNetworkLvGrade struct { | |||||
Lv int `json:"lv"` // 会员级别 | |||||
LvName string `json:"lv_name"` // 会员名称 | |||||
ReturnType []string `json:"return_type"` //返利类型 | |||||
CommonWealthSystem map[string]string `json:"common_wealth_system"` //共富制度比例 | |||||
SelfRateList map[string]string `json:"self_rate_list"` // 自购比例 | |||||
DirectPush map[string]string `json:"direct_push"` // 直推奖励比例 | |||||
} | |||||
type PublicPlatoonDoubleNetworkRelateCommissionReq struct { | |||||
Pvd string `json:"pvd"` //平台供应商 (taobao/jd/pdd/mall_goods ...) | |||||
Uid string `json:"uid"` | |||||
UserLevel string `json:"user_level"` //用户等级 | |||||
PendingAmount string `json:"pending_amount"` //待处理金额 | |||||
Oid string `json:"oid"` //订单id | |||||
PendingIntegral string `json:"pending_integral"` //待处理金额 | |||||
} | |||||
type AddPublicPlatoonDoubleNetworkDoubleNetworkRelateCommissionReq struct { | |||||
Uid string `json:"uid"` | |||||
RecommendUid string `json:"recommend_uid"` //推荐人uid | |||||
} |
@@ -48,8 +48,14 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends | oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends | ||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | ||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | ||||
originalFunds, _ := decimal.NewFromString(chain.OriginalFunds) //原始资金 | |||||
afterOriginalFundValues := originalFunds.Add(nowPrice.Mul(amountValue)).RoundFloor(8).String() | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityFundValues = chain.OriginalFunds //原始资金 | oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityFundValues = chain.OriginalFunds //原始资金 | ||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityFundValues = chain.OriginalFunds | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityFundValues = afterOriginalFundValues | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds //市商资金 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds | |||||
break | break | ||||
case int(enum.TeamActivePointRedemption): //团队活跃积分兑换 | case int(enum.TeamActivePointRedemption): //团队活跃积分兑换 | ||||
beforeOriginalQuantity, _ := decimal.NewFromString(chain.OriginalQuantityNums) | beforeOriginalQuantity, _ := decimal.NewFromString(chain.OriginalQuantityNums) | ||||
@@ -74,8 +80,14 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends | oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends | ||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | ||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | ||||
originalFunds, _ := decimal.NewFromString(chain.OriginalFunds) //原始资金 | |||||
afterOriginalFundValues := originalFunds.Add(nowPrice.Mul(amountValue)).RoundFloor(8).String() | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityFundValues = chain.OriginalFunds //原始资金 | oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityFundValues = chain.OriginalFunds //原始资金 | ||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityFundValues = chain.OriginalFunds | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityFundValues = afterOriginalFundValues | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds //市商资金 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds | |||||
break | break | ||||
case int(enum.SettlementOfGreenEnergyRelease): //结算绿色能量释放 | case int(enum.SettlementOfGreenEnergyRelease): //结算绿色能量释放 | ||||
oneCirclesAvailableGreenEnergyPointsFlow.Direction = 1 | oneCirclesAvailableGreenEnergyPointsFlow.Direction = 1 | ||||
@@ -101,6 +113,8 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | ||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityFundValues = chain.OriginalFunds //原始资金 | oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityFundValues = chain.OriginalFunds //原始资金 | ||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityFundValues = chain.OriginalFunds | oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityFundValues = chain.OriginalFunds | ||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds //市商资金 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds | |||||
break | break | ||||
case int(enum.SignInReward): //签到奖励 | case int(enum.SignInReward): //签到奖励 | ||||
beforeTotalActiveGiveaways, _ := decimal.NewFromString(chain.TotalActiveGiveaways) | beforeTotalActiveGiveaways, _ := decimal.NewFromString(chain.TotalActiveGiveaways) | ||||
@@ -129,6 +143,8 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds | oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds | ||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityFundValues = chain.OriginalFunds //原始资金 | oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityFundValues = chain.OriginalFunds //原始资金 | ||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityFundValues = chain.OriginalFunds | oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityFundValues = chain.OriginalFunds | ||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds //市商资金 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds | |||||
break | break | ||||
case int(enum.AccountBalanceExchange): //账户余额兑换 | case int(enum.AccountBalanceExchange): //账户余额兑换 | ||||
beforeOriginalQuantity, _ := decimal.NewFromString(chain.OriginalQuantityNums) | beforeOriginalQuantity, _ := decimal.NewFromString(chain.OriginalQuantityNums) | ||||
@@ -153,13 +169,14 @@ func DealAvailableGreenEnergyCoin(session *xorm.Session, kind int, amount, amoun | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends | oneCirclesAvailableGreenEnergyPointsFlow.AfterStarLevelDividendsValues = chain.StarLevelDividends | ||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | oneCirclesAvailableGreenEnergyPointsFlow.BeforeDestructionQuantityValues = chain.DestructionQuantityNums //销毁数量 | ||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | oneCirclesAvailableGreenEnergyPointsFlow.AfterDestructionQuantityValues = chain.DestructionQuantityNums | ||||
originalFunds, _ := decimal.NewFromString(chain.OriginalFunds) //原始资金 | originalFunds, _ := decimal.NewFromString(chain.OriginalFunds) //原始资金 | ||||
afterOriginalFundValues := originalFunds.Add(nowPrice.Mul(amountValue)).RoundFloor(8).String() | afterOriginalFundValues := originalFunds.Add(nowPrice.Mul(amountValue)).RoundFloor(8).String() | ||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityFundValues = chain.OriginalFunds //原始资金 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityFundValues = afterOriginalFundValues | |||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds //市商资金 | oneCirclesAvailableGreenEnergyPointsFlow.BeforeMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds //市商资金 | ||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds | oneCirclesAvailableGreenEnergyPointsFlow.AfterMarketplaceMerchantFundValues = chain.MarketplaceMerchantFunds | ||||
oneCirclesAvailableGreenEnergyPointsFlow.BeforeOriginalQuantityFundValues = chain.OriginalFunds //原始资金 | |||||
oneCirclesAvailableGreenEnergyPointsFlow.AfterOriginalQuantityFundValues = afterOriginalFundValues | |||||
break | break | ||||
case int(enum.GreenEnergyExchangeBalance): //绿色能量兑换余额 | case int(enum.GreenEnergyExchangeBalance): //绿色能量兑换余额 | ||||
var destructionSetting *md2.DestructionSettingStruct | var destructionSetting *md2.DestructionSettingStruct | ||||
@@ -0,0 +1,345 @@ | |||||
package rule | |||||
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" | |||||
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" | |||||
"math" | |||||
"math/rand" | |||||
"strings" | |||||
"time" | |||||
"xorm.io/xorm" | |||||
) | |||||
// AddPublicPlatoonDoubleNetworkRelateCommission 新增公排用户关系记录 | |||||
func AddPublicPlatoonDoubleNetworkRelateCommission(engine *xorm.Engine, AddPublicPlatoonDoubleNetworkRelateCommissionReqList []*md.AddPublicPlatoonDoubleNetworkDoubleNetworkRelateCommissionReq) (map[string]*model.UserPublicPlatoonDoubleNetworkRelation, error) { | |||||
var resp = map[string]*model.UserPublicPlatoonDoubleNetworkRelation{} | |||||
//查找 `user_public_platoon_setting` 基础设置 | |||||
userPublicPlatoonDoubleNetworkSetting, err := db.UserPublicPlatoonDoubleNetworkSettingGetOneByParams(engine, map[string]interface{}{ | |||||
"key": "is_open", | |||||
"value": 1, | |||||
}) | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
for _, param := range AddPublicPlatoonDoubleNetworkRelateCommissionReqList { | |||||
//TODO::判断是否有uid为-1 (代表等待新用户填充) 的记录 | |||||
userPublicPlatoonDoubleNetworkRelation, err := db.UserPublicPlatoonDoubleNetworkRelationGetOneByParams(engine, map[string]interface{}{ | |||||
"key": "uid", | |||||
"value": -1, | |||||
}) | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
if userPublicPlatoonDoubleNetworkRelation != nil { | |||||
now := time.Now() | |||||
uniqueIdentifier := strings.Split(userPublicPlatoonDoubleNetworkRelation.UniqueIdentifier, "-") | |||||
uniqueIdentifier[1] = param.Uid | |||||
userPublicPlatoonDoubleNetworkRelation.Uid = zhios_order_relate_utils.StrToInt(param.Uid) | |||||
userPublicPlatoonDoubleNetworkRelation.UniqueIdentifier = strings.Join(uniqueIdentifier, "-") | |||||
userPublicPlatoonDoubleNetworkRelation.RecommendUid = zhios_order_relate_utils.StrToInt(param.RecommendUid) | |||||
userPublicPlatoonDoubleNetworkRelation.ReturnCommissionNum = 0 | |||||
userPublicPlatoonDoubleNetworkRelation.JoinAt = now | |||||
userPublicPlatoonDoubleNetworkRelation.CreateAt = now | |||||
userPublicPlatoonDoubleNetworkRelation.UpdateAt = now | |||||
updateAffected, err := db.UserPublicPlatoonDoubleNetworkRelationUpdate(engine.NewSession(), userPublicPlatoonDoubleNetworkRelation.Id, userPublicPlatoonDoubleNetworkRelation) | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
if updateAffected == 0 { | |||||
err = errors.New("更新 user_public_platoon_relation 记录失败") | |||||
return nil, err | |||||
} else { | |||||
resp[param.Uid] = userPublicPlatoonDoubleNetworkRelation | |||||
} | |||||
continue | |||||
} | |||||
res, err := publicPlatoonDoubleNetwork(engine, zhios_order_relate_utils.StrToInt(param.Uid), zhios_order_relate_utils.StrToInt(param.RecommendUid), *userPublicPlatoonDoubleNetworkSetting) | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
resp[param.Uid] = &res | |||||
} | |||||
return resp, nil | |||||
} | |||||
/* | |||||
公排方法 | |||||
TODO 相关公式: | |||||
1: 每个等级的起始值(1+5^0+5^1+5^2+...+5^x-2), 每个等级的结束值(`5^0+5^1+5^2+...+5^x-1) | |||||
2: 根据position查找父级position { (position-1)/5 } | |||||
3: 根据position查找等级level {position-5^0-5^1-5^2-...-5^x 是否 <0 ? => x+1 } | |||||
4: 根据最新自增`id` 逆向推导 position {levelFirstPosition + (position-1)%5} | |||||
*/ | |||||
func publicPlatoonDoubleNetwork(engine *xorm.Engine, uid, recommendUid int, userPublicPlatoonDoubleNetworkSetting model.UserPublicPlatoonDoubleNetworkSetting) (model.UserPublicPlatoonDoubleNetworkRelation, error) { | |||||
var userPublicPlatoonDoubleNetworkRelation model.UserPublicPlatoonDoubleNetworkRelation | |||||
//1、 查找当前 user_public_platoon_relation 中 `position` 最大的记录 | |||||
var m model.UserPublicPlatoonDoubleNetworkRelation | |||||
has, err := engine.OrderBy("id desc").Get(&m) | |||||
if err != nil { | |||||
return userPublicPlatoonDoubleNetworkRelation, err | |||||
} | |||||
if has == false { | |||||
return userPublicPlatoonDoubleNetworkRelation, errors.New("查询 user_public_platoon_relation 记录失败") | |||||
} | |||||
//TODO::判断 `position + userPublicPlatoonDoubleNetworkSetting.SeveralTimes(几乘)` OR `position + 1` | |||||
var position, position1, position2 int | |||||
position1 = m.Position + 1 | |||||
position2 = m.Position + userPublicPlatoonDoubleNetworkSetting.SeveralTimes | |||||
var level, level1, level2 float64 | |||||
makeSearchLevelDoubleNetwork(&position1, float64(userPublicPlatoonDoubleNetworkSetting.SeveralTimes), &level1) | |||||
makeSearchLevelDoubleNetwork(&position2, float64(userPublicPlatoonDoubleNetworkSetting.SeveralTimes), &level2) | |||||
level = level1 + 1 //TODO::根据公式需要 + 1 | |||||
if level > 2 { | |||||
if level1 != level2 { | |||||
//if position1 == getLevelForLastPositionDoubleNetwork(int(level), userPublicPlatoonDoubleNetworkSetting.SeveralTimes) { | |||||
// position = position1 | |||||
//} else { | |||||
position = reverseDeductionPositionDoubleNetwork(m.Position, getLevelForFirstPositionDoubleNetwork(int(level), userPublicPlatoonDoubleNetworkSetting.SeveralTimes), userPublicPlatoonDoubleNetworkSetting.SeveralTimes) | |||||
//} | |||||
} else { | |||||
if position1 == getLevelForFirstPositionDoubleNetwork(int(level), userPublicPlatoonDoubleNetworkSetting.SeveralTimes) { | |||||
position = position1 | |||||
} else { | |||||
position = position2 | |||||
} | |||||
} | |||||
} else { | |||||
position = position1 | |||||
} | |||||
pid := makeSearchPidDoubleNetwork(position, userPublicPlatoonDoubleNetworkSetting.SeveralTimes) | |||||
//2、查找对应pid的 user_public_platoon_relation 记录 | |||||
var m1 model.UserPublicPlatoonDoubleNetworkRelation | |||||
if has, err := engine.Where("position=?", pid).Get(&m1); err != nil || has == false { | |||||
return userPublicPlatoonDoubleNetworkRelation, err | |||||
} | |||||
var fatherUid string | |||||
if m1.FatherUid == "" { | |||||
//TODO::顶级 | |||||
fatherUid = zhios_order_relate_utils.IntToStr(m1.Position) | |||||
} else { | |||||
fatherUids := strings.Split(m1.FatherUid, "-") | |||||
if len(fatherUids) > userPublicPlatoonDoubleNetworkSetting.SeveralRows { | |||||
fatherUid = zhios_order_relate_utils.IntToStr(m1.Position) + "-" + strings.Join(fatherUids[0:userPublicPlatoonDoubleNetworkSetting.SeveralRows:len(fatherUids)], "-") | |||||
} else { | |||||
fatherUid = zhios_order_relate_utils.IntToStr(m1.Position) + "-" + m1.FatherUid | |||||
} | |||||
} | |||||
//唯一标识符(父级id-uid-等级-位置) | |||||
var uniqueIdentifier = zhios_order_relate_utils.IntToStr(pid) + "-" + zhios_order_relate_utils.IntToStr(uid) + "-" + zhios_order_relate_utils.IntToStr(int(level)) + "-" + zhios_order_relate_utils.IntToStr(position) | |||||
// 3、插入 user_public_platoon_relation 记录 | |||||
now := time.Now() | |||||
userPublicPlatoonDoubleNetworkRelation.Uid = uid | |||||
userPublicPlatoonDoubleNetworkRelation.FatherUid = fatherUid | |||||
userPublicPlatoonDoubleNetworkRelation.Pid = pid | |||||
userPublicPlatoonDoubleNetworkRelation.RecommendUid = recommendUid | |||||
userPublicPlatoonDoubleNetworkRelation.Level = int(level) | |||||
userPublicPlatoonDoubleNetworkRelation.Position = position | |||||
userPublicPlatoonDoubleNetworkRelation.UniqueIdentifier = uniqueIdentifier | |||||
userPublicPlatoonDoubleNetworkRelation.JoinAt = now | |||||
userPublicPlatoonDoubleNetworkRelation.CreateAt = now | |||||
userPublicPlatoonDoubleNetworkRelation.UpdateAt = now | |||||
_, err = db.UserPublicPlatoonDoubleNetworkRelationInsert(engine, &userPublicPlatoonDoubleNetworkRelation) | |||||
if err != nil { | |||||
return model.UserPublicPlatoonDoubleNetworkRelation{}, err | |||||
} | |||||
return userPublicPlatoonDoubleNetworkRelation, nil | |||||
} | |||||
// reverseDeductionPositionDoubleNetwork 逆向推导 position | |||||
func reverseDeductionPositionDoubleNetwork(calcPosition, levelFirstPosition, severalTimes int) (position int) { | |||||
remainder := (calcPosition - 1) % severalTimes | |||||
position = levelFirstPosition + remainder | |||||
return | |||||
} | |||||
// getLevelForFirstPositionDoubleNetwork 返回当前等级的起始值 | |||||
func getLevelForFirstPositionDoubleNetwork(level, severalTimes int) (position int) { | |||||
position = position + 1 | |||||
for n := 0; n <= (level - 2); n++ { | |||||
position += int(math.Pow(float64(severalTimes), float64(n))) | |||||
} | |||||
return | |||||
} | |||||
// getLevelForLastPositionDoubleNetwork 每个等级的结束值 | |||||
func getLevelForLastPositionDoubleNetwork(level, severalTimes int) (position int) { | |||||
for n := 0; n <= (level - 1); n++ { | |||||
position += int(math.Pow(float64(severalTimes), float64(n))) | |||||
} | |||||
return | |||||
} | |||||
//递归查找等级 | |||||
func makeSearchLevelDoubleNetwork(position *int, rows float64, times *float64) (level int) { | |||||
difference := *position - int(math.Pow(rows, *times)) | |||||
if difference <= 0 { | |||||
return int(*times) | |||||
} else { | |||||
position = &difference | |||||
*times++ | |||||
return makeSearchLevelDoubleNetwork(position, rows, times) | |||||
} | |||||
} | |||||
//查找归属父级id | |||||
func makeSearchPidDoubleNetwork(position int, row int) (pid int) { | |||||
divisionValue := (position - 1) / row | |||||
if divisionValue == 0 { | |||||
pid = 1 | |||||
return | |||||
} else { | |||||
if (divisionValue*row + 1) == position { | |||||
pid = divisionValue | |||||
return | |||||
} else { | |||||
pid = divisionValue + 1 | |||||
return | |||||
} | |||||
} | |||||
} | |||||
// JudgeUserBelowLevelDoubleNetwork 判断当前用户下几级排满 | |||||
func JudgeUserBelowLevelDoubleNetworkDoubleNetwork(engine *xorm.Engine, uid int) (level int, err error) { | |||||
//1、查找 `user_public_platoon_setting` 基础设置 | |||||
userPublicPlatoonDoubleNetworkSetting, err := db.UserPublicPlatoonDoubleNetworkSettingGetOneByParams(engine, map[string]interface{}{ | |||||
"key": "is_open", | |||||
"value": 1, | |||||
}) | |||||
if err != nil { | |||||
return | |||||
} | |||||
//2、查找当前用户所在的公排记录 | |||||
var m model.UserPublicPlatoonDoubleNetworkRelation | |||||
has, err := engine.Where("uid =?", uid).Get(&m) | |||||
if err != nil { | |||||
return | |||||
} | |||||
if !has { | |||||
err = errors.New("未查询到当前用户的公排记录") | |||||
return | |||||
} | |||||
//3、查找当前用户下最下级的层数 | |||||
var son model.UserPublicPlatoonDoubleNetworkRelation | |||||
hasSon, err := engine.Where("father_uid LIKE ?", "%-"+zhios_order_relate_utils.IntToStr(m.Id)). | |||||
Or("father_uid LIKE ?", zhios_order_relate_utils.IntToStr(m.Id)+"-%"). | |||||
Or("father_uid LIKE ?", "%-"+zhios_order_relate_utils.IntToStr(m.Id)+"-%"). | |||||
Or("father_uid = ?", m.Id). | |||||
OrderBy("id Desc").Get(&son) | |||||
if err != nil { | |||||
return | |||||
} | |||||
if !hasSon { | |||||
return | |||||
} | |||||
level = son.Level - m.Level | |||||
var list []model.UserPublicPlatoonDoubleNetworkRelation | |||||
if err = engine.Where("father_uid =?", son.FatherUid). | |||||
Find(&list); err != nil { | |||||
return | |||||
} | |||||
if len(list) == userPublicPlatoonDoubleNetworkSetting.SeveralTimes { | |||||
level++ | |||||
} | |||||
return | |||||
} | |||||
// FindRandUserDoubleNetwork 随机查找指定数量用户 | |||||
func FindRandUserDoubleNetwork(engine *xorm.Engine, nums int) (resp []int64, err error) { | |||||
//1、查找最小、最大 位置的公排位置 | |||||
var minM, maxM model.UserPublicPlatoonDoubleNetworkRelation | |||||
has, err := engine.Asc("id").Get(&minM) | |||||
if err != nil { | |||||
return | |||||
} | |||||
if !has { | |||||
err = errors.New("未查询到最小公排记录") | |||||
return | |||||
} | |||||
has, err = engine.Desc("id").Get(&maxM) | |||||
if err != nil { | |||||
return | |||||
} | |||||
if !has { | |||||
err = errors.New("未查询到最大公排记录") | |||||
return | |||||
} | |||||
var m model.UserPublicPlatoonDoubleNetworkRelation | |||||
count, err := engine.Count(&m) | |||||
if err != nil { | |||||
return | |||||
} | |||||
if int(count) < nums { | |||||
//TODO::直接查询所有的数据返回即可 | |||||
var list []model.UserPublicPlatoonDoubleNetworkRelation | |||||
if err1 := engine.Where("1=1"). | |||||
Find(&list); err1 != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err1) | |||||
} | |||||
for _, v := range list { | |||||
resp = append(resp, int64(v.Uid)) | |||||
} | |||||
return | |||||
nums = int(count) | |||||
} | |||||
var uniqueMap = map[int64]bool{} | |||||
var j = 0 | |||||
for { | |||||
ids := randSeedIntDoubleNetwork(int64(minM.Id), int64(maxM.Id), nums-len(resp), uniqueMap, &[]int64{}) | |||||
var list []model.UserPublicPlatoonDoubleNetworkRelation | |||||
if err1 := engine.In("id", ids). | |||||
Find(&list); err1 != nil { | |||||
return nil, zhios_order_relate_logx.Warn(err1) | |||||
} | |||||
for _, v := range list { | |||||
resp = append(resp, int64(v.Uid)) | |||||
uniqueMap[int64(v.Id)] = true | |||||
} | |||||
if len(resp) == nums { | |||||
break | |||||
} | |||||
if j == 10 { | |||||
//TODO::避免出现死循环 | |||||
break | |||||
} | |||||
j++ | |||||
} | |||||
return | |||||
} | |||||
func randSeedIntDoubleNetwork(start, end int64, nums int, uniqueMap map[int64]bool, resp *[]int64) (res []int64) { | |||||
rand.Seed(time.Now().UnixNano()) | |||||
for { | |||||
result := rand.Int63n(end) + start | |||||
if !uniqueMap[result] { | |||||
*resp = append(*resp, result) | |||||
uniqueMap[result] = true | |||||
break | |||||
} | |||||
} | |||||
if len(*resp) < nums { | |||||
randSeedIntDoubleNetwork(start, end, nums, uniqueMap, resp) | |||||
} | |||||
res = *resp | |||||
return res | |||||
} |