Browse Source

add reverse:for v1.8.5 test

tags/v1.8.5
huangjiajun 2 years ago
parent
commit
071855cb78
5 changed files with 130 additions and 3 deletions
  1. +3
    -3
      db/db_extend_commission.go
  2. +8
    -0
      db/db_user.go
  3. +29
    -0
      db/model/fin_user_flow.go
  4. +18
    -0
      db/model/mark_settle_record.go
  5. +72
    -0
      svc/extend_agent_commission.go

+ 3
- 3
db/db_extend_commission.go View File

@@ -7,15 +7,15 @@ import (

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)
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) {
func GetExtendAgentCommissionRelateWithSession(session *xorm.Session, oid, pvd, coinId string) (*model.ExtendAgentCommissionRelate, error) {
var ord model.ExtendAgentCommissionRelate
has, err := session.Where("oid=? and pvd=?", oid, pvd).Get(&ord)
has, err := session.Where("oid=? and pvd=? and coin_id=?", oid, pvd, coinId).Get(&ord)
if has == false || err != nil {
return nil, err
}


+ 8
- 0
db/db_user.go View File

@@ -23,3 +23,11 @@ func UserProfileFindByID(Db *xorm.Engine, id interface{}) (*model.UserProfile, e
}
return &m, nil
}
func UserProfileFindByIDWithSession(sess *xorm.Session, id interface{}) (*model.UserProfile, error) {
var m model.UserProfile
if has, err := sess.Where("uid = ?", id).
Get(&m); err != nil || has == false {
return nil, zhios_order_relate_logx.Warn(err)
}
return &m, nil
}

+ 29
- 0
db/model/fin_user_flow.go View File

@@ -0,0 +1,29 @@
package model

import (
"time"
)

type FinUserFlow struct {
Id int64 `json:"id" xorm:"pk autoincr comment('流水编号') BIGINT(20)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"`
Type int `json:"type" xorm:"not null default 0 comment('0收入,1支出') TINYINT(1)"`
Amount string `json:"amount" xorm:"not null default 0.0000 comment('变动金额') DECIMAL(11,4)"`
BeforeAmount string `json:"before_amount" xorm:"not null default 0.0000 comment('变动前金额') DECIMAL(11,4)"`
AfterAmount string `json:"after_amount" xorm:"not null default 0.0000 comment('变动后金额') DECIMAL(11,4)"`
SysFee string `json:"sys_fee" xorm:"not null default 0.0000 comment('手续费') DECIMAL(11,4)"`
PaymentType int `json:"payment_type" xorm:"not null default 1 comment('1支付宝,2微信.3手动转账') TINYINT(1)"`
OrdType string `json:"ord_type" xorm:"not null default '' comment('订单类型taobao,jd,pdd,vip,suning,kaola,own自营,withdraw提现') VARCHAR(20)"`
OrdId string `json:"ord_id" xorm:"not null default '' comment('对应订单编号') VARCHAR(50)"`
OrdTitle string `json:"ord_title" xorm:"not null default '' comment('订单标题') VARCHAR(50)"`
OrdAction int `json:"ord_action" xorm:"not null default 0 comment('10自购,11推广,12团队,20提现,21消费') TINYINT(2)"`
OrdTime int `json:"ord_time" xorm:"not null default 0 comment('下单时间or提现时间') INT(11)"`
OrdDetail string `json:"ord_detail" xorm:"not null default '' comment('记录商品ID或提现账号') VARCHAR(50)"`
ExpectedTime string `json:"expected_time" xorm:"not null default '0' comment('预期到账时间,字符串用于直接显示,结算后清除内容') VARCHAR(30)"`
State int `json:"state" xorm:"not null default 1 comment('1未到账,2已到账') TINYINT(1)"`
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(2000)"`
OtherId int64 `json:"other_id" xorm:"not null default 0 comment('其他关联订单,具体根据订单类型判断') BIGINT(20)"`
AliOrdId string `json:"ali_ord_id" xorm:"default '' comment('支付宝订单号') VARCHAR(128)"`
CreateAt time.Time `json:"create_at" xorm:"created not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"`
UpdateAt time.Time `json:"update_at" xorm:"updated not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"`
}

+ 18
- 0
db/model/mark_settle_record.go View File

@@ -0,0 +1,18 @@
package model

import (
"time"
)

type MarkSettleRecord struct {
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
Uid int `json:"uid" xorm:"default 0 INT(11)"`
Amount string `json:"amount" xorm:"default 0.0000 DECIMAL(11,4)"`
Time time.Time `json:"time" xorm:"DATETIME"`
Type string `json:"type" xorm:"default '' VARCHAR(255)"`
Extra string `json:"extra" xorm:" TEXT"`
CoinId int `json:"coin_id" xorm:"default 0 INT(11)"`
BelongTime string `json:"belong_time" xorm:"default '' comment('所属月份') VARCHAR(255)"`
Oid string `json:"oid" xorm:"default '' comment('') VARCHAR(255)"`
Pvd string `json:"pvd" xorm:"default '' comment('') VARCHAR(255)"`
}

+ 72
- 0
svc/extend_agent_commission.go View File

@@ -5,6 +5,7 @@ import (
"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"
"encoding/json"
"time"
"xorm.io/xorm"
@@ -106,3 +107,74 @@ func AddExtendAgentCommission(eg *xorm.Engine, args map[string]string) {

return
}

//结算分佣抽成部分
/***
oid 订单号
pvd 渠道
title 描述
*/
func SettleExtendUidCommission(session *xorm.Session, args map[string]string) bool {
relate, err := db.GetExtendAgentCommissionRelateWithSession(session, args["oid"], args["pvd"], "0")
if err != nil {
return false
}
if relate == nil {
return true
}
if relate.SettleTime.IsZero() == false {
return true
}
user, _ := db.UserProfileFindByIDWithSession(session, relate.Uid)
amount := zhios_order_relate_utils.StrToFloat64(relate.Amount)
mBeforeAmount := zhios_order_relate_utils.StrToFloat64(user.FinValid)
mAfterAmount := mBeforeAmount + amount
//
now := time.Now()
var finUserFlow = model.FinUserFlow{
Type: 0,
Uid: relate.Uid,
Amount: zhios_order_relate_utils.AnyToString(amount),
BeforeAmount: zhios_order_relate_utils.AnyToString(mBeforeAmount),
AfterAmount: zhios_order_relate_utils.AnyToString(mAfterAmount),
OrdType: "own",
OrdId: zhios_order_relate_utils.AnyToString(relate.Oid),
OrdAction: 14,
OrdDetail: zhios_order_relate_utils.AnyToString(relate.Oid),
State: 2,
OrdTitle: "推荐代理购买商品",
OrdTime: int(now.Unix()),
CreateAt: now,
UpdateAt: now,
}
user.FinValid = zhios_order_relate_utils.Float64ToStrByPrec(mAfterAmount, 4)
affected, err := session.Where("uid=?", user.Uid).Cols("fin_valid").Update(user)
has, errs := session.Insert(&finUserFlow)
if affected == 0 || err != nil || errs != nil || has == 0 {
_ = zhios_order_relate_logx.Warn(err)
return false
}
relate.SettleTime = time.Now()
update, err := session.Where("id=?", relate.Id).Cols("settle_time").Update(relate)
if update == 0 || err != nil {
_ = zhios_order_relate_logx.Warn(err)
return false
}
t := time.Now()
//
_, err = session.Insert(&model.MarkSettleRecord{
Uid: relate.Uid,
Amount: zhios_order_relate_utils.Float64ToStrByPrec(amount, 4),
Time: t,
Type: "extend_agent_commission",
CoinId: 0,
BelongTime: t.Format("2006-01"),
Pvd: args["pvd"],
Oid: args["oid"],
})
if err != nil {
_ = zhios_order_relate_logx.Warn(err)
return false
}
return true
}

Loading…
Cancel
Save