@@ -6,3 +6,7 @@ func QueryNativeString(Db *xorm.Engine, sql string, args ...interface{}) ([]map[ | |||||
results, err := Db.SQL(sql, args...).QueryString() | results, err := Db.SQL(sql, args...).QueryString() | ||||
return results, err | return results, err | ||||
} | } | ||||
func QueryNativeStringSess(sess *xorm.Session, sql string, args ...interface{}) ([]map[string]string, error) { | |||||
results, err := sess.SQL(sql, args...).QueryString() | |||||
return results, err | |||||
} |
@@ -53,6 +53,28 @@ func UpdateCapitalPool(engine *xorm.Engine, pool *model.CapitalPoolAgent) (int64 | |||||
session.Commit() | session.Commit() | ||||
return update, err | return update, err | ||||
} | } | ||||
func InitNewCapitalPool(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 GetCapitalPool(engine *xorm.Engine) (pool model.CapitalPoolAgent, err error) { | func GetCapitalPool(engine *xorm.Engine) (pool model.CapitalPoolAgent, err error) { | ||||
@@ -81,3 +103,29 @@ func GetCapitalPool(engine *xorm.Engine) (pool model.CapitalPoolAgent, err error | |||||
} | } | ||||
return | return | ||||
} | } | ||||
func GetNewCapitalPool(engine *xorm.Engine) (pool model.NewCapitalPool, err error) { | |||||
get, err := engine.Where("1 = 1").Get(&pool) | |||||
if err != nil { | |||||
return model.NewCapitalPool{}, err | |||||
} | |||||
if !get { | |||||
err := InitNewCapitalPool(engine) | |||||
if err != nil { | |||||
return model.NewCapitalPool{}, err | |||||
} | |||||
capitalPool, err := GetNewCapitalPool(engine) | |||||
if err != nil { | |||||
return model.NewCapitalPool{}, err | |||||
} | |||||
if capitalPool.SettleCardinality == "" { | |||||
capitalPool.SettleCardinality = "commission" | |||||
} | |||||
return capitalPool, err | |||||
} else { | |||||
if pool.SettleCardinality == "" { | |||||
pool.SettleCardinality = "commission" | |||||
} | |||||
} | |||||
return | |||||
} |
@@ -0,0 +1,57 @@ | |||||
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" | |||||
"errors" | |||||
"time" | |||||
"xorm.io/xorm" | |||||
) | |||||
func InsertCapitalPoolLossMoney(sess *xorm.Session, uid, money, title, types, formType string) error { | |||||
if zhios_order_relate_utils.StrToFloat64(money) <= 0 { | |||||
return nil | |||||
} | |||||
moneyData, err := GetCapitalPoolLossMoney(sess, uid) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
if moneyData == nil { | |||||
return errors.New("查不到损失记录") | |||||
} | |||||
beforeMoney := moneyData.Money | |||||
moneyData.Money = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(beforeMoney)+zhios_order_relate_utils.StrToFloat64(money), 3) | |||||
afterMoney := moneyData.Money | |||||
update, err := sess.Where("uid=?", uid).Update(moneyData) | |||||
if update == 0 || err != nil { | |||||
return errors.New("失败") | |||||
} | |||||
var flow = &model.CapitalPoolLossMoneyFlow{ | |||||
Uid: zhios_order_relate_utils.StrToInt(uid), | |||||
Money: money, | |||||
Time: time.Now(), | |||||
BeforeMoney: beforeMoney, | |||||
AfterMoney: afterMoney, | |||||
Type: zhios_order_relate_utils.StrToInt(types), | |||||
FormType: formType, | |||||
Title: title, | |||||
} | |||||
insert, err := sess.Insert(flow) | |||||
if insert == 0 || err != nil { | |||||
return errors.New("失败") | |||||
} | |||||
return nil | |||||
} | |||||
func GetCapitalPoolLossMoney(sess *xorm.Session, uid string) (*model.CapitalPoolLossMoney, error) { | |||||
var data model.CapitalPoolLossMoney | |||||
get, err := sess.Where("uid=?", uid).Get(&data) | |||||
if err != nil { | |||||
return nil, err | |||||
} | |||||
if get == false { | |||||
data = model.CapitalPoolLossMoney{Uid: zhios_order_relate_utils.StrToInt(uid)} | |||||
sess.Insert(&data) | |||||
} | |||||
return &data, nil | |||||
} |
@@ -0,0 +1,20 @@ | |||||
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" | |||||
"xorm.io/xorm" | |||||
) | |||||
func GetMaxPrice(eg *xorm.Engine, uid string) *model.MallOrdCapitalPoolTotal { | |||||
var data model.MallOrdCapitalPoolTotal | |||||
get, err := eg.Where("uid=? and type=?", uid, 0).Get(&data) | |||||
if err != nil { | |||||
return nil | |||||
} | |||||
if get == false { | |||||
data = model.MallOrdCapitalPoolTotal{Uid: zhios_order_relate_utils.StrToInt(uid)} | |||||
eg.Insert(&data) | |||||
} | |||||
return &data | |||||
} |
@@ -0,0 +1,7 @@ | |||||
package model | |||||
type CapitalPoolLossMoney struct { | |||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||||
Uid int `json:"uid" xorm:"default 0 INT(11)"` | |||||
Money string `json:"money" xorm:"default 0.0000 DECIMAL(20,4)"` | |||||
} |
@@ -0,0 +1,17 @@ | |||||
package model | |||||
import ( | |||||
"time" | |||||
) | |||||
type CapitalPoolLossMoneyFlow struct { | |||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||||
Uid int `json:"uid" xorm:"default 0 INT(11)"` | |||||
Money string `json:"money" xorm:"default 0.0000 DECIMAL(20,4)"` | |||||
Time time.Time `json:"time" xorm:"DATETIME"` | |||||
BeforeMoney string `json:"before_money" xorm:"DECIMAL(20,4)"` | |||||
AfterMoney string `json:"after_money" xorm:"DECIMAL(20,4)"` | |||||
Type int `json:"type" xorm:"default 0 INT(1)"` | |||||
FormType string `json:"form_type" xorm:"VARCHAR(255)"` | |||||
Title string `json:"title" xorm:"VARCHAR(255)"` | |||||
} |
@@ -0,0 +1,17 @@ | |||||
package model | |||||
import ( | |||||
"time" | |||||
) | |||||
type MallOrdCapitalPoolTotal struct { | |||||
Id int `json:"id" xorm:"not null pk INT(11)"` | |||||
Uid int `json:"uid" xorm:"default 0 INT(11)"` | |||||
Price string `json:"price" xorm:"default 0.0000 DECIMAL(20,4)"` | |||||
LeavePrice string `json:"leave_price" xorm:"default 0.0000 DECIMAL(20,4)"` | |||||
Num int `json:"num" xorm:"default 0 INT(11)"` | |||||
UpdateTime time.Time `json:"update_time" xorm:"DATETIME"` | |||||
Oid string `json:"oid" xorm:"VARCHAR(255)"` | |||||
Type int `json:"type" xorm:"INT(11) DEFAULT 0"` | |||||
OtherPrice string `json:"other_price" xorm:"default 0.0000 DECIMAL(20,4)"` | |||||
} |
@@ -0,0 +1,26 @@ | |||||
package model | |||||
import ( | |||||
"time" | |||||
) | |||||
type NewCapitalPool 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)"` | |||||
} |
@@ -0,0 +1,20 @@ | |||||
package model | |||||
import ( | |||||
"time" | |||||
) | |||||
type NewCapitalPoolOrd 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)"` | |||||
} |
@@ -1,24 +1,25 @@ | |||||
package model | package model | ||||
type PlanReward struct { | type PlanReward struct { | ||||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||||
Pvd string `json:"pvd" xorm:"not null comment('供应商') unique VARCHAR(255)"` | |||||
PvdRate float32 `json:"pvd_rate" xorm:"not null default 0.0000 comment('供应商抽成比例') FLOAT(6,4)"` | |||||
SysRate float32 `json:"sys_rate" xorm:"not null default 0.0000 comment('平台抽成比例') FLOAT(6,4)"` | |||||
RegionRate float32 `json:"region_rate" xorm:"not null default 0.0000 comment('区域代理抽成比例') FLOAT(6,4)"` | |||||
RegionSubRate float32 `json:"region_sub_rate" xorm:"not null default 0.0000 comment('区域代理抽成比例') FLOAT(6,4)"` | |||||
GlobalRate float32 `json:"global_rate" xorm:"not null default 0.0000 comment('全球分红抽成比例') FLOAT(6,4)"` | |||||
SettleMode int `json:"settle_mode" xorm:"not null default 1 comment('0.手动方案,1.自动方案') TINYINT(1)"` | |||||
PlanCommissionId int `json:"plan_commission_id" xorm:"not null default 0 comment('佣金方案0未设置,>0对应方案') TINYINT(3)"` | |||||
PlanSettleId int `json:"plan_settle_id" xorm:"not null default 0 comment('结算方案0未设置,>0对应方案') TINYINT(3)"` | |||||
State int `json:"state" xorm:"not null default 1 comment('0关闭,1开启') TINYINT(1)"` | |||||
SubsidyRate float32 `json:"subsidy_rate" xorm:"not null default 0.0000 comment('待删除字段') FLOAT(6,4)"` | |||||
Source int `json:"source" xorm:"not null default 1 comment('佣金来源:1联盟佣金 2补贴金额') TINYINT(1)"` | |||||
AppType int `json:"app_type" xorm:"not null default 1 comment('所属应用:1导购 2自营 4O2O') TINYINT(3)"` | |||||
MerchantRate float32 `json:"merchant_rate" xorm:"not null default 0.0000 comment('o2o商家抽成比例') FLOAT(6,4)"` | |||||
NewAgentRate float32 `json:"new_agent_rate" xorm:"not null default 0.0000 comment('') FLOAT(6,4)"` | |||||
PushHandRate float32 `json:"push_hand_rate" xorm:"not null default 0.0000 comment('o2o推手抽成比例') FLOAT(6,4)"` | |||||
OrderBeforeRate float32 `json:"order_before_rate" xorm:"not null default 0.0000 comment('下单前的联盟抽成') FLOAT(6,4)"` | |||||
IntegralOpen int `json:"integral_open" xorm:"not null default 0 comment('积分抽成') TINYINT(1)"` | |||||
PointType int `json:"point_type" xorm:"not null default 0 comment('') TINYINT(1)"` | |||||
Id int `json:"id" xorm:"not null pk autoincr INT(10)"` | |||||
Pvd string `json:"pvd" xorm:"not null comment('供应商') unique VARCHAR(255)"` | |||||
PvdRate float32 `json:"pvd_rate" xorm:"not null default 0.0000 comment('供应商抽成比例') FLOAT(6,4)"` | |||||
SysRate float32 `json:"sys_rate" xorm:"not null default 0.0000 comment('平台抽成比例') FLOAT(6,4)"` | |||||
RegionRate float32 `json:"region_rate" xorm:"not null default 0.0000 comment('区域代理抽成比例') FLOAT(6,4)"` | |||||
RegionSubRate float32 `json:"region_sub_rate" xorm:"not null default 0.0000 comment('区域代理抽成比例') FLOAT(6,4)"` | |||||
GlobalRate float32 `json:"global_rate" xorm:"not null default 0.0000 comment('全球分红抽成比例') FLOAT(6,4)"` | |||||
SelfBuyGlobalRate float64 `json:"self_buy_global_rate" xorm:"not null default 0.0000 comment('全球分红抽成比例') FLOAT(6,4)"` | |||||
SettleMode int `json:"settle_mode" xorm:"not null default 1 comment('0.手动方案,1.自动方案') TINYINT(1)"` | |||||
PlanCommissionId int `json:"plan_commission_id" xorm:"not null default 0 comment('佣金方案0未设置,>0对应方案') TINYINT(3)"` | |||||
PlanSettleId int `json:"plan_settle_id" xorm:"not null default 0 comment('结算方案0未设置,>0对应方案') TINYINT(3)"` | |||||
State int `json:"state" xorm:"not null default 1 comment('0关闭,1开启') TINYINT(1)"` | |||||
SubsidyRate float32 `json:"subsidy_rate" xorm:"not null default 0.0000 comment('待删除字段') FLOAT(6,4)"` | |||||
Source int `json:"source" xorm:"not null default 1 comment('佣金来源:1联盟佣金 2补贴金额') TINYINT(1)"` | |||||
AppType int `json:"app_type" xorm:"not null default 1 comment('所属应用:1导购 2自营 4O2O') TINYINT(3)"` | |||||
MerchantRate float32 `json:"merchant_rate" xorm:"not null default 0.0000 comment('o2o商家抽成比例') FLOAT(6,4)"` | |||||
NewAgentRate float32 `json:"new_agent_rate" xorm:"not null default 0.0000 comment('') FLOAT(6,4)"` | |||||
PushHandRate float32 `json:"push_hand_rate" xorm:"not null default 0.0000 comment('o2o推手抽成比例') FLOAT(6,4)"` | |||||
OrderBeforeRate float32 `json:"order_before_rate" xorm:"not null default 0.0000 comment('下单前的联盟抽成') FLOAT(6,4)"` | |||||
IntegralOpen int `json:"integral_open" xorm:"not null default 0 comment('积分抽成') TINYINT(1)"` | |||||
PointType int `json:"point_type" xorm:"not null default 0 comment('') TINYINT(1)"` | |||||
} | } |
@@ -29,15 +29,16 @@ type PlanOpt struct { | |||||
CommissionMode string // 佣金返佣方式 | CommissionMode string // 佣金返佣方式 | ||||
//IntegralMode string // 积分返佣方式 | //IntegralMode string // 积分返佣方式 | ||||
//BlockIconsMode string // 区块币返佣方式 | //BlockIconsMode string // 区块币返佣方式 | ||||
SysRate float64 // 系统占佣比例 | |||||
PvdRate float64 // 供应商占佣比例 | |||||
RegionRate float64 // 区域代理占佣比例 | |||||
RegionSubRate float64 // 区域代理占佣比例 | |||||
GlobalRate float64 // 全球分红占佣比例 | |||||
MerchantRate float64 //商家占佣比例 | |||||
NewAgentRate float64 //代理分红占佣比例 | |||||
OrderBeforeRate float64 | |||||
PushHandRate float64 //推手占佣比例 | |||||
SysRate float64 // 系统占佣比例 | |||||
PvdRate float64 // 供应商占佣比例 | |||||
RegionRate float64 // 区域代理占佣比例 | |||||
RegionSubRate float64 // 区域代理占佣比例 | |||||
GlobalRate float64 // 全球分红占佣比例 | |||||
SelfBuyGlobalRate float64 | |||||
MerchantRate float64 //商家占佣比例 | |||||
NewAgentRate float64 //代理分红占佣比例 | |||||
OrderBeforeRate float64 | |||||
PushHandRate float64 //推手占佣比例 | |||||
//IntegralBili float64 // 积分兑换比例 | //IntegralBili float64 // 积分兑换比例 | ||||
//BlockIconsBili float64 // 区块币兑换比例 | //BlockIconsBili float64 // 区块币兑换比例 | ||||
UserRate map[int]*LvGrade // 供应商对应的等级比例 | UserRate map[int]*LvGrade // 供应商对应的等级比例 | ||||
@@ -0,0 +1,232 @@ | |||||
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" | |||||
"errors" | |||||
"github.com/jinzhu/copier" | |||||
"time" | |||||
"xorm.io/xorm" | |||||
) | |||||
func AddOrder(eg *xorm.Engine, req map[string]string) { | |||||
max := db.GetMaxPrice(eg, req["uid"]) | |||||
if req["type"] == "mall_goods_user_lv" { | |||||
for i := 0; i < zhios_order_relate_utils.StrToInt(req["num"]); i++ { | |||||
var data = &model.MallOrdCapitalPoolTotal{ | |||||
Uid: zhios_order_relate_utils.StrToInt(req["uid"]), | |||||
Price: req["price"], | |||||
LeavePrice: req["price"], | |||||
Num: 1, | |||||
UpdateTime: time.Now(), | |||||
Oid: req["oid"], | |||||
Type: 1, | |||||
} | |||||
eg.Insert(data) | |||||
} | |||||
} else { | |||||
if max != nil { | |||||
max.LeavePrice = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(max.LeavePrice)+zhios_order_relate_utils.StrToFloat64(req["price"]), 3) | |||||
max.OtherPrice = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(max.OtherPrice)+zhios_order_relate_utils.StrToFloat64(req["price"]), 3) | |||||
max.UpdateTime = time.Now() | |||||
eg.Where("id=?", max.Id, max) | |||||
} | |||||
} | |||||
} | |||||
func Pool(eg *xorm.Engine, price string) { | |||||
if zhios_order_relate_utils.StrToFloat64(price) == 0 { | |||||
return | |||||
} | |||||
session := eg.NewSession() | |||||
defer session.Close() | |||||
err := session.Begin() | |||||
if err != nil { | |||||
session.Rollback() | |||||
return | |||||
} | |||||
//统计数量 | |||||
//礼包的 | |||||
sql := `SELECT SUM(sum) as sum,uid FROM mall_ord_capital_pool_total WHERE leave_price>0 and type=1 GROUP BY uid;` | |||||
nativeString, err := db.QueryNativeStringSess(session, sql) | |||||
if err != nil { | |||||
return | |||||
} | |||||
sqlFirst := `SELECT uid FROM mall_ord_capital_pool_total WHERE type=0 GROUP BY uid;` | |||||
nativeStringFirst, errFirst := db.QueryNativeStringSess(session, sqlFirst) | |||||
if errFirst != nil { | |||||
return | |||||
} | |||||
sum := 0 | |||||
ids := make([]string, 0) | |||||
newIds := make([]string, 0) | |||||
//礼包的算份数 | |||||
for _, v := range nativeString { | |||||
sum += zhios_order_relate_utils.StrToInt(v["sum"]) | |||||
ids = append(ids, v["uid"]) | |||||
} | |||||
//非礼包的 站位 | |||||
for _, v := range nativeStringFirst { | |||||
if zhios_order_relate_utils.InArr(v["uid"], ids) == false || len(ids) == 0 { | |||||
sum += 1 | |||||
newIds = append(newIds, v["uid"]) | |||||
} | |||||
} | |||||
oneMoney := zhios_order_relate_utils.StrToFloat64(price) / float64(sum) | |||||
//金额小的先扣 扣不完 给下一个 | |||||
var userMap = make(map[string]float64) | |||||
for _, v := range ids { | |||||
//读取用户的记录 | |||||
var leave float64 = 0 | |||||
var data []model.MallOrdCapitalPoolTotal | |||||
err := eg.Where("uid=? and type=? and leave_price>?", v, 1, 0).Find(&data) | |||||
if err != nil { | |||||
session.Rollback() | |||||
return | |||||
} | |||||
for _, v1 := range data { | |||||
leave, err = OneDoing(session, v1, oneMoney, leave) | |||||
if err != nil { | |||||
session.Rollback() | |||||
return | |||||
} | |||||
} | |||||
//这里判断下有没有初始记录有金额 如果没有的话就进入损失金额 | |||||
if leave > 0 { | |||||
var oneData model.MallOrdCapitalPoolTotal | |||||
has, err := session.Where("uid=? and type=? ", v, 0).Get(&oneData) | |||||
if err != nil { | |||||
session.Rollback() | |||||
return | |||||
} | |||||
if has { | |||||
//先扣除 剩下的进损失 | |||||
if zhios_order_relate_utils.StrToFloat64(oneData.LeavePrice)-leave < 0 { | |||||
leave = leave - zhios_order_relate_utils.StrToFloat64(oneData.LeavePrice) | |||||
oneData.LeavePrice = "0" | |||||
} else { | |||||
oneData.LeavePrice = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(oneData.LeavePrice)-leave, 2) | |||||
leave = 0 | |||||
} | |||||
update, err := session.Where("id=?", oneData.Id).Cols("leave_price").Update(&oneData) | |||||
if update == 0 || err != nil { | |||||
session.Rollback() | |||||
return | |||||
} | |||||
} | |||||
//剩下的进损失 | |||||
err = db.InsertCapitalPoolLossMoney(session, v, zhios_order_relate_utils.Float64ToStrByPrec(leave, 3), "分红损失", "0", "capital_pool") | |||||
if err != nil { | |||||
session.Rollback() | |||||
return | |||||
} | |||||
leave = 0 | |||||
} | |||||
userMap[v] = leave | |||||
} | |||||
for _, v := range nativeStringFirst { | |||||
var leave float64 = 0 | |||||
money, ok := userMap[v["uid"]] | |||||
if ok { | |||||
leave = money | |||||
} | |||||
if zhios_order_relate_utils.InArr(v["uid"], ids) == false || len(ids) == 0 { | |||||
var oneData model.MallOrdCapitalPoolTotal | |||||
_, err := session.Where("uid=? and type=? ", v["uid"], 0).Get(&oneData) | |||||
if err != nil { | |||||
session.Rollback() | |||||
return | |||||
} | |||||
//这里还能分 | |||||
leave, err = OneDoing(session, oneData, oneMoney, leave) | |||||
if err != nil { | |||||
session.Rollback() | |||||
return | |||||
} | |||||
} else { | |||||
//这里只需要判断要不要扣 多出的进入损失金额 | |||||
if leave > 0 { | |||||
var oneData model.MallOrdCapitalPoolTotal | |||||
has, err := session.Where("uid=? and type=? ", v, 0).Get(&oneData) | |||||
if err != nil { | |||||
session.Rollback() | |||||
return | |||||
} | |||||
if has { | |||||
//先扣除 剩下的进损失 | |||||
if zhios_order_relate_utils.StrToFloat64(oneData.LeavePrice)-leave < 0 { | |||||
leave = leave - zhios_order_relate_utils.StrToFloat64(oneData.LeavePrice) | |||||
oneData.LeavePrice = "0" | |||||
} else { | |||||
leave = 0 | |||||
oneData.LeavePrice = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(oneData.LeavePrice)-leave, 2) | |||||
} | |||||
update, err := session.Where("id=?", oneData.Id).Cols("leave_price").Update(&oneData) | |||||
if update == 0 || err != nil { | |||||
session.Rollback() | |||||
return | |||||
} | |||||
} | |||||
} | |||||
} | |||||
if leave > 0 { | |||||
//剩下的进损失 | |||||
err = db.InsertCapitalPoolLossMoney(session, v["uid"], zhios_order_relate_utils.Float64ToStrByPrec(leave, 3), "分红损失", "0", "capital_pool") | |||||
if err != nil { | |||||
session.Rollback() | |||||
return | |||||
} | |||||
} | |||||
} | |||||
} | |||||
func OneDoing(sess *xorm.Session, data model.MallOrdCapitalPoolTotal, oneMoney, leave float64) (float64, error) { | |||||
money := oneMoney + leave | |||||
if zhios_order_relate_utils.StrToFloat64(data.LeavePrice)-money < 0 { | |||||
money = zhios_order_relate_utils.StrToFloat64(data.LeavePrice) | |||||
leave = money - zhios_order_relate_utils.StrToFloat64(data.LeavePrice) | |||||
data.LeavePrice = "0" | |||||
} else { | |||||
leave = 0 | |||||
data.LeavePrice = zhios_order_relate_utils.Float64ToStrByPrec(zhios_order_relate_utils.StrToFloat64(data.LeavePrice)-money, 2) | |||||
} | |||||
update, err := sess.Where("id=?", data.Id).Cols("leave_price").Update(&data) | |||||
if update == 0 || err != nil { | |||||
return leave, errors.New("失败") | |||||
} | |||||
return leave, nil | |||||
} | |||||
func AddBonusOrd(engine *xorm.Engine, t *md.BonusOrdParam) error { | |||||
//获取分红基础设置 | |||||
pool, err := db.GetNewCapitalPool(engine) | |||||
if err != nil || pool.Id == 0 { | |||||
return errors.New("分红设置有误") | |||||
} | |||||
if pool.IsUse == 0 { | |||||
return errors.New("功能没有开始使用,插入分红失败") | |||||
} | |||||
var capitalPoolOrd model.NewCapitalPoolOrd | |||||
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 | |||||
} |
@@ -75,6 +75,7 @@ func GetPlanCfg(eg *xorm.Engine, pvd, masterId string, rewardOpts map[string]*mo | |||||
opt.RegionRate = float64(int64(rewardOpt.RegionRate*1e4)) / 1e4 | opt.RegionRate = float64(int64(rewardOpt.RegionRate*1e4)) / 1e4 | ||||
opt.RegionSubRate = float64(int64(rewardOpt.RegionSubRate*1e4)) / 1e4 | opt.RegionSubRate = float64(int64(rewardOpt.RegionSubRate*1e4)) / 1e4 | ||||
opt.GlobalRate = float64(int64(rewardOpt.GlobalRate*1e4)) / 1e4 | opt.GlobalRate = float64(int64(rewardOpt.GlobalRate*1e4)) / 1e4 | ||||
opt.SelfBuyGlobalRate = float64(int64(rewardOpt.SelfBuyGlobalRate*1e4)) / 1e4 | |||||
opt.PushHandRate = float64(int64(rewardOpt.PushHandRate*1e4)) / 1e4 | opt.PushHandRate = float64(int64(rewardOpt.PushHandRate*1e4)) / 1e4 | ||||
opt.MerchantRate = float64(int64(rewardOpt.MerchantRate*1e4)) / 1e4 | opt.MerchantRate = float64(int64(rewardOpt.MerchantRate*1e4)) / 1e4 | ||||
opt.NewAgentRate = float64(int64(rewardOpt.NewAgentRate*1e4)) / 1e4 | opt.NewAgentRate = float64(int64(rewardOpt.NewAgentRate*1e4)) / 1e4 | ||||
@@ -199,15 +200,16 @@ func PlanOpts(eg *xorm.Engine) map[string]*comm_plan.PlanOpt { | |||||
continue | continue | ||||
} | } | ||||
opts[v.Pvd] = &comm_plan.PlanOpt{ | opts[v.Pvd] = &comm_plan.PlanOpt{ | ||||
Pvd: v.Pvd, | |||||
PlanCommissionId: v.PlanCommissionId, | |||||
Mode: commissionPlans[v.PlanCommissionId].Mode, | |||||
CommissionMode: commissionPlans[v.PlanCommissionId].CommissionMode, | |||||
SysRate: float64(v.SysRate), | |||||
PvdRate: float64(v.PvdRate), | |||||
RegionRate: float64(v.RegionRate), | |||||
GlobalRate: float64(v.GlobalRate), | |||||
UserRate: subsidyTmp, | |||||
Pvd: v.Pvd, | |||||
PlanCommissionId: v.PlanCommissionId, | |||||
Mode: commissionPlans[v.PlanCommissionId].Mode, | |||||
CommissionMode: commissionPlans[v.PlanCommissionId].CommissionMode, | |||||
SysRate: float64(v.SysRate), | |||||
PvdRate: float64(v.PvdRate), | |||||
RegionRate: float64(v.RegionRate), | |||||
GlobalRate: float64(v.GlobalRate), | |||||
SelfBuyGlobalRate: v.SelfBuyGlobalRate, | |||||
UserRate: subsidyTmp, | |||||
} | } | ||||
} | } | ||||
@@ -487,17 +487,18 @@ func CommFee(fee float64, opt *comm_plan.PlanOpt, types, isGoods string) (float6 | |||||
fee = float64(int64(float64(fee1)/100)) / 100 | fee = float64(int64(float64(fee1)/100)) / 100 | ||||
} | } | ||||
} | } | ||||
pvdFee := fee * opt.PvdRate // 供应商联盟比例 | |||||
sysFee := fee * opt.SysRate // 平台比例 | |||||
regionFee := fee * opt.RegionRate // 区域代理比例 | |||||
globalFee := fee * opt.GlobalRate // 全球分红比例 | |||||
pvdFee := fee * opt.PvdRate // 供应商联盟比例 | |||||
sysFee := fee * opt.SysRate // 平台比例 | |||||
regionFee := fee * opt.RegionRate // 区域代理比例 | |||||
globalFee := fee * opt.GlobalRate // 全球分红比例 | |||||
selfBuyGlobalFee := fee * opt.SelfBuyGlobalRate // 全球分红比例 | |||||
pushHandFee := fee * opt.PushHandRate | pushHandFee := fee * opt.PushHandRate | ||||
merchantFee := fee * opt.MerchantRate | merchantFee := fee * opt.MerchantRate | ||||
newAgentFee := fee * opt.NewAgentRate | newAgentFee := fee * opt.NewAgentRate | ||||
regionSubFee := fee * opt.RegionSubRate | regionSubFee := fee * opt.RegionSubRate | ||||
// 剩余可分配的佣金 | // 剩余可分配的佣金 | ||||
total := int64(fee*1e4) - int64(pvdFee*1e4) - int64(sysFee*1e4) - int64(regionFee*1e4) - int64(regionSubFee*1e4) - int64(globalFee*1e4) - int64(pushHandFee*1e4) - int64(merchantFee*1e4) - int64(newAgentFee*1e4) | |||||
total := int64(fee*1e4) - int64(pvdFee*1e4) - int64(sysFee*1e4) - int64(regionFee*1e4) - int64(regionSubFee*1e4) - int64(globalFee*1e4) - int64(selfBuyGlobalFee*1e4) - int64(pushHandFee*1e4) - int64(merchantFee*1e4) - int64(newAgentFee*1e4) | |||||
fee = float64(total) / 1e4 | fee = float64(total) / 1e4 | ||||
if fee < 0 { | if fee < 0 { | ||||