@@ -0,0 +1,23 @@ | |||||
package db | |||||
import ( | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" | |||||
"xorm.io/xorm" | |||||
) | |||||
func GetExtendAgentCommissionRelate(eg *xorm.Engine, oid, pvd string) (*model.ExtendAgentCommissionRelate, error) { | |||||
var ord model.ExtendAgentCommissionRelate | |||||
has, err := eg.Where("oid=? and pvd=?", oid, pvd).Get(&ord) | |||||
if has == false || err != nil { | |||||
return nil, err | |||||
} | |||||
return &ord, nil | |||||
} | |||||
func GetExtendAgentCommissionRelateWithSession(session *xorm.Session, oid, pvd string) (*model.ExtendAgentCommissionRelate, error) { | |||||
var ord model.ExtendAgentCommissionRelate | |||||
has, err := session.Where("oid=? and pvd=?", oid, pvd).Get(&ord) | |||||
if has == false || err != nil { | |||||
return nil, err | |||||
} | |||||
return &ord, nil | |||||
} |
@@ -0,0 +1,18 @@ | |||||
package db | |||||
import ( | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/db/model" | |||||
zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" | |||||
"fmt" | |||||
"xorm.io/xorm" | |||||
) | |||||
// GetCountByRegionalAgentUserInfoByParams 通过传入的参数查询数据(单条) | |||||
func GetCountByRegionalAgentUserInfoByParams(Db *xorm.Engine, params map[string]interface{}) (*model.RegionalAgentUser, error) { | |||||
var m model.RegionalAgentUser | |||||
var query = fmt.Sprintf("%s =?", params["key"]) | |||||
if has, err := Db.Where(query, params["value"]).And("deleted_time is null").Get(&m); err != nil || has == false { | |||||
return nil, zhios_order_relate_logx.Error(err) | |||||
} | |||||
return &m, nil | |||||
} |
@@ -0,0 +1,18 @@ | |||||
package model | |||||
import ( | |||||
"time" | |||||
) | |||||
type ExtendAgentCommissionRelate struct { | |||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||||
Uid int `json:"uid" xorm:"default 0 comment('奖励用户id') INT(11)"` | |||||
FormUid int `json:"form_uid" xorm:"default 0 comment('来自用户id') INT(11)"` | |||||
Pvd string `json:"pvd" xorm:"default '' comment('渠道') VARCHAR(255)"` | |||||
Oid string `json:"oid" xorm:"default '' comment('子订单') VARCHAR(255)"` | |||||
CreateTime time.Time `json:"create_time" xorm:"DATETIME"` | |||||
Amount string `json:"amount" xorm:"default 0.0000 comment('金额') DECIMAL(11,4)"` | |||||
Rate string `json:"rate" xorm:"default 0.0000 comment('当时比例') DECIMAL(11,4)"` | |||||
SettleTime time.Time `json:"settle_time" xorm:"DATETIME"` | |||||
CoinId int `json:"coin_id" xorm:"default 0 comment('积分id 0为佣金') INT(11)"` | |||||
} |
@@ -0,0 +1,25 @@ | |||||
package model | |||||
import ( | |||||
"time" | |||||
) | |||||
type RegionalAgentUser struct { | |||||
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20)"` | |||||
SchemeId int `json:"scheme_id" xorm:"not null comment('方案id') INT(11)"` | |||||
Uid int `json:"uid" xorm:"not null comment('参与区域代理的用户id') index(mgbgu_uid_ord_id_group_id_index) INT(11)"` | |||||
RegionId int `json:"region_id" xorm:"not null comment('区域id') index(mgbgu_uid_ord_id_group_id_index) INT(11)"` | |||||
IsFailure int `json:"is_failure" xorm:"not null default 0 comment('是否已失效:0否 1是') TINYINT(1)"` | |||||
FailureTime int `json:"failure_time" xorm:"not null comment('剩下失效时间(单位:月)0代表永久') INT(11)"` | |||||
ProvinceId int64 `json:"province_id" xorm:"comment('省级区域id') BIGINT(20)"` | |||||
CityId int64 `json:"city_id" xorm:"comment('市级区域id') BIGINT(20)"` | |||||
DistrictId int64 `json:"district_id" xorm:"comment('区/县级id') BIGINT(20)"` | |||||
SiteId int64 `json:"site_id" xorm:"comment('网点id') BIGINT(20)"` | |||||
RegionalName string `json:"regional_name" xorm:"not null comment('地区名:(例如:广东省;广东省-珠海市;广东省-珠海市-香洲区;广东省-珠海市-香洲区-港湾一号)') VARCHAR(255)"` | |||||
Level int `json:"level" xorm:"not null default 0 comment('等级(1:省级;2:市级;3:区/县 级;4:网点)') TINYINT(1)"` | |||||
CreateTime time.Time `json:"create_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('创建时间') index(mgbgu_uid_ord_id_group_id_index) TIMESTAMP"` | |||||
UpdateTime time.Time `json:"update_time" xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"` | |||||
DeletedTime time.Time `json:"deleted_time" xorm:"comment('删除时间') TIMESTAMP"` | |||||
DateType int `json:"date_type" xorm:"not null comment('1:包月,2:包季,3:包年,4:永久') TINYINT(1)"` | |||||
AutoRenewal int `json:"auto_renewal" xorm:"not null comment('是否自动续费0否 1是') TINYINT(1)"` | |||||
} |
@@ -18,4 +18,5 @@ type ExtendPriceRewardListDetail struct { | |||||
BaseVal string `json:"base_val"` | BaseVal string `json:"base_val"` | ||||
Bili string `json:"bili"` | Bili string `json:"bili"` | ||||
PositionBili string `json:"position_bili"` | PositionBili string `json:"position_bili"` | ||||
ExtendAgentBili string `json:"extend_agent_bili"` | |||||
} | } |
@@ -0,0 +1,113 @@ | |||||
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" | |||||
"encoding/json" | |||||
"time" | |||||
"xorm.io/xorm" | |||||
) | |||||
//加入区域代理直推上级分佣 抽成部分 | |||||
/*** | |||||
commission 总佣金 | |||||
bili 抽成 除以100之后的 | |||||
uid 用户id | |||||
oid 订单号 | |||||
pvd 渠道 | |||||
*/ | |||||
func AddExtendAgentCommission(eg *xorm.Engine, args map[string]string) { | |||||
user, err := db.UserProfileFindByID(eg, args["uid"]) | |||||
if err != nil || user == nil { | |||||
return | |||||
} | |||||
if user.ParentUid == 0 { | |||||
return | |||||
} | |||||
//判断是不是代理 | |||||
//查出用户是否区域代理 | |||||
agentUser, err := db.GetCountByRegionalAgentUserInfoByParams(eg, map[string]interface{}{ | |||||
"key": "uid", | |||||
"value": user.Uid, | |||||
}) | |||||
if agentUser == nil || err != nil { | |||||
return | |||||
} | |||||
// 有效期计算 | |||||
if agentUser.IsFailure == 1 { | |||||
return | |||||
} | |||||
now := time.Now().Unix() | |||||
if agentUser.FailureTime > 0 && agentUser.FailureTime < int(now) { | |||||
return | |||||
} | |||||
commissionOpt, err := db.DbsPlanCommissionById(eg, zhios_order_relate_utils.StrToInt(args["plan_commission_id"])) | |||||
if err != nil || commissionOpt == nil || commissionOpt.Id == 0 { | |||||
return | |||||
} | |||||
var subsidyTmp = make(map[int]*md.ExtendRewardLvGrade) | |||||
var tmp map[int]*md.ExtendRewardLvGrade | |||||
if err := json.Unmarshal([]byte(commissionOpt.Data), &tmp); err != nil { | |||||
return | |||||
} | |||||
for _, v := range tmp { | |||||
subsidyTmp[v.Lv] = v | |||||
} | |||||
userProfile, err := db.UserProfileFindByID(eg, args["uid"]) | |||||
if err != nil || userProfile == nil { | |||||
return | |||||
} | |||||
if userProfile.ParentUid == 0 { | |||||
return | |||||
} | |||||
//查询用户等级 | |||||
parentUser, err := db.UserFindByID(eg, userProfile.ParentUid) | |||||
if err != nil || parentUser == nil { | |||||
return | |||||
} | |||||
lvGrade := subsidyTmp[parentUser.Level] | |||||
var rewardList = make(map[string]md.ExtendPriceRewardList) | |||||
for _, v := range lvGrade.ExtendPriceRewardList { | |||||
rewardList[v.CoinID] = v | |||||
} | |||||
//判断有没有存过 | |||||
relate, _ := db.GetExtendAgentCommissionRelate(eg, args["oid"], args["pvd"]) | |||||
if relate != nil { | |||||
return | |||||
} | |||||
for k, v := range rewardList { | |||||
var amount float64 = 0 | |||||
rewardData := v | |||||
reward := md.ExtendPriceRewardListDetail{} | |||||
if agentUser.Level == 1 { | |||||
reward = rewardData.ProvinceAgent | |||||
} | |||||
if agentUser.Level == 2 { | |||||
reward = rewardData.CityAgent | |||||
} | |||||
if agentUser.Level == 3 { | |||||
reward = rewardData.AreaAgent | |||||
} | |||||
amount = zhios_order_relate_utils.StrToFloat64(args["commission"]) * zhios_order_relate_utils.StrToFloat64(reward.ExtendAgentBili) / 100 | |||||
if amount == 0 { | |||||
continue | |||||
} | |||||
var ord = model.ExtendAgentCommissionRelate{ | |||||
Uid: user.ParentUid, | |||||
FormUid: user.Uid, | |||||
Pvd: args["pvd"], | |||||
Oid: args["oid"], | |||||
CreateTime: time.Now(), | |||||
Amount: zhios_order_relate_utils.Float64ToStrByPrec(amount, 4), | |||||
Rate: args["bili"], | |||||
CoinId: zhios_order_relate_utils.StrToInt(k), | |||||
} | |||||
eg.InsertOne(&ord) | |||||
} | |||||
return | |||||
} |