2022-04-27 02:25:55 +00:00
|
|
|
package model
|
|
|
|
|
2022-05-10 07:17:34 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"github.com/codinl/go-logger"
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
"mh-server/lib/utils"
|
|
|
|
"time"
|
|
|
|
)
|
2022-04-27 02:25:55 +00:00
|
|
|
|
|
|
|
// gen:qs
|
2024-01-31 10:02:20 +00:00
|
|
|
//
|
|
|
|
//go:generate goqueryset -in cooperative_business.go
|
2022-04-27 02:25:55 +00:00
|
|
|
type CooperativeBusiness struct {
|
|
|
|
Model
|
2022-05-10 07:17:34 +00:00
|
|
|
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"`
|
2022-04-27 02:25:55 +00:00
|
|
|
|
2022-05-10 07:17:34 +00:00
|
|
|
CooperativeMemberDeduct *CooperativeMemberDeduct `json:"cooperative_member_deduct" gorm:"-"`
|
|
|
|
CooperativeAssistantMemberDeduct *CooperativeAssistantMemberDeduct `json:"cooperative_assistant_member_deduct" gorm:"-"`
|
|
|
|
//Identification string `json:"identification"` // 标识
|
|
|
|
// cooperative_business
|
2022-04-27 02:25:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
门店
|
|
|
|
游戏
|
|
|
|
卡
|
|
|
|
库存
|
2022-05-10 07:17:34 +00:00
|
|
|
用户 绑定门店 店员
|
2022-04-27 02:25:55 +00:00
|
|
|
|
2022-05-10 07:17:34 +00:00
|
|
|
借卡 订单
|
2022-04-27 02:25:55 +00:00
|
|
|
|
|
|
|
*/
|
2022-05-10 07:17:34 +00:00
|
|
|
|
|
|
|
// gen:qs
|
|
|
|
type CooperativeMemberDeduct struct {
|
|
|
|
Model
|
2022-07-25 04:02:53 +00:00
|
|
|
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"` // 续费黑金金会员提成
|
2022-05-10 07:17:34 +00:00
|
|
|
// cooperative_member_deduct
|
|
|
|
}
|
|
|
|
|
|
|
|
// gen:qs
|
|
|
|
type CooperativeAssistantMemberDeduct struct {
|
|
|
|
Model
|
2022-07-25 04:02:53 +00:00
|
|
|
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"` // 续费黑金金会员提成
|
2022-05-10 07:17:34 +00:00
|
|
|
// 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"`
|
2022-07-29 02:02:33 +00:00
|
|
|
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"` // 待发起结算 待财务打款 已结算
|
2022-07-25 04:02:53 +00:00
|
|
|
|
2024-01-31 10:02:20 +00:00
|
|
|
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"` // 升级:白金->黑金数量
|
2022-07-25 04:02:53 +00:00
|
|
|
|
2022-05-10 07:17:34 +00:00
|
|
|
// cooperative_member_promotion
|
|
|
|
}
|
|
|
|
|
|
|
|
// 合作商推广会员门店 饼图
|
|
|
|
// gen:qs
|
|
|
|
type CooperativeMemberPromotionStore struct {
|
|
|
|
Model
|
2024-01-31 10:02:20 +00:00
|
|
|
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"` // 升级:白金->黑金数量
|
2022-05-10 07:17:34 +00:00
|
|
|
// cooperative_member_promotion_store
|
|
|
|
}
|
|
|
|
|
|
|
|
// 合作商推广会员每天
|
|
|
|
// gen:qs
|
|
|
|
type CooperativeMemberPromotionDay struct {
|
|
|
|
Model
|
2024-01-31 10:02:20 +00:00
|
|
|
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"` // 升级:白金->黑金数量
|
2022-05-10 07:17:34 +00:00
|
|
|
// cooperative_member_promotion_day
|
|
|
|
}
|
|
|
|
|
|
|
|
// 合作商推广会员门店每天 柱状图
|
|
|
|
// gen:qs
|
|
|
|
type CooperativeMemberPromotionStoreDay struct {
|
|
|
|
Model
|
2024-01-31 10:02:20 +00:00
|
|
|
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"` // 升级:白金->黑金数量
|
2022-05-12 05:42:45 +00:00
|
|
|
// cooperative_member_promotion_store_day
|
2022-05-10 07:17:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// gen:qs
|
|
|
|
type CooperativeDeductSettle struct {
|
|
|
|
Model
|
|
|
|
CooperativeMemberPromotionId uint32 `json:"cooperative_member_promotion_id" gorm:"index"`
|
|
|
|
CooperativeBusinessId uint32 `json:"cooperative_business_id" gorm:"index"`
|
2022-07-29 02:02:33 +00:00
|
|
|
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"` // 黑金会员数量
|
2022-07-25 04:02:53 +00:00
|
|
|
|
|
|
|
GoldDeduct uint32 `json:"gold_deduct"` // 黄金会员提成配置
|
|
|
|
PlatinumDeduct uint32 `json:"platinum_deduct"` // 白金会员提成配置
|
|
|
|
BlackGoldDeduct uint32 `json:"black_gold_deduct"` // 黑金会员提成配置
|
|
|
|
|
2022-07-29 02:02:33 +00:00
|
|
|
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"` // 续费黑金会员数量
|
2022-07-25 04:02:53 +00:00
|
|
|
|
|
|
|
RenewalGoldDeduct uint32 `json:"renewal_gold_deduct"` // 续费黄金会员提成
|
|
|
|
RenewalPlatinumDeduct uint32 `json:"renewal_platinum_deduct"` // 续费白金会员提成
|
|
|
|
RenewalBlackGoldDeduct uint32 `json:"renewal_black_gold_deduct"` // 续费黑金金会员提成
|
2022-05-10 07:17:34 +00:00
|
|
|
}
|
|
|
|
|
2024-02-01 10:24:57 +00:00
|
|
|
func AddCooperativeMemberPromotion(cooperativeId, storeId, assistantUid uint32, memberLevel, memberGenre int) {
|
2022-05-10 07:17:34 +00:00
|
|
|
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
|
|
|
|
}
|
2024-05-31 09:53:15 +00:00
|
|
|
fmt.Println("cooperativeId:", cooperativeId)
|
|
|
|
fmt.Println("storeId:", storeId)
|
|
|
|
fmt.Println("assistantUid:", assistantUid)
|
|
|
|
fmt.Println("memberLevel:", memberLevel)
|
2022-05-10 07:17:34 +00:00
|
|
|
|
|
|
|
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()
|
2022-05-12 05:42:45 +00:00
|
|
|
err = promotion.AddPromotion(begin, memberLevel)
|
2022-05-10 07:17:34 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-05-31 09:53:15 +00:00
|
|
|
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
|
|
|
|
}
|
2022-05-10 07:17:34 +00:00
|
|
|
}
|
|
|
|
|
2024-05-31 09:53:15 +00:00
|
|
|
if assistantUid != 0 {
|
|
|
|
err = inviteReport.AddPromotion(begin, memberLevel, memberGenre)
|
|
|
|
if err != nil {
|
|
|
|
begin.Rollback()
|
|
|
|
logger.Error("promotion add promotion err:", err)
|
|
|
|
return
|
|
|
|
}
|
2022-05-10 07:17:34 +00:00
|
|
|
}
|
2024-05-31 09:53:15 +00:00
|
|
|
|
2022-05-10 07:17:34 +00:00
|
|
|
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 " +
|
2022-05-12 05:42:45 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d", dateString, m.CooperativeBusinessId)
|
2022-05-10 07:17:34 +00:00
|
|
|
m.GoldCount = 1
|
|
|
|
case 4:
|
|
|
|
sql = "UPDATE cooperative_member_promotion SET platinum_count=platinum_count+1 " +
|
2022-05-12 05:42:45 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d", dateString, m.CooperativeBusinessId)
|
2022-05-10 07:17:34 +00:00
|
|
|
m.PlatinumCount = 1
|
|
|
|
case 5:
|
|
|
|
sql = "UPDATE cooperative_member_promotion SET black_gold_count=black_gold_count+1 " +
|
2022-05-12 05:42:45 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d", dateString, m.CooperativeBusinessId)
|
2022-05-10 07:17:34 +00:00
|
|
|
m.BlackGoldCount = 1
|
|
|
|
}
|
|
|
|
fmt.Println("邀请会员sql:", sql)
|
|
|
|
exist, err := QueryRecordExist(fmt.Sprintf(
|
2022-05-13 09:35:10 +00:00
|
|
|
"SELECT * FROM cooperative_member_promotion WHERE cooperative_business_id=%d AND date='%s' ",
|
2022-05-10 07:17:34 +00:00
|
|
|
m.CooperativeBusinessId, dateString))
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("cooperative member promotion record exist err:", err)
|
|
|
|
return err
|
|
|
|
}
|
2022-05-12 05:42:45 +00:00
|
|
|
//fmt.Println("是否存在数据:", fmt.Sprintf(
|
|
|
|
// "SELECT * FROM cooperative_member_promotion WHERE cooperative_business_id=%d AND date='%s'",
|
|
|
|
// m.CooperativeBusinessId, dateString))
|
2022-05-10 07:17:34 +00:00
|
|
|
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 " +
|
2022-05-12 05:42:45 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND store_id=%d",
|
2022-05-10 07:17:34 +00:00
|
|
|
dateString, m.CooperativeBusinessId, storeId)
|
|
|
|
m.GoldCount = 1
|
|
|
|
case 4:
|
|
|
|
sql = "UPDATE cooperative_member_promotion_store SET platinum_count=platinum_count+1 " +
|
2022-05-12 05:42:45 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND store_id=%d",
|
2022-05-10 07:17:34 +00:00
|
|
|
dateString, m.CooperativeBusinessId, storeId)
|
|
|
|
m.PlatinumCount = 1
|
|
|
|
case 5:
|
|
|
|
sql = "UPDATE cooperative_member_promotion_store SET black_gold_count=black_gold_count+1 " +
|
2022-05-12 05:42:45 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND store_id=%d",
|
2022-05-10 07:17:34 +00:00
|
|
|
dateString, m.CooperativeBusinessId, storeId)
|
|
|
|
m.BlackGoldCount = 1
|
|
|
|
}
|
|
|
|
exist, err := QueryRecordExist(fmt.Sprintf(
|
2022-05-12 05:42:45 +00:00
|
|
|
"SELECT * FROM cooperative_member_promotion_store WHERE cooperative_business_id=%d AND date='%s' AND store_id=%d",
|
2022-05-10 07:17:34 +00:00
|
|
|
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 " +
|
2022-05-12 05:42:45 +00:00
|
|
|
fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d", dayString, m.CooperativeBusinessId)
|
2022-05-10 07:17:34 +00:00
|
|
|
m.GoldCount = 1
|
|
|
|
case 4:
|
|
|
|
sql = "UPDATE cooperative_member_promotion_day SET platinum_count=platinum_count+1 " +
|
2022-05-12 05:42:45 +00:00
|
|
|
fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d", dayString, m.CooperativeBusinessId)
|
2022-05-10 07:17:34 +00:00
|
|
|
m.PlatinumCount = 1
|
|
|
|
case 5:
|
|
|
|
sql = "UPDATE cooperative_member_promotion_day SET black_gold_count=black_gold_count+1 " +
|
2022-05-12 05:42:45 +00:00
|
|
|
fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d", dayString, m.CooperativeBusinessId)
|
2022-05-10 07:17:34 +00:00
|
|
|
m.BlackGoldCount = 1
|
|
|
|
}
|
|
|
|
exist, err := QueryRecordExist(fmt.Sprintf(
|
2022-05-12 05:42:45 +00:00
|
|
|
"SELECT * FROM cooperative_member_promotion_day WHERE cooperative_business_id=%d AND day_time='%s'",
|
2022-05-10 07:17:34 +00:00
|
|
|
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 " +
|
2022-05-12 05:42:45 +00:00
|
|
|
fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d AND store_id=%d",
|
2022-05-10 07:17:34 +00:00
|
|
|
dateString, m.CooperativeBusinessId, storeId)
|
|
|
|
m.GoldCount = 1
|
|
|
|
case 4:
|
|
|
|
sql = "UPDATE cooperative_member_promotion_store_day SET platinum_count=platinum_count+1 " +
|
2022-05-12 05:42:45 +00:00
|
|
|
fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d AND store_id=%d",
|
2022-05-10 07:17:34 +00:00
|
|
|
dateString, m.CooperativeBusinessId, storeId)
|
|
|
|
m.PlatinumCount = 1
|
|
|
|
case 5:
|
|
|
|
sql = "UPDATE cooperative_member_promotion_store_day SET black_gold_count=black_gold_count+1 " +
|
2022-05-12 05:42:45 +00:00
|
|
|
fmt.Sprintf("WHERE day_time='%s' AND cooperative_business_id=%d AND store_id=%d",
|
2022-05-10 07:17:34 +00:00
|
|
|
dateString, m.CooperativeBusinessId, storeId)
|
|
|
|
m.BlackGoldCount = 1
|
|
|
|
}
|
|
|
|
exist, err := QueryRecordExist("SELECT * FROM cooperative_member_promotion_store_day " +
|
2022-05-12 05:42:45 +00:00
|
|
|
fmt.Sprintf("WHERE cooperative_business_id=%d AND day_time='%s' AND store_id=%d",
|
2022-05-10 07:17:34 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-02-01 10:24:57 +00:00
|
|
|
func (m *InviteMemberReport) AddPromotion(gdb *gorm.DB, memberLevel, memberGenre int) error {
|
2022-05-10 07:17:34 +00:00
|
|
|
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")
|
|
|
|
}
|
2022-05-13 09:35:10 +00:00
|
|
|
m.Date = dateString
|
2022-05-10 07:17:34 +00:00
|
|
|
sql := ""
|
|
|
|
switch memberLevel {
|
|
|
|
case 2:
|
2024-02-01 10:24:57 +00:00
|
|
|
switch memberGenre {
|
|
|
|
case 200: // 年度黄金
|
|
|
|
sql = "UPDATE invite_member_report SET gold_count=gold_count+1 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2024-02-01 10:24:57 +00:00
|
|
|
m.GoldCount = 1
|
|
|
|
case 201: // 季度黄金
|
|
|
|
sql = "UPDATE invite_member_report SET gold_count_quarter=gold_count_quarter+1 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2024-02-01 10:24:57 +00:00
|
|
|
m.GoldCountQuarter = 1
|
|
|
|
case 202: // 半年黄金
|
|
|
|
sql = "UPDATE invite_member_report SET gold_count_half=gold_count_half+1 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2024-02-01 10:24:57 +00:00
|
|
|
m.GoldCountHalf = 1
|
|
|
|
}
|
2022-05-10 07:17:34 +00:00
|
|
|
case 4:
|
|
|
|
sql = "UPDATE invite_member_report SET platinum_count=platinum_count+1 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2022-05-10 07:17:34 +00:00
|
|
|
m.PlatinumCount = 1
|
|
|
|
case 5:
|
|
|
|
sql = "UPDATE invite_member_report SET black_gold_count=black_gold_count+1 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2022-05-10 07:17:34 +00:00
|
|
|
m.BlackGoldCount = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
exist, err := QueryRecordExist(fmt.Sprintf(
|
2024-05-27 11:37:57 +00:00
|
|
|
"SELECT * FROM invite_member_report WHERE cooperative_business_id=%d AND date='%s' AND uid=%d",
|
|
|
|
m.CooperativeBusinessId, dateString, m.Uid))
|
2022-05-10 07:17:34 +00:00
|
|
|
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
|
|
|
|
}
|
2022-07-25 04:02:53 +00:00
|
|
|
|
2024-05-27 11:37:57 +00:00
|
|
|
func AddCooperativeMemberRenewal(cooperativeId, storeId, assistantUid uint32, memberLevel, memberGenre int, autoRenewFlag bool) {
|
2022-07-25 04:02:53 +00:00
|
|
|
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
|
|
|
|
}
|
2024-05-31 09:53:15 +00:00
|
|
|
fmt.Println("cooperativeId:", cooperativeId)
|
|
|
|
fmt.Println("storeId:", storeId)
|
|
|
|
fmt.Println("assistantUid:", assistantUid)
|
|
|
|
fmt.Println("memberLevel:", memberLevel)
|
|
|
|
fmt.Println("autoRenewFlag:", autoRenewFlag)
|
2022-07-25 04:02:53 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-05-31 09:53:15 +00:00
|
|
|
if storeId != 0 {
|
|
|
|
err = promotionStore.AddRenewal(begin, memberLevel, storeId)
|
|
|
|
if err != nil {
|
|
|
|
begin.Rollback()
|
|
|
|
logger.Error("promotion add promotion err:", err)
|
|
|
|
return
|
|
|
|
}
|
2022-07-25 04:02:53 +00:00
|
|
|
|
2024-05-31 09:53:15 +00:00
|
|
|
err = promotionStoreDay.AddRenewal(begin, memberLevel, storeId)
|
|
|
|
if err != nil {
|
|
|
|
begin.Rollback()
|
|
|
|
logger.Error("promotion add promotion err:", err)
|
|
|
|
return
|
|
|
|
}
|
2024-05-27 11:37:57 +00:00
|
|
|
}
|
2024-05-31 09:53:15 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2022-07-25 04:02:53 +00:00
|
|
|
}
|
2024-05-31 09:53:15 +00:00
|
|
|
|
2022-07-25 04:02:53 +00:00
|
|
|
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 {
|
2022-07-29 02:02:33 +00:00
|
|
|
|
2022-07-25 04:02:53 +00:00
|
|
|
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 {
|
2022-07-29 02:02:33 +00:00
|
|
|
|
2022-07-25 04:02:53 +00:00
|
|
|
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 {
|
2022-07-29 02:02:33 +00:00
|
|
|
|
2022-07-25 04:02:53 +00:00
|
|
|
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 {
|
2022-07-29 02:02:33 +00:00
|
|
|
|
2022-07-25 04:02:53 +00:00
|
|
|
err = gdb.Create(m).Error
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("create cooperative member promotion store day err:", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-05-27 11:37:57 +00:00
|
|
|
// AddRenewalAuto 用户自动续费后更新记录
|
|
|
|
func (m *InviteMemberReport) AddRenewalAuto(gdb *gorm.DB, memberLevel, memberGenre int) error {
|
2022-07-25 04:02:53 +00:00
|
|
|
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
|
2022-07-29 02:02:33 +00:00
|
|
|
|
2022-07-25 04:02:53 +00:00
|
|
|
sql := ""
|
|
|
|
switch memberLevel {
|
|
|
|
case 2:
|
2024-02-01 10:24:57 +00:00
|
|
|
switch memberGenre {
|
|
|
|
case 200: // 年度黄金
|
|
|
|
sql = "UPDATE invite_member_report SET renewal_gold_count=renewal_gold_count+1 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2024-02-01 10:24:57 +00:00
|
|
|
m.RenewalGoldCount = 1
|
|
|
|
case 201: // 季度黄金
|
|
|
|
sql = "UPDATE invite_member_report SET renewal_gold_count_quarter=renewal_gold_count_quarter+1 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2024-02-01 10:24:57 +00:00
|
|
|
m.RenewalGoldCountQuarter = 1
|
|
|
|
case 202: // 半年黄金
|
|
|
|
sql = "UPDATE invite_member_report SET renewal_gold_count_half=renewal_gold_count_half+1 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2024-02-01 10:24:57 +00:00
|
|
|
m.RenewalGoldCountHalf = 1
|
|
|
|
}
|
|
|
|
|
2024-05-27 11:37:57 +00:00
|
|
|
case 4: // 白金
|
2022-07-25 04:02:53 +00:00
|
|
|
sql = "UPDATE invite_member_report SET renewal_platinum_count=renewal_platinum_count+1 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2022-07-25 04:02:53 +00:00
|
|
|
m.RenewalPlatinumCount = 1
|
2024-05-27 11:37:57 +00:00
|
|
|
case 5: // 黑金
|
2022-07-25 04:02:53 +00:00
|
|
|
sql = "UPDATE invite_member_report SET renewal_black_gold_count=renewal_black_gold_count+1 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2022-07-25 04:02:53 +00:00
|
|
|
m.RenewalBlackGoldCount = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
exist, err := QueryRecordExist(fmt.Sprintf(
|
2024-05-27 11:37:57 +00:00
|
|
|
"SELECT * FROM invite_member_report WHERE cooperative_business_id=%d AND date='%s' AND uid=%d",
|
|
|
|
m.CooperativeBusinessId, dateString, m.Uid))
|
2022-07-25 04:02:53 +00:00
|
|
|
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 {
|
2022-07-29 02:02:33 +00:00
|
|
|
|
2022-07-25 04:02:53 +00:00
|
|
|
//m.State = PromotionStateUnSettlement
|
|
|
|
err = gdb.Create(m).Error
|
|
|
|
if err != nil {
|
|
|
|
logger.Error("create cooperative member promotion err:", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2024-01-31 10:02:20 +00:00
|
|
|
|
2024-05-27 11:37:57 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2024-01-31 10:02:20 +00:00
|
|
|
// 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
|
|
|
|
}
|
2024-05-31 09:53:15 +00:00
|
|
|
fmt.Println("cooperativeId:", cooperativeId)
|
|
|
|
fmt.Println("storeId:", storeId)
|
|
|
|
fmt.Println("assistantUid:", assistantUid)
|
|
|
|
fmt.Println("memberLevel:", memberLevel)
|
|
|
|
fmt.Println("autoFlag:", autoFlag)
|
2024-01-31 10:02:20 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-05-31 09:53:15 +00:00
|
|
|
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
|
|
|
|
}
|
2024-01-31 10:02:20 +00:00
|
|
|
}
|
|
|
|
|
2024-05-31 09:53:15 +00:00
|
|
|
if assistantUid != 0 {
|
|
|
|
err = inviteReport.AddUpgrade(begin, beforeMemberLevel, memberLevel, autoFlag)
|
|
|
|
if err != nil {
|
|
|
|
begin.Rollback()
|
|
|
|
logger.Error("promotion add promotion err:", err)
|
|
|
|
return
|
|
|
|
}
|
2024-01-31 10:02:20 +00:00
|
|
|
}
|
2024-05-31 09:53:15 +00:00
|
|
|
|
2024-01-31 10:02:20 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2024-05-31 09:53:15 +00:00
|
|
|
fmt.Println("CooperativeMemberPromotion AddUpgrade 邀请会员sql:", sql)
|
2024-01-31 10:02:20 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2024-05-31 09:53:15 +00:00
|
|
|
fmt.Println("CooperativeMemberPromotionDay AddUpgrade 邀请会员sql:", sql)
|
2024-01-31 10:02:20 +00:00
|
|
|
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 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2024-01-31 10:02:20 +00:00
|
|
|
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 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2024-01-31 10:02:20 +00:00
|
|
|
m.UpgradeGoldToBlackCount = 1
|
|
|
|
} else { // 白金->黑金
|
|
|
|
sql = "UPDATE invite_member_report SET upgrade_platinum_to_black_count=upgrade_platinum_to_black_count+1 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2024-01-31 10:02:20 +00:00
|
|
|
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 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2024-01-31 10:02:20 +00:00
|
|
|
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 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2024-01-31 10:02:20 +00:00
|
|
|
m.InviteUpgradeGoldToBlackCount = 1
|
|
|
|
} else { // 白金->黑金
|
|
|
|
sql = "UPDATE invite_member_report SET invite_upgrade_platinum_to_black_count=invite_upgrade_platinum_to_black_count+1 " +
|
2024-05-27 11:37:57 +00:00
|
|
|
fmt.Sprintf("WHERE date='%s' AND cooperative_business_id=%d AND uid=%d",
|
|
|
|
dateString, m.CooperativeBusinessId, m.Uid)
|
2024-01-31 10:02:20 +00:00
|
|
|
m.InviteUpgradePlatinumToBlackCount = 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-31 09:53:15 +00:00
|
|
|
fmt.Println("InviteMemberReport AddUpgrade 邀请会员升级sql:", sql)
|
2024-01-31 10:02:20 +00:00
|
|
|
exist, err := QueryRecordExist(fmt.Sprintf(
|
2024-05-27 11:37:57 +00:00
|
|
|
"SELECT * FROM invite_member_report WHERE cooperative_business_id=%d AND date='%s' AND uid=%d",
|
|
|
|
m.CooperativeBusinessId, dateString, m.Uid))
|
2024-01-31 10:02:20 +00:00
|
|
|
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
|
|
|
|
}
|