|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- package consume
-
- import (
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/utils"
- "applet/app/utils/logx"
- "applet/consume/md"
- model2 "code.fnuoos.com/go_rely_warehouse/zyos_go_condition_statistics.git/db/model"
- "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=? and task_id>0", 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 SUM(olr.amount) 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)
-
- var sum float64 = 0
- if err != nil {
- _ = logx.Warn(err)
- sum = 0
- } else {
- sum = utils.StrToFloat64(todayResult[0]["amount"])
- }
- sqlTpl = `SELECT SUM(olr.amount) AS amount
- FROM o2o_ord_list_relate olr
- LEFT JOIN o2o_ord ol ON olr.oid = ol.ord_id
- LEFT JOIN o2o_pay_to_merchant optm ON optm.pay_id = olr.oid
- WHERE olr.uid = ? AND (ol.state IN (1,2,3,4) or optm.state=1);
- `
- todayResult, err = db.QueryNativeString(eg, sqlTpl, uid)
- if err != nil {
- _ = logx.Warn(err)
- sum += 0
- } else {
- sum += utils.StrToFloat64(todayResult[0]["amount"])
- }
-
- sqlTpl = `SELECT SUM(olr.amount) AS amount
- FROM b2c_ord_list_relate olr
- JOIN b2c_ord ol ON olr.oid = ol.ord_id
- WHERE olr.uid = ? AND ol.state IN (1,2,3,4);
- `
- todayResult, err = db.QueryNativeString(eg, sqlTpl, uid)
- if err != nil {
- _ = logx.Warn(err)
- sum += 0
- } else {
- sum += utils.StrToFloat64(todayResult[0]["amount"])
- }
- sqlTpl = `SELECT SUM(olr.amount) AS amount
- FROM mall_ord_list_relate olr
- JOIN mall_ord ol ON olr.oid = ol.ord_id
- WHERE olr.uid = ? AND ol.state IN (1,2,3);
- `
- todayResult, err = db.QueryNativeString(eg, sqlTpl, uid)
- if err != nil {
- _ = logx.Warn(err)
- sum += 0
- } else {
- sum += utils.StrToFloat64(todayResult[0]["amount"])
- }
- // 累计佣金
- if sum >= utils.AnyToFloat64(v) {
- todone--
- }
- case "orderPay":
- count, _ := eg.Where("uid=?", user.Uid).In("state", []string{"1", "2", "3", "5"}).Sum(&model.OrdList{}, "paid_price")
- count1, _ := eg.Where("uid=?", user.Uid).In("state", []string{"1", "2", "3"}).Sum(&model.MallOrd{}, "cost_price")
- count2, _ := eg.Where("uid=?", user.Uid).In("state", []string{"1", "2", "3"}).Sum(&model2.O2oOrd{}, "cost_price")
- count3, _ := eg.Where("uid=?", user.Uid).In("state", []string{"1", "2", "3"}).Sum(&model2.B2cOrd{}, "cost_price")
- if count+count3+count2+count1 > utils.AnyToFloat64(v) {
- todone--
- }
- case "receive":
- // 已收货
- count, _ := eg.Where("uid=?", user.Uid).In("state", []string{"1", "2", "3", "5"}).Count(&model.OrdList{})
- count1, _ := eg.Where("uid=?", user.Uid).In("state", []string{"3"}).Count(&model.MallOrd{})
- count2, _ := eg.Where("uid=?", user.Uid).In("state", []string{"3"}).Count(&model2.O2oOrd{})
- count3, _ := eg.Where("uid=?", user.Uid).In("state", []string{"3"}).Count(&model2.B2cOrd{})
- if count+count3+count2+count1 > 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
- }
|