From 9cbcd77b17a3caf208340def1ca18f4c07b1b466 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Mon, 15 Aug 2022 19:34:07 +0800 Subject: [PATCH] add reverse:for v1.8.2 test --- db/db_capital_pool.go | 83 ++++++++++++++++++++++++++++++ db/model/capital_pool_agent.go | 26 ++++++++++ db/model/capital_pool_agent_ord.go | 20 +++++++ md/pool_bonus.go | 71 +++++++++++++++++++++++++ svc/svc_pool_bonus_agent_ord.go | 43 ++++++++++++++++ 5 files changed, 243 insertions(+) create mode 100644 db/db_capital_pool.go create mode 100644 db/model/capital_pool_agent.go create mode 100644 db/model/capital_pool_agent_ord.go create mode 100644 md/pool_bonus.go create mode 100644 svc/svc_pool_bonus_agent_ord.go diff --git a/db/db_capital_pool.go b/db/db_capital_pool.go new file mode 100644 index 0000000..4fbd8ee --- /dev/null +++ b/db/db_capital_pool.go @@ -0,0 +1,83 @@ +package db + +import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" + "errors" + "time" + "xorm.io/xorm" +) + +//初始化资金池基础设置 +func InitCapitalPool(engine *xorm.Engine) error { + pool := &model.CapitalPoolAgent{ + IsUse: 0, + IsAuto: 0, + BonusType: "1", + BonusDateType: 1, + BonusTime: "", + BonusLevelType: 1, + UserLevelGroup: "", + CreateAt: time.Now(), + UpdateAt: time.Now(), + SettleCardinality: "commission", + } + addCapitalPool, err := AddCapitalPool(engine, pool) + if err != nil { + return err + } + if addCapitalPool != 1 { + return errors.New("插入条数有误!") + } + return nil +} + +//新增资金池基础设置 +func AddCapitalPool(engine *xorm.Engine, pool *model.CapitalPoolAgent) (int64, error) { + one, err := engine.InsertOne(pool) + return one, err +} + +//编辑资金池基础设置 +func UpdateCapitalPool(engine *xorm.Engine, pool *model.CapitalPoolAgent) (int64, error) { + session := engine.NewSession() + defer session.Close() + err := session.Begin() + if err != nil { + return 0, err + } + update, err := session.ID(pool.Id).AllCols().Update(pool) + if err != nil { + session.Rollback() + return 0, err + } + session.Commit() + return update, err +} + +//获取资金池基础设置 +func GetCapitalPool(engine *xorm.Engine) (pool model.CapitalPoolAgent, err error) { + get, err := engine.Where("1 = 1").Get(&pool) + if err != nil { + return model.CapitalPoolAgent{}, err + } + + if !get { + err := InitCapitalPool(engine) + if err != nil { + return model.CapitalPoolAgent{}, err + } + capitalPool, err := GetCapitalPool(engine) + if err != nil { + return model.CapitalPoolAgent{}, err + } + if capitalPool.SettleCardinality == "" { + capitalPool.SettleCardinality = "commission" + } + return capitalPool, err + } else { + if pool.SettleCardinality == "" { + pool.SettleCardinality = "commission" + } + } + return +} diff --git a/db/model/capital_pool_agent.go b/db/model/capital_pool_agent.go new file mode 100644 index 0000000..860f1ff --- /dev/null +++ b/db/model/capital_pool_agent.go @@ -0,0 +1,26 @@ +package model + +import ( + "time" +) + +type CapitalPoolAgent struct { + Id int `json:"id" xorm:"not null pk autoincr comment('主键id') INT(11)"` + IsUse int `json:"is_use" xorm:"not null comment('是否开启(否:0;是:1)') TINYINT(1)"` + IsAuto int `json:"is_auto" xorm:"not null default 0 comment('是否自动分红(否:0;是:1)') TINYINT(1)"` + BonusType string `json:"bonus_type" xorm:"not null default '0' comment('分红类型(1佣金,2积分,3区块币)多个以逗号隔开') VARCHAR(255)"` + BonusDateType int `json:"bonus_date_type" xorm:"not null default 0 comment('日期类型(1每天,2固定时间)') TINYINT(1)"` + BonusTime string `json:"bonus_time" xorm:"default '0' comment('分红日期(1,15,30)多个日期已逗号分隔开;ps 只有日期类型是2才是有数据') VARCHAR(255)"` + BonusLevelType int `json:"bonus_level_type" xorm:"not null default 0 comment('用户等级分红类型(1,指定等级,2大于或等于指定等级)') TINYINT(1)"` + UserLevelGroup string `json:"user_level_group" xorm:"not null comment('指定用户等级组json') TEXT"` + UserGroup string `json:"user_group" xorm:"not null comment('指定用户组json') LONGTEXT"` + OpenSecurities int `json:"open_securities" xorm:"not null comment('是否开启分红劵功能') TINYINT(1)"` + SecuritiesId string `json:"securities_id" xorm:"not null default '' comment('虚拟币id') VARCHAR(255)"` + ExchangeSecuritiesId string `json:"exchange_securities_id" xorm:"comment('兑换分红券虚拟币id') VARCHAR(255)"` + ExchangeRate string `json:"exchange_rate" xorm:"comment('兑换比例,固定为x:1') VARCHAR(255)"` + UserLevelLimit string `json:"user_level_limit" xorm:"comment('用户等级限制组json') TEXT"` + CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') TIMESTAMP"` + UpdateAt time.Time `json:"update_at" xorm:"default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"` + SettleCardinality string `json:"settle_cardinality" xorm:"comment('基数') VARCHAR(255)"` + QuantityAllocation int `json:"quantity_allocation" xorm:"not null comment('数量分配 0按人数 1按份数') TINYINT(1)"` +} diff --git a/db/model/capital_pool_agent_ord.go b/db/model/capital_pool_agent_ord.go new file mode 100644 index 0000000..7f15846 --- /dev/null +++ b/db/model/capital_pool_agent_ord.go @@ -0,0 +1,20 @@ +package model + +import ( + "time" +) + +type CapitalPoolAgentOrd struct { + Id int `json:"id" xorm:"not null pk autoincr comment('主键id') INT(11)"` + Uid int `json:"uid" xorm:"not null comment('用户id') INT(11)"` + Pvd string `json:"pvd" xorm:"not null comment('订单渠道:自营,导购,o2o。。。。') VARCHAR(255)"` + OrdId int64 `json:"ord_id" xorm:"not null default 0 comment('订单id') BIGINT(20)"` + Commission string `json:"commission" xorm:"not null comment('订单总佣金') DECIMAL(12,6)"` + Price string `json:"price" xorm:"not null comment('付款金额') DECIMAL(12,6)"` + CommissionType string `json:"commission_type" xorm:"not null default '0' comment('佣金类型(CNY,虚拟币1Id,虚拟币2Id)') VARCHAR(100)"` + CapitalPoolRate string `json:"capital_pool_rate" xorm:"not null comment('资金池存入比例') DECIMAL(6,4)"` + DepositValue string `json:"deposit_value" xorm:"not null comment('存入金额') DECIMAL(12,6)"` + CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') TIMESTAMP"` + UpdateAt time.Time `json:"update_at" xorm:"default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"` + SettleCardinality string `json:"settle_cardinality" xorm:"comment('基数') VARCHAR(255)"` +} diff --git a/md/pool_bonus.go b/md/pool_bonus.go new file mode 100644 index 0000000..82a1ac5 --- /dev/null +++ b/md/pool_bonus.go @@ -0,0 +1,71 @@ +package md + +type PoolBonus struct { + BonusLevelType int `json:"bonus_level_type"` + BonusValue float64 `json:"bonus_value"` //分红金额 + BonusCoinType map[string]string `json:"bonus_coin_type"` //分红币种和金额比例 + SecuritiesId string `json:"securities_id"` + QuantityAllocation string `json:"quantity_allocation"` + BonusUserLevelGroup []*BonusUserLevel //分红的前置条件 + BonusUserGroup []*BonusUserGroup //分红的前置条件 +} + +type BonusUserLevel struct { + CoinTypeList []*CoinTypeList `json:"coin_type_list"` + LevelID string `json:"level_id"` + LevelWeight string `json:"level_weight"` + SecuritiesValue string `json:"securities_value"` + ChildLevelId string `json:"child_level_id"` + Num string `json:"num"` +} + +type CoinTypeList struct { + CoinID string `json:"coin_id"` + CoinRate string `json:"coin_rate"` +} +type BonusUserGroup struct { + CoinTypeList []*CoinTypeList `json:"coin_type_list"` + Uid string `json:"uid"` + Phone string `json:"phone"` + SecuritiesValue string `json:"securities_value"` + ChildLevelId string `json:"child_level_id"` + Num string `json:"num"` +} +type BonusCapitalInfo struct { + BonusLevelType int `json:"bonus_level_type"` + BonusCoinType map[string]string `json:"bonus_coin_type"` //分红币种和金额比例 + BonusValue float64 `json:"bonus_value"` //分红金额 + //BonusCoinType map[string]string `json:"bonus_coin_type"`//分红币种和分红金额 + UserLevelGroupBonus []*UserLevelGroupBonus `json:"user_level_group_bonus"` + UserGroupBonus []*UserGroupBonus `json:"user_group_bonus"` + Massage string `json:"massage"` +} +type UserLevelGroupBonus struct { + UserLevelId string `json:"user_level_id"` //等级id + UserNum string `json:"user_num"` //用户人数 + BonusCoinTypeList []*BonusCoinType `json:"bonus_coin_type_list"` // +} +type UserGroupBonus struct { + Uid string `json:"uid"` //id + UserNum string `json:"user_num"` //用户人数 + BonusCoinTypeList []*BonusCoinType `json:"bonus_coin_type_list"` // + Phone string `json:"phone"` //id + +} +type BonusCoinType struct { + CoinID string `json:"coin_id"` //币种类型 + CoinValue string `json:"coin_value"` //分红总金额 + AverageValue string `json:"average_value"` //人均分红金额 +} + +type BonusOrdParam struct { + Uid string `json:"uid" remark:"用户id"` + Pvd string `json:"pvd" remark:"订单渠道:自营,导购,o2o。。。。"` + OrdId string `json:"ord_id" remark:"订单id"` + Commission string `json:"commission" remark:"订单总佣金"` + CommissionType string `json:"commission_type" remark:"佣金类型(CNY,虚拟币1Id,虚拟币2Id)"` + CapitalPoolRate string `json:"capital_pool_rate" remark:"资金池存入比例"` + DepositValue string `json:"deposit_value" remark:"存入金额"` + Price string `json:"price" remark:"价格"` + PriceValue string `json:"price_value" remark:"价格"` +} diff --git a/svc/svc_pool_bonus_agent_ord.go b/svc/svc_pool_bonus_agent_ord.go new file mode 100644 index 0000000..7960d80 --- /dev/null +++ b/svc/svc_pool_bonus_agent_ord.go @@ -0,0 +1,43 @@ +package svc + +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" + "errors" + "github.com/jinzhu/copier" + "time" + "xorm.io/xorm" +) + +func AddBonusOrd(engine *xorm.Engine, t *md.BonusOrdParam) error { + + //获取分红基础设置 + pool, err := db.GetCapitalPool(engine) + if err != nil || pool.Id == 0 { + return errors.New("分红设置有误") + } + if pool.IsUse == 0 { + return errors.New("功能没有开始使用,插入分红失败") + } + var capitalPoolOrd model.CapitalPoolAgentOrd + copier.Copy(&capitalPoolOrd, &t) + capitalPoolOrd.Uid = zhios_order_relate_utils.StrToInt(t.Uid) + capitalPoolOrd.OrdId = zhios_order_relate_utils.AnyToInt64(t.OrdId) + capitalPoolOrd.CreateAt = time.Now() + capitalPoolOrd.UpdateAt = time.Now() + capitalPoolOrd.SettleCardinality = pool.SettleCardinality + if pool.SettleCardinality == "price" { //价格为基数 + capitalPoolOrd.DepositValue = t.PriceValue + capitalPoolOrd.Commission = t.PriceValue + } + one, err := engine.InsertOne(&capitalPoolOrd) + if err != nil || one == 0 { + if err == nil { + err = errors.New("插入数据有误!") + } + return err + } + return nil +}