From 61f303631bd34a9ed73967cece857e563a0d767c Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 9 Jul 2024 17:24:04 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/db/db_newcomers_free_product.go | 14 ++++++++++---- consume/md/md_zhios_capital_pool_order_total.go | 1 + consume/zhios_order_free.go | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/db/db_newcomers_free_product.go b/app/db/db_newcomers_free_product.go index 8102014..633c889 100644 --- a/app/db/db_newcomers_free_product.go +++ b/app/db/db_newcomers_free_product.go @@ -11,7 +11,7 @@ import ( ) // 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) var has bool 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) } else { - m.GoodId = gid + sess.Where("good_id=?", gid) + if skuId != "" { + sess.Or("good_id=?", skuId) + } has, err = sess.Get(m) } @@ -35,7 +38,7 @@ func FreeProductByID(sess *xorm.Session, gid, provider string) (*model.Newcomers 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) var has bool 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) } else { - m.GoodId = gid + sess.Where("good_id=?", gid) + if skuId != "" { + sess.Or("good_id=?", skuId) + } has, err = sess.Get(m) } diff --git a/consume/md/md_zhios_capital_pool_order_total.go b/consume/md/md_zhios_capital_pool_order_total.go index f6053e4..d671d90 100644 --- a/consume/md/md_zhios_capital_pool_order_total.go +++ b/consume/md/md_zhios_capital_pool_order_total.go @@ -38,6 +38,7 @@ type ZhiosMallConsume struct { type ZhiosOrderFree struct { ItemId string `json:"item_id"` + SkuId string `json:"sku_id"` OptPvd string `json:"opt_pvd"` OrderType string `json:"order_type"` Pid string `json:"pid"` diff --git a/consume/zhios_order_free.go b/consume/zhios_order_free.go index 77ab2ee..15c21a6 100644 --- a/consume/zhios_order_free.go +++ b/consume/zhios_order_free.go @@ -343,7 +343,7 @@ func handleZhiosOrderFree(msg []byte) error { } 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 if m != nil && m.StoreId > 0 { //小于多少份就不能出售了 guideStoreStock := db.SysCfgGetWithDb(eg, canalMsg.Mid, "guide_store_stock") @@ -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 { - m, err := db.MoreFreeProductByID(sess, canalMsg.ItemId, canalMsg.OptPvd) + m, err := db.MoreFreeProductByID(sess, canalMsg.ItemId, canalMsg.SkuId, canalMsg.OptPvd) stock := 0 if m != nil && m.StoreId > 0 { //小于多少份就不能出售了 guideStoreStock := db.SysCfgGetWithDb(eg, canalMsg.Mid, "guide_store_stock") From d2318b2c57613c8469bb2f97c4c5e00afaade320 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 9 Jul 2024 17:24:33 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consume/init.go | 90 ++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/consume/init.go b/consume/init.go index f65fc66..8eaa96f 100644 --- a/consume/init.go +++ b/consume/init.go @@ -19,47 +19,47 @@ func Init() { func initConsumes() { //jobs[consumeMd.ZhiosGuideStoreOrderFunName] = ZhiosGuideStoreOrder - //jobs[consumeMd.ZhiosIntegralProxyRechargeFunName] = ZhiosIntegralProxyRecharge - //jobs[consumeMd.ZhiosUserUpLvFunName] = ZhiosUserUpLv - //jobs[consumeMd.CanalGuideOrderByUserUpLvConsume] = CanalGuideOrderByUserUpLvConsume - //jobs[consumeMd.ZhiosOrderFreeFunName] = ZhiosOrderFree - //jobs[consumeMd.ZhiosOrderTotalFunName] = ZhiosOrderTotal - //jobs[consumeMd.ZhiosOrderTotalSecondFunName] = ZhiosOrderTotalSecond - //// - //jobs[consumeMd.ZhiosOrderSettleTotalFunName] = ZhiosSettleTotal - //jobs[consumeMd.ZhiosOrderHjyFunName] = ZhiosOrderHjy - //jobs[consumeMd.ZhiosOrderBuckleFunName] = ZhiosOrderBuckle - //// - //jobs[consumeMd.ZhiosSupplierAfterOrderFunName] = ZhiosSupplierAfterOrder + jobs[consumeMd.ZhiosIntegralProxyRechargeFunName] = ZhiosIntegralProxyRecharge + jobs[consumeMd.ZhiosUserUpLvFunName] = ZhiosUserUpLv + jobs[consumeMd.CanalGuideOrderByUserUpLvConsume] = CanalGuideOrderByUserUpLvConsume + jobs[consumeMd.ZhiosOrderFreeFunName] = ZhiosOrderFree + jobs[consumeMd.ZhiosOrderTotalFunName] = ZhiosOrderTotal + jobs[consumeMd.ZhiosOrderTotalSecondFunName] = ZhiosOrderTotalSecond // - //jobs[consumeMd.ZhiosAppreciationFunName] = ZhiosAppreciation - //jobs[consumeMd.ZhiosValidUserFunName] = ZhiosValidUser + jobs[consumeMd.ZhiosOrderSettleTotalFunName] = ZhiosSettleTotal + jobs[consumeMd.ZhiosOrderHjyFunName] = ZhiosOrderHjy + jobs[consumeMd.ZhiosOrderBuckleFunName] = ZhiosOrderBuckle // - //jobs[consumeMd.ZhiosAcquisitionConditionFunName] = ZhiosAcquisitionCondition - // - //jobs[consumeMd.DouShenUserRegisterConsumeForOfficialFunName] = DouShenUserRegisterConsumeForOfficial - //jobs[consumeMd.DouShenUserRegisterConsumeForOperationCenterFunName] = DouShenUserRegisterConsumeForOperationCenter - //jobs[consumeMd.DouShenUserRegisterConsumeForMyRecommenderFunName] = DouShenUserRegisterConsumeForMyRecommender - //jobs[consumeMd.DouShenUserRegisterConsumeForMyFansFunName] = DouShenUserRegisterConsumeForMyFans - //jobs[consumeMd.DouShenUserRegisterConsumeForUserRegisterUpLvFunName] = DouShenUserRegisterConsumeForUserRegisterUpLv - // - //jobs[consumeMd.ZhiosFastReturnOrderPayFunName] = ZhiosFastReturnOrderPay - //jobs[consumeMd.ZhiosFastReturnOrderSuccessFunName] = ZhiosFastReturnOrderSuccess - //jobs[consumeMd.ZhiosFastReturnOrderRefundFunName] = ZhiosFastReturnOrderRefund - //jobs[consumeMd.ZhiosFastReturnOrderRefundSecondFunName] = ZhiosFastReturnOrderRefundSecond - // - //jobs[consumeMd.YoumishangExchangeStoreFunName] = YoumishangExchangeStore - // - //jobs[consumeMd.ZhiosRechargeOrderFailFunName] = ZhiosRechargeOrderFail - // - //jobs[consumeMd.CloudIssuanceAsyncMLoginFunName] = CloudIssuanceAsyncMLoginConsume - //jobs[consumeMd.ZhiosTikTokUpdateFunName] = ZhiosTikTokUpdate - //jobs[consumeMd.ZhiosTikTokAllUpdateFunName] = ZhiosTikTokAllUpdate - // - //jobs[consumeMd.ZhiosCapitalPoolOrderTotalFunName] = ZhiosCapitalPoolOrderTotal - //jobs[consumeMd.ZhiosExpressOrderFail] = ZhiosExpressOrderFail - //jobs[consumeMd.ZhiosWithdrawReward] = ZhiosWithdrawReward - //jobs[consumeMd.ZhiosTaskTotal] = ZhiosTaskTotal + jobs[consumeMd.ZhiosSupplierAfterOrderFunName] = ZhiosSupplierAfterOrder + + jobs[consumeMd.ZhiosAppreciationFunName] = ZhiosAppreciation + jobs[consumeMd.ZhiosValidUserFunName] = ZhiosValidUser + + jobs[consumeMd.ZhiosAcquisitionConditionFunName] = ZhiosAcquisitionCondition + + jobs[consumeMd.DouShenUserRegisterConsumeForOfficialFunName] = DouShenUserRegisterConsumeForOfficial + jobs[consumeMd.DouShenUserRegisterConsumeForOperationCenterFunName] = DouShenUserRegisterConsumeForOperationCenter + jobs[consumeMd.DouShenUserRegisterConsumeForMyRecommenderFunName] = DouShenUserRegisterConsumeForMyRecommender + jobs[consumeMd.DouShenUserRegisterConsumeForMyFansFunName] = DouShenUserRegisterConsumeForMyFans + jobs[consumeMd.DouShenUserRegisterConsumeForUserRegisterUpLvFunName] = DouShenUserRegisterConsumeForUserRegisterUpLv + + jobs[consumeMd.ZhiosFastReturnOrderPayFunName] = ZhiosFastReturnOrderPay + jobs[consumeMd.ZhiosFastReturnOrderSuccessFunName] = ZhiosFastReturnOrderSuccess + jobs[consumeMd.ZhiosFastReturnOrderRefundFunName] = ZhiosFastReturnOrderRefund + jobs[consumeMd.ZhiosFastReturnOrderRefundSecondFunName] = ZhiosFastReturnOrderRefundSecond + + jobs[consumeMd.YoumishangExchangeStoreFunName] = YoumishangExchangeStore + + jobs[consumeMd.ZhiosRechargeOrderFailFunName] = ZhiosRechargeOrderFail + + jobs[consumeMd.CloudIssuanceAsyncMLoginFunName] = CloudIssuanceAsyncMLoginConsume + jobs[consumeMd.ZhiosTikTokUpdateFunName] = ZhiosTikTokUpdate + jobs[consumeMd.ZhiosTikTokAllUpdateFunName] = ZhiosTikTokAllUpdate + + jobs[consumeMd.ZhiosCapitalPoolOrderTotalFunName] = ZhiosCapitalPoolOrderTotal + jobs[consumeMd.ZhiosExpressOrderFail] = ZhiosExpressOrderFail + jobs[consumeMd.ZhiosWithdrawReward] = ZhiosWithdrawReward + jobs[consumeMd.ZhiosTaskTotal] = ZhiosTaskTotal // @@ -80,12 +80,12 @@ func initConsumes() { //////////////////////////////////////// oneCircles ///////////////////////////////////////////////////// - jobs[consumeMd.OneCirclesSignInGreenEnergyFunName] = OneCirclesSignInGreenEnergyConsume - jobs[consumeMd.OneCirclesStartLevelDividendFunName] = OneCirclesStartLevelDividendConsume - jobs[consumeMd.OneCirclesActivityCoinAutoExchangeGreenEnergyFunName] = OneCirclesActivityCoinAutoExchangeGreenEnergyConsume - jobs[consumeMd.OneCirclesActivityCoinAutoExchangeGreenEnergyForTeamFunName] = OneCirclesActivityCoinAutoExchangeGreenEnergyForTeamConsume - jobs[consumeMd.OneCirclesSettlementPublicGiveActivityCoinFunName] = OneCirclesSettlementPublicGiveActivityCoinConsume - //jobs[consumeMd.OneCirclesSignInCopyGreenEnergyFunName] = OneCirclesSignInCopyGreenEnergyConsume + //jobs[consumeMd.OneCirclesSignInGreenEnergyFunName] = OneCirclesSignInGreenEnergyConsume + //jobs[consumeMd.OneCirclesStartLevelDividendFunName] = OneCirclesStartLevelDividendConsume + //jobs[consumeMd.OneCirclesActivityCoinAutoExchangeGreenEnergyFunName] = OneCirclesActivityCoinAutoExchangeGreenEnergyConsume + //jobs[consumeMd.OneCirclesActivityCoinAutoExchangeGreenEnergyForTeamFunName] = OneCirclesActivityCoinAutoExchangeGreenEnergyForTeamConsume + //jobs[consumeMd.OneCirclesSettlementPublicGiveActivityCoinFunName] = OneCirclesSettlementPublicGiveActivityCoinConsume + ////jobs[consumeMd.OneCirclesSignInCopyGreenEnergyFunName] = OneCirclesSignInCopyGreenEnergyConsume //////////////////////////////////////// withdraw ///////////////////////////////////////////////////// //jobs[consumeMd.WithdrawConsumeFunName] = WithdrawConsume From aeac2425c88c6fcc66a2b118184236efb3323127 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Wed, 10 Jul 2024 16:24:13 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/db/db_order.go | 5 +- app/db/dbs_map.go | 3 +- consume/init.go | 1 + consume/md/consume_key.go | 10 ++ consume/md/md.go | 5 +- consume/zhios_order_free.go | 2 +- consume/zhios_user_profile_invite_code.go | 173 ++++++++++++++++++++++ go.mod | 4 +- 8 files changed, 195 insertions(+), 8 deletions(-) create mode 100644 consume/zhios_user_profile_invite_code.go diff --git a/app/db/db_order.go b/app/db/db_order.go index f81c648..6b67352 100644 --- a/app/db/db_order.go +++ b/app/db/db_order.go @@ -455,8 +455,9 @@ func OrderListCountByPriceType(sess *xorm.Session, uid string, priceType, day in } // 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 { today := utils.GetTimeRange("today") sess = sess.And("create_at>=?", today["end"]-int64(day*86400)) diff --git a/app/db/dbs_map.go b/app/db/dbs_map.go index ceb1e16..bc2472d 100644 --- a/app/db/dbs_map.go +++ b/app/db/dbs_map.go @@ -110,8 +110,7 @@ func GetAllDatabaseDev() *[]model.DbMapping { fmt.Println("cfg.Local is: ", cfg.Local) if cfg.Local { // 本地调试 加快速度 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 { err = Db.Where("deleted_at != ? AND is_dev = '1' ", 1).Find(&m) } diff --git a/consume/init.go b/consume/init.go index 8eaa96f..a6c4300 100644 --- a/consume/init.go +++ b/consume/init.go @@ -60,6 +60,7 @@ func initConsumes() { jobs[consumeMd.ZhiosExpressOrderFail] = ZhiosExpressOrderFail jobs[consumeMd.ZhiosWithdrawReward] = ZhiosWithdrawReward jobs[consumeMd.ZhiosTaskTotal] = ZhiosTaskTotal + //jobs[consumeMd.ZhiosUserProfileInviteCode] = ZhiosUserProfileInviteCode // diff --git a/consume/md/consume_key.go b/consume/md/consume_key.go index a5473a5..84cafb4 100644 --- a/consume/md/consume_key.go +++ b/consume/md/consume_key.go @@ -290,6 +290,15 @@ var RabbitMqQueueKeyList = []*MqQueue{ BindKey: "", 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_valid.exchange", Name: "zhios_user_valid", @@ -584,5 +593,6 @@ const ( FlexibleEmploymentWithdrawForGongMaoConsumeFunName = "FlexibleEmploymentWithdrawForGongMaoConsume" FlexibleEmploymentWithdrawForPupiaoConsumeFunName = "FlexibleEmploymentWithdrawForPupiaoConsume" ZhiosTaskTotal = "zhiosTaskTotal" + ZhiosUserProfileInviteCode = "ZhiosUserProfileInviteCode" InstallmentPaymentAutoRepaidConsumeFunName = "InstallmentPaymentAutoRepaidConsume" ) diff --git a/consume/md/md.go b/consume/md/md.go index 61a9acd..6af4330 100644 --- a/consume/md/md.go +++ b/consume/md/md.go @@ -7,7 +7,10 @@ type ZhiosAcquisition struct { Mid string `json:"mid"` Id string `json:"id"` } - +type ZhiosUserProfile struct { + Uid string `json:"uid"` + Mid string `json:"mid"` +} type AcquisitionCfg struct { Id string `json:"id"` Status string `json:"status"` diff --git a/consume/zhios_order_free.go b/consume/zhios_order_free.go index 15c21a6..2e9c236 100644 --- a/consume/zhios_order_free.go +++ b/consume/zhios_order_free.go @@ -376,7 +376,7 @@ func orderFreeCheck(eg *xorm.Engine, sess *xorm.Session, canalMsg *md.ZhiosOrder } //判断当前栏目购买商品数量 并且开启了 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) { sess.Rollback() return nil diff --git a/consume/zhios_user_profile_invite_code.go b/consume/zhios_user_profile_invite_code.go new file mode 100644 index 0000000..593c291 --- /dev/null +++ b/consume/zhios_user_profile_invite_code.go @@ -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 +} diff --git a/go.mod b/go.mod index b7ff074..2d2d74b 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,7 @@ require ( github.com/syyongx/php2go v0.9.8 github.com/tidwall/gjson v1.14.1 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 gopkg.in/natefinch/lumberjack.v2 v2.2.1 gopkg.in/yaml.v2 v2.4.0 @@ -98,7 +98,7 @@ require ( golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.6.0 // 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 honnef.co/go/tools v0.0.1-2020.1.4 // indirect xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect From 28cd84bdb63f3848d711332b93434a97845b38e6 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Thu, 11 Jul 2024 09:50:24 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/db/db_un_freeze_user.go | 15 +++ app/db/model/un_freeze_user.go | 19 +++ consume/init.go | 3 +- consume/md/consume_key.go | 10 ++ consume/md/md.go | 4 + consume/zhios_user_auto_un_freeze.go | 174 +++++++++++++++++++++++++++ 6 files changed, 224 insertions(+), 1 deletion(-) create mode 100644 app/db/db_un_freeze_user.go create mode 100644 app/db/model/un_freeze_user.go create mode 100644 consume/zhios_user_auto_un_freeze.go diff --git a/app/db/db_un_freeze_user.go b/app/db/db_un_freeze_user.go new file mode 100644 index 0000000..37c6274 --- /dev/null +++ b/app/db/db_un_freeze_user.go @@ -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 +} diff --git a/app/db/model/un_freeze_user.go b/app/db/model/un_freeze_user.go new file mode 100644 index 0000000..022fdb3 --- /dev/null +++ b/app/db/model/un_freeze_user.go @@ -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"` +} diff --git a/consume/init.go b/consume/init.go index a6c4300..994fbfd 100644 --- a/consume/init.go +++ b/consume/init.go @@ -60,7 +60,8 @@ func initConsumes() { jobs[consumeMd.ZhiosExpressOrderFail] = ZhiosExpressOrderFail jobs[consumeMd.ZhiosWithdrawReward] = ZhiosWithdrawReward jobs[consumeMd.ZhiosTaskTotal] = ZhiosTaskTotal - //jobs[consumeMd.ZhiosUserProfileInviteCode] = ZhiosUserProfileInviteCode + jobs[consumeMd.ZhiosAutoUnFreeze] = ZhiosAutoUnFreeze + ////jobs[consumeMd.ZhiosUserProfileInviteCode] = ZhiosUserProfileInviteCode // diff --git a/consume/md/consume_key.go b/consume/md/consume_key.go index 84cafb4..5edf3d6 100644 --- a/consume/md/consume_key.go +++ b/consume/md/consume_key.go @@ -299,6 +299,15 @@ var RabbitMqQueueKeyList = []*MqQueue{ 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", Name: "zhios_user_valid", @@ -594,5 +603,6 @@ const ( FlexibleEmploymentWithdrawForPupiaoConsumeFunName = "FlexibleEmploymentWithdrawForPupiaoConsume" ZhiosTaskTotal = "zhiosTaskTotal" ZhiosUserProfileInviteCode = "ZhiosUserProfileInviteCode" + ZhiosAutoUnFreeze = "ZhiosAutoUnFreeze" InstallmentPaymentAutoRepaidConsumeFunName = "InstallmentPaymentAutoRepaidConsume" ) diff --git a/consume/md/md.go b/consume/md/md.go index 6af4330..7af48c8 100644 --- a/consume/md/md.go +++ b/consume/md/md.go @@ -11,6 +11,10 @@ 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 { Id string `json:"id"` Status string `json:"status"` diff --git a/consume/zhios_user_auto_un_freeze.go b/consume/zhios_user_auto_un_freeze.go new file mode 100644 index 0000000..bf13a8d --- /dev/null +++ b/consume/zhios_user_auto_un_freeze.go @@ -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 +}