@@ -40,7 +40,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err | |||||
} | } | ||||
err = handelWatering(engine, *req, *happyOrchardBasicSetting) | err = handelWatering(engine, *req, *happyOrchardBasicSetting) | ||||
if err != nil { | if err != nil { | ||||
return err | |||||
return | |||||
} | } | ||||
break | break | ||||
case enum.DealUserWatersKindForSevenDaysSign: | case enum.DealUserWatersKindForSevenDaysSign: | ||||
@@ -51,7 +51,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err | |||||
} | } | ||||
err = handelSevenDaysSign(engine, *req, *happyOrchardBasicSetting) | err = handelSevenDaysSign(engine, *req, *happyOrchardBasicSetting) | ||||
if err != nil { | if err != nil { | ||||
return err | |||||
return | |||||
} | } | ||||
break | break | ||||
case enum.DealUserWatersKindForTimerSign: | case enum.DealUserWatersKindForTimerSign: | ||||
@@ -62,7 +62,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err | |||||
} | } | ||||
err = handelTimerSign(engine, *req, *happyOrchardBasicSetting) | err = handelTimerSign(engine, *req, *happyOrchardBasicSetting) | ||||
if err != nil { | if err != nil { | ||||
return err | |||||
return | |||||
} | } | ||||
break | break | ||||
case enum.DealUserWatersKindForPlaceOrderReward: | case enum.DealUserWatersKindForPlaceOrderReward: | ||||
@@ -73,7 +73,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err | |||||
} | } | ||||
err = handelPlaceOrderReward(engine, *req, *happyOrchardBasicSetting) | err = handelPlaceOrderReward(engine, *req, *happyOrchardBasicSetting) | ||||
if err != nil { | if err != nil { | ||||
return err | |||||
return | |||||
} | } | ||||
break | break | ||||
case enum.DealUserWatersKindForSharingAssistance: | case enum.DealUserWatersKindForSharingAssistance: | ||||
@@ -84,7 +84,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err | |||||
} | } | ||||
err = handelSharingAssistance(engine, *req, *happyOrchardBasicSetting) | err = handelSharingAssistance(engine, *req, *happyOrchardBasicSetting) | ||||
if err != nil { | if err != nil { | ||||
return err | |||||
return | |||||
} | } | ||||
break | break | ||||
case enum.DealUserWatersKindForInvitingNewPlayers: | case enum.DealUserWatersKindForInvitingNewPlayers: | ||||
@@ -95,7 +95,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err | |||||
} | } | ||||
err = handelInvitingNewPlayers(engine, *req, *happyOrchardBasicSetting) | err = handelInvitingNewPlayers(engine, *req, *happyOrchardBasicSetting) | ||||
if err != nil { | if err != nil { | ||||
return err | |||||
return | |||||
} | } | ||||
break | break | ||||
case enum.DealUserWatersKindForBrowsingInterface: | case enum.DealUserWatersKindForBrowsingInterface: | ||||
@@ -106,7 +106,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err | |||||
} | } | ||||
err = handelBrowsingInterface(engine, *req, *happyOrchardBasicSetting) | err = handelBrowsingInterface(engine, *req, *happyOrchardBasicSetting) | ||||
if err != nil { | if err != nil { | ||||
return err | |||||
return | |||||
} | } | ||||
break | break | ||||
case enum.DealUserWatersKindForPlayGoldenEggGame: | case enum.DealUserWatersKindForPlayGoldenEggGame: | ||||
@@ -117,7 +117,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err | |||||
} | } | ||||
err = handelPlayGoldenEggGame(engine, *req, *happyOrchardBasicSetting) | err = handelPlayGoldenEggGame(engine, *req, *happyOrchardBasicSetting) | ||||
if err != nil { | if err != nil { | ||||
return err | |||||
return | |||||
} | } | ||||
break | break | ||||
case enum.DealUserWatersKindForPlayRaffleGame: | case enum.DealUserWatersKindForPlayRaffleGame: | ||||
@@ -128,7 +128,7 @@ func DealUserWaters(engine *xorm.Engine, kind string, args interface{}) (err err | |||||
} | } | ||||
err = handelPlayRaffleGame(engine, *req, *happyOrchardBasicSetting) | err = handelPlayRaffleGame(engine, *req, *happyOrchardBasicSetting) | ||||
if err != nil { | if err != nil { | ||||
return err | |||||
return | |||||
} | } | ||||
break | break | ||||
} | } | ||||
@@ -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 | |||||
} |
@@ -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" | ||||
"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/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/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" | "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" | zhios_order_relate_logx "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/utils/logx" | ||||
"errors" | "errors" | ||||
@@ -71,7 +72,7 @@ func AutoReleaseExchangeGreenEnergy(engine *xorm.Engine, masterId string) (err e | |||||
session.Begin() | session.Begin() | ||||
//4.2给相应的用户加上个人的绿色积分(可用数量) | //4.2给相应的用户加上个人的绿色积分(可用数量) | ||||
err = DealUserCoin(session, md.DealUserCoinReq{ | |||||
err = rule.DealUserCoin(session, md.DealUserCoinReq{ | |||||
Kind: "add", | Kind: "add", | ||||
Mid: masterId, | Mid: masterId, | ||||
Title: md.OneCirclesSettlementGreenEnergyExchangeGreenEnergy, | Title: md.OneCirclesSettlementGreenEnergyExchangeGreenEnergy, | ||||
@@ -83,7 +84,7 @@ func AutoReleaseExchangeGreenEnergy(engine *xorm.Engine, masterId string) (err e | |||||
}) | }) | ||||
//4.2给相应的用户减少个人的绿色积分(结算数量) | //4.2给相应的用户减少个人的绿色积分(结算数量) | ||||
err = DealUserCoin(session, md.DealUserCoinReq{ | |||||
err = rule.DealUserCoin(session, md.DealUserCoinReq{ | |||||
Kind: "sub", | Kind: "sub", | ||||
Mid: masterId, | Mid: masterId, | ||||
Title: md.OneCirclesSettlementGreenEnergyExchangeTobeGreenEnergy, | Title: md.OneCirclesSettlementGreenEnergyExchangeTobeGreenEnergy, | ||||
@@ -3,6 +3,7 @@ package one_circles | |||||
import ( | 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/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/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" | "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_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" | 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 { | for _, v := range list { | ||||
//4、 给相应的用户加上分红权益 | //4、 给相应的用户加上分红权益 | ||||
err = DealUserCoin(session, md.DealUserCoinReq{ | |||||
err = rule.DealUserCoin(session, md.DealUserCoinReq{ | |||||
Kind: "add", | Kind: "add", | ||||
Mid: masterId, | Mid: masterId, | ||||
Title: md.OneCirclesCommunityDividends, | Title: md.OneCirclesCommunityDividends, | ||||
@@ -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" | ||||
"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/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/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" | 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" | 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" | "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() | session.Begin() | ||||
//给相应的用户加上"个人"活跃积分 | //给相应的用户加上"个人"活跃积分 | ||||
err = DealUserCoin(session, md.DealUserCoinReq{ | |||||
err = rule.DealUserCoin(session, md.DealUserCoinReq{ | |||||
Kind: "add", | Kind: "add", | ||||
Mid: masterId, | Mid: masterId, | ||||
Title: md.OneCirclesWatchAdRewardPersonalActiveCoin, | Title: md.OneCirclesWatchAdRewardPersonalActiveCoin, | ||||
@@ -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" | ||||
"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/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/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" | "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" | 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" | "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 | var reduceTotalGreenEnergy float64 | ||||
//4.2给相应的用户加上个人的绿色积分(可用数量) | //4.2给相应的用户加上个人的绿色积分(可用数量) | ||||
err = DealUserCoin(session, md.DealUserCoinReq{ | |||||
err = rule.DealUserCoin(session, md.DealUserCoinReq{ | |||||
Kind: "add", | Kind: "add", | ||||
Mid: masterId, | Mid: masterId, | ||||
Title: md.OneCirclesGreenEnergySignInSettlementPersonalReward, | 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", | Kind: "add", | ||||
Mid: masterId, | Mid: masterId, | ||||
Title: md.OneCirclesGreenEnergySignInSettlementTeamReward, | Title: md.OneCirclesGreenEnergySignInSettlementTeamReward, | ||||