|
|
@@ -10,6 +10,7 @@ import ( |
|
|
|
"applet/app/utils/cache" |
|
|
|
"applet/app/utils/logx" |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/lib/comm_plan" |
|
|
|
"code.fnuoos.com/go_rely_warehouse/zyos_model.git/src/models" |
|
|
|
"fmt" |
|
|
|
"github.com/tidwall/gjson" |
|
|
|
"strings" |
|
|
@@ -144,6 +145,8 @@ func DeductMoney(eg *xorm.Engine, existOrd model.OrdList, ords map[string]md.Ord |
|
|
|
commRefund(eg, session, &existOrd, existOrd.Uid, existOrd.Pvd, existOrd.ItemId, rebateList, str, dbName) |
|
|
|
commAreaRefund(session, existOrd.Uid, utils.Int64ToStr(existOrd.OrdId), md.PVD_GUIDE, existOrd.ItemId, str) |
|
|
|
commStoreRefund(eg, session, utils.Int64ToStr(existOrd.OrdId), existOrd.Pvd) |
|
|
|
refundServiceVirtualAmount(eg, session, existOrd.OrdId) |
|
|
|
|
|
|
|
existOrd.IsRefund = 1 |
|
|
|
} |
|
|
|
_, _ = db.OrdUpdateOneAll(eg, &existOrd) |
|
|
@@ -162,6 +165,60 @@ func DeductMoney(eg *xorm.Engine, existOrd model.OrdList, ords map[string]md.Ord |
|
|
|
} |
|
|
|
return |
|
|
|
} |
|
|
|
func refundServiceVirtualAmount(eg *xorm.Engine, sess *xorm.Session, oid int64) (bool, error) { |
|
|
|
var list = make([]models.ServiceAwardReturnFlow, 0) |
|
|
|
sess.Where("oid=? and is_end=?", oid, 0).Find(&list) |
|
|
|
for _, v := range list { |
|
|
|
// 退虚拟币 |
|
|
|
var userVirtualAmount model.UserVirtualAmount |
|
|
|
var beforeCoinAmount = "" |
|
|
|
has, err := sess.Where("uid = ? AND coin_id = ?", v.Uid, v.CoinId).Get(&userVirtualAmount) |
|
|
|
if err != nil { |
|
|
|
return false, err |
|
|
|
} |
|
|
|
var virtualAmount = 0.0 |
|
|
|
if !has { |
|
|
|
continue |
|
|
|
} else if utils.StrToFloat64(userVirtualAmount.Amount) > 0 { |
|
|
|
beforeCoinAmount = userVirtualAmount.Amount |
|
|
|
virtualAmount = utils.StrToFloat64(v.HasReturnMoney) |
|
|
|
if utils.StrToFloat64(beforeCoinAmount)-utils.StrToFloat64(v.HasReturnMoney) < 0 { |
|
|
|
virtualAmount = utils.StrToFloat64(beforeCoinAmount) |
|
|
|
} |
|
|
|
userVirtualAmount.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(userVirtualAmount.Amount)-virtualAmount, 6) |
|
|
|
_, err := sess.Where("id = ?", userVirtualAmount.Id).AllCols().Update(&userVirtualAmount) |
|
|
|
if err != nil { |
|
|
|
logx.Warn(err) |
|
|
|
return false, err |
|
|
|
} |
|
|
|
// 虚拟币流水 |
|
|
|
coinFlow := model.UserVirtualCoinFlow{ |
|
|
|
Uid: v.Uid, |
|
|
|
CoinId: v.CoinId, |
|
|
|
Direction: 2, |
|
|
|
Title: "退款扣除分红", |
|
|
|
OrdId: utils.AnyToString(oid), |
|
|
|
Amout: utils.Float64ToStrByPrec(virtualAmount, 6), |
|
|
|
BeforeAmout: beforeCoinAmount, |
|
|
|
AfterAmout: userVirtualAmount.Amount, |
|
|
|
SysFee: "0.00", |
|
|
|
CreateTime: time.Now(), |
|
|
|
TransferType: 99, |
|
|
|
} |
|
|
|
_, err = sess.Insert(&coinFlow) |
|
|
|
if err != nil { |
|
|
|
return false, err |
|
|
|
} |
|
|
|
} |
|
|
|
v.IsEnd = 1 |
|
|
|
update, err := sess.Where("id=?", v.Id).Cols("is_end").Update(&v) |
|
|
|
if update == 0 || err != nil { |
|
|
|
return false, err |
|
|
|
} |
|
|
|
} |
|
|
|
return true, nil |
|
|
|
} |
|
|
|
|
|
|
|
func deductMoneySecond(eg *xorm.Engine, existOrd model.OrdList, dbName, str string) { |
|
|
|
if existOrd.Uid == 0 { |
|
|
|
return |
|
|
@@ -190,6 +247,8 @@ func deductMoneySecond(eg *xorm.Engine, existOrd model.OrdList, dbName, str stri |
|
|
|
commRefund(eg, session, &existOrd, existOrd.Uid, existOrd.Pvd, existOrd.ItemId, rebateList, str, dbName) |
|
|
|
commAreaRefund(session, existOrd.Uid, utils.Int64ToStr(existOrd.OrdId), md.PVD_GUIDE, existOrd.ItemId, str) |
|
|
|
commStoreRefund(eg, session, utils.Int64ToStr(existOrd.OrdId), existOrd.Pvd) |
|
|
|
refundServiceVirtualAmount(eg, session, existOrd.OrdId) |
|
|
|
|
|
|
|
existOrd.IsRefund = 1 |
|
|
|
} |
|
|
|
_, _ = db.OrdUpdateOneAll(eg, &existOrd) |
|
|
|