@@ -12,4 +12,6 @@ type SubsidyWithUser struct { | |||||
CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | ||||
UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` | ||||
IsCanSubsidy int `json:"is_can_subsidy" xorm:"not null default 1 comment('()') INT(1)"` | IsCanSubsidy int `json:"is_can_subsidy" xorm:"not null default 1 comment('()') INT(1)"` | ||||
Day int `json:"day" xorm:"not null default 0 comment('') TINYINT(1)"` | |||||
LeaveDay int `json:"leave_day" xorm:"not null default 0 comment('') TINYINT(1)"` | |||||
} | } |
@@ -11,4 +11,6 @@ type SubsidyWithUserFlow struct { | |||||
Month int `json:"month" xorm:"default 0 comment('202312') INT(11)"` | Month int `json:"month" xorm:"default 0 comment('202312') INT(11)"` | ||||
Uid int `json:"uid" xorm:"default 0 INT(11)"` | Uid int `json:"uid" xorm:"default 0 INT(11)"` | ||||
Date string `json:"date" xorm:"comment('2023-12-01') VARCHAR(255)"` | Date string `json:"date" xorm:"comment('2023-12-01') VARCHAR(255)"` | ||||
Day int `json:"day" xorm:"not null default 0 comment('') TINYINT(1)"` | |||||
LeaveDay int `json:"leave_day" xorm:"not null default 0 comment('') TINYINT(1)"` | |||||
} | } |
@@ -3,19 +3,17 @@ module code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git | |||||
go 1.15 | go 1.15 | ||||
// go.mod文件中 | // go.mod文件中 | ||||
replace ( | |||||
code.fnuoos.com/go_rely_warehouse/zyos_model.git => E:/company/go_rely_warehouse/zyos_model/ | |||||
) | |||||
replace code.fnuoos.com/go_rely_warehouse/zyos_model.git => E:/company/go_rely_warehouse/zyos_model/ | |||||
require ( | require ( | ||||
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.3 | code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.3 | ||||
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.3 // indirect | |||||
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.3 | |||||
github.com/gin-gonic/gin v1.9.1 | github.com/gin-gonic/gin v1.9.1 | ||||
github.com/go-redis/redis v6.15.9+incompatible | github.com/go-redis/redis v6.15.9+incompatible | ||||
github.com/gomodule/redigo v1.8.9 | github.com/gomodule/redigo v1.8.9 | ||||
github.com/jinzhu/copier v0.3.5 | github.com/jinzhu/copier v0.3.5 | ||||
github.com/shopspring/decimal v1.3.1 | github.com/shopspring/decimal v1.3.1 | ||||
github.com/syyongx/php2go v0.9.6 | |||||
github.com/syyongx/php2go v0.9.8 | |||||
go.uber.org/zap v1.13.0 | go.uber.org/zap v1.13.0 | ||||
golang.org/x/sync v0.1.0 | golang.org/x/sync v0.1.0 | ||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 | ||||
@@ -2,8 +2,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT | |||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= | cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= | ||||
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.3 h1:SPp5AswPmkDO2ML6WwGlzhIuls+/1dUfU40iOeH0dh4= | code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.3 h1:SPp5AswPmkDO2ML6WwGlzhIuls+/1dUfU40iOeH0dh4= | ||||
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.3/go.mod h1:TTcCnFn/LhBGapnutpezlW+GXkLRNPMWkziOoCsXQqY= | code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.3/go.mod h1:TTcCnFn/LhBGapnutpezlW+GXkLRNPMWkziOoCsXQqY= | ||||
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.3 h1:XmPPfEinfIm+oOn4Mu9VdA6mqg6be6DR7C+iO/Tds8I= | |||||
code.fnuoos.com/go_rely_warehouse/zyos_model.git v0.0.3/go.mod h1:C8Cnjh+TKbSqhsbENGgVg17byUhsn6+SsSAEww0eBak= | |||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= | |||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= | filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= | ||||
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s= | gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s= | ||||
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU= | gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU= | ||||
@@ -99,8 +98,8 @@ github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QX | |||||
github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg= | github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg= | ||||
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= | github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= | ||||
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= | github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= | ||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= | |||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= | github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= | ||||
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= | |||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= | github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= | ||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= | ||||
github.com/goccy/go-json v0.8.1/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= | github.com/goccy/go-json v0.8.1/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= | ||||
@@ -397,8 +396,8 @@ github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gt | |||||
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= | github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= | ||||
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= | github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= | ||||
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= | github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= | ||||
github.com/syyongx/php2go v0.9.6 h1:NFJlFwV5SKonYE7e/EtAcVxaJAVX9piRLpapw23HOQ8= | |||||
github.com/syyongx/php2go v0.9.6/go.mod h1:meN2eIhhUoxOd2nMxbpe8g6cFPXI5O9/UAAuz7oDdzw= | |||||
github.com/syyongx/php2go v0.9.8 h1:FNwV1y+RaZxl7KTm/ICh0Zrhca/70d5JRMpwByuQ1FM= | |||||
github.com/syyongx/php2go v0.9.8/go.mod h1:meN2eIhhUoxOd2nMxbpe8g6cFPXI5O9/UAAuz7oDdzw= | |||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= | github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= | ||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= | github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= | ||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= | github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= | ||||
@@ -612,8 +611,7 @@ gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4= | |||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= | gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= | ||||
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= | gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= | ||||
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= | gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= | ||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= | |||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= | |||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= | |||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= | gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= | ||||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= | ||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= | ||||
@@ -123,10 +123,12 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask | |||||
} | } | ||||
if hasConsumeTotal > 0 { | if hasConsumeTotal > 0 { | ||||
for _, v := range subsidyWithUserForConsumeList { | for _, v := range subsidyWithUserForConsumeList { | ||||
consumeTotalMap[v.Uid] = consumeTotalMap[v.Uid].Add(decimal.NewFromFloat(consumeValue)) | |||||
totalMap[v.Uid] = totalMap[v.Uid].Add(decimal.NewFromFloat(consumeValue)) | |||||
consumeTotalCountMap[v.Uid]++ | |||||
consumeValueTotal = consumeValueTotal.Add(decimal.NewFromFloat(consumeValue)) | |||||
if v.LeaveDay > 0 { | |||||
consumeTotalMap[v.Uid] = consumeTotalMap[v.Uid].Add(decimal.NewFromFloat(consumeValue)) | |||||
totalMap[v.Uid] = totalMap[v.Uid].Add(decimal.NewFromFloat(consumeValue)) | |||||
consumeTotalCountMap[v.Uid]++ | |||||
consumeValueTotal = consumeValueTotal.Add(decimal.NewFromFloat(consumeValue)) | |||||
} | |||||
err1 := DealUserConsumeIntegral(session, &v, consumeValue, mid) | err1 := DealUserConsumeIntegral(session, &v, consumeValue, mid) | ||||
if err1 != nil { | if err1 != nil { | ||||
_ = session.Rollback() | _ = session.Rollback() | ||||
@@ -155,10 +157,12 @@ func DailySettlementBlockConsumeIntegral(engine *xorm.Engine, mid string, isTask | |||||
return err, totalMap, storeTotalMap | return err, totalMap, storeTotalMap | ||||
} | } | ||||
for _, v := range subsidyWithUserForExperienceList { | for _, v := range subsidyWithUserForExperienceList { | ||||
experienceTotalCountMap[v.Uid]++ | |||||
totalMap[v.Uid] = totalMap[v.Uid].Add(decimal.NewFromFloat(experienceValue)) | |||||
experienceTotalMap[v.Uid] = experienceTotalMap[v.Uid].Add(decimal.NewFromFloat(experienceValue)) | |||||
experienceValueTotal = experienceValueTotal.Add(decimal.NewFromFloat(experienceValue)) | |||||
if v.LeaveDay > 0 { | |||||
experienceTotalCountMap[v.Uid]++ | |||||
totalMap[v.Uid] = totalMap[v.Uid].Add(decimal.NewFromFloat(experienceValue)) | |||||
experienceTotalMap[v.Uid] = experienceTotalMap[v.Uid].Add(decimal.NewFromFloat(experienceValue)) | |||||
experienceValueTotal = experienceValueTotal.Add(decimal.NewFromFloat(experienceValue)) | |||||
} | |||||
err1 := DealUserExperienceIntegral(session, &v, experienceValue, mid) | err1 := DealUserExperienceIntegral(session, &v, experienceValue, mid) | ||||
if err1 != nil { | if err1 != nil { | ||||
_ = session.Rollback() | _ = session.Rollback() | ||||
@@ -302,8 +306,8 @@ func Total(sess *xorm.Session, date, dayPayAmount string) error { | |||||
data.AllAmount = AllAmount | data.AllAmount = AllAmount | ||||
data.AllIntegral = AllIntegral | data.AllIntegral = AllIntegral | ||||
data.AllIntegralAmount = AllIntegralAmount | data.AllIntegralAmount = AllIntegralAmount | ||||
update, err := sess.Where("id=?", data.Id).Update(&data) | |||||
if update == 0 || err != nil { | |||||
_, err := sess.Where("id=?", data.Id).Update(&data) | |||||
if err != nil { | |||||
return errors.New("失败") | return errors.New("失败") | ||||
} | } | ||||
return nil | return nil | ||||
@@ -354,36 +358,42 @@ func calcNowEverydayStoreIntegral(consumeValue, bili float64) (value float64, er | |||||
func DealUserConsumeIntegral(session *xorm.Session, subsidyWithUser *model.SubsidyWithUser, consumeIntegralValue float64, mid string) (err error) { | func DealUserConsumeIntegral(session *xorm.Session, subsidyWithUser *model.SubsidyWithUser, consumeIntegralValue float64, mid string) (err error) { | ||||
now := time.Now() | now := time.Now() | ||||
//1、扣除 subsidy_with_user 的 balance_amount、state | //1、扣除 subsidy_with_user 的 balance_amount、state | ||||
if subsidyWithUser.Amount == subsidyWithUser.BalanceAmount { | |||||
if subsidyWithUser.Day >= subsidyWithUser.LeaveDay && subsidyWithUser.State < 2 { | |||||
subsidyWithUser.State = 2 //补贴中 | subsidyWithUser.State = 2 //补贴中 | ||||
} | } | ||||
balanceAmount, _ := decimal.NewFromString(subsidyWithUser.BalanceAmount) | |||||
afterAmount, _ := balanceAmount.Sub(decimal.NewFromFloat(consumeIntegralValue)).Float64() | |||||
balanceAmount := subsidyWithUser.LeaveDay | |||||
afterAmount := balanceAmount - 1 | |||||
isEnd := 0 | |||||
if afterAmount < 0 { | |||||
isEnd = 1 | |||||
} | |||||
if afterAmount <= 0 { | if afterAmount <= 0 { | ||||
afterAmount = 0 | afterAmount = 0 | ||||
consumeIntegralValue = zhios_order_relate_utils.StrToFloat64(subsidyWithUser.BalanceAmount) | |||||
subsidyWithUser.State = 3 //补贴完 | subsidyWithUser.State = 3 //补贴完 | ||||
} | } | ||||
subsidyWithUser.BalanceAmount = zhios_order_relate_utils.Float64ToStr(afterAmount) | |||||
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "balance_amount", "state") | |||||
subsidyWithUser.LeaveDay = afterAmount | |||||
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "leave_day", "state") | |||||
if err != nil { | if err != nil { | ||||
return err | return err | ||||
} | } | ||||
if updateAffected <= 0 { | if updateAffected <= 0 { | ||||
return errors.New("修改 subsidy_with_user 记录失败") | return errors.New("修改 subsidy_with_user 记录失败") | ||||
} | } | ||||
if isEnd == 1 { | |||||
return nil | |||||
} | |||||
//2、新增 subsidy_with_user_flow 记录 | //2、新增 subsidy_with_user_flow 记录 | ||||
var subsidyWitUserFlow = &model.SubsidyWithUserFlow{ | var subsidyWitUserFlow = &model.SubsidyWithUserFlow{ | ||||
RecordsId: subsidyWithUser.Id, | |||||
Amount: zhios_order_relate_utils.Float64ToStr(consumeIntegralValue), | |||||
BalanceAmount: zhios_order_relate_utils.Float64ToStr(afterAmount), | |||||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||||
Date: now.Format("2006-01-02"), | |||||
Uid: subsidyWithUser.Uid, | |||||
Kind: subsidyWithUser.Kind, | |||||
Month: zhios_order_relate_utils.StrToInt(now.Format("200601")), | |||||
RecordsId: subsidyWithUser.Id, | |||||
Day: 1, | |||||
Amount: zhios_order_relate_utils.Float64ToStr(consumeIntegralValue), | |||||
LeaveDay: afterAmount, | |||||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||||
Date: now.Format("2006-01-02"), | |||||
Uid: subsidyWithUser.Uid, | |||||
Kind: subsidyWithUser.Kind, | |||||
Month: zhios_order_relate_utils.StrToInt(now.Format("200601")), | |||||
} | } | ||||
insertAffected, err := db.SubsidyWithUserFlowInsert(session, subsidyWitUserFlow) | insertAffected, err := db.SubsidyWithUserFlowInsert(session, subsidyWitUserFlow) | ||||
if err != nil { | if err != nil { | ||||
@@ -427,36 +437,42 @@ func DealUserConsumeIntegral(session *xorm.Session, subsidyWithUser *model.Subsi | |||||
func DealUserExperienceIntegral(session *xorm.Session, subsidyWithUser *model.SubsidyWithUser, experienceIntegralValue float64, mid string) (err error) { | func DealUserExperienceIntegral(session *xorm.Session, subsidyWithUser *model.SubsidyWithUser, experienceIntegralValue float64, mid string) (err error) { | ||||
now := time.Now() | now := time.Now() | ||||
//1、扣除 subsidy_with_user 的 balance_amount、state | //1、扣除 subsidy_with_user 的 balance_amount、state | ||||
if subsidyWithUser.Amount == subsidyWithUser.BalanceAmount { | |||||
if subsidyWithUser.Day >= subsidyWithUser.LeaveDay && subsidyWithUser.State < 2 { | |||||
subsidyWithUser.State = 2 //补贴中 | subsidyWithUser.State = 2 //补贴中 | ||||
} | } | ||||
balanceAmount, _ := decimal.NewFromString(subsidyWithUser.BalanceAmount) | |||||
afterAmount, _ := balanceAmount.Sub(decimal.NewFromFloat(experienceIntegralValue)).Float64() | |||||
balanceAmount := subsidyWithUser.LeaveDay | |||||
afterAmount := balanceAmount - 1 | |||||
isEnd := 0 | |||||
if afterAmount < 0 { | |||||
isEnd = 1 | |||||
} | |||||
if afterAmount <= 0 { | if afterAmount <= 0 { | ||||
afterAmount = 0 | afterAmount = 0 | ||||
experienceIntegralValue = zhios_order_relate_utils.StrToFloat64(subsidyWithUser.BalanceAmount) | |||||
subsidyWithUser.State = 3 //补贴完 | subsidyWithUser.State = 3 //补贴完 | ||||
} | } | ||||
subsidyWithUser.BalanceAmount = zhios_order_relate_utils.Float64ToStr(afterAmount) | |||||
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "balance_amount", "state") | |||||
subsidyWithUser.LeaveDay = afterAmount | |||||
updateAffected, err := db.SubsidyWithUserUpdate(session, subsidyWithUser.Id, subsidyWithUser, "leave_day", "state") | |||||
if err != nil { | if err != nil { | ||||
return err | return err | ||||
} | } | ||||
if updateAffected <= 0 { | if updateAffected <= 0 { | ||||
return errors.New("修改 subsidy_with_user 记录失败") | return errors.New("修改 subsidy_with_user 记录失败") | ||||
} | } | ||||
if isEnd == 1 { | |||||
return nil | |||||
} | |||||
//2、新增 subsidy_with_user_flow 记录 | //2、新增 subsidy_with_user_flow 记录 | ||||
var subsidyWitUserFlow = &model.SubsidyWithUserFlow{ | var subsidyWitUserFlow = &model.SubsidyWithUserFlow{ | ||||
RecordsId: subsidyWithUser.Id, | |||||
Uid: subsidyWithUser.Uid, | |||||
Kind: subsidyWithUser.Kind, | |||||
Amount: zhios_order_relate_utils.Float64ToStr(experienceIntegralValue), | |||||
BalanceAmount: zhios_order_relate_utils.Float64ToStr(afterAmount), | |||||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||||
Date: now.Format("2006-01-02"), | |||||
Month: zhios_order_relate_utils.StrToInt(now.Format("200601")), | |||||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||||
RecordsId: subsidyWithUser.Id, | |||||
Uid: subsidyWithUser.Uid, | |||||
Kind: subsidyWithUser.Kind, | |||||
Amount: zhios_order_relate_utils.Float64ToStr(experienceIntegralValue), | |||||
Day: 1, | |||||
LeaveDay: afterAmount, | |||||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||||
Date: now.Format("2006-01-02"), | |||||
Month: zhios_order_relate_utils.StrToInt(now.Format("200601")), | |||||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||||
} | } | ||||
insertAffected, err := db.SubsidyWithUserFlowInsert(session, subsidyWitUserFlow) | insertAffected, err := db.SubsidyWithUserFlowInsert(session, subsidyWitUserFlow) | ||||
if err != nil { | if err != nil { | ||||