From 6da1c473cdb74d06e1d6bbe21ebfcf26888524ba Mon Sep 17 00:00:00 2001 From: dengbiao Date: Wed, 22 May 2024 15:36:27 +0800 Subject: [PATCH] update --- .../happy_orchard_user_waters.go | 18 ++-- rule/one_circles/coin_settlement.go | 91 ------------------- .../one_circles_auto_release_green_energy.go | 5 +- .../one_circles_community_dividends.go | 3 +- ...ircles_public_platoon_give_activty_coin.go | 3 +- ...circles_sign_in_green_energy_settlement.go | 5 +- 6 files changed, 19 insertions(+), 106 deletions(-) delete mode 100644 rule/one_circles/coin_settlement.go diff --git a/rule/micro_applications/happy_orchard_user_waters.go b/rule/micro_applications/happy_orchard_user_waters.go index 23c2bb7..3b251e8 100644 --- a/rule/micro_applications/happy_orchard_user_waters.go +++ b/rule/micro_applications/happy_orchard_user_waters.go @@ -40,7 +40,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err } err = handelWatering(engine, *req, *happyOrchardBasicSetting) if err != nil { - return err + return } break case enum.DealUserWatersKindForSevenDaysSign: @@ -51,7 +51,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err } err = handelSevenDaysSign(engine, *req, *happyOrchardBasicSetting) if err != nil { - return err + return } break case enum.DealUserWatersKindForTimerSign: @@ -62,7 +62,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err } err = handelTimerSign(engine, *req, *happyOrchardBasicSetting) if err != nil { - return err + return } break case enum.DealUserWatersKindForPlaceOrderReward: @@ -73,7 +73,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err } err = handelPlaceOrderReward(engine, *req, *happyOrchardBasicSetting) if err != nil { - return err + return } break case enum.DealUserWatersKindForSharingAssistance: @@ -84,7 +84,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err } err = handelSharingAssistance(engine, *req, *happyOrchardBasicSetting) if err != nil { - return err + return } break case enum.DealUserWatersKindForInvitingNewPlayers: @@ -95,7 +95,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err } err = handelInvitingNewPlayers(engine, *req, *happyOrchardBasicSetting) if err != nil { - return err + return } break case enum.DealUserWatersKindForBrowsingInterface: @@ -106,7 +106,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err } err = handelBrowsingInterface(engine, *req, *happyOrchardBasicSetting) if err != nil { - return err + return } break case enum.DealUserWatersKindForPlayGoldenEggGame: @@ -117,7 +117,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err } err = handelPlayGoldenEggGame(engine, *req, *happyOrchardBasicSetting) if err != nil { - return err + return } break case enum.DealUserWatersKindForPlayRaffleGame: @@ -128,7 +128,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err } err = handelPlayRaffleGame(engine, *req, *happyOrchardBasicSetting) if err != nil { - return err + return } break } diff --git a/rule/one_circles/coin_settlement.go b/rule/one_circles/coin_settlement.go deleted file mode 100644 index 636b099..0000000 --- a/rule/one_circles/coin_settlement.go +++ /dev/null @@ -1,91 +0,0 @@ -package one_circles - -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" - md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/md" - "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/svc" - zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" - "errors" - "fmt" - "github.com/shopspring/decimal" - "strconv" - "time" - "xorm.io/xorm" -) - -// DealUserCoin 处理给用户虚拟币积分 -func DealUserCoin(session *xorm.Session, req md.DealUserCoinReq) (err error) { - if req.Amount < 0 { - req.Amount = 0 - } - //1、分布式锁阻拦 - requestIdPrefix := fmt.Sprintf(md2.DealUserCoinRequestIdPrefix, req.Mid, req.CoinId, req.Uid) - cb, err := svc.HandleDistributedLock(req.Mid, strconv.Itoa(req.Uid), requestIdPrefix) - if err != nil { - return err - } - if cb != nil { - defer cb() // 释放锁 - } - - //2、计算&&组装数据 - now := time.Now() - coinAmount, err := svc.GetUserCoinAmount(session, req.Mid, req.CoinId, req.Uid) - if err != nil { - return err - } - coinAmountValue := decimal.NewFromFloat(zhios_order_relate_utils.StrToFloat64(coinAmount)) - amountValue := decimal.NewFromFloat(req.Amount).RoundFloor(8) - - var userVirtualCoinFlow model.UserVirtualCoinFlow - userVirtualCoinFlow.CoinId = req.CoinId - userVirtualCoinFlow.Title = req.Title - userVirtualCoinFlow.TransferType = req.TransferType - userVirtualCoinFlow.Uid = req.Uid - userVirtualCoinFlow.ToUid = req.ToUid - userVirtualCoinFlow.OrdId = req.OrdId - userVirtualCoinFlow.BeforeAmout = coinAmount - userVirtualCoinFlow.Amout = amountValue.String() - userVirtualCoinFlow.CreateTime = now - - if req.Kind == "add" { - userVirtualCoinFlow.Direction = 1 - userVirtualCoinFlow.AfterAmout = coinAmountValue.Add(amountValue).RoundFloor(8).String() - } else if req.Kind == "sub" { - userVirtualCoinFlow.Direction = 2 - userVirtualCoinFlow.AfterAmout = coinAmountValue.Sub(amountValue).RoundFloor(8).String() - } else { - err = errors.New("错误的kind类型") - return err - } - if zhios_order_relate_utils.StrToFloat64(userVirtualCoinFlow.AfterAmout) < 0 { - var coin model.VirtualCoin - _, err = session.Where("id = ?", req.CoinId).Get(&coin) - if err != nil { - return err - } - zhios_order_relate_utils.FilePutContents("virtual_coin_not", zhios_order_relate_utils.SerializeStr(map[string]interface{}{ - "uid": userVirtualCoinFlow.Uid, - "amount": userVirtualCoinFlow.Amout, - "before_amount": userVirtualCoinFlow.BeforeAmout, - "after_amount": userVirtualCoinFlow.AfterAmout, - "coin_id": userVirtualCoinFlow.CoinId, - })) - return errors.New("用户" + zhios_order_relate_utils.IntToStr(userVirtualCoinFlow.Uid) + "的" + coin.Name + "不足") - } - //3、插入 `user_virtual_coin_flow` 记录 - _, err = db.UserVirtualCoinFlowInsert(session, &userVirtualCoinFlow) - if err != nil { - return err - } - - //4、修改 `user_virtual_amount`的amount值 && 及缓存 - err = svc.SetCacheUserVirtualAmount(session, req.Mid, userVirtualCoinFlow.AfterAmout, req.CoinId, req.Uid, true) - if err != nil { - return err - } - - return nil -} diff --git a/rule/one_circles/one_circles_auto_release_green_energy.go b/rule/one_circles/one_circles_auto_release_green_energy.go index c5fd018..cd0ff96 100644 --- a/rule/one_circles/one_circles_auto_release_green_energy.go +++ b/rule/one_circles/one_circles_auto_release_green_energy.go @@ -4,6 +4,7 @@ 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" + "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule" "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/cache" zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" "errors" @@ -71,7 +72,7 @@ func AutoReleaseExchangeGreenEnergy(engine *xorm.Engine, masterId string) (err e session.Begin() //4.2给相应的用户加上个人的绿色积分(可用数量) - err = DealUserCoin(session, md.DealUserCoinReq{ + err = rule.DealUserCoin(session, md.DealUserCoinReq{ Kind: "add", Mid: masterId, Title: md.OneCirclesSettlementGreenEnergyExchangeGreenEnergy, @@ -83,7 +84,7 @@ func AutoReleaseExchangeGreenEnergy(engine *xorm.Engine, masterId string) (err e }) //4.2给相应的用户减少个人的绿色积分(结算数量) - err = DealUserCoin(session, md.DealUserCoinReq{ + err = rule.DealUserCoin(session, md.DealUserCoinReq{ Kind: "sub", Mid: masterId, Title: md.OneCirclesSettlementGreenEnergyExchangeTobeGreenEnergy, diff --git a/rule/one_circles/one_circles_community_dividends.go b/rule/one_circles/one_circles_community_dividends.go index 2fbb1cc..36a25cc 100644 --- a/rule/one_circles/one_circles_community_dividends.go +++ b/rule/one_circles/one_circles_community_dividends.go @@ -3,6 +3,7 @@ package one_circles 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" + "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule" "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/enum" 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" @@ -50,7 +51,7 @@ func CommunityDividends(engine *xorm.Engine, masterId string) (err error) { for _, v := range list { //4、 给相应的用户加上分红权益 - err = DealUserCoin(session, md.DealUserCoinReq{ + err = rule.DealUserCoin(session, md.DealUserCoinReq{ Kind: "add", Mid: masterId, Title: md.OneCirclesCommunityDividends, diff --git a/rule/one_circles/one_circles_public_platoon_give_activty_coin.go b/rule/one_circles/one_circles_public_platoon_give_activty_coin.go index f4fbbe3..8066edf 100644 --- a/rule/one_circles/one_circles_public_platoon_give_activty_coin.go +++ b/rule/one_circles/one_circles_public_platoon_give_activty_coin.go @@ -5,6 +5,7 @@ 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" + "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule" md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/md" zhios_order_relate_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils" "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/cache" @@ -165,7 +166,7 @@ func SettlementPublicGiveActivityCoin(engine *xorm.Engine, masterId string, uid session.Begin() //给相应的用户加上"个人"活跃积分 - err = DealUserCoin(session, md.DealUserCoinReq{ + err = rule.DealUserCoin(session, md.DealUserCoinReq{ Kind: "add", Mid: masterId, Title: md.OneCirclesWatchAdRewardPersonalActiveCoin, diff --git a/rule/one_circles/one_circles_sign_in_green_energy_settlement.go b/rule/one_circles/one_circles_sign_in_green_energy_settlement.go index b975deb..7b3f40a 100644 --- a/rule/one_circles/one_circles_sign_in_green_energy_settlement.go +++ b/rule/one_circles/one_circles_sign_in_green_energy_settlement.go @@ -5,6 +5,7 @@ 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" + "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule" "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/enum" md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/md" "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule/one_circles/svc" @@ -126,7 +127,7 @@ func HandleSettlementSignInGreenEnergy(engine *xorm.Engine, masterId string, id var reduceTotalGreenEnergy float64 //4.2给相应的用户加上个人的绿色积分(可用数量) - err = DealUserCoin(session, md.DealUserCoinReq{ + err = rule.DealUserCoin(session, md.DealUserCoinReq{ Kind: "add", Mid: masterId, Title: md.OneCirclesGreenEnergySignInSettlementPersonalReward, @@ -183,7 +184,7 @@ func HandleSettlementSignInGreenEnergy(engine *xorm.Engine, masterId string, id } } - err = DealUserCoin(session, md.DealUserCoinReq{ + err = rule.DealUserCoin(session, md.DealUserCoinReq{ Kind: "add", Mid: masterId, Title: md.OneCirclesGreenEnergySignInSettlementTeamReward,