feat: 迁移商务旗下渠道查询和抽屉
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package business
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gorm.io/gorm"
|
||||
"kra/internal/biz/business"
|
||||
)
|
||||
|
||||
type businessPromoteRepo struct{ data Provider }
|
||||
|
||||
func NewBusinessPromoteRepo(data Provider) business.BusinessPromoteRepo {
|
||||
return &businessPromoteRepo{data: data}
|
||||
}
|
||||
|
||||
type directPromotePO struct {
|
||||
ID uint64
|
||||
Account string
|
||||
SourceDB string `gorm:"column:source_db"`
|
||||
BusierID uint64
|
||||
}
|
||||
|
||||
func (r *businessPromoteRepo) ListDirect(ctx context.Context, filter business.BusinessPromoteFilter, options ...business.ListOption) (*business.BusinessPromotePage, error) {
|
||||
page := &business.BusinessPromotePage{Rows: []*business.BusinessPromote{}, Available: true}
|
||||
db := r.data.DB().WithContext(ctx)
|
||||
bindings := func() *gorm.DB {
|
||||
q := db.Table("sys_user_bind_platform b").Where("b.user_id = ? AND b.status = ?", filter.UserID, "0")
|
||||
if filter.SourceDB != "" {
|
||||
q = q.Where("b.source_db = ?", filter.SourceDB)
|
||||
}
|
||||
if filter.BusierID != 0 {
|
||||
q = q.Where("b.platform_busier_id = ?", filter.BusierID)
|
||||
}
|
||||
return q
|
||||
}
|
||||
var count int64
|
||||
if err := bindings().Count(&count).Error; err != nil {
|
||||
return nil, business.ErrStorage
|
||||
}
|
||||
if count == 0 {
|
||||
return page, nil
|
||||
}
|
||||
available, err := businessTableAvailable(db, "tab_promote")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !available {
|
||||
page.Available = false
|
||||
return page, nil
|
||||
}
|
||||
q := db.Table("tab_promote p").Where("p.promote_level = ?", 1).Where("EXISTS (?)", bindings().Select("1").Where("b.source_db = p.source_db AND b.platform_busier_id = p.busier_id"))
|
||||
if err := q.Count(&page.Total).Error; err != nil {
|
||||
return nil, business.ErrStorage
|
||||
}
|
||||
o := business.NewListOptions(options...)
|
||||
var pos []directPromotePO
|
||||
if err := q.Select("p.id,p.account,p.source_db,p.busier_id").Order("p.id DESC,p.source_db ASC").Offset(o.Offset).Limit(o.Limit).Scan(&pos).Error; err != nil {
|
||||
return nil, business.ErrStorage
|
||||
}
|
||||
for _, po := range pos {
|
||||
page.Rows = append(page.Rows, &business.BusinessPromote{ID: po.ID, Account: po.Account, SourceDB: po.SourceDB, BusierID: po.BusierID})
|
||||
}
|
||||
return page, nil
|
||||
}
|
||||
Reference in New Issue
Block a user