@@ -11,7 +11,7 @@ import ( | |||||
) | ) | ||||
// FreeProductByID is 获取新人免单对应的商品id | // FreeProductByID is 获取新人免单对应的商品id | ||||
func FreeProductByID(sess *xorm.Session, gid, provider string) (*model.NewcomersFreeProduct, error) { | |||||
func FreeProductByID(sess *xorm.Session, gid, skuId, provider string) (*model.NewcomersFreeProduct, error) { | |||||
m := new(model.NewcomersFreeProduct) | m := new(model.NewcomersFreeProduct) | ||||
var has bool | var has bool | ||||
var err error | var err error | ||||
@@ -22,7 +22,10 @@ func FreeProductByID(sess *xorm.Session, gid, provider string) (*model.Newcomers | |||||
} | } | ||||
has, err = sess.Where("good_id LIKE ?", "%-"+gid).Get(m) | has, err = sess.Where("good_id LIKE ?", "%-"+gid).Get(m) | ||||
} else { | } else { | ||||
m.GoodId = gid | |||||
sess.Where("good_id=?", gid) | |||||
if skuId != "" { | |||||
sess.Or("good_id=?", skuId) | |||||
} | |||||
has, err = sess.Get(m) | has, err = sess.Get(m) | ||||
} | } | ||||
@@ -35,7 +38,7 @@ func FreeProductByID(sess *xorm.Session, gid, provider string) (*model.Newcomers | |||||
return m, nil | return m, nil | ||||
} | } | ||||
func MoreFreeProductByID(sess *xorm.Session, gid, provider string) (*model.MoreNewcomersFreeProduct, error) { | |||||
func MoreFreeProductByID(sess *xorm.Session, gid, skuId, provider string) (*model.MoreNewcomersFreeProduct, error) { | |||||
m := new(model.MoreNewcomersFreeProduct) | m := new(model.MoreNewcomersFreeProduct) | ||||
var has bool | var has bool | ||||
var err error | var err error | ||||
@@ -46,7 +49,10 @@ func MoreFreeProductByID(sess *xorm.Session, gid, provider string) (*model.MoreN | |||||
} | } | ||||
has, err = sess.Where("good_id LIKE ?", "%-"+gid).Get(m) | has, err = sess.Where("good_id LIKE ?", "%-"+gid).Get(m) | ||||
} else { | } else { | ||||
m.GoodId = gid | |||||
sess.Where("good_id=?", gid) | |||||
if skuId != "" { | |||||
sess.Or("good_id=?", skuId) | |||||
} | |||||
has, err = sess.Get(m) | has, err = sess.Get(m) | ||||
} | } | ||||
@@ -455,8 +455,9 @@ func OrderListCountByPriceType(sess *xorm.Session, uid string, priceType, day in | |||||
} | } | ||||
// OrderListCountByItemId is 计算免单单个商品购买的次数 | // OrderListCountByItemId is 计算免单单个商品购买的次数 | ||||
func OrderListCountByItemId(sess *xorm.Session, uid string, itemId string, day int) (int64, error) { | |||||
sess = sess.Where(" uid = ? AND state != 4 AND item_id = ? and price_type>0", uid, itemId) | |||||
func OrderListCountByItemId(sess *xorm.Session, uid string, itemId, skuId string, day int) (int64, error) { | |||||
sess = sess.Where(" uid = ? AND state != 4 AND (item_id = ? or (num_item_id=? and num_item_id!='')) and price_type>0", uid, itemId, skuId) | |||||
if day > 0 { | if day > 0 { | ||||
today := utils.GetTimeRange("today") | today := utils.GetTimeRange("today") | ||||
sess = sess.And("create_at>=?", today["end"]-int64(day*86400)) | sess = sess.And("create_at>=?", today["end"]-int64(day*86400)) | ||||
@@ -0,0 +1,15 @@ | |||||
package db | |||||
import ( | |||||
"applet/app/db/model" | |||||
"xorm.io/xorm" | |||||
) | |||||
func GetUnFreezeUser(eg *xorm.Engine, id string) *model.UnFreezeUser { | |||||
var data model.UnFreezeUser | |||||
get, err := eg.Where("id=?", id).Get(&data) | |||||
if get == false || err != nil { | |||||
return nil | |||||
} | |||||
return &data | |||||
} |
@@ -110,8 +110,7 @@ func GetAllDatabaseDev() *[]model.DbMapping { | |||||
fmt.Println("cfg.Local is: ", cfg.Local) | fmt.Println("cfg.Local is: ", cfg.Local) | ||||
if cfg.Local { // 本地调试 加快速度 | if cfg.Local { // 本地调试 加快速度 | ||||
fmt.Println("notice:LOCAL TEST, only masterId:** 123456 ** available!") | fmt.Println("notice:LOCAL TEST, only masterId:** 123456 ** available!") | ||||
err = Db.Where("deleted_at != ? AND is_dev = '1' AND db_master_id=?", 1, 123456). | |||||
Or("db_master_id = ?", 32053480).Find(&m) | |||||
err = Db.Where("deleted_at != ? AND is_dev = '1' AND db_master_id=?", 1, 123456).Find(&m) | |||||
} else { | } else { | ||||
err = Db.Where("deleted_at != ? AND is_dev = '1' ", 1).Find(&m) | err = Db.Where("deleted_at != ? AND is_dev = '1' ", 1).Find(&m) | ||||
} | } | ||||
@@ -0,0 +1,19 @@ | |||||
package model | |||||
import ( | |||||
"time" | |||||
) | |||||
type UnFreezeUser struct { | |||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||||
Uid int `json:"uid" xorm:"default 0 INT(11)"` | |||||
Time int `json:"time" xorm:"default 0 INT(11)"` | |||||
NextTime int `json:"next_time" xorm:"INT(11)"` | |||||
CoinId int `json:"coin_id" xorm:"default 0 INT(11)"` | |||||
Money string `json:"money" xorm:"default 0.00 DECIMAL(20,2)"` | |||||
IsUse int `json:"is_use" xorm:"default 0 INT(1)"` | |||||
Day int `json:"day" xorm:"default 0 INT(11)"` | |||||
IsTest int `json:"is_test" xorm:"default 0 INT(1)"` | |||||
UpdateTime time.Time `json:"update_time" xorm:"DATETIME"` | |||||
CreateTime time.Time `json:"create_time" xorm:"DATETIME"` | |||||
} |
@@ -25,41 +25,43 @@ func initConsumes() { | |||||
//jobs[consumeMd.ZhiosOrderFreeFunName] = ZhiosOrderFree | //jobs[consumeMd.ZhiosOrderFreeFunName] = ZhiosOrderFree | ||||
//jobs[consumeMd.ZhiosOrderTotalFunName] = ZhiosOrderTotal | //jobs[consumeMd.ZhiosOrderTotalFunName] = ZhiosOrderTotal | ||||
//jobs[consumeMd.ZhiosOrderTotalSecondFunName] = ZhiosOrderTotalSecond | //jobs[consumeMd.ZhiosOrderTotalSecondFunName] = ZhiosOrderTotalSecond | ||||
//// | |||||
//jobs[consumeMd.ZhiosOrderSettleTotalFunName] = ZhiosSettleTotal | //jobs[consumeMd.ZhiosOrderSettleTotalFunName] = ZhiosSettleTotal | ||||
//jobs[consumeMd.ZhiosOrderHjyFunName] = ZhiosOrderHjy | //jobs[consumeMd.ZhiosOrderHjyFunName] = ZhiosOrderHjy | ||||
//jobs[consumeMd.ZhiosOrderBuckleFunName] = ZhiosOrderBuckle | //jobs[consumeMd.ZhiosOrderBuckleFunName] = ZhiosOrderBuckle | ||||
//// | |||||
//jobs[consumeMd.ZhiosSupplierAfterOrderFunName] = ZhiosSupplierAfterOrder | //jobs[consumeMd.ZhiosSupplierAfterOrderFunName] = ZhiosSupplierAfterOrder | ||||
// | |||||
//jobs[consumeMd.ZhiosAppreciationFunName] = ZhiosAppreciation | //jobs[consumeMd.ZhiosAppreciationFunName] = ZhiosAppreciation | ||||
//jobs[consumeMd.ZhiosValidUserFunName] = ZhiosValidUser | //jobs[consumeMd.ZhiosValidUserFunName] = ZhiosValidUser | ||||
// | |||||
//jobs[consumeMd.ZhiosAcquisitionConditionFunName] = ZhiosAcquisitionCondition | //jobs[consumeMd.ZhiosAcquisitionConditionFunName] = ZhiosAcquisitionCondition | ||||
// | |||||
//jobs[consumeMd.DouShenUserRegisterConsumeForOfficialFunName] = DouShenUserRegisterConsumeForOfficial | //jobs[consumeMd.DouShenUserRegisterConsumeForOfficialFunName] = DouShenUserRegisterConsumeForOfficial | ||||
//jobs[consumeMd.DouShenUserRegisterConsumeForOperationCenterFunName] = DouShenUserRegisterConsumeForOperationCenter | //jobs[consumeMd.DouShenUserRegisterConsumeForOperationCenterFunName] = DouShenUserRegisterConsumeForOperationCenter | ||||
//jobs[consumeMd.DouShenUserRegisterConsumeForMyRecommenderFunName] = DouShenUserRegisterConsumeForMyRecommender | //jobs[consumeMd.DouShenUserRegisterConsumeForMyRecommenderFunName] = DouShenUserRegisterConsumeForMyRecommender | ||||
//jobs[consumeMd.DouShenUserRegisterConsumeForMyFansFunName] = DouShenUserRegisterConsumeForMyFans | //jobs[consumeMd.DouShenUserRegisterConsumeForMyFansFunName] = DouShenUserRegisterConsumeForMyFans | ||||
//jobs[consumeMd.DouShenUserRegisterConsumeForUserRegisterUpLvFunName] = DouShenUserRegisterConsumeForUserRegisterUpLv | //jobs[consumeMd.DouShenUserRegisterConsumeForUserRegisterUpLvFunName] = DouShenUserRegisterConsumeForUserRegisterUpLv | ||||
// | |||||
//jobs[consumeMd.ZhiosFastReturnOrderPayFunName] = ZhiosFastReturnOrderPay | //jobs[consumeMd.ZhiosFastReturnOrderPayFunName] = ZhiosFastReturnOrderPay | ||||
//jobs[consumeMd.ZhiosFastReturnOrderSuccessFunName] = ZhiosFastReturnOrderSuccess | //jobs[consumeMd.ZhiosFastReturnOrderSuccessFunName] = ZhiosFastReturnOrderSuccess | ||||
//jobs[consumeMd.ZhiosFastReturnOrderRefundFunName] = ZhiosFastReturnOrderRefund | //jobs[consumeMd.ZhiosFastReturnOrderRefundFunName] = ZhiosFastReturnOrderRefund | ||||
//jobs[consumeMd.ZhiosFastReturnOrderRefundSecondFunName] = ZhiosFastReturnOrderRefundSecond | //jobs[consumeMd.ZhiosFastReturnOrderRefundSecondFunName] = ZhiosFastReturnOrderRefundSecond | ||||
// | |||||
//jobs[consumeMd.YoumishangExchangeStoreFunName] = YoumishangExchangeStore | //jobs[consumeMd.YoumishangExchangeStoreFunName] = YoumishangExchangeStore | ||||
// | |||||
//jobs[consumeMd.ZhiosRechargeOrderFailFunName] = ZhiosRechargeOrderFail | //jobs[consumeMd.ZhiosRechargeOrderFailFunName] = ZhiosRechargeOrderFail | ||||
// | |||||
//jobs[consumeMd.CloudIssuanceAsyncMLoginFunName] = CloudIssuanceAsyncMLoginConsume | //jobs[consumeMd.CloudIssuanceAsyncMLoginFunName] = CloudIssuanceAsyncMLoginConsume | ||||
//jobs[consumeMd.ZhiosTikTokUpdateFunName] = ZhiosTikTokUpdate | //jobs[consumeMd.ZhiosTikTokUpdateFunName] = ZhiosTikTokUpdate | ||||
//jobs[consumeMd.ZhiosTikTokAllUpdateFunName] = ZhiosTikTokAllUpdate | //jobs[consumeMd.ZhiosTikTokAllUpdateFunName] = ZhiosTikTokAllUpdate | ||||
// | |||||
//jobs[consumeMd.ZhiosCapitalPoolOrderTotalFunName] = ZhiosCapitalPoolOrderTotal | //jobs[consumeMd.ZhiosCapitalPoolOrderTotalFunName] = ZhiosCapitalPoolOrderTotal | ||||
//jobs[consumeMd.ZhiosExpressOrderFail] = ZhiosExpressOrderFail | //jobs[consumeMd.ZhiosExpressOrderFail] = ZhiosExpressOrderFail | ||||
//jobs[consumeMd.ZhiosWithdrawReward] = ZhiosWithdrawReward | //jobs[consumeMd.ZhiosWithdrawReward] = ZhiosWithdrawReward | ||||
//jobs[consumeMd.ZhiosTaskTotal] = ZhiosTaskTotal | //jobs[consumeMd.ZhiosTaskTotal] = ZhiosTaskTotal | ||||
//jobs[consumeMd.ZhiosAutoUnFreeze] = ZhiosAutoUnFreeze | |||||
////jobs[consumeMd.ZhiosUserProfileInviteCode] = ZhiosUserProfileInviteCode | |||||
// | // | ||||
@@ -299,6 +299,24 @@ var RabbitMqQueueKeyList = []*MqQueue{ | |||||
BindKey: "", | BindKey: "", | ||||
ConsumeFunName: "zhiosTaskTotal", | ConsumeFunName: "zhiosTaskTotal", | ||||
}, | }, | ||||
{ | |||||
ExchangeName: "zhios.user_profile.exchange", | |||||
Name: "zhios_user_profile_invite_code", | |||||
Type: DirectQueueType, | |||||
IsPersistent: false, | |||||
RoutKey: "user_profile_invite_code", | |||||
BindKey: "", | |||||
ConsumeFunName: "ZhiosUserProfileInviteCode", | |||||
}, | |||||
{ | |||||
ExchangeName: "zhios.user_profile.exchange", | |||||
Name: "zhios_auto_un_freeze", | |||||
Type: DirectQueueType, | |||||
IsPersistent: false, | |||||
RoutKey: "auto_un_freeze", | |||||
BindKey: "", | |||||
ConsumeFunName: "ZhiosAutoUnFreeze", | |||||
}, | |||||
{ | { | ||||
ExchangeName: "zhios.user_valid.exchange", | ExchangeName: "zhios.user_valid.exchange", | ||||
Name: "zhios_user_valid", | Name: "zhios_user_valid", | ||||
@@ -604,5 +622,7 @@ const ( | |||||
FlexibleEmploymentWithdrawForGongMaoConsumeFunName = "FlexibleEmploymentWithdrawForGongMaoConsume" | FlexibleEmploymentWithdrawForGongMaoConsumeFunName = "FlexibleEmploymentWithdrawForGongMaoConsume" | ||||
FlexibleEmploymentWithdrawForPupiaoConsumeFunName = "FlexibleEmploymentWithdrawForPupiaoConsume" | FlexibleEmploymentWithdrawForPupiaoConsumeFunName = "FlexibleEmploymentWithdrawForPupiaoConsume" | ||||
ZhiosTaskTotal = "zhiosTaskTotal" | ZhiosTaskTotal = "zhiosTaskTotal" | ||||
ZhiosUserProfileInviteCode = "ZhiosUserProfileInviteCode" | |||||
ZhiosAutoUnFreeze = "ZhiosAutoUnFreeze" | |||||
InstallmentPaymentAutoRepaidConsumeFunName = "InstallmentPaymentAutoRepaidConsume" | InstallmentPaymentAutoRepaidConsumeFunName = "InstallmentPaymentAutoRepaidConsume" | ||||
) | ) |
@@ -7,7 +7,14 @@ type ZhiosAcquisition struct { | |||||
Mid string `json:"mid"` | Mid string `json:"mid"` | ||||
Id string `json:"id"` | Id string `json:"id"` | ||||
} | } | ||||
type ZhiosUserProfile struct { | |||||
Uid string `json:"uid"` | |||||
Mid string `json:"mid"` | |||||
} | |||||
type ZhiosAutoUnFreezes struct { | |||||
Id string `json:"id"` | |||||
Mid string `json:"mid"` | |||||
} | |||||
type AcquisitionCfg struct { | type AcquisitionCfg struct { | ||||
Id string `json:"id"` | Id string `json:"id"` | ||||
Status string `json:"status"` | Status string `json:"status"` | ||||
@@ -38,6 +38,7 @@ type ZhiosMallConsume struct { | |||||
type ZhiosOrderFree struct { | type ZhiosOrderFree struct { | ||||
ItemId string `json:"item_id"` | ItemId string `json:"item_id"` | ||||
SkuId string `json:"sku_id"` | |||||
OptPvd string `json:"opt_pvd"` | OptPvd string `json:"opt_pvd"` | ||||
OrderType string `json:"order_type"` | OrderType string `json:"order_type"` | ||||
Pid string `json:"pid"` | Pid string `json:"pid"` | ||||
@@ -343,7 +343,7 @@ func handleZhiosOrderFree(msg []byte) error { | |||||
} | } | ||||
func orderFreeCheck(eg *xorm.Engine, sess *xorm.Session, canalMsg *md.ZhiosOrderFree) *model.NewcomersFreeProduct { | func orderFreeCheck(eg *xorm.Engine, sess *xorm.Session, canalMsg *md.ZhiosOrderFree) *model.NewcomersFreeProduct { | ||||
m, err := db.FreeProductByID(sess, canalMsg.ItemId, canalMsg.OptPvd) | |||||
m, err := db.FreeProductByID(sess, canalMsg.ItemId, canalMsg.SkuId, canalMsg.OptPvd) | |||||
stock := 0 | stock := 0 | ||||
if m != nil && m.StoreId > 0 { //小于多少份就不能出售了 | if m != nil && m.StoreId > 0 { //小于多少份就不能出售了 | ||||
guideStoreStock := db.SysCfgGetWithDb(eg, canalMsg.Mid, "guide_store_stock") | guideStoreStock := db.SysCfgGetWithDb(eg, canalMsg.Mid, "guide_store_stock") | ||||
@@ -376,7 +376,7 @@ func orderFreeCheck(eg *xorm.Engine, sess *xorm.Session, canalMsg *md.ZhiosOrder | |||||
} | } | ||||
//判断当前栏目购买商品数量 并且开启了 | //判断当前栏目购买商品数量 并且开启了 | ||||
if limitBuyConditions.OpenOnegoodsBuy == "1" && utils.StrToInt64(limitBuyConditions.OnegoodsBuyLimit) > 0 { | if limitBuyConditions.OpenOnegoodsBuy == "1" && utils.StrToInt64(limitBuyConditions.OnegoodsBuyLimit) > 0 { | ||||
moreGoodsCount, _ := db.OrderListCountByItemId(sess, canalMsg.Uid, canalMsg.ItemId, utils.StrToInt(limitBuyConditions.OnegoodsBuyLimitDay)) | |||||
moreGoodsCount, _ := db.OrderListCountByItemId(sess, canalMsg.Uid, canalMsg.ItemId, canalMsg.SkuId, utils.StrToInt(limitBuyConditions.OnegoodsBuyLimitDay)) | |||||
if moreGoodsCount+1 > utils.StrToInt64(limitBuyConditions.OnegoodsBuyLimit) { | if moreGoodsCount+1 > utils.StrToInt64(limitBuyConditions.OnegoodsBuyLimit) { | ||||
sess.Rollback() | sess.Rollback() | ||||
return nil | return nil | ||||
@@ -483,7 +483,7 @@ func orderFreeCheck(eg *xorm.Engine, sess *xorm.Session, canalMsg *md.ZhiosOrder | |||||
} | } | ||||
func moreOrderFreeCheck(eg *xorm.Engine, sess *xorm.Session, canalMsg *md.ZhiosOrderFree) *model.MoreNewcomersFreeProduct { | func moreOrderFreeCheck(eg *xorm.Engine, sess *xorm.Session, canalMsg *md.ZhiosOrderFree) *model.MoreNewcomersFreeProduct { | ||||
m, err := db.MoreFreeProductByID(sess, canalMsg.ItemId, canalMsg.OptPvd) | |||||
m, err := db.MoreFreeProductByID(sess, canalMsg.ItemId, canalMsg.SkuId, canalMsg.OptPvd) | |||||
stock := 0 | stock := 0 | ||||
if m != nil && m.StoreId > 0 { //小于多少份就不能出售了 | if m != nil && m.StoreId > 0 { //小于多少份就不能出售了 | ||||
guideStoreStock := db.SysCfgGetWithDb(eg, canalMsg.Mid, "guide_store_stock") | guideStoreStock := db.SysCfgGetWithDb(eg, canalMsg.Mid, "guide_store_stock") | ||||
@@ -0,0 +1,174 @@ | |||||
package consume | |||||
import ( | |||||
"applet/app/db" | |||||
"applet/app/db/model" | |||||
"applet/app/utils" | |||||
"applet/app/utils/logx" | |||||
"applet/consume/md" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | |||||
"encoding/json" | |||||
"errors" | |||||
"fmt" | |||||
"github.com/streadway/amqp" | |||||
"time" | |||||
"xorm.io/xorm" | |||||
) | |||||
func ZhiosAutoUnFreeze(queue md.MqQueue) { | |||||
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>") | |||||
ch, err := rabbit.Cfg.Pool.GetChannel() | |||||
if err != nil { | |||||
logx.Error(err) | |||||
return | |||||
} | |||||
defer ch.Release() | |||||
//1、将自己绑定到交换机上 | |||||
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey) | |||||
//2、取出数据进行消费 | |||||
ch.Qos(1) | |||||
delivery := ch.Consume(queue.Name, false) | |||||
var res amqp.Delivery | |||||
var ok bool | |||||
for { | |||||
res, ok = <-delivery | |||||
if ok == true { | |||||
//fmt.Println(string(res.Body)) | |||||
fmt.Println(">>>>>>>>>>>>>>>>CanalOrderConsume<<<<<<<<<<<<<<<<<<<<<<<<<") | |||||
err = AutoUnFreeze(res.Body) | |||||
//_ = res.Reject(false) | |||||
if err == nil { | |||||
_ = res.Ack(true) | |||||
} | |||||
} else { | |||||
panic(errors.New("error getting message")) | |||||
} | |||||
} | |||||
fmt.Println("get msg done") | |||||
} | |||||
func AutoUnFreeze(msg []byte) error { | |||||
//1、解析canal采集至mq中queue的数据结构体 | |||||
var canalMsg *md.ZhiosAutoUnFreezes | |||||
fmt.Println(string(msg)) | |||||
var tmpString string | |||||
err := json.Unmarshal(msg, &tmpString) | |||||
if err != nil { | |||||
fmt.Println(err.Error()) | |||||
return err | |||||
} | |||||
fmt.Println(tmpString) | |||||
err = json.Unmarshal([]byte(tmpString), &canalMsg) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
mid := canalMsg.Mid | |||||
eg := db.DBs[mid] | |||||
if eg == nil { | |||||
return nil | |||||
} | |||||
tmp := db.GetUnFreezeUser(eg, canalMsg.Id) | |||||
if tmp == nil { | |||||
return nil | |||||
} | |||||
if utils.StrToFloat64(tmp.Money) == 0 { | |||||
return nil | |||||
} | |||||
sess := eg.NewSession() | |||||
defer sess.Close() | |||||
sess.Begin() | |||||
if tmp.CoinId == 0 { | |||||
err = finDoing(sess, tmp) | |||||
} else { | |||||
err = coinDoing(sess, tmp) | |||||
} | |||||
if err != nil { | |||||
sess.Rollback() | |||||
return nil | |||||
} | |||||
sess.Commit() | |||||
return nil | |||||
} | |||||
func finDoing(sess *xorm.Session, data *model.UnFreezeUser) error { | |||||
user, _ := db.UserProfileFindByIDSess(sess, data.Uid) | |||||
if user == nil { | |||||
return nil | |||||
} | |||||
if utils.StrToFloat64(user.FinInvalid) <= 0 { | |||||
return nil | |||||
} | |||||
money := data.Money | |||||
if utils.StrToFloat64(user.FinInvalid) < utils.StrToFloat64(data.Money) { | |||||
money = user.FinInvalid | |||||
} | |||||
beforeAmount := user.FinValid | |||||
user.FinInvalid = utils.Float64ToStrByPrec(utils.StrToFloat64(user.FinInvalid)-utils.StrToFloat64(money), 8) | |||||
user.FinValid = utils.Float64ToStrByPrec(utils.StrToFloat64(user.FinValid)+utils.StrToFloat64(money), 8) | |||||
update, err := sess.Where("uid=?", user.Uid).Cols("fin_valid,fin_invalid").Update(user) | |||||
if update == 0 || err != nil { | |||||
return errors.New("失败") | |||||
} | |||||
var flowData = model.FinUserFlow{ | |||||
Uid: user.Uid, | |||||
Type: 0, | |||||
Amount: money, | |||||
BeforeAmount: beforeAmount, | |||||
AfterAmount: user.FinValid, | |||||
OrdType: "auto_freeze", | |||||
OrdId: "", | |||||
OrdTitle: "自动解冻金额", | |||||
OrdAction: 30, | |||||
OrdTime: int(time.Now().Unix()), | |||||
State: 2, | |||||
CreateAt: time.Now(), | |||||
UpdateAt: time.Now(), | |||||
} | |||||
insert, err := sess.Insert(&flowData) | |||||
if insert == 0 || err != nil { | |||||
return errors.New("失败") | |||||
} | |||||
return nil | |||||
} | |||||
func coinDoing(sess *xorm.Session, data *model.UnFreezeUser) error { | |||||
user, _ := db.UserVirtualAmountFindById(sess, data.Uid, data.CoinId) | |||||
if user == nil { | |||||
return nil | |||||
} | |||||
if utils.StrToFloat64(user.FreezeAmount) <= 0 { | |||||
return nil | |||||
} | |||||
money := data.Money | |||||
if utils.StrToFloat64(user.FreezeAmount) < utils.StrToFloat64(data.Money) { | |||||
money = user.FreezeAmount | |||||
} | |||||
beforeAmount := user.Amount | |||||
beforeFreezeAmount := user.FreezeAmount | |||||
user.FreezeAmount = utils.Float64ToStrByPrec(utils.StrToFloat64(user.FreezeAmount)-utils.StrToFloat64(money), 8) | |||||
user.Amount = utils.Float64ToStrByPrec(utils.StrToFloat64(user.Amount)+utils.StrToFloat64(money), 8) | |||||
update, err := sess.Where("uid=?", user.Uid).Cols("freeze_amount,amount").Update(user) | |||||
if update == 0 || err != nil { | |||||
return errors.New("失败") | |||||
} | |||||
var flowData = model.UserVirtualCoinFlow{ | |||||
Uid: user.Uid, | |||||
CoinId: data.CoinId, | |||||
Direction: 1, | |||||
Title: "自动解冻", | |||||
OrdId: "", | |||||
Date: "", | |||||
Amout: money, | |||||
BeforeAmout: beforeAmount, | |||||
AfterAmout: user.Amount, | |||||
CreateTime: time.Now(), | |||||
TransferType: 200, | |||||
FreezeBeforeAmout: beforeFreezeAmount, | |||||
FreezeAfterAmout: user.FreezeAmount, | |||||
} | |||||
insert, err := sess.Insert(&flowData) | |||||
if insert == 0 || err != nil { | |||||
return errors.New("失败") | |||||
} | |||||
return nil | |||||
} |
@@ -0,0 +1,173 @@ | |||||
package consume | |||||
import ( | |||||
"applet/app/db" | |||||
"applet/app/utils/logx" | |||||
"applet/consume/md" | |||||
"applet/mall/utils" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | |||||
"encoding/json" | |||||
"errors" | |||||
"fmt" | |||||
"github.com/streadway/amqp" | |||||
"math/rand" | |||||
"unicode" | |||||
"xorm.io/xorm" | |||||
) | |||||
func ZhiosUserProfileInviteCode(queue md.MqQueue) { | |||||
fmt.Println(">>>>>>>>>>>>>>>>>>>>>>>>") | |||||
ch, err := rabbit.Cfg.Pool.GetChannel() | |||||
if err != nil { | |||||
logx.Error(err) | |||||
return | |||||
} | |||||
defer ch.Release() | |||||
//1、将自己绑定到交换机上 | |||||
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey) | |||||
//2、取出数据进行消费 | |||||
ch.Qos(1) | |||||
delivery := ch.Consume(queue.Name, false) | |||||
var res amqp.Delivery | |||||
var ok bool | |||||
for { | |||||
res, ok = <-delivery | |||||
if ok == true { | |||||
//fmt.Println(string(res.Body)) | |||||
fmt.Println(">>>>>>>>>>>>>>>>CanalOrderConsume<<<<<<<<<<<<<<<<<<<<<<<<<") | |||||
err = UserProfileInviteCode(res.Body) | |||||
//_ = res.Reject(false) | |||||
if err == nil { | |||||
_ = res.Ack(true) | |||||
//TODO::重新推回队列末尾,避免造成队列堵塞 | |||||
var msg *md.ZhiosUserProfile | |||||
var tmpString string | |||||
err := json.Unmarshal(res.Body, &tmpString) | |||||
if err != nil { | |||||
return | |||||
} | |||||
fmt.Println(tmpString) | |||||
err = json.Unmarshal([]byte(tmpString), &msg) | |||||
if err != nil { | |||||
return | |||||
} | |||||
ch.Publish(queue.ExchangeName, utils.SerializeStr(msg), queue.RoutKey) | |||||
} | |||||
} else { | |||||
panic(errors.New("error getting message")) | |||||
} | |||||
} | |||||
fmt.Println("get msg done") | |||||
} | |||||
func UserProfileInviteCode(msg []byte) error { | |||||
//1、解析canal采集至mq中queue的数据结构体 | |||||
var canalMsg *md.ZhiosUserProfile | |||||
fmt.Println(string(msg)) | |||||
var tmpString string | |||||
err := json.Unmarshal(msg, &tmpString) | |||||
if err != nil { | |||||
fmt.Println(err.Error()) | |||||
return err | |||||
} | |||||
fmt.Println(tmpString) | |||||
err = json.Unmarshal([]byte(tmpString), &canalMsg) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
mid := canalMsg.Mid | |||||
eg := db.DBs[mid] | |||||
if eg == nil { | |||||
return nil | |||||
} | |||||
userProfile, _ := db.UserProfileFindByID(eg, canalMsg.Uid) | |||||
if userProfile == nil { | |||||
return nil | |||||
} | |||||
if userProfile.InviteCode != "" { | |||||
return nil | |||||
} | |||||
inviteData := db.SysCfgFindWithDb(eg, mid, "app_invite_length", "app_invite_type") | |||||
l := utils.StrToInt(inviteData["app_invite_length"]) | |||||
types := utils.StrToInt(inviteData["app_invite_type"]) | |||||
code := returnCode(eg, l, types, 0) | |||||
if code == "" { | |||||
return errors.New("继续") | |||||
} | |||||
userProfile.InviteCode = code | |||||
fmt.Println(userProfile) | |||||
_, err = db.UserProfileUpdate(eg, userProfile.Uid, userProfile, "invite_code") | |||||
if err != nil { | |||||
return nil | |||||
} | |||||
return nil | |||||
} | |||||
func IsLetter(s string) bool { | |||||
for _, r := range s { | |||||
if !unicode.IsLetter(r) { | |||||
return false | |||||
} | |||||
} | |||||
return true | |||||
} | |||||
func GetRandomString(l, isLetter int) string { | |||||
str := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |||||
if isLetter != 1 { | |||||
str = "0123456789" | |||||
} | |||||
strs := []rune(str) | |||||
result := make([]rune, l) | |||||
for i := range result { | |||||
result[i] = strs[rand.Intn(len(strs))] | |||||
} | |||||
if IsLetter(string(result)) && isLetter == 1 { | |||||
return GetRandomString(l, isLetter) | |||||
} | |||||
return string(result) | |||||
} | |||||
func returnCode(eg *xorm.Engine, l, types, num int) string { | |||||
if num > 5 { | |||||
return "" | |||||
} | |||||
//循环3次判断是否存在该邀请码 | |||||
var code string | |||||
var ( | |||||
codes []string | |||||
) | |||||
for i := 0; i < 3; i++ { | |||||
oneCode := GetRandomString(l, types) | |||||
codes = append(codes, oneCode) | |||||
} | |||||
//判断是不是存在邀请码了 | |||||
tmp, _ := db.UserProfileFindByInviteCodes(eg, codes...) | |||||
//判断自定义是不是存在邀请码了 | |||||
customTmp, _ := db.UserProfileFindByCustomInviteCodes(eg, codes...) | |||||
//循环生成的邀请码 判断tmp里有没有这个邀请码 如果邀请码没有就赋值 再判断是否存在 存在就清空 | |||||
for _, v := range codes { | |||||
if code != "" { //如果存在并且数据库没有就跳过 | |||||
continue | |||||
} | |||||
code = v | |||||
for _, v1 := range *tmp { | |||||
//如果存在就清空 | |||||
if v1.InviteCode == v { | |||||
code = "" | |||||
} | |||||
} | |||||
for _, v1 := range *customTmp { | |||||
//如果存在就清空 | |||||
if v1.CustomInviteCode == v { | |||||
code = "" | |||||
} | |||||
} | |||||
} | |||||
//如果都没有就继续加一位继续查 | |||||
if code == "" { | |||||
return returnCode(eg, l+1, types, num+1) | |||||
} | |||||
return code | |||||
} |
@@ -43,7 +43,7 @@ require ( | |||||
github.com/syyongx/php2go v0.9.8 | github.com/syyongx/php2go v0.9.8 | ||||
github.com/tidwall/gjson v1.14.1 | github.com/tidwall/gjson v1.14.1 | ||||
go.uber.org/zap v1.16.0 | go.uber.org/zap v1.16.0 | ||||
google.golang.org/grpc v1.32.0 | |||||
google.golang.org/grpc v1.33.2 | |||||
google.golang.org/protobuf v1.33.0 | google.golang.org/protobuf v1.33.0 | ||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 | gopkg.in/natefinch/lumberjack.v2 v2.2.1 | ||||
gopkg.in/yaml.v2 v2.4.0 | gopkg.in/yaml.v2 v2.4.0 | ||||
@@ -101,7 +101,7 @@ require ( | |||||
golang.org/x/text v0.14.0 // indirect | golang.org/x/text v0.14.0 // indirect | ||||
golang.org/x/tools v0.6.0 // indirect | golang.org/x/tools v0.6.0 // indirect | ||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect | ||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect | |||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect | |||||
gopkg.in/yaml.v3 v3.0.1 // indirect | gopkg.in/yaml.v3 v3.0.1 // indirect | ||||
honnef.co/go/tools v0.0.1-2020.1.4 // indirect | honnef.co/go/tools v0.0.1-2020.1.4 // indirect | ||||
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect | xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect | ||||