package model import ( "errors" "fmt" "github.com/codinl/go-logger" "github.com/jinzhu/gorm" "mh-server/lib/utils" "time" ) // gen:qs // //go:generate goqueryset -in cooperative_business.go type CooperativeBusiness struct { Model Name string `json:"name" binding:"required"` // AddTime time.Time `json:"add_time"` // 加入时间 Avatar string `json:"avatar" binding:"required"` Address string `json:"address" binding:"required"` Tel string `json:"tel" binding:"required"` CooperativeMemberDeduct *CooperativeMemberDeduct `json:"cooperative_member_deduct" gorm:"-"` CooperativeAssistantMemberDeduct *CooperativeAssistantMemberDeduct `json:"cooperative_assistant_member_deduct" gorm:"-"` //Identification string `json:"identification"` // 标识 // cooperative_business } /* 门店 游戏 卡 库存 用户 绑定门店 店员 借卡 订单 */ // gen:qs type CooperativeMemberDeduct struct { Model CooperativeBusinessId uint32 `json:"cooperative_business_id" gorm:"index"` GoldDeduct uint32 `json:"gold_deduct"` // 黄金会员提成 PlatinumDeduct uint32 `json:"platinum_deduct"` // 白金会员提成 BlackGoldDeduct uint32 `json:"black_gold_deduct"` // 黑金金会员提成 RenewalGoldDeduct uint32 `json:"renewal_gold_deduct"` // 续费黄金会员提成 RenewalPlatinumDeduct uint32 `json:"renewal_platinum_deduct"` // 续费白金会员提成 RenewalBlackGoldDeduct uint32 `json:"renewal_black_gold_deduct"` // 续费黑金金会员提成 // cooperative_member_deduct } // gen:qs type CooperativeAssistantMemberDeduct struct { Model CooperativeBusinessId uint32 `json:"cooperative_business_id" gorm:"index"` StoreId uint32 `json:"store_id" gorm:"index"` // GoldDeduct uint32 `json:"gold_deduct"` // 黄金会员提成 PlatinumDeduct uint32 `json:"platinum_deduct"` // 白金会员提成 BlackGoldDeduct uint32 `json:"black_gold_deduct"` // 黑金金会员提成 RenewalGoldDeduct uint32 `json:"renewal_gold_deduct"` // 续费黄金会员提成 RenewalPlatinumDeduct uint32 `json:"renewal_platinum_deduct"` // 续费白金会员提成 RenewalBlackGoldDeduct uint32 `json:"renewal_black_gold_deduct"` // 续费黑金金会员提成 // cooperative_assistant_member_deduct } const ( PromotionStateUnSettlement = "un_settlement" PromotionStateFinancePay = "finance_pay" PromotionStateSettled = "settled" ) // 合作商推广会员 // gen:qs type CooperativeMemberPromotion struct { Model CooperativeBusinessId uint32 `json:"cooperative_business_id" gorm:"index"` CooperativeName string `json:"cooperative_name"` // 合作商名称 GoldCount uint32 `json:"gold_count" gorm:"default:0"` // 黄金会员数量 PlatinumCount uint32 `json:"platinum_count" gorm:"default:0"` // 白金会员数量 BlackGoldCount uint32 `json:"black_gold_count" gorm:"default:0"` // 黑金会员数量 Date string `json:"date" gorm:"index"` // State string `json:"state"` // 待发起结算 待财务打款 已结算 RenewalGoldCount uint32 `json:"renewal_gold_count" gorm:"default:0"` // 续费黄金会员数量 RenewalPlatinumCount uint32 `json:"renewal_platinum_count" gorm:"default:0"` // 续费白金会员数量 RenewalBlackGoldCount uint32 `json:"renewal_black_gold_count" gorm:"default:0"` // 续费黑金会员数量 UpgradeGoldToPlatinumCount uint32 `json:"upgrade_gold_to_platinum_count" gorm:"default:0"` // 升级:黄金->白金数量 UpgradeGoldToBlackCount uint32 `json:"upgrade_gold_to_black_count" gorm:"default:0"` // 升级:黄金->黑金数量 UpgradePlatinumToBlackCount uint32 `json:"upgrade_platinum_to_black_count" gorm:"default:0"` // 升级:白金->黑金数量 // cooperative_member_promotion } // 合作商推广会员门店 饼图 // gen:qs type CooperativeMemberPromotionStore struct { Model CooperativeBusinessId uint32 `json:"cooperative_business_id" gorm:"index"` CooperativeName string `json:"cooperative_name"` // 合作商名称 StoreId uint32 `json:"store_id" gorm:"index"` // 门店id GoldCount uint32 `json:"gold_count" gorm:"default:0"` // 黄金会员数量 PlatinumCount uint32 `json:"platinum_count" gorm:"default:0"` // 白金会员数量 BlackGoldCount uint32 `json:"black_gold_count" gorm:"default:0"` // 黑金会员数量 Date string `json:"date" gorm:"index"` // RenewalGoldCount uint32 `json:"renewal_gold_count" gorm:"default:0"` // 续费黄金会员数量 RenewalPlatinumCount uint32 `json:"renewal_platinum_count" gorm:"default:0"` // 续费白金会员数量 RenewalBlackGoldCount uint32 `json:"renewal_black_gold_count" gorm:"default:0"` // 续费黑金会员数量 UpgradeGoldToPlatinumCount uint32 `json:"upgrade_gold_to_platinum_count" gorm:"default:0"` // 升级:黄金->白金数量 UpgradeGoldToBlackCount uint32 `json:"upgrade_gold_to_black_count" gorm:"default:0"` // 升级:黄金->黑金数量 UpgradePlatinumToBlackCount uint32 `json:"upgrade_platinum_to_black_count" gorm:"default:0"` // 升级:白金->黑金数量 // cooperative_member_promotion_store } // 合作商推广会员每天 // gen:qs type CooperativeMemberPromotionDay struct { Model CooperativeBusinessId uint32 `json:"cooperative_business_id" gorm:"index"` CooperativeName string `json:"cooperative_name"` // 合作商名称 GoldCount uint32 `json:"gold_count" gorm:"default:0"` // 黄金会员数量 PlatinumCount uint32 `json:"platinum_count" gorm:"default:0"` // 白金会员数量 BlackGoldCount uint32 `json:"black_gold_count" gorm:"default:0"` // 黑金会员数量 DayTime string `json:"day_time" gorm:"index"` // RenewalGoldCount uint32 `json:"renewal_gold_count" gorm:"default:0"` // 续费黄金会员数量 RenewalPlatinumCount uint32 `json:"renewal_platinum_count" gorm:"default:0"` // 续费白金会员数量 RenewalBlackGoldCount uint32 `json:"renewal_black_gold_count" gorm:"default:0"` // 续费黑金会员数量 UpgradeGoldToPlatinumCount uint32 `json:"upgrade_gold_to_platinum_count" gorm:"default:0"` // 升级:黄金->白金数量 UpgradeGoldToBlackCount uint32 `json:"upgrade_gold_to_black_count" gorm:"default:0"` // 升级:黄金->黑金数量 UpgradePlatinumToBlackCount uint32 `json:"upgrade_platinum_to_black_count" gorm:"default:0"` // 升级:白金->黑金数量 // cooperative_member_promotion_day } // 合作商推广会员门店每天 柱状图 // gen:qs type CooperativeMemberPromotionStoreDay struct { Model CooperativeBusinessId uint32 `json:"cooperative_business_id" gorm:"index"` CooperativeName string `json:"cooperative_name"` // 合作商名称 StoreId uint32 `json:"store_id" gorm:"index"` // 门店id GoldCount uint32 `json:"gold_count" gorm:"default:0"` // 黄金会员数量 PlatinumCount uint32 `json:"platinum_count" gorm:"default:0"` // 白金会员数量 BlackGoldCount uint32 `json:"black_gold_count" gorm:"default:0"` // 黑金会员数量 DayTime string `json:"day_time" gorm:"index"` // RenewalGoldCount uint32 `json:"renewal_gold_count" gorm:"default:0"` // 续费黄金会员数量 RenewalPlatinumCount uint32 `json:"renewal_platinum_count" gorm:"default:0"` // 续费白金会员数量 RenewalBlackGoldCount uint32 `json:"renewal_black_gold_count" gorm:"default:0"` // 续费黑金会员数量 UpgradeGoldToPlatinumCount uint32 `json:"upgrade_gold_to_platinum_count" gorm:"default:0"` // 升级:黄金->白金数量 UpgradeGoldToBlackCount uint32 `json:"upgrade_gold_to_black_count" gorm:"default:0"` // 升级:黄金->黑金数量 UpgradePlatinumToBlackCount uint32 `json:"upgrade_platinum_to_black_count" gorm:"default:0"` // 升级:白金->黑金数量 // cooperative_member_promotion_store_day } // gen:qs type CooperativeDeductSettle struct { Model CooperativeMemberPromotionId uint32 `json:"cooperative_member_promotion_id" gorm:"index"` CooperativeBusinessId uint32 `json:"cooperative_business_id" gorm:"index"` CooperativeName string `json:"cooperative_name"` // 合作商名称 DeductAmount uint32 `json:"deduct_amount"` // 提成金额 Date string `json:"date" gorm:"index"` // State string `json:"state"` // 待财务打款 已结算 GoldCount uint32 `json:"gold_count" gorm:"default:0"` // 黄金会员数量 PlatinumCount uint32 `json:"platinum_count" gorm:"default:0"` // 白金会员数量 BlackGoldCount uint32 `json:"black_gold_count" gorm:"default:0"` // 黑金会员数量 GoldDeduct uint32 `json:"gold_deduct"` // 黄金会员提成配置 PlatinumDeduct uint32 `json:"platinum_deduct"` // 白金会员提成配置 BlackGoldDeduct uint32 `json:"black_gold_deduct"` // 黑金会员提成配置 RenewalGoldCount uint32 `json:"renewal_gold_count" gorm:"default:0"` // 续费黄金会员数量 RenewalPlatinumCount uint32 `json:"renewal_platinum_count" gorm:"default:0"` // 续费白金会员数量 RenewalBlackGoldCount uint32 `json:"renewal_black_gold_count" gorm:"default:0"` // 续费黑金会员数量 RenewalGoldDeduct uint32 `json:"renewal_gold_deduct"` // 续费黄金会员提成 RenewalPlatinumDeduct uint32 `json:"renewal_platinum_deduct"` // 续费白金会员提成 RenewalBlackGoldDeduct uint32 `json:"renewal_black_gold_deduct"` // 续费黑金金会员提成 } func AddCooperativeMemberPromotion(cooperativeId, storeId, assistantUid uint32, memberLevel, memberGenre int) { defer func() { if err := recover(); err != nil { logger.Error("err:", err) } }() var cooperativeBusiness CooperativeBusiness err := NewCooperativeBusinessQuerySet(DB).IDEq(cooperativeId).One(&cooperativeBusiness) if err != nil { logger.Error("cooperative business err:", err) return } fmt.Println("cooperativeId:", cooperativeId) fmt.Println("storeId:", storeId) fmt.Println("assistantUid:", assistantUid) fmt.Println("memberLevel:", memberLevel) go func() { promotion := &CooperativeMemberPromotion{CooperativeBusinessId: cooperativeId, CooperativeName: cooperativeBusiness.Name} promotionStore := &CooperativeMemberPromotionStore{CooperativeBusinessId: cooperativeId, CooperativeName: cooperativeBusiness.Name} promotionDay := &CooperativeMemberPromotionDay{CooperativeBusinessId: cooperativeId, CooperativeName: cooperativeBusiness.Name} promotionStoreDay := &CooperativeMemberPromotionStoreDay{CooperativeBusinessId: cooperativeId, CooperativeName: cooperativeBusiness.Name} inviteReport := &InviteMemberReport{CooperativeBusinessId: cooperativeId, CooperativeName: cooperativeBusiness.Name, Uid: assistantUid, StoreId: storeId, } begin := DB.Begin() err = promotion.AddPromotion(begin, memberLevel) if err != nil { begin.Rollback() logger.Error("promotion add promotion err:", err) return } err = promotionDay.AddPromotion(begin, memberLevel) if err != nil { begin.Rollback() logger.Error("promotion add promotion err:", err) return } if storeId != 0 { err = promotionStore.AddPromotion(begin, memberLevel, storeId) if err != nil { begin.Rollback() logger.Error("promotion add promotion err:", err) return } err = promotionStoreDay.AddPromotion(begin, memberLevel, storeId) if err != nil { begin.Rollback() logger.Error("promotion add promotion err:", err) return } } if assistantUid != 0 { err = inviteReport.AddPromotion(begin, memberLevel, memberGenre) if err != nil { begin.Rollback() logger.Error("promotion add promotion err:", err) return } } err = begin.Commit().Error if err != nil { begin.Rollback() logger.Error("commit err:", err) return } }() } func (m *CooperativeMemberPromotion) AddPromotion(gdb *gorm.DB, memberLevel int) error { dateString := utils.MonthDate() if memberLevel < 0 { return errors.New("member level err") } m.Date = dateString sql := "" switch memberLevel { case 2: sql = "UPDATE cooperative_member_promotion SET gold_count=gold_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d", dateString, m.CooperativeBusinessId) m.GoldCount = 1 case 4: sql = "UPDATE cooperative_member_promotion SET platinum_count=platinum_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d", dateString, m.CooperativeBusinessId) m.PlatinumCount = 1 case 5: sql = "UPDATE cooperative_member_promotion SET black_gold_count=black_gold_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d", dateString, m.CooperativeBusinessId) m.BlackGoldCount = 1 } fmt.Println("邀请会员sql:", sql) exist, err := QueryRecordExist(fmt.Sprintf( "SELECT * FROM cooperative_member_promotion WHERE cooperative_business_id=%d AND date='%s' ", m.CooperativeBusinessId, dateString)) if err != nil { logger.Error("cooperative member promotion record exist err:", err) return err } //fmt.Println("是否存在数据:", fmt.Sprintf( // "SELECT * FROM cooperative_member_promotion WHERE cooperative_business_id=%d AND date='%s'", // m.CooperativeBusinessId, dateString)) if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion err:", err) return err } } else { m.State = PromotionStateUnSettlement err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion err:", err) return err } } return nil } func (m *CooperativeMemberPromotionStore) AddPromotion(gdb *gorm.DB, memberLevel int, storeId uint32) error { dateString := utils.MonthDate() if memberLevel < 0 { return errors.New("member level err") } m.Date = dateString m.StoreId = storeId sql := "" switch memberLevel { case 2: sql = "UPDATE cooperative_member_promotion_store SET gold_count=gold_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.GoldCount = 1 case 4: sql = "UPDATE cooperative_member_promotion_store SET platinum_count=platinum_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.PlatinumCount = 1 case 5: sql = "UPDATE cooperative_member_promotion_store SET black_gold_count=black_gold_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.BlackGoldCount = 1 } exist, err := QueryRecordExist(fmt.Sprintf( "SELECT * FROM cooperative_member_promotion_store WHERE cooperative_business_id=%d AND date='%s' AND store_id=%d", m.CooperativeBusinessId, dateString, storeId)) if err != nil { logger.Error("cooperative member promotion record exist err:", err) return err } if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion err:", err) return err } } else { err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion err:", err) return err } } return nil } func (m *CooperativeMemberPromotionDay) AddPromotion(gdb *gorm.DB, memberLevel int) error { dayString := utils.TodayZeroDateFormat() if memberLevel < 0 { return errors.New("member level err") } m.DayTime = dayString sql := "" switch memberLevel { case 2: sql = "UPDATE cooperative_member_promotion_day SET gold_count=gold_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d", dayString, m.CooperativeBusinessId) m.GoldCount = 1 case 4: sql = "UPDATE cooperative_member_promotion_day SET platinum_count=platinum_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d", dayString, m.CooperativeBusinessId) m.PlatinumCount = 1 case 5: sql = "UPDATE cooperative_member_promotion_day SET black_gold_count=black_gold_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d", dayString, m.CooperativeBusinessId) m.BlackGoldCount = 1 } exist, err := QueryRecordExist(fmt.Sprintf( "SELECT * FROM cooperative_member_promotion_day WHERE cooperative_business_id=%d AND day_time='%s'", m.CooperativeBusinessId, dayString)) if err != nil { logger.Error("cooperative member promotion record exist err:", err) return err } if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion day err:", err) return err } } else { err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion day err:", err) return err } } return nil } func (m *CooperativeMemberPromotionStoreDay) AddPromotion(gdb *gorm.DB, memberLevel int, storeId uint32) error { dateString := utils.TodayZeroDateFormat() if memberLevel < 0 { return errors.New("member level err") } m.DayTime = dateString m.StoreId = storeId sql := "" switch memberLevel { case 2: sql = "UPDATE cooperative_member_promotion_store_day SET gold_count=gold_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.GoldCount = 1 case 4: sql = "UPDATE cooperative_member_promotion_store_day SET platinum_count=platinum_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.PlatinumCount = 1 case 5: sql = "UPDATE cooperative_member_promotion_store_day SET black_gold_count=black_gold_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.BlackGoldCount = 1 } exist, err := QueryRecordExist("SELECT * FROM cooperative_member_promotion_store_day " + fmt.Sprintf("WHERE cooperative_business_id=%d AND day_time='%s' AND store_id=%d", m.CooperativeBusinessId, dateString, storeId)) if err != nil { logger.Error("cooperative member promotion store day record exist err:", err) return err } if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion store day err:", err) return err } } else { err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion store day err:", err) return err } } return nil } func (m *InviteMemberReport) AddPromotion(gdb *gorm.DB, memberLevel, memberGenre int) error { dateString := utils.MonthDate() if memberLevel < 0 { return errors.New("member level err") } if gdb == nil { gdb = DB } if m.StoreId == 0 { return errors.New("store id is null") } if m.Uid == 0 { return errors.New("uid is null") } m.Date = dateString sql := "" switch memberLevel { case 2: switch memberGenre { case 200: // 年度黄金 sql = "UPDATE invite_member_report SET gold_count=gold_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.GoldCount = 1 case 201: // 季度黄金 sql = "UPDATE invite_member_report SET gold_count_quarter=gold_count_quarter+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.GoldCountQuarter = 1 case 202: // 半年黄金 sql = "UPDATE invite_member_report SET gold_count_half=gold_count_half+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.GoldCountHalf = 1 } case 4: sql = "UPDATE invite_member_report SET platinum_count=platinum_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.PlatinumCount = 1 case 5: sql = "UPDATE invite_member_report SET black_gold_count=black_gold_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.BlackGoldCount = 1 } exist, err := QueryRecordExist(fmt.Sprintf( "SELECT * FROM invite_member_report WHERE cooperative_business_id=%d AND date='%s' AND uid=%d", m.CooperativeBusinessId, dateString, m.Uid)) if err != nil { logger.Error("cooperative member promotion record exist err:", err) return err } if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion err:", err) return err } } else { //m.State = PromotionStateUnSettlement err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion err:", err) return err } } return nil } func (m *CooperativeBusiness) SetAssistantMemberDeductConfig(storeId uint32) { var assistantDeductConfig CooperativeAssistantMemberDeduct err := DB.Table("cooperative_assistant_member_deduct").Where("cooperative_business_id=?", m.ID). Where("store_id=?", storeId).Order("id DESC").Limit(1).Find(&assistantDeductConfig).Error if err != nil && err != RecordNotFound { logger.Error("cooperative err:", err) return } m.CooperativeAssistantMemberDeduct = &assistantDeductConfig } func AddCooperativeMemberRenewal(cooperativeId, storeId, assistantUid uint32, memberLevel, memberGenre int, autoRenewFlag bool) { defer func() { if err := recover(); err != nil { logger.Error("err:", err) } }() var cooperativeBusiness CooperativeBusiness err := NewCooperativeBusinessQuerySet(DB).IDEq(cooperativeId).One(&cooperativeBusiness) if err != nil { logger.Error("cooperative business err:", err) return } fmt.Println("cooperativeId:", cooperativeId) fmt.Println("storeId:", storeId) fmt.Println("assistantUid:", assistantUid) fmt.Println("memberLevel:", memberLevel) fmt.Println("autoRenewFlag:", autoRenewFlag) go func() { promotion := &CooperativeMemberPromotion{CooperativeBusinessId: cooperativeId, CooperativeName: cooperativeBusiness.Name} promotionStore := &CooperativeMemberPromotionStore{CooperativeBusinessId: cooperativeId, CooperativeName: cooperativeBusiness.Name} promotionDay := &CooperativeMemberPromotionDay{CooperativeBusinessId: cooperativeId, CooperativeName: cooperativeBusiness.Name} promotionStoreDay := &CooperativeMemberPromotionStoreDay{CooperativeBusinessId: cooperativeId, CooperativeName: cooperativeBusiness.Name} inviteReport := &InviteMemberReport{CooperativeBusinessId: cooperativeId, CooperativeName: cooperativeBusiness.Name, Uid: assistantUid, StoreId: storeId, } begin := DB.Begin() err = promotion.AddRenewal(begin, memberLevel) if err != nil { begin.Rollback() logger.Error("promotion add promotion err:", err) return } err = promotionDay.AddRenewal(begin, memberLevel) if err != nil { begin.Rollback() logger.Error("promotion add promotion err:", err) return } if storeId != 0 { err = promotionStore.AddRenewal(begin, memberLevel, storeId) if err != nil { begin.Rollback() logger.Error("promotion add promotion err:", err) return } err = promotionStoreDay.AddRenewal(begin, memberLevel, storeId) if err != nil { begin.Rollback() logger.Error("promotion add promotion err:", err) return } } if assistantUid != 0 { if autoRenewFlag { // 自动续费 err = inviteReport.AddRenewalAuto(begin, memberLevel, memberGenre) } else { // 干预续费 err = inviteReport.AddRenewalInvite(begin, memberLevel, memberGenre) } if err != nil { begin.Rollback() logger.Error("promotion add promotion err:", err) return } } err = begin.Commit().Error if err != nil { begin.Rollback() logger.Error("commit err:", err) return } }() } func (m *CooperativeMemberPromotion) AddRenewal(gdb *gorm.DB, memberLevel int) error { dateString := utils.MonthDate() if memberLevel < 0 { return errors.New("member level err") } m.Date = dateString sql := "" switch memberLevel { case 2: sql = "UPDATE cooperative_member_promotion SET renewal_gold_count=renewal_gold_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d", dateString, m.CooperativeBusinessId) m.RenewalGoldCount = 1 case 4: sql = "UPDATE cooperative_member_promotion SET renewal_platinum_count=renewal_platinum_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d", dateString, m.CooperativeBusinessId) m.RenewalPlatinumCount = 1 case 5: sql = "UPDATE cooperative_member_promotion SET renewal_black_gold_count=renewal_black_gold_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d", dateString, m.CooperativeBusinessId) m.RenewalBlackGoldCount = 1 } fmt.Println("邀请会员sql:", sql) exist, err := QueryRecordExist(fmt.Sprintf( "SELECT * FROM cooperative_member_promotion WHERE cooperative_business_id=%d AND date='%s' ", m.CooperativeBusinessId, dateString)) if err != nil { logger.Error("cooperative member promotion record exist err:", err) return err } //fmt.Println("是否存在数据:", fmt.Sprintf( // "SELECT * FROM cooperative_member_promotion WHERE cooperative_business_id=%d AND date='%s'", // m.CooperativeBusinessId, dateString)) if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion err:", err) return err } } else { m.State = PromotionStateUnSettlement err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion err:", err) return err } } return nil } func (m *CooperativeMemberPromotionStore) AddRenewal(gdb *gorm.DB, memberLevel int, storeId uint32) error { dateString := utils.MonthDate() if memberLevel < 0 { return errors.New("member level err") } m.Date = dateString m.StoreId = storeId sql := "" switch memberLevel { case 2: sql = "UPDATE cooperative_member_promotion_store SET renewal_gold_count=renewal_gold_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.RenewalGoldCount = 1 case 4: sql = "UPDATE cooperative_member_promotion_store SET renewal_platinum_count=renewal_platinum_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.RenewalPlatinumCount = 1 case 5: sql = "UPDATE cooperative_member_promotion_store SET renewal_black_gold_count=renewal_black_gold_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.RenewalBlackGoldCount = 1 } exist, err := QueryRecordExist(fmt.Sprintf( "SELECT * FROM cooperative_member_promotion_store WHERE cooperative_business_id=%d AND date='%s' AND store_id=%d", m.CooperativeBusinessId, dateString, storeId)) if err != nil { logger.Error("cooperative member promotion record exist err:", err) return err } if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion err:", err) return err } } else { err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion err:", err) return err } } return nil } func (m *CooperativeMemberPromotionDay) AddRenewal(gdb *gorm.DB, memberLevel int) error { dayString := utils.TodayZeroDateFormat() if memberLevel < 0 { return errors.New("member level err") } m.DayTime = dayString sql := "" switch memberLevel { case 2: sql = "UPDATE cooperative_member_promotion_day SET renewal_gold_count=renewal_gold_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d", dayString, m.CooperativeBusinessId) m.RenewalGoldCount = 1 case 4: sql = "UPDATE cooperative_member_promotion_day SET renewal_platinum_count=renewal_platinum_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d", dayString, m.CooperativeBusinessId) m.RenewalPlatinumCount = 1 case 5: sql = "UPDATE cooperative_member_promotion_day SET renewal_black_gold_count=renewal_black_gold_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d", dayString, m.CooperativeBusinessId) m.RenewalBlackGoldCount = 1 } exist, err := QueryRecordExist(fmt.Sprintf( "SELECT * FROM cooperative_member_promotion_day WHERE cooperative_business_id=%d AND day_time='%s'", m.CooperativeBusinessId, dayString)) if err != nil { logger.Error("cooperative member promotion record exist err:", err) return err } if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion day err:", err) return err } } else { err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion day err:", err) return err } } return nil } func (m *CooperativeMemberPromotionStoreDay) AddRenewal(gdb *gorm.DB, memberLevel int, storeId uint32) error { dateString := utils.TodayZeroDateFormat() if memberLevel < 0 { return errors.New("member level err") } m.DayTime = dateString m.StoreId = storeId sql := "" switch memberLevel { case 2: sql = "UPDATE cooperative_member_promotion_store_day SET renewal_gold_count=renewal_gold_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.RenewalGoldCount = 1 case 4: sql = "UPDATE cooperative_member_promotion_store_day SET renewal_platinum_count=renewal_platinum_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.RenewalPlatinumCount = 1 case 5: sql = "UPDATE cooperative_member_promotion_store_day SET renewal_black_gold_count=renewal_black_gold_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.RenewalBlackGoldCount = 1 } exist, err := QueryRecordExist("SELECT * FROM cooperative_member_promotion_store_day " + fmt.Sprintf("WHERE cooperative_business_id=%d AND day_time='%s' AND store_id=%d", m.CooperativeBusinessId, dateString, storeId)) if err != nil { logger.Error("cooperative member promotion store day record exist err:", err) return err } if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion store day err:", err) return err } } else { err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion store day err:", err) return err } } return nil } // AddRenewalAuto 用户自动续费后更新记录 func (m *InviteMemberReport) AddRenewalAuto(gdb *gorm.DB, memberLevel, memberGenre int) error { dateString := utils.MonthDate() if memberLevel < 0 { return errors.New("member level err") } if gdb == nil { gdb = DB } if m.StoreId == 0 { return errors.New("store id is null") } if m.Uid == 0 { return errors.New("uid is null") } m.Date = dateString sql := "" switch memberLevel { case 2: switch memberGenre { case 200: // 年度黄金 sql = "UPDATE invite_member_report SET renewal_gold_count=renewal_gold_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.RenewalGoldCount = 1 case 201: // 季度黄金 sql = "UPDATE invite_member_report SET renewal_gold_count_quarter=renewal_gold_count_quarter+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.RenewalGoldCountQuarter = 1 case 202: // 半年黄金 sql = "UPDATE invite_member_report SET renewal_gold_count_half=renewal_gold_count_half+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.RenewalGoldCountHalf = 1 } case 4: // 白金 sql = "UPDATE invite_member_report SET renewal_platinum_count=renewal_platinum_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.RenewalPlatinumCount = 1 case 5: // 黑金 sql = "UPDATE invite_member_report SET renewal_black_gold_count=renewal_black_gold_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.RenewalBlackGoldCount = 1 } exist, err := QueryRecordExist(fmt.Sprintf( "SELECT * FROM invite_member_report WHERE cooperative_business_id=%d AND date='%s' AND uid=%d", m.CooperativeBusinessId, dateString, m.Uid)) if err != nil { logger.Error("cooperative member promotion record exist err:", err) return err } if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion err:", err) return err } } else { //m.State = PromotionStateUnSettlement err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion err:", err) return err } } return nil } // AddRenewalInvite 邀请用户续费后更新记录 func (m *InviteMemberReport) AddRenewalInvite(gdb *gorm.DB, memberLevel, memberGenre int) error { dateString := utils.MonthDate() if memberLevel < 0 { return errors.New("member level err") } if gdb == nil { gdb = DB } if m.StoreId == 0 { return errors.New("store id is null") } if m.Uid == 0 { return errors.New("uid is null") } m.Date = dateString sql := "" switch memberLevel { case 2: // 黄金 sql = "UPDATE invite_member_report SET invite_renewal_gold_count=invite_renewal_gold_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.InviteRenewalGoldCount = 1 case 4: // 白金 sql = "UPDATE invite_member_report SET invite_renewal_platinum_count=invite_renewal_platinum_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.InviteRenewalPlatinumCount = 1 case 5: // 黑金 sql = "UPDATE invite_member_report SET invite_renewal_black_gold_count=invite_renewal_black_gold_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.InviteRenewalBlackGoldCount = 1 } exist, err := QueryRecordExist(fmt.Sprintf( "SELECT * FROM invite_member_report WHERE cooperative_business_id=%d AND date='%s' AND uid=%d", m.CooperativeBusinessId, dateString, m.Uid)) if err != nil { logger.Error("cooperative member promotion record exist err:", err) return err } if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion err:", err) return err } } else { //m.State = PromotionStateUnSettlement err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion err:", err) return err } } return nil } // AddCooperativeMemberUpgrade 同步记录会员升级数量 func AddCooperativeMemberUpgrade(cooperativeId, storeId, assistantUid, beforeMemberLevel uint32, memberLevel int, autoFlag bool) { defer func() { if err := recover(); err != nil { logger.Error("err:", err) } }() var cooperativeBusiness CooperativeBusiness err := NewCooperativeBusinessQuerySet(DB).IDEq(cooperativeId).One(&cooperativeBusiness) if err != nil { logger.Error("cooperative business err:", err) return } fmt.Println("cooperativeId:", cooperativeId) fmt.Println("storeId:", storeId) fmt.Println("assistantUid:", assistantUid) fmt.Println("memberLevel:", memberLevel) fmt.Println("autoFlag:", autoFlag) go func() { promotion := &CooperativeMemberPromotion{CooperativeBusinessId: cooperativeId, CooperativeName: cooperativeBusiness.Name} promotionStore := &CooperativeMemberPromotionStore{CooperativeBusinessId: cooperativeId, CooperativeName: cooperativeBusiness.Name} promotionDay := &CooperativeMemberPromotionDay{CooperativeBusinessId: cooperativeId, CooperativeName: cooperativeBusiness.Name} promotionStoreDay := &CooperativeMemberPromotionStoreDay{CooperativeBusinessId: cooperativeId, CooperativeName: cooperativeBusiness.Name} inviteReport := &InviteMemberReport{CooperativeBusinessId: cooperativeId, CooperativeName: cooperativeBusiness.Name, Uid: assistantUid, StoreId: storeId, } begin := DB.Begin() err = promotion.AddUpgrade(begin, beforeMemberLevel, memberLevel) if err != nil { begin.Rollback() logger.Error("promotion add promotion err:", err) return } err = promotionDay.AddUpgrade(begin, beforeMemberLevel, memberLevel) if err != nil { begin.Rollback() logger.Error("promotion add promotion err:", err) return } if storeId != 0 { err = promotionStore.AddUpgrade(begin, beforeMemberLevel, memberLevel, storeId) if err != nil { begin.Rollback() logger.Error("promotion add promotion err:", err) return } err = promotionStoreDay.AddUpgrade(begin, beforeMemberLevel, memberLevel, storeId) if err != nil { begin.Rollback() logger.Error("promotion add promotion err:", err) return } } if assistantUid != 0 { err = inviteReport.AddUpgrade(begin, beforeMemberLevel, memberLevel, autoFlag) if err != nil { begin.Rollback() logger.Error("promotion add promotion err:", err) return } } err = begin.Commit().Error if err != nil { begin.Rollback() logger.Error("commit err:", err) return } }() } func (m *CooperativeMemberPromotion) AddUpgrade(gdb *gorm.DB, beforeMemberLevel uint32, memberLevel int) error { dateString := utils.MonthDate() if memberLevel < 0 { return errors.New("member level err") } m.Date = dateString sql := "" switch memberLevel { case 4: // 白金:黄金->白金 sql = "UPDATE cooperative_member_promotion SET upgrade_gold_to_platinum_count=upgrade_gold_to_platinum_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d", dateString, m.CooperativeBusinessId) m.UpgradeGoldToPlatinumCount = 1 case 5: if beforeMemberLevel == 2 { // 黄金->黑金 sql = "UPDATE cooperative_member_promotion SET upgrade_gold_to_black_count=upgrade_gold_to_black_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d", dateString, m.CooperativeBusinessId) m.UpgradeGoldToBlackCount = 1 } else { // 白金-->黑金 sql = "UPDATE cooperative_member_promotion SET upgrade_platinum_to_black_count=upgrade_platinum_to_black_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d", dateString, m.CooperativeBusinessId) m.UpgradePlatinumToBlackCount = 1 } } fmt.Println("CooperativeMemberPromotion AddUpgrade 邀请会员sql:", sql) exist, err := QueryRecordExist(fmt.Sprintf( "SELECT * FROM cooperative_member_promotion WHERE cooperative_business_id=%d AND date='%s' ", m.CooperativeBusinessId, dateString)) if err != nil { logger.Error("cooperative member promotion record exist err:", err) return err } if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion err:", err) return err } } else { m.State = PromotionStateUnSettlement err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion err:", err) return err } } return nil } func (m *CooperativeMemberPromotionStore) AddUpgrade(gdb *gorm.DB, beforeMemberLevel uint32, memberLevel int, storeId uint32) error { dateString := utils.MonthDate() if memberLevel < 0 { return errors.New("member level err") } m.Date = dateString m.StoreId = storeId sql := "" switch memberLevel { case 4: // 白金:黄金->白金 sql = "UPDATE cooperative_member_promotion_store SET upgrade_gold_to_platinum_count=upgrade_gold_to_platinum_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.UpgradeGoldToPlatinumCount = 1 case 5: if beforeMemberLevel == 2 { // 黄金->黑金 sql = "UPDATE cooperative_member_promotion_store SET upgrade_gold_to_black_count=upgrade_gold_to_black_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.UpgradeGoldToBlackCount = 1 } else { // 白金->黑金 sql = "UPDATE cooperative_member_promotion_store SET upgrade_platinum_to_black_count=upgrade_platinum_to_black_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.UpgradePlatinumToBlackCount = 1 } } exist, err := QueryRecordExist(fmt.Sprintf( "SELECT * FROM cooperative_member_promotion_store WHERE cooperative_business_id=%d AND date='%s' AND store_id=%d", m.CooperativeBusinessId, dateString, storeId)) if err != nil { logger.Error("cooperative member promotion record exist err:", err) return err } if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion err:", err) return err } } else { err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion err:", err) return err } } return nil } func (m *CooperativeMemberPromotionDay) AddUpgrade(gdb *gorm.DB, beforeMemberLevel uint32, memberLevel int) error { dayString := utils.TodayZeroDateFormat() if memberLevel < 0 { return errors.New("member level err") } m.DayTime = dayString sql := "" switch memberLevel { case 4: // 黄金->白金 sql = "UPDATE cooperative_member_promotion_day SET upgrade_gold_to_platinum_count=upgrade_gold_to_platinum_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d", dayString, m.CooperativeBusinessId) m.UpgradeGoldToPlatinumCount = 1 case 5: if beforeMemberLevel == 2 { // 黄金->黑金 sql = "UPDATE cooperative_member_promotion_day SET upgrade_gold_to_black_count=upgrade_gold_to_black_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d", dayString, m.CooperativeBusinessId) m.UpgradeGoldToBlackCount = 1 } else { // 白金->黑金 sql = "UPDATE cooperative_member_promotion_day SET upgrade_platinum_to_black_count=upgrade_platinum_to_black_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d", dayString, m.CooperativeBusinessId) m.UpgradePlatinumToBlackCount = 1 } } fmt.Println("CooperativeMemberPromotionDay AddUpgrade 邀请会员sql:", sql) exist, err := QueryRecordExist(fmt.Sprintf( "SELECT * FROM cooperative_member_promotion_day WHERE cooperative_business_id=%d AND day_time='%s'", m.CooperativeBusinessId, dayString)) if err != nil { logger.Error("cooperative member promotion record exist err:", err) return err } if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion day err:", err) return err } } else { err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion day err:", err) return err } } return nil } func (m *CooperativeMemberPromotionStoreDay) AddUpgrade(gdb *gorm.DB, beforeMemberLevel uint32, memberLevel int, storeId uint32) error { dateString := utils.TodayZeroDateFormat() if memberLevel < 0 { return errors.New("member level err") } m.DayTime = dateString m.StoreId = storeId sql := "" switch memberLevel { case 4: // 白金:黄金->白金 sql = "UPDATE cooperative_member_promotion_store_day SET upgrade_gold_to_platinum_count=upgrade_gold_to_platinum_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.UpgradeGoldToPlatinumCount = 1 case 5: if beforeMemberLevel == 2 { // 黄金->黑金 sql = "UPDATE cooperative_member_promotion_store_day SET upgrade_gold_to_black_count=upgrade_gold_to_black_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.UpgradeGoldToBlackCount = 1 } else { sql = "UPDATE cooperative_member_promotion_store_day SET upgrade_platinum_to_black_count=upgrade_platinum_to_black_count+1 " + fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d AND store_id=%d", dateString, m.CooperativeBusinessId, storeId) m.UpgradePlatinumToBlackCount = 1 } } exist, err := QueryRecordExist("SELECT * FROM cooperative_member_promotion_store_day " + fmt.Sprintf("WHERE cooperative_business_id=%d AND day_time='%s' AND store_id=%d", m.CooperativeBusinessId, dateString, storeId)) if err != nil { logger.Error("cooperative member promotion store day record exist err:", err) return err } if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion store day err:", err) return err } } else { err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion store day err:", err) return err } } return nil } func (m *InviteMemberReport) AddUpgrade(gdb *gorm.DB, beforeMemberLevel uint32, memberLevel int, autoFlag bool) error { dateString := utils.MonthDate() if memberLevel < 0 { return errors.New("member level err") } if gdb == nil { gdb = DB } if m.StoreId == 0 { return errors.New("store id is null") } if m.Uid == 0 { return errors.New("uid is null") } m.Date = dateString sql := "" if autoFlag { // 自动 switch memberLevel { case 4: // 白金:黄金->白金 sql = "UPDATE invite_member_report SET upgrade_gold_to_platinum_count=upgrade_gold_to_platinum_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.UpgradeGoldToPlatinumCount = 1 case 5: // 黑金 if beforeMemberLevel == 2 { // 黄金->黑金 sql = "UPDATE invite_member_report SET upgrade_gold_to_black_count=upgrade_gold_to_black_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.UpgradeGoldToBlackCount = 1 } else { // 白金->黑金 sql = "UPDATE invite_member_report SET upgrade_platinum_to_black_count=upgrade_platinum_to_black_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.UpgradePlatinumToBlackCount = 1 } } } else { // 干预 switch memberLevel { case 4: // 白金:黄金->白金 sql = "UPDATE invite_member_report SET invite_upgrade_gold_to_platinum_count=invite_upgrade_gold_to_platinum_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.InviteUpgradeGoldToPlatinumCount = 1 case 5: // 黑金 if beforeMemberLevel == 2 { // 黄金->黑金 sql = "UPDATE invite_member_report SET invite_upgrade_gold_to_black_count=invite_upgrade_gold_to_black_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.InviteUpgradeGoldToBlackCount = 1 } else { // 白金->黑金 sql = "UPDATE invite_member_report SET invite_upgrade_platinum_to_black_count=invite_upgrade_platinum_to_black_count+1 " + fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d", dateString, m.CooperativeBusinessId, m.Uid) m.InviteUpgradePlatinumToBlackCount = 1 } } } fmt.Println("InviteMemberReport AddUpgrade 邀请会员升级sql:", sql) exist, err := QueryRecordExist(fmt.Sprintf( "SELECT * FROM invite_member_report WHERE cooperative_business_id=%d AND date='%s' AND uid=%d", m.CooperativeBusinessId, dateString, m.Uid)) if err != nil { logger.Error("cooperative member promotion record exist err:", err) return err } if exist { err = gdb.Exec(sql).Error if err != nil { logger.Error("update cooperative member promotion err:", err) return err } } else { err = gdb.Create(m).Error if err != nil { logger.Error("create cooperative member promotion err:", err) return err } } return nil }