Browse Source

add Reverse:for 1.0.2 加入商家奖励结算

tags/v1.0.2
huangjuajun 2 years ago
parent
commit
be14a5301e
5 changed files with 127 additions and 6 deletions
  1. +16
    -0
      db/db_merchant.go
  2. +8
    -0
      db/db_store_commission_relate.go
  3. +31
    -0
      db/model/o2o_fin_user_flow.go
  4. +67
    -1
      o2o/add_store_commission.go
  5. +5
    -5
      o2o/add_store_fans.go

+ 16
- 0
db/db_merchant.go View File

@@ -36,6 +36,22 @@ func MerchantFindByMobileOrId(Db *xorm.Engine, mobileOrId string) (*model.O2oMer
}
return &m, nil
}

func MerchantUpdateWithSession(sess *xorm.Session, merchant *model.O2oMerchant, forceCols ...string) (int64, error) {
var (
affected int64
err error
)
if forceCols != nil {
affected, err = sess.Where("id = ?", merchant.Id).Cols(forceCols...).Update(merchant)
} else {
affected, err = sess.Where("id = ?", merchant.Id).Update(merchant)
}
if err != nil {
return 0, err
}
return affected, nil
}
func MerchantFindByUId(Db *xorm.Engine, uid string) (*model.O2oMerchant, error) {
var m model.O2oMerchant
if has, err := Db.Where("uid = ?", uid).


+ 8
- 0
db/db_store_commission_relate.go View File

@@ -13,3 +13,11 @@ func GetStoreCommissionRelate(eg *xorm.Engine, oid, pvd string) (*model.StoreCom
}
return &ord, nil
}
func GetStoreCommissionRelateWithSession(session *xorm.Session, oid, pvd string) (*model.StoreCommissionRelate, error) {
var ord model.StoreCommissionRelate
has, err := session.Where("oid=? and pvd=?", oid, pvd).Get(&ord)
if has == false || err != nil {
return nil, err
}
return &ord, nil
}

+ 31
- 0
db/model/o2o_fin_user_flow.go View File

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

import (
"time"
)

type O2oFinUserFlow struct {
Id int64 `json:"id" xorm:"pk autoincr comment('流水编号') BIGINT(20)"`
Uid int `json:"uid" xorm:"not null default 0 comment('用户id') INT(11)"`
MerchantId int `json:"merchant_id" xorm:"default 0 comment('商家id') INT(11)"`
StoreId int `json:"store_id" xorm:"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手动转账,4列表红包奖励,5收款码') TINYINT(1)"`
OrdType string `json:"ord_type" xorm:"not null default '' comment('订单类型 o2o_goods(小店), o2o_hotel(酒店) withdraw(提现) red_packet_reward(列表红包奖励) collection_code(收款码)') VARCHAR(255)"`
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团队,13免单,20提现,21消费,22退款,23拼团返佣,24区域代理,25重置虚拟币 26充值 27裂变红包奖励') 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('其他关联订单,具体根据订单类型判断') index 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"`
}

+ 67
- 1
o2o/add_store_commission.go View File

@@ -4,6 +4,8 @@ import (
"code.fnuoos.com/go_rely_warehouse/zyos_go_o2o_business.git/db"
"code.fnuoos.com/go_rely_warehouse/zyos_go_o2o_business.git/db/model"
zhios_o2o_business_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_o2o_business.git/utils"
zhios_o2o_business_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_o2o_business.git/utils/logx"
"strconv"
"time"
"xorm.io/xorm"
)
@@ -25,7 +27,7 @@ func AddStoreCommission(eg *xorm.Engine, args map[string]string) {
return
}
//判断是不是商家
manager := GetO2oStore(eg, zhios_o2o_business_utils.IntToStr(user.ParentUid))
_, manager := GetO2oStore(eg, zhios_o2o_business_utils.IntToStr(user.ParentUid))
if manager == nil {
return
}
@@ -35,6 +37,9 @@ func AddStoreCommission(eg *xorm.Engine, args map[string]string) {
return
}
amount := zhios_o2o_business_utils.StrToFloat64(args["amount"]) * zhios_o2o_business_utils.StrToFloat64(args["bili"])
if amount == 0 {
return
}
var ord = model.StoreCommissionRelate{
Uid: user.ParentUid,
FormUid: user.Uid,
@@ -47,3 +52,64 @@ func AddStoreCommission(eg *xorm.Engine, args map[string]string) {
eg.InsertOne(&ord)
return
}

//结算商家分佣 商家抽成部分
/***
oid 订单号
pvd 渠道
title 描述
*/
func SettleStoreCommission(eg *xorm.Engine, session *xorm.Session, args map[string]string) bool {
relate, err := db.GetStoreCommissionRelateWithSession(session, args["oid"], args["pvd"])
if err != nil {
return false
}
if relate == nil {
return true
}
if relate.SettleTime.IsZero() == false {
return true
}
//判断是不是商家
merchant, manager := GetO2oStore(eg, zhios_o2o_business_utils.IntToStr(relate.Uid))
if manager == nil {
return true
}
if manager.Id > 0 {
amount := zhios_o2o_business_utils.StrToFloat64(relate.Amount)
mBeforeAmount := merchant.Amount
mAfterAmount := mBeforeAmount + amount
// o2o_fin_user_flow 新增流水记录
var o2oFinUserFlow = model.O2oFinUserFlow{
Uid: relate.Uid,
MerchantId: relate.Uid,
StoreId: manager.Id,
Type: 0,
Amount: strconv.FormatFloat(amount, 'f', 4, 64),
BeforeAmount: strconv.FormatFloat(mBeforeAmount, 'f', 4, 64),
AfterAmount: strconv.FormatFloat(mAfterAmount, 'f', 4, 64),
OrdType: relate.Pvd,
OrdId: relate.Oid,
OrdTitle: args["title"],
OrdAction: 11,
OrdTime: int(time.Now().Unix()),
State: 2,
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
merchant.Amount = mAfterAmount
affected, err := db.MerchantUpdateWithSession(session, merchant, "amount")
has, errs := session.Insert(&o2oFinUserFlow)
if affected == 0 || err != nil || errs != nil || has == 0 {
_ = zhios_o2o_business_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_o2o_business_logx.Warn(err)
return false
}
}
return true
}

+ 5
- 5
o2o/add_store_fans.go View File

@@ -11,22 +11,22 @@ import (

//通过上级查询是否商家,绑定关系
func GetParentUidToBindFans(eg *xorm.Engine, uid, parentUid string) {
manager := GetO2oStore(eg, parentUid)
_, manager := GetO2oStore(eg, parentUid)
if manager == nil {
return
}
DealCommonPayStoreFans(eg, uid, zhios_o2o_business_utils.IntToStr(manager.Id), "0", "拉新", "1")
}
func GetO2oStore(eg *xorm.Engine, parentUid string) *model.O2oStore {
func GetO2oStore(eg *xorm.Engine, parentUid string) (*model.O2oMerchant, *model.O2oStore) {
merchantList, err := db.MerchantFindByUId(eg, parentUid)
if err != nil || merchantList == nil {
return nil
return nil, nil
}
manager, err := db.MerchantFindByStoreManager(eg, zhios_o2o_business_utils.IntToStr(merchantList.Id))
if err != nil || manager == nil {
return nil
return nil, nil
}
return manager
return merchantList, manager
}

//DealCommonPayStoreFans 處理通用支付中的店鋪粉絲


Loading…
Cancel
Save