949 lines
35 KiB
Go
949 lines
35 KiB
Go
package models
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/codinl/go-logger"
|
|
orm "go-admin/common/global"
|
|
"gorm.io/gorm"
|
|
"regexp"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// gen:qs
|
|
//
|
|
//go:generate goqueryset -in cooperative_business.go
|
|
type CooperativeBusiness struct {
|
|
Model
|
|
|
|
Name string `json:"name" binding:"required"` // 供应商名称
|
|
Avatar string `json:"avatar" binding:"required"` // logo
|
|
Address string `json:"address"` // 地址
|
|
Tel string `json:"tel" binding:"required"` // 电话
|
|
AddTime time.Time `json:"add_time"` // 加入时间
|
|
Username string `json:"username" binding:"required"` // 用户名
|
|
Password string `json:"password" binding:"required"` // 密码
|
|
|
|
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:"-"` // 续费黑金金会员提成
|
|
|
|
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"` // 升级:白金->黑金数量
|
|
|
|
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"` // 续费黑金会员数量
|
|
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"` // 升级:白金->黑金数量
|
|
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"` // 续费黑金会员数量
|
|
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
|
|
}
|
|
|
|
// 合作商推广会员门店每天 柱状图
|
|
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"` // 续费黑金会员数量
|
|
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"` // 升级:白金->黑金数量
|
|
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"`
|
|
}
|
|
|
|
type CooperativeBusinessListResp struct {
|
|
Count int64 `json:"count"`
|
|
List []CooperativeBusiness `json:"list"`
|
|
PageIndex int `json:"pageIndex"`
|
|
TotalPage int `json:"total_page"`
|
|
}
|
|
|
|
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.EndTime)
|
|
}
|
|
page := m.Page - 1
|
|
if page < 0 {
|
|
page = 0
|
|
}
|
|
if m.PageSize == 0 {
|
|
m.PageSize = 10
|
|
}
|
|
var count int64
|
|
err := qs.Count(&count).Error
|
|
if err != nil {
|
|
logger.Error("count err:", err)
|
|
return cooperatives, 0, err
|
|
}
|
|
|
|
//totalPage :=int(count) /m.PageSize + 1
|
|
|
|
err = qs.Order("id DESC").Offset(page * m.PageSize).Limit(m.PageSize).Find(&cooperatives).Error
|
|
if err != nil && err != RecordNotFound {
|
|
logger.Error("count err:", err)
|
|
return cooperatives, count, err
|
|
}
|
|
cooperatives = CooperativeBusinessListSetCooperativeMemberDeduct(cooperatives)
|
|
|
|
return cooperatives, count, nil
|
|
}
|
|
|
|
func CooperativeBusinessListSetCooperativeMemberDeduct(list []CooperativeBusiness) []CooperativeBusiness {
|
|
ids := make([]uint32, 0, len(list))
|
|
for i, _ := range list {
|
|
ids = append(ids, list[i].ID)
|
|
}
|
|
deductMap, err := GetCooperativeMemberDeductMap(ids)
|
|
if err != nil {
|
|
logger.Error("err:", err)
|
|
return list
|
|
}
|
|
for i, _ := range list {
|
|
v, ok := deductMap[list[i].ID]
|
|
if ok {
|
|
list[i].CooperativeMemberDeduct = v
|
|
}
|
|
}
|
|
|
|
return list
|
|
}
|
|
|
|
func CooperativeMemberPromotionStoreListSetStore(list []CooperativeMemberPromotionStore) []CooperativeMemberPromotionStore {
|
|
ids := make([]uint32, 0, len(list))
|
|
for i, _ := range list {
|
|
ids = append(ids, list[i].StoreId)
|
|
}
|
|
if len(ids) == 0 {
|
|
return list
|
|
}
|
|
|
|
storeMap := GetStoreMapByIds(ids)
|
|
|
|
for i, _ := range list {
|
|
v, ok := storeMap[uint64(list[i].StoreId)]
|
|
if ok {
|
|
list[i].Store = v
|
|
}
|
|
}
|
|
|
|
return list
|
|
}
|
|
|
|
func CooperativeMemberPromotionStoreDayListSetStore(list []CooperativeMemberPromotionStoreDay) []CooperativeMemberPromotionStoreDay {
|
|
ids := make([]uint32, 0, len(list))
|
|
for i, _ := range list {
|
|
ids = append(ids, list[i].StoreId)
|
|
}
|
|
if len(ids) == 0 {
|
|
return list
|
|
}
|
|
|
|
storeMap := GetStoreMapByIds(ids)
|
|
|
|
for i, _ := range list {
|
|
v, ok := storeMap[uint64(list[i].StoreId)]
|
|
if ok {
|
|
list[i].Store = v
|
|
}
|
|
|
|
}
|
|
|
|
return list
|
|
}
|
|
|
|
type CooperativeMemberPromotionReq struct {
|
|
CooperativeBusinessId uint32 `json:"cooperative_business_id"`
|
|
Date string `json:"date"` //
|
|
Page int `json:"pageIndex"`
|
|
PageSize int `json:"pageSize"`
|
|
}
|
|
|
|
func (m *CooperativeMemberPromotionReq) List() ([]CooperativeMemberPromotion, int64, error) {
|
|
fmt.Println(" m.CooperativeBusinessId", m.CooperativeBusinessId)
|
|
fmt.Println(" m.Date", m.Date)
|
|
var memberPromotions []CooperativeMemberPromotion
|
|
qs := orm.Eloquent.Table("cooperative_member_promotion").Where("cooperative_business_id=?", m.CooperativeBusinessId)
|
|
if m.Date != "" {
|
|
qs = qs.Where("date=?", m.Date)
|
|
}
|
|
page := m.Page - 1
|
|
if page < 0 {
|
|
page = 0
|
|
}
|
|
if m.PageSize == 0 {
|
|
m.PageSize = 10
|
|
}
|
|
var count int64
|
|
err := qs.Count(&count).Error
|
|
if err != nil {
|
|
logger.Error("count err:", err)
|
|
return memberPromotions, 0, err
|
|
}
|
|
|
|
//totalPage :=int(count) /m.PageSize + 1
|
|
|
|
err = qs.Order("id DESC").Offset(page * m.PageSize).Limit(m.PageSize).Find(&memberPromotions).Error
|
|
if err != nil && err != RecordNotFound {
|
|
logger.Error("count err:", err)
|
|
return memberPromotions, count, err
|
|
}
|
|
|
|
return memberPromotions, count, nil
|
|
}
|
|
|
|
type CooperativeMemberPromotionStoreReq struct {
|
|
CooperativeBusinessId uint32 `json:"cooperative_business_id"`
|
|
//CooperativeMemberPromotionId uint32 `json:"cooperative_member_promotion_id"`
|
|
StoreId uint32 `json:"store_id"`
|
|
Date string `json:"date"`
|
|
Page int `json:"pageIndex"`
|
|
PageSize int `json:"pageSize"`
|
|
}
|
|
|
|
func (m *CooperativeMemberPromotionStoreReq) List() ([]CooperativeMemberPromotionStore, int64, error) {
|
|
var memberStorePromotions []CooperativeMemberPromotionStore
|
|
//var promotion CooperativeMemberPromotion
|
|
//err := orm.Eloquent.Table("cooperative_member_promotion").Where("id=?", m.CooperativeMemberPromotionId).Find(&promotion).Error
|
|
//if err != nil {
|
|
// logger.Error("cooperative member promotion err:", err)
|
|
// return memberStorePromotions, 0, err
|
|
//}
|
|
//qs := orm.Eloquent.Table("cooperative_member_promotion_store").Where("store_id=?", m.StoreId)
|
|
qs := orm.Eloquent.Table("cooperative_member_promotion_store").Where("cooperative_business_id=?", m.CooperativeBusinessId)
|
|
if m.StoreId != 0 {
|
|
qs = qs.Where("store_id=?", m.StoreId)
|
|
}
|
|
if m.Date != "" {
|
|
qs = qs.Where("date=?", m.Date)
|
|
}
|
|
page := m.Page - 1
|
|
if page < 0 {
|
|
page = 0
|
|
}
|
|
if m.PageSize == 0 {
|
|
m.PageSize = 10
|
|
}
|
|
var count int64
|
|
err := qs.Count(&count).Error
|
|
if err != nil {
|
|
logger.Error("count err:", err)
|
|
return memberStorePromotions, 0, err
|
|
}
|
|
|
|
//totalPage :=int(count) /m.PageSize + 1
|
|
|
|
err = qs.Order("id DESC").Offset(page * m.PageSize).Limit(m.PageSize).Find(&memberStorePromotions).Error
|
|
if err != nil && err != RecordNotFound {
|
|
logger.Error("count err:", err)
|
|
return memberStorePromotions, count, err
|
|
}
|
|
memberStorePromotions = CooperativeMemberPromotionStoreListSetStore(memberStorePromotions)
|
|
return memberStorePromotions, count, nil
|
|
}
|
|
|
|
type CooperativeMemberPromotionDayReq struct {
|
|
CooperativeBusinessId uint32 `json:"cooperative_business_id"`
|
|
Page int `json:"pageIndex"`
|
|
PageSize int `json:"pageSize"`
|
|
}
|
|
|
|
func (m *CooperativeMemberPromotionDayReq) List() ([]CooperativeMemberPromotionDay, int64, error) {
|
|
var memberDayPromotions []CooperativeMemberPromotionDay
|
|
qs := orm.Eloquent.Table("cooperative_member_promotion_day").Where("cooperative_business_id=?", m.CooperativeBusinessId)
|
|
|
|
page := m.Page - 1
|
|
if page < 0 {
|
|
page = 0
|
|
}
|
|
if m.PageSize == 0 {
|
|
m.PageSize = 10
|
|
}
|
|
var count int64
|
|
err := qs.Count(&count).Error
|
|
if err != nil {
|
|
logger.Error("count err:", err)
|
|
return memberDayPromotions, 0, err
|
|
}
|
|
|
|
//totalPage :=int(count) /m.PageSize + 1
|
|
|
|
err = qs.Order("id DESC").Offset(page * m.PageSize).Limit(m.PageSize).Find(&memberDayPromotions).Error
|
|
if err != nil && err != RecordNotFound {
|
|
logger.Error("count err:", err)
|
|
return memberDayPromotions, count, err
|
|
}
|
|
|
|
return memberDayPromotions, count, nil
|
|
}
|
|
|
|
type CooperativeMemberPromotionStoreDayReq struct {
|
|
CooperativeBusinessId uint32 `json:"cooperative_business_id"`
|
|
StoreId uint32 `json:"store_id"`
|
|
Page int `json:"pageIndex"`
|
|
PageSize int `json:"pageSize"`
|
|
}
|
|
|
|
func (m *CooperativeMemberPromotionStoreDayReq) List() ([]CooperativeMemberPromotionStoreDay, int64, error) {
|
|
|
|
var memberStoreDayPromotions []CooperativeMemberPromotionStoreDay
|
|
qs := orm.Eloquent.Table("cooperative_member_promotion_store_day").Where("store_id=?", m.StoreId).
|
|
Where("cooperative_business_id=?", m.CooperativeBusinessId)
|
|
|
|
page := m.Page - 1
|
|
if page < 0 {
|
|
page = 0
|
|
}
|
|
if m.PageSize == 0 {
|
|
m.PageSize = 10
|
|
}
|
|
var count int64
|
|
err := qs.Count(&count).Error
|
|
if err != nil {
|
|
logger.Error("count err:", err)
|
|
return memberStoreDayPromotions, 0, err
|
|
}
|
|
|
|
//totalPage :=int(count) /m.PageSize + 1
|
|
|
|
err = qs.Order("id DESC").Offset(page * m.PageSize).Limit(m.PageSize).Find(&memberStoreDayPromotions).Error
|
|
if err != nil && err != RecordNotFound {
|
|
logger.Error("count err:", err)
|
|
return memberStoreDayPromotions, count, err
|
|
}
|
|
memberStoreDayPromotions = CooperativeMemberPromotionStoreDayListSetStore(memberStoreDayPromotions)
|
|
return memberStoreDayPromotions, count, nil
|
|
}
|
|
|
|
type CooperativeMemberPromotionSettleReq struct {
|
|
StartTime time.Time `json:"start_time"` // 开始时间
|
|
EndTime time.Time `json:"end_time"` // 结束时间
|
|
Page int `json:"pageIndex"`
|
|
PageSize int `json:"pageSize"`
|
|
CooperativeBusinessId uint32 `json:"cooperative_business_id"`
|
|
}
|
|
|
|
func (m *CooperativeMemberPromotionSettleReq) List() ([]CooperativeDeductSettle, int64, error) {
|
|
var cooperatives []CooperativeDeductSettle
|
|
qs := orm.Eloquent.Table("cooperative_deduct_settle")
|
|
|
|
if !m.StartTime.IsZero() {
|
|
qs = qs.Where("created_at>?", m.StartTime)
|
|
}
|
|
if !m.EndTime.IsZero() {
|
|
qs = qs.Where("created_at<?", m.EndTime)
|
|
}
|
|
page := m.Page - 1
|
|
if page < 0 {
|
|
page = 0
|
|
}
|
|
if m.PageSize == 0 {
|
|
m.PageSize = 10
|
|
}
|
|
var count int64
|
|
err := qs.Count(&count).Error
|
|
if err != nil {
|
|
logger.Error("count err:", err)
|
|
return cooperatives, 0, err
|
|
}
|
|
|
|
//totalPage :=int(count) /m.PageSize + 1
|
|
|
|
err = qs.Order("id DESC").Offset(page * m.PageSize).Limit(m.PageSize).Find(&cooperatives).Error
|
|
if err != nil && err != RecordNotFound {
|
|
logger.Error("count err:", err)
|
|
return cooperatives, count, err
|
|
}
|
|
|
|
return cooperatives, count, nil
|
|
}
|
|
|
|
type RecordExist struct {
|
|
RecordExist int64 `json:"record_exist"`
|
|
}
|
|
|
|
func QueryRecordExist(sql string) (bool, error) {
|
|
var recordExist RecordExist
|
|
existSql := fmt.Sprintf("SELECT EXISTS (%s) AS record_exist;", sql)
|
|
err := orm.Eloquent.Raw(existSql).Scan(&recordExist).Error
|
|
if err != nil {
|
|
logger.Error("err:", err)
|
|
return false, err
|
|
}
|
|
|
|
return recordExist.RecordExist == 1, nil
|
|
}
|
|
|
|
type CooperativePromotionMemberReq struct {
|
|
CooperativeBusinessId uint32 `json:"cooperative_business_id"`
|
|
StoreId uint32 `json:"store_id"`
|
|
StartTime time.Time `json:"start_time"` // 开始时间
|
|
EndTime time.Time `json:"end_time"` // 结束时间
|
|
Page int `json:"pageIndex"`
|
|
PageSize int `json:"pageSize"`
|
|
}
|
|
|
|
func (m *CooperativePromotionMemberReq) List() ([]UserInfo, int64, error) {
|
|
var members []UserInfo
|
|
qs := orm.Eloquent.Table("user").Where("cooperative_business_id=?", m.CooperativeBusinessId).
|
|
Where("member_level in (?)", []uint32{2, 4, 5})
|
|
if m.StoreId != 0 {
|
|
qs = qs.Where("store_id=?", m.StoreId)
|
|
}
|
|
if !m.StartTime.IsZero() {
|
|
qs = qs.Where("created_at>?", m.StartTime)
|
|
}
|
|
if !m.EndTime.IsZero() {
|
|
qs = qs.Where("created_at<?", m.EndTime)
|
|
}
|
|
page := m.Page - 1
|
|
if page < 0 {
|
|
page = 0
|
|
}
|
|
if m.PageSize == 0 {
|
|
m.PageSize = 10
|
|
}
|
|
var count int64
|
|
err := qs.Count(&count).Error
|
|
if err != nil {
|
|
logger.Error("count err:", err)
|
|
return members, 0, err
|
|
}
|
|
|
|
//totalPage :=int(count) /m.PageSize + 1
|
|
|
|
err = qs.Order("id DESC").Offset(page * m.PageSize).Limit(m.PageSize).Find(&members).Error
|
|
if err != nil && err != RecordNotFound {
|
|
logger.Error("count err:", err)
|
|
return members, count, err
|
|
}
|
|
UserInfoListDesensitization(members)
|
|
return members, count, nil
|
|
}
|
|
|
|
func UserInfoListDesensitization(list []UserInfo) []UserInfo {
|
|
for i, _ := range list {
|
|
list[i].WxName = HideStar(list[i].WxName)
|
|
list[i].Tel = HideStar(list[i].Tel)
|
|
list[i].CooperativeName = HideStar(list[i].CooperativeName)
|
|
list[i].ShopAssistantName = HideStar(list[i].ShopAssistantName)
|
|
list[i].WxOpenID = HideStar(list[i].WxOpenID)
|
|
|
|
list[i].Gender = 0
|
|
list[i].City = ""
|
|
list[i].Province = ""
|
|
list[i].Deposit = 0
|
|
list[i].UserType = 0
|
|
}
|
|
return list
|
|
}
|
|
|
|
func HideStar(str string) (result string) {
|
|
if str == "" {
|
|
return "***"
|
|
}
|
|
if strings.Contains(str, "@") { // 邮箱
|
|
res := strings.Split(str, "@")
|
|
if len(res[0]) < 3 {
|
|
resString := "***"
|
|
result = resString + "@" + res[1]
|
|
} else {
|
|
res2 := Substr2(str, 0, 3)
|
|
resString := res2 + "***"
|
|
result = resString + "@" + res[1]
|
|
}
|
|
return result
|
|
} else {
|
|
reg := `^1[0-9]\d{9}$`
|
|
rgx := regexp.MustCompile(reg)
|
|
mobileMatch := rgx.MatchString(str)
|
|
if mobileMatch { // 手机号
|
|
result = Substr2(str, 0, 3) + "****" + Substr2(str, 7, 11)
|
|
} else {
|
|
nameRune := []rune(str)
|
|
lens := len(nameRune)
|
|
if lens <= 1 {
|
|
result = "***"
|
|
} else if lens == 2 {
|
|
result = string(nameRune[:1]) + "*"
|
|
} else if lens == 3 {
|
|
result = string(nameRune[:1]) + "*" + string(nameRune[2:3])
|
|
} else if lens == 4 {
|
|
result = string(nameRune[:1]) + "**" + string(nameRune[lens-1:lens])
|
|
} else if lens > 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
|
|
|
|
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"` // 升级:白金->黑金数量
|
|
|
|
Store *Store `json:"store" gorm:"-"`
|
|
// cooperative_member_promotion_day
|
|
}
|
|
|
|
type CooperativeMemberPromotionStatisticReq struct {
|
|
Type uint32 `json:"type"` // 1-按天展示 2-按月展示
|
|
CooperativeBusinessId uint32 `json:"cooperative_business_id"` // 合作商id
|
|
StartDate string `json:"start_date"` // 开始月份
|
|
EndDate string `json:"end_date"` // 结束月份
|
|
StoreId uint32 `json:"store_id"` // 门店ID
|
|
Page int `json:"pageIndex"` // 页码
|
|
PageSize int `json:"pageSize"` // 每页条数
|
|
IsExport uint32 `json:"is_export"` // 1-导出
|
|
}
|
|
|
|
type CooperativeMemberPromotionStatisticListResp struct {
|
|
Count int64 `json:"count"`
|
|
PageIndex int `json:"pageIndex"`
|
|
List []CooperativeMemberPromotionStatistic `json:"list"`
|
|
}
|
|
|
|
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<?", endTime)
|
|
}
|
|
err = qs.Order("id DESC").Offset(page * m.PageSize).Limit(m.PageSize).Find(&memberDayStorePromotions).Error
|
|
|
|
list = CooperativeMemberPromotionStoreDayToStatistic(memberDayStorePromotions)
|
|
} else {
|
|
var memberDayPromotions []CooperativeMemberPromotionDay
|
|
qs = orm.Eloquent.Table("cooperative_member_promotion_day").Where("cooperative_business_id=?", m.CooperativeBusinessId)
|
|
if !startTime.IsZero() {
|
|
qs = qs.Where("created_at>?", startTime)
|
|
}
|
|
if !endTime.IsZero() {
|
|
qs = qs.Where("created_at<?", endTime)
|
|
}
|
|
err = qs.Order("id DESC").Offset(page * m.PageSize).Limit(m.PageSize).Find(&memberDayPromotions).Error
|
|
list = CooperativeMemberPromotionDayListToStatistic(memberDayPromotions)
|
|
}
|
|
|
|
case 2:
|
|
if m.StoreId != 0 {
|
|
var memberStorePromotions []CooperativeMemberPromotionStore
|
|
qs = orm.Eloquent.Table("cooperative_member_promotion_store").Where("cooperative_business_id=?", m.CooperativeBusinessId)
|
|
if m.StoreId != 0 {
|
|
qs = qs.Where("store_id=?", m.StoreId)
|
|
}
|
|
//if m.Date != "" {
|
|
// qs = qs.Where("date=?", m.Date)
|
|
//}
|
|
if !startTime.IsZero() {
|
|
qs = qs.Where("created_at>?", startTime)
|
|
}
|
|
if !endTime.IsZero() {
|
|
qs = qs.Where("created_at<?", endTime)
|
|
}
|
|
err = qs.Order("id DESC").Offset(page * m.PageSize).Limit(m.PageSize).Find(&memberStorePromotions).Error
|
|
list = CooperativeMemberPromotionStoreToStatistic(memberStorePromotions)
|
|
} else {
|
|
var memberPromotions []CooperativeMemberPromotion
|
|
qs = orm.Eloquent.Table("cooperative_member_promotion").Where("cooperative_business_id=?", m.CooperativeBusinessId)
|
|
//if m.Date != "" {
|
|
// qs = qs.Where("date=?", m.Date)
|
|
//}
|
|
if !startTime.IsZero() {
|
|
qs = qs.Where("created_at>?", startTime)
|
|
}
|
|
if !endTime.IsZero() {
|
|
qs = qs.Where("created_at<?", endTime)
|
|
}
|
|
err = qs.Order("id DESC").Offset(page * m.PageSize).Limit(m.PageSize).Find(&memberPromotions).Error
|
|
list = CooperativeMemberPromotionToStatistic(memberPromotions)
|
|
}
|
|
|
|
}
|
|
if err != nil && err != RecordNotFound {
|
|
logger.Error("count err:", err)
|
|
return list, count, err
|
|
}
|
|
|
|
err = qs.Count(&count).Error
|
|
if err != nil {
|
|
logger.Error("count err:", err)
|
|
return list, 0, err
|
|
}
|
|
|
|
return list, count, nil
|
|
}
|
|
|
|
func CooperativeMemberPromotionDayListToStatistic(list []CooperativeMemberPromotionDay) []CooperativeMemberPromotionStatistic {
|
|
promotions := make([]CooperativeMemberPromotionStatistic, 0, len(list))
|
|
if len(list) == 0 {
|
|
return promotions
|
|
}
|
|
for i, _ := range list {
|
|
promotions = append(promotions, CooperativeMemberPromotionStatistic{
|
|
Model: list[i].Model,
|
|
CooperativeBusinessId: list[i].CooperativeBusinessId,
|
|
CooperativeName: list[i].CooperativeName,
|
|
GoldCount: list[i].GoldCount,
|
|
PlatinumCount: list[i].PlatinumCount,
|
|
BlackGoldCount: list[i].BlackGoldCount,
|
|
DayTime: list[i].DayTime,
|
|
RenewalGoldCount: list[i].RenewalGoldCount,
|
|
RenewalPlatinumCount: list[i].RenewalPlatinumCount,
|
|
RenewalBlackGoldCount: list[i].RenewalBlackGoldCount,
|
|
//Date: list[i].DayTime,
|
|
})
|
|
}
|
|
return promotions
|
|
}
|
|
|
|
func CooperativeMemberPromotionStoreDayToStatistic(list []CooperativeMemberPromotionStoreDay) []CooperativeMemberPromotionStatistic {
|
|
promotions := make([]CooperativeMemberPromotionStatistic, 0, len(list))
|
|
if len(list) == 0 {
|
|
return promotions
|
|
}
|
|
CooperativeMemberPromotionStoreDayListSetStore(list)
|
|
for i, _ := range list {
|
|
promotions = append(promotions, CooperativeMemberPromotionStatistic{
|
|
Model: list[i].Model,
|
|
CooperativeBusinessId: list[i].CooperativeBusinessId,
|
|
CooperativeName: list[i].CooperativeName,
|
|
GoldCount: list[i].GoldCount,
|
|
PlatinumCount: list[i].PlatinumCount,
|
|
BlackGoldCount: list[i].BlackGoldCount,
|
|
DayTime: list[i].DayTime,
|
|
RenewalGoldCount: list[i].RenewalGoldCount,
|
|
RenewalPlatinumCount: list[i].RenewalPlatinumCount,
|
|
RenewalBlackGoldCount: list[i].RenewalBlackGoldCount,
|
|
//Date: list[i].DayTime,
|
|
StoreId: list[i].StoreId,
|
|
Store: list[i].Store,
|
|
})
|
|
}
|
|
return promotions
|
|
}
|
|
|
|
func CooperativeMemberPromotionToStatistic(list []CooperativeMemberPromotion) []CooperativeMemberPromotionStatistic {
|
|
promotions := make([]CooperativeMemberPromotionStatistic, 0, len(list))
|
|
if len(list) == 0 {
|
|
return promotions
|
|
}
|
|
for i, _ := range list {
|
|
promotions = append(promotions, CooperativeMemberPromotionStatistic{
|
|
Model: list[i].Model,
|
|
CooperativeBusinessId: list[i].CooperativeBusinessId,
|
|
CooperativeName: list[i].CooperativeName,
|
|
GoldCount: list[i].GoldCount,
|
|
PlatinumCount: list[i].PlatinumCount,
|
|
BlackGoldCount: list[i].BlackGoldCount,
|
|
RenewalGoldCount: list[i].RenewalGoldCount,
|
|
RenewalPlatinumCount: list[i].RenewalPlatinumCount,
|
|
RenewalBlackGoldCount: list[i].RenewalBlackGoldCount,
|
|
Date: list[i].Date,
|
|
UpgradePlatinumToBlackCount: list[i].UpgradePlatinumToBlackCount,
|
|
UpgradeGoldToBlackCount: list[i].UpgradeGoldToBlackCount,
|
|
UpgradeGoldToPlatinumCount: list[i].UpgradeGoldToPlatinumCount,
|
|
//StoreId: list[i].StoreId,
|
|
})
|
|
}
|
|
return promotions
|
|
}
|
|
|
|
func CooperativeMemberPromotionStoreToStatistic(list []CooperativeMemberPromotionStore) []CooperativeMemberPromotionStatistic {
|
|
promotions := make([]CooperativeMemberPromotionStatistic, 0, len(list))
|
|
if len(list) == 0 {
|
|
return promotions
|
|
}
|
|
CooperativeMemberPromotionStoreListSetStore(list)
|
|
for i, _ := range list {
|
|
promotions = append(promotions, CooperativeMemberPromotionStatistic{
|
|
Model: list[i].Model,
|
|
CooperativeBusinessId: list[i].CooperativeBusinessId,
|
|
CooperativeName: list[i].CooperativeName,
|
|
GoldCount: list[i].GoldCount,
|
|
PlatinumCount: list[i].PlatinumCount,
|
|
BlackGoldCount: list[i].BlackGoldCount,
|
|
//DayTime: list[i].DayTime,
|
|
RenewalGoldCount: list[i].RenewalGoldCount,
|
|
RenewalPlatinumCount: list[i].RenewalPlatinumCount,
|
|
RenewalBlackGoldCount: list[i].RenewalBlackGoldCount,
|
|
Date: list[i].Date,
|
|
StoreId: list[i].StoreId,
|
|
Store: list[i].Store,
|
|
UpgradeGoldToPlatinumCount: list[i].UpgradeGoldToPlatinumCount,
|
|
UpgradeGoldToBlackCount: list[i].UpgradeGoldToBlackCount,
|
|
UpgradePlatinumToBlackCount: list[i].UpgradePlatinumToBlackCount,
|
|
})
|
|
}
|
|
return promotions
|
|
}
|