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" "xorm.io/xorm" ) func ZhiosValidUser(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(300) 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(">>>>>>>>>>>>>>>>ZhiosAcquisitionCondition<<<<<<<<<<<<<<<<<<<<<<<<<") err = handleValidUser(res.Body) //_ = res.Reject(false) fmt.Println(err) _ = res.Ack(true) } else { panic(errors.New("error getting message")) } } fmt.Println("get msg done") } func handleValidUser(msg []byte) error { //1、解析canal采集至mq中queue的数据结构体 var canalMsg *md.ZhiosAcquisition 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 } if canalMsg.Uid == "" { return nil } RoutineUpdateUserComm(eg, mid, canalMsg.Uid) return nil } func RoutineUpdateUserComm(eg *xorm.Engine, dbName, uid string) { if utils.StrToInt(uid) == 0 { return } user, _ := db.UserFindByID(eg, uid) if user == nil { return } userProfile, _ := db.UserProfileFindByID(eg, uid) if userProfile == nil { return } if userProfile.IsVerify == 1 { return } validConditionMap := map[string]interface{}{} checkMap := map[string]interface{}{} todone := 0 //有效会员 校验 vdata := db.SysCfgGetWithDb(eg, dbName, "valid_member_condition") if err := json.Unmarshal([]byte(vdata), &validConditionMap); err != nil { return logx.Warn(err) } for k, v := range validConditionMap { if v != "" && utils.AnyToFloat64(v) > 0 { todone++ checkMap[k] = v } } for k, v := range checkMap { switch k { case "taskVideo": sum, _ := eg.Where("uid=? and task_type=?", user.Uid, 3).Sum(&model.TaskVideoNum{}, "count") if sum >= utils.AnyToFloat64(v) { todone-- } case "realCheck": // 检查实名认证 one, _ := db.GetRealNameAuthByUidWithState(eg, user.Uid, 1) if one != nil && one.Uid == user.Uid { todone-- } case "bindPhone": // 检查绑定手机号 if user.Phone != "" { todone-- } case "goodsCommission": sqlTpl := `SELECT cast(SUM(LEFT(olr.amount,LENGTH(olr.amount)-2)) as decimal(50,4)) AS amount FROM ord_list_relate olr LEFT JOIN ord_list ol ON olr.oid = ol.ord_id LEFT JOIN privilege_card_ord pco ON olr.oid =pco.ord_id LEFT JOIN duoyou_ord_list dol ON olr.oid =dol.oid LEFT JOIN recharge_order ro ON olr.oid =ro.oid LEFT JOIN playlet_sale_order pso ON olr.oid =pso.custom_oid WHERE olr.uid = ? AND (ol.state<>4 or pco.state=1 or dol.id>0 or ro.status<>'已退款' or pso.status<>'订单退款'); ` todayResult, err := db.QueryNativeString(eg, sqlTpl, uid) today := "0" if err == nil { today = todayResult[0]["amount"] } // 累计佣金 if utils.StrToFloat64(today) >= utils.AnyToFloat64(v) { todone-- } case "orderPay": // 付款订单满足v元 ms, err := db.OrderListByUIDByPaidPrice(eg, user.Uid, v, []string{"0", "1", "2", "3", "5"}) if err != nil { logx.Warn(err) } mss := *ms if len(mss) > 0 { todone-- } case "receive": // 已收货 ms, err := db.OrderListByUIDByState(eg, user.Uid, []string{"1", "2", "3", "5"}) if err != nil { logx.Warn(err) } mss := *ms if len(mss) > 0 { todone-- } case "tbAuth": // 是否淘宝授权 if userProfile.AccTaobaoAuthTime != 0 { todone-- } case "withdraw": // 提现 sum, err := db.UserWithDrawApplySumByState(eg, user.Uid, "1", "2") if err != nil { logx.Warn(err) } if sum > 0 { todone-- } } } // 满足条件则将改用户打为有效用户 if todone == 0 { userProfile.IsVerify = 1 } _, err := db.UserProfileUpdate(eg, userProfile.Uid, userProfile) if err != nil { logx.Warn(err) } return }