package models import ( "fmt" "github.com/codinl/go-logger" orm "go-admin/common/global" "gorm.io/gorm" "regexp" "strings" "time" ) //go:generate goqueryset -in cooperative_business.go // gen:qs type CooperativeBusiness struct { Model Name string `json:"name" binding:"required"` Avatar string `json:"avatar" binding:"required"` Address string `json:"address" binding:"required"` Tel string `json:"tel" binding:"required"` AddTime time.Time `json:"add_time"` // 加入时间 CooperativeMemberDeduct *CooperativeMemberDeduct `json:"cooperative_member_deduct" gorm:"-"` CooperativeAssistantMemberDeduct *CooperativeAssistantMemberDeduct `json:"cooperative_assistant_member_deduct" gorm:"-"` //Identification string `json:"identification"` // 标识 // cooperative_business } /* 门店 游戏 卡 库存 用户 绑定门店 店员 借卡 订单 */ type CooperativeMemberDeduct struct { Model CooperativeBusinessId uint32 `json:"cooperative_business_id"` GoldDeduct uint32 `json:"gold_deduct" binding:"required"` // 黄金会员提成 PlatinumDeduct uint32 `json:"platinum_deduct" binding:"required"` // 白金会员提成 BlackGoldDeduct uint32 `json:"black_gold_deduct" binding:"required"` // 黑金金会员提成 RenewalGoldDeduct uint32 `json:"renewal_gold_deduct" binding:"required"` // 续费黄金会员提成 RenewalPlatinumDeduct uint32 `json:"renewal_platinum_deduct" binding:"required"` // 续费白金会员提成 RenewalBlackGoldDeduct uint32 `json:"renewal_black_gold_deduct" binding:"required"` // 续费黑金金会员提成 // cooperative_member_deduct } type CooperativeAssistantMemberDeduct struct { Model CooperativeBusinessId uint32 `json:"cooperative_business_id" ` StoreId uint32 `json:"store_id" ` // 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 } func (m *CooperativeBusiness) SetMemberDeductConfig() { var deductConfig CooperativeMemberDeduct err := orm.Eloquent.Table("cooperative_member_deduct").Where("cooperative_business_id=?", m.ID). Order("id DESC").Limit(1).Find(&deductConfig).Error if err != nil && err != RecordNotFound { logger.Error("cooperative err:", err) return } m.CooperativeMemberDeduct = &deductConfig } func (m *CooperativeBusiness) SetAssistantMemberDeductConfig(storeId uint32) { var assistantDeductConfig CooperativeAssistantMemberDeduct err := orm.Eloquent.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 } const ( PromotionStateUnSettlement = "un_settlement" // 待发起结算 PromotionStateFinancePay = "finance_pay" // 待财务打款 PromotionStateSettled = "settled" // 已解散 ) // 合作商推广会员 type CooperativeMemberPromotion struct { Model CooperativeBusinessId uint32 `json:"cooperative_business_id" gorm:"index"` CooperativeName string `json:"cooperative_name"` // 合作商名称 GoldCount uint32 `json:"gold_count"` // 黄金会员数量 PlatinumCount uint32 `json:"platinum_count"` // 白金会员数量 BlackGoldCount uint32 `json:"black_gold_count"` // 黑金会员数量 Date string `json:"date" gorm:"index"` // State string `json:"state"` // 待发起结算 待财务打款 已结算 RenewalGoldCount uint32 `json:"renewal_gold_count"` // 续费黄金会员数量 RenewalPlatinumCount uint32 `json:"renewal_platinum_count"` // 续费白金会员数量 RenewalBlackGoldCount uint32 `json:"renewal_black_gold_count"` // 续费黑金会员数量 GoldDeduct uint32 `json:"gold_deduct" gorm:"-"` // 黄金会员提成 PlatinumDeduct uint32 `json:"platinum_deduct" gorm:"-"` // 白金会员提成 BlackGoldDeduct uint32 `json:"black_gold_deduct" gorm:"-"` // 黑金金会员提成 RenewalGoldDeduct uint32 `json:"renewal_gold_deduct" gorm:"-"` // 续费黄金会员提成 RenewalPlatinumDeduct uint32 `json:"renewal_platinum_deduct" gorm:"-"` // 续费白金会员提成 RenewalBlackGoldDeduct uint32 `json:"renewal_black_gold_deduct" gorm:"-"` // 续费黑金金会员提成 DeductAmount uint32 `json:"deduct_amount" gorm:"-"` // 结算净额 // cooperative_member_promotion } // 合作商推广会员门店 饼图 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"` // 黄金会员数量 PlatinumCount uint32 `json:"platinum_count"` // 白金会员数量 BlackGoldCount uint32 `json:"black_gold_count"` // 黑金会员数量 Date string `json:"date" gorm:"index"` // RenewalGoldCount uint32 `json:"renewal_gold_count"` // 续费黄金会员数量 RenewalPlatinumCount uint32 `json:"renewal_platinum_count"` // 续费白金会员数量 RenewalBlackGoldCount uint32 `json:"renewal_black_gold_count"` // 续费黑金会员数量 Store *Store `json:"store" gorm:"-"` // cooperative_member_promotion_store } // 合作商推广会员每天 type CooperativeMemberPromotionDay struct { Model CooperativeBusinessId uint32 `json:"cooperative_business_id" gorm:"index"` CooperativeName string `json:"cooperative_name"` // 合作商名称 GoldCount uint32 `json:"gold_count"` // 黄金会员数量 PlatinumCount uint32 `json:"platinum_count"` // 白金会员数量 BlackGoldCount uint32 `json:"black_gold_count"` // 黑金会员数量 DayTime string `json:"day_time" gorm:"index"` // RenewalGoldCount uint32 `json:"renewal_gold_count"` // 续费黄金会员数量 RenewalPlatinumCount uint32 `json:"renewal_platinum_count"` // 续费白金会员数量 RenewalBlackGoldCount uint32 `json:"renewal_black_gold_count"` // 续费黑金会员数量 // cooperative_member_promotion_day } // 合作商推广会员门店每天 柱状图 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"` // 黄金会员数量 PlatinumCount uint32 `json:"platinum_count"` // 白金会员数量 BlackGoldCount uint32 `json:"black_gold_count"` // 黑金会员数量 DayTime string `json:"day_time" gorm:"index"` // RenewalGoldCount uint32 `json:"renewal_gold_count"` // 续费黄金会员数量 RenewalPlatinumCount uint32 `json:"renewal_platinum_count"` // 续费白金会员数量 RenewalBlackGoldCount uint32 `json:"renewal_black_gold_count"` // 续费黑金会员数量 Store *Store `json:"store" gorm:"-"` // cooperative_member_promotion_store_day } 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"` // 黄金会员数量 PlatinumCount uint32 `json:"platinum_count"` // 白金会员数量 BlackGoldCount uint32 `json:"black_gold_count"` // 黑金会员数量 GoldDeduct uint32 `json:"gold_deduct"` // 黄金会员提成配置 PlatinumDeduct uint32 `json:"platinum_deduct"` // 白金会员提成配置 BlackGoldDeduct uint32 `json:"black_gold_deduct"` // 黑金会员提成配置 RenewalGoldCount uint32 `json:"renewal_gold_count"` // 续费黄金会员数量 RenewalPlatinumCount uint32 `json:"renewal_platinum_count"` // 续费白金会员数量 RenewalBlackGoldCount uint32 `json:"renewal_black_gold_count"` // 续费黑金会员数量 RenewalGoldDeduct uint32 `json:"renewal_gold_deduct"` // 续费黄金会员提成 RenewalPlatinumDeduct uint32 `json:"renewal_platinum_deduct"` // 续费白金会员提成 RenewalBlackGoldDeduct uint32 `json:"renewal_black_gold_deduct"` // 续费黑金金会员提成 // cooperative_deduct_settle } type CooperativeBusinessListReq struct { StartTime time.Time `json:"start_time"` // 开始时间 EndTime time.Time `json:"end_time"` // 结束时间 Page int `json:"pageIndex"` PageSize int `json:"pageSize"` } func (m *CooperativeBusinessListReq) List() ([]CooperativeBusiness, int64, error) { var cooperatives []CooperativeBusiness qs := orm.Eloquent.Table("cooperative_business") if !m.StartTime.IsZero() { qs = qs.Where("created_at>?", m.StartTime) } if !m.EndTime.IsZero() { qs = qs.Where("created_at?", m.StartTime) } if !m.EndTime.IsZero() { qs = qs.Where("created_at?", m.StartTime) } if !m.EndTime.IsZero() { qs = qs.Where("created_at 4 { result = string(nameRune[:2]) + "***" + string(nameRune[lens-2:lens]) } } return } } func Substr2(str string, start int, end int) string { rs := []rune(str) return string(rs[start:end]) } func GetCooperativeMemberDeductMap(ids []uint32) (map[uint32]*CooperativeMemberDeduct, error) { deductMap := make(map[uint32]*CooperativeMemberDeduct, 0) if len(ids) == 0 { return deductMap, nil } var deducts []CooperativeMemberDeduct err := orm.Eloquent.Table("cooperative_member_deduct").Where("cooperative_business_id in (?)", ids).Find(&deducts).Error if err != nil { logger.Error("deducts err:", err) return deductMap, err } for i, _ := range deducts { deductMap[deducts[i].CooperativeBusinessId] = &deducts[i] } return deductMap, nil } func GetCooperativeAssistantMemberDeductMap(ids []uint32) (map[uint32]*CooperativeAssistantMemberDeduct, error) { deductMap := make(map[uint32]*CooperativeAssistantMemberDeduct, 0) if len(ids) == 0 { return deductMap, nil } var deducts []CooperativeAssistantMemberDeduct err := orm.Eloquent.Table("cooperative_assistant_member_deduct").Where("store_id in (?)", ids).Find(&deducts).Error if err != nil { logger.Error("deducts err:", err) return deductMap, err } for i, _ := range deducts { deductMap[deducts[i].StoreId] = &deducts[i] } return deductMap, nil } type CooperativeMemberPromotionStatistic struct { Model CooperativeBusinessId uint32 `json:"cooperative_business_id" gorm:"index"` CooperativeName string `json:"cooperative_name"` // 合作商名称 GoldCount uint32 `json:"gold_count"` // 黄金会员数量 PlatinumCount uint32 `json:"platinum_count"` // 白金会员数量 BlackGoldCount uint32 `json:"black_gold_count"` // 黑金会员数量 DayTime string `json:"day_time" gorm:"index"` // RenewalGoldCount uint32 `json:"renewal_gold_count"` // 续费黄金会员数量 RenewalPlatinumCount uint32 `json:"renewal_platinum_count"` // 续费白金会员数量 RenewalBlackGoldCount uint32 `json:"renewal_black_gold_count"` // 续费黑金会员数量 Date string `json:"date" gorm:"index"` // StoreId uint32 `json:"store_id" gorm:"index"` // 门店id Store *Store `json:"store" gorm:"-"` // cooperative_member_promotion_day } type CooperativeMemberPromotionStatisticReq struct { Type uint32 `json:"type"` // 1-日店员推广 2-日门店店员推广 CooperativeBusinessId uint32 `json:"cooperative_business_id"` StartDate string `json:"start_date"` EndDate string `json:"end_date"` StoreId uint32 `json:"store_id"` Page int `json:"pageIndex"` PageSize int `json:"pageSize"` } func (m *CooperativeMemberPromotionStatisticReq) List() ([]CooperativeMemberPromotionStatistic, int64, error) { list := make([]CooperativeMemberPromotionStatistic, 0) page := m.Page - 1 if page < 0 { page = 0 } if m.PageSize == 0 { m.PageSize = 10 } startTime := time.Time{} endTime := time.Time{} if m.StartDate != "" { format := "" if m.Type == 1 { //format = DateFormat format = time.RFC3339 } else { format = MDateFormat } startTime, _ = time.Parse(format, m.StartDate) } if m.EndDate != "" { format := "" if m.Type == 1 { //format = DateFormat format = time.RFC3339 } else { format = MDateFormat } endTime, _ = time.Parse(format, m.EndDate) } var count int64 var err error qs := new(gorm.DB) switch m.Type { case 1: if m.StoreId != 0 { var memberDayStorePromotions []CooperativeMemberPromotionStoreDay qs = orm.Eloquent.Table("cooperative_member_promotion_store_day").Where("store_id=?", m.StoreId). Where("cooperative_business_id=?", m.CooperativeBusinessId) if !startTime.IsZero() { qs = qs.Where("created_at>?", startTime) } if !endTime.IsZero() { qs = qs.Where("created_at?", startTime) } if !endTime.IsZero() { qs = qs.Where("created_at?", startTime) } if !endTime.IsZero() { qs = qs.Where("created_at?", startTime) } if !endTime.IsZero() { qs = qs.Where("created_at