@@ -0,0 +1,15 @@ | |||||
package db | |||||
import ( | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" | |||||
"xorm.io/xorm" | |||||
) | |||||
// BatchAddUserPublicPlatoonIncomeRecordss 批量新增数据 | |||||
func BatchAddUserPublicPlatoonIncomeRecordss(session *xorm.Session, UserPublicPlatoonIncomeRecordsData []*model.UserPublicPlatoonIncomeRecords) (int64, error) { | |||||
affected, err := session.Insert(UserPublicPlatoonIncomeRecordsData) | |||||
if err != nil { | |||||
return 0, err | |||||
} | |||||
return affected, nil | |||||
} |
@@ -0,0 +1,20 @@ | |||||
package model | |||||
import ( | |||||
"time" | |||||
) | |||||
type UserPublicPlatoonIncomeRecords struct { | |||||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||||
Uid int `json:"uid" xorm:"not null comment('用户id') index INT(11)"` | |||||
CoinId int `json:"coin_id" xorm:"not null default 0 comment('虚拟币id(0为金额)') INT(11)"` | |||||
Amount string `json:"amount" xorm:"not null default '' comment('结算金额') VARCHAR(50)"` | |||||
Title string `json:"title" xorm:"comment('标题') VARCHAR(255)"` | |||||
Date string `json:"date" xorm:"not null default '' comment('结算日期(0000-00)') VARCHAR(50)"` | |||||
Kind int `json:"kind" xorm:"not null default 1 comment('结算种类(1:转入用户余额 2:清零)') TINYINT(1)"` | |||||
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"` | |||||
Oid string `json:"oid" xorm:"comment('订单号') VARCHAR(100)"` | |||||
Type int `json:"type" xorm:"not null default 0 comment('0收入 1支出') INT(11)"` | |||||
BeforeAmount string `json:"before_amount" xorm:"comment('变更前金额') VARCHAR(100)"` | |||||
} |
@@ -258,6 +258,8 @@ func DealCommonWealthReward(engine *xorm.Engine, uid int, isCompleteReward bool) | |||||
//2、完成共富奖励(插入 user_public_platoon_settlement_records 记录) && 构造返回数据 | //2、完成共富奖励(插入 user_public_platoon_settlement_records 记录) && 构造返回数据 | ||||
var userPublicPlatoonSettlementRecords []*model.UserPublicPlatoonSettlementRecords | var userPublicPlatoonSettlementRecords []*model.UserPublicPlatoonSettlementRecords | ||||
var userPublicPlatoonIncomeRecords []*model.UserPublicPlatoonIncomeRecords | |||||
now := time.Now() | now := time.Now() | ||||
for _, param := range *params { | for _, param := range *params { | ||||
var userPublicPlatoonSettlementRecord = model.UserPublicPlatoonSettlementRecords{ | var userPublicPlatoonSettlementRecord = model.UserPublicPlatoonSettlementRecords{ | ||||
@@ -269,17 +271,33 @@ func DealCommonWealthReward(engine *xorm.Engine, uid int, isCompleteReward bool) | |||||
CreateAt: now, | CreateAt: now, | ||||
UpdateAt: now, | UpdateAt: now, | ||||
} | } | ||||
//流水表 | |||||
var userPublicPlatoonIncomeRecord = model.UserPublicPlatoonIncomeRecords{ | |||||
Uid: param.Uid, | |||||
CoinId: param.CoinId, | |||||
Amount: param.Amount, | |||||
Date: now.AddDate(0, 0, 30).Format("2006-01-02"), | |||||
CreateAt: now, | |||||
UpdateAt: now, | |||||
} | |||||
if isCompleteReward { | if isCompleteReward { | ||||
userPublicPlatoonIncomeRecord.Title = "共富收益转入余额" | |||||
userPublicPlatoonIncomeRecord.Kind = 1 | |||||
userPublicPlatoonSettlementRecord.Kind = 1 | userPublicPlatoonSettlementRecord.Kind = 1 | ||||
resp = append(resp, map[string]string{ | resp = append(resp, map[string]string{ | ||||
zhios_order_relate_utils.AnyToString(param.CoinId): param.Amount, | zhios_order_relate_utils.AnyToString(param.CoinId): param.Amount, | ||||
}) | }) | ||||
} else { | } else { | ||||
userPublicPlatoonIncomeRecord.Title = "共富收益清零" | |||||
userPublicPlatoonIncomeRecord.Kind = 2 | |||||
userPublicPlatoonSettlementRecord.Kind = 2 | userPublicPlatoonSettlementRecord.Kind = 2 | ||||
} | } | ||||
if zhios_order_relate_utils.StrToFloat64(userPublicPlatoonSettlementRecord.Amount) > 0 { | if zhios_order_relate_utils.StrToFloat64(userPublicPlatoonSettlementRecord.Amount) > 0 { | ||||
userPublicPlatoonSettlementRecords = append(userPublicPlatoonSettlementRecords, &userPublicPlatoonSettlementRecord) | userPublicPlatoonSettlementRecords = append(userPublicPlatoonSettlementRecords, &userPublicPlatoonSettlementRecord) | ||||
} | } | ||||
if zhios_order_relate_utils.StrToFloat64(userPublicPlatoonIncomeRecord.Amount) > 0 { | |||||
userPublicPlatoonIncomeRecords = append(userPublicPlatoonIncomeRecords, &userPublicPlatoonIncomeRecord) | |||||
} | |||||
} | } | ||||
affected, err := db.BatchAddUserPublicPlatoonSettlementRecordss(session, userPublicPlatoonSettlementRecords) | affected, err := db.BatchAddUserPublicPlatoonSettlementRecordss(session, userPublicPlatoonSettlementRecords) | ||||
if err != nil { | if err != nil { | ||||
@@ -291,6 +309,16 @@ func DealCommonWealthReward(engine *xorm.Engine, uid int, isCompleteReward bool) | |||||
_ = session.Rollback() | _ = session.Rollback() | ||||
return | return | ||||
} | } | ||||
affectedIncome, errIncome := db.BatchAddUserPublicPlatoonIncomeRecordss(session, userPublicPlatoonIncomeRecords) | |||||
if errIncome != nil { | |||||
_ = session.Rollback() | |||||
return | |||||
} | |||||
if affectedIncome == 0 { | |||||
err = errors.New("插入 user_public_platoon_settlement_records 记录失败") | |||||
_ = session.Rollback() | |||||
return | |||||
} | |||||
//3、将 user_public_platoon_amount 相关记录的 amount 置 0 | //3、将 user_public_platoon_amount 相关记录的 amount 置 0 | ||||
sql := "update user_public_platoon_amount set amount = ? where uid = ?" | sql := "update user_public_platoon_amount set amount = ? where uid = ?" | ||||
@@ -34,7 +34,7 @@ func PublicPlatoonSettle(session *xorm.Session, ItemTitle, ordId string, uid, co | |||||
return false | return false | ||||
} | } | ||||
} | } | ||||
finUserFlow := model.UserPublicPlatoonSettlementRecords{ | |||||
finUserFlow := model.UserPublicPlatoonIncomeRecords{ | |||||
Type: 0, | Type: 0, | ||||
Uid: uid, | Uid: uid, | ||||
Amount: zhios_order_relate_utils.AnyToString(amount), | Amount: zhios_order_relate_utils.AnyToString(amount), | ||||
@@ -53,3 +53,47 @@ func PublicPlatoonSettle(session *xorm.Session, ItemTitle, ordId string, uid, co | |||||
} | } | ||||
return true | return true | ||||
} | } | ||||
func PublicPlatoonAddRecord(eg *xorm.Engine, ItemTitle, ordId string, uid, coinId, kind, types int, amount float64, beforeAmount string) bool { | |||||
now := time.Now() | |||||
finUserFlow := model.UserPublicPlatoonIncomeRecords{ | |||||
Type: types, | |||||
Uid: uid, | |||||
Amount: zhios_order_relate_utils.AnyToString(amount), | |||||
CreateAt: now, | |||||
UpdateAt: now, | |||||
Date: now.Format("2006-01"), | |||||
Kind: kind, | |||||
CoinId: coinId, | |||||
Title: ItemTitle, | |||||
BeforeAmount: beforeAmount, | |||||
Oid: ordId, | |||||
} | |||||
_, err := eg.Insert(&finUserFlow) | |||||
if err != nil { | |||||
return false | |||||
} | |||||
return true | |||||
} | |||||
func PublicPlatoonAddRecordWithSession(session *xorm.Session, ItemTitle, ordId string, uid, coinId, kind, types int, amount float64, beforeAmount string) bool { | |||||
now := time.Now() | |||||
finUserFlow := model.UserPublicPlatoonIncomeRecords{ | |||||
Type: types, | |||||
Uid: uid, | |||||
Amount: zhios_order_relate_utils.AnyToString(amount), | |||||
CreateAt: now, | |||||
UpdateAt: now, | |||||
Date: now.Format("2006-01"), | |||||
Kind: kind, | |||||
CoinId: coinId, | |||||
Title: ItemTitle, | |||||
BeforeAmount: beforeAmount, | |||||
Oid: ordId, | |||||
} | |||||
_, err := session.Insert(&finUserFlow) | |||||
if err != nil { | |||||
return false | |||||
} | |||||
return true | |||||
} |
@@ -150,6 +150,32 @@ func SettleCommWithGoodsDetail(eg *xorm.Engine, dbName string, CommissionParam m | |||||
profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, virType) | profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, virType) | ||||
return profit, pvdFee, sysFee, subsidyFee, lvUser, err | return profit, pvdFee, sysFee, subsidyFee, lvUser, err | ||||
} | } | ||||
func SettleCommWithOrder(eg *xorm.Engine, dbName string, CommissionParam md.CommissionFirstParam) (float64, float64, float64, float64, *comm_plan.LvUser, error) { | |||||
var ( | |||||
isShare = false | |||||
isAllLevelReturn = false | |||||
) | |||||
if CommissionParam.IsShare != 0 { | |||||
isShare = true | |||||
} | |||||
if CommissionParam.IsAllLevelReturn != 0 { | |||||
isAllLevelReturn = true | |||||
} | |||||
var mapData = map[string]string{ | |||||
"old_lv": CommissionParam.OldLv, | |||||
"new_lv": CommissionParam.NewLv, | |||||
"ownbuy_return_type": zhios_order_relate_utils.IntToStr(CommissionParam.OwnbuyReturnType), | |||||
} | |||||
virCfg, _ := db.SysCfgGetOne(eg, "virtual_coin_rebate_type") | |||||
var virType = "price" | |||||
if virCfg != nil && virCfg.Val != "" { | |||||
virType = virCfg.Val | |||||
} | |||||
CommissionParam.CommissionParam.Oid = CommissionParam.GoodsId | |||||
profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, virType) | |||||
return profit, pvdFee, sysFee, subsidyFee, lvUser, err | |||||
} | |||||
//获取自购分享佣金的 | //获取自购分享佣金的 | ||||
func GetRewardCommission(eg *xorm.Engine, dbName, mode string, CommissionParam md.CommissionFirstParam) (float64, float64, *comm_plan.LvUser, error) { | func GetRewardCommission(eg *xorm.Engine, dbName, mode string, CommissionParam md.CommissionFirstParam) (float64, float64, *comm_plan.LvUser, error) { | ||||