From 530fed8ec225453572d57b15c200ab062c335457 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 01 十一月 2023 19:20:21 +0800
Subject: [PATCH] 公海member_id使用0

---
 model/serviceFeeManage.go |  124 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 113 insertions(+), 11 deletions(-)

diff --git a/model/serviceFeeManage.go b/model/serviceFeeManage.go
index 6db6e76..f54d3e7 100644
--- a/model/serviceFeeManage.go
+++ b/model/serviceFeeManage.go
@@ -1,6 +1,7 @@
 package model
 
 import (
+	"aps_crm/constvar"
 	"aps_crm/pkg/mysqlx"
 	"gorm.io/gorm"
 	"time"
@@ -8,19 +9,26 @@
 
 type (
 	ServiceFeeManage struct {
-		Id         int       `json:"id" gorm:"column:id;primaryKey;autoIncrement;not null"`
-		ClientId   int       `json:"client_id" gorm:"column:client_id;type:int(11);comment:瀹㈡埛ID"`
-		Client     *Client   `json:"client" gorm:"foreignKey:ClientId"`
-		MemberId   int       `json:"member_id" gorm:"column:member_id;type:int(11);comment:鍛樺伐ID"`
-		LatestDate time.Time `json:"latest_date" gorm:"column:latest_date;type:datetime;comment:鏈�鏅氭湇鍔℃椂闂�"`
-		Remark     string    `json:"remark" gorm:"column:remark;type:varchar(255);comment:澶囨敞"`
-		File       string    `json:"file" gorm:"column:file;type:varchar(255);comment:鏂囦欢"`
+		Id         int         `json:"id" gorm:"column:id;primaryKey;autoIncrement;not null"`
+		ClientId   int         `json:"client_id" gorm:"column:client_id;type:int(11);comment:瀹㈡埛ID"`
+		Client     *Client     `json:"client" gorm:"foreignKey:ClientId"`
+		MemberId   int         `json:"member_id" gorm:"column:member_id;type:int(11);comment:鍛樺伐ID"`
+		LatestDate *CustomTime `json:"latest_date" gorm:"column:latest_date;type:datetime;comment:鏈�鏅氭湇鍔℃椂闂�"`
+		Remark     string      `json:"remark" gorm:"column:remark;type:varchar(255);comment:澶囨敞"`
+		File       string      `json:"file" gorm:"column:file;type:varchar(255);comment:鏂囦欢"`
 		gorm.Model `json:"-"`
 	}
 
 	ServiceFeeManageSearch struct {
 		ServiceFeeManage
-		Orm *gorm.DB
+		Orm         *gorm.DB
+		QueryClass  constvar.ServiceFeeQueryClass
+		KeywordType constvar.ServiceFeeKeywordType
+		Keyword     string
+		OrderBy     string
+		PageNum     int
+		PageSize    int
+		MemberIds   []int
 	}
 )
 
@@ -47,6 +55,54 @@
 		db.Where("client_id = ?", slf.ClientId)
 	}
 
+	if len(slf.MemberIds) > 0 {
+		db.Where("service_fee_manage.member_id in ?", slf.MemberIds)
+	}
+
+	switch slf.QueryClass {
+	case constvar.ServiceFeeQueryClassExpireLessThen60Days:
+		db = db.Where("latest_date > ? and latest_date < ?", time.Now(), time.Now().AddDate(0, 0, 60))
+	case constvar.ServiceFeeQueryClassExpireLessThen30Days:
+		db = db.Where("latest_date > ? and latest_date < ?", time.Now(), time.Now().AddDate(0, 0, 30))
+	case constvar.ServiceFeeQueryClassExpireAboutTo60Day:
+		db = db.Where("latest_date = ?", time.Now().AddDate(0, 0, -60))
+	case constvar.ServiceFeeQueryClassExpireAboutTo30Day:
+		db = db.Where("latest_date = ?", time.Now().AddDate(0, 0, -30))
+	case constvar.ServiceFeeQueryClassExpired:
+		db = db.Where("latest_date < ?", time.Now())
+	case constvar.ServiceFeeQueryClassNoService:
+		db = db.Where("latest_date < ?", time.Now().AddDate(0, 0, -60))
+
+	}
+
+	switch slf.KeywordType {
+	case constvar.ServiceFeeKeywordCustomerName:
+		db.Joins("left join clients on clients.id = service_fee_manage.client_id")
+		db = db.Where("clients.name = ?", slf.Keyword)
+	case constvar.ServiceFeeKeywordCustomerType:
+		db.Joins("left join clients on clients.id = service_fee_manage.client_id")
+		db = db.Where("clients.client_type_id = ?", slf.Keyword)
+	case constvar.ServiceFeeKeywordSalesPrincipal:
+		db.Joins("left join clients on clients.id = service_fee_manage.client_id")
+		db = db.Where("clients.member_id = ?", slf.Keyword)
+	case constvar.ServiceFeeKeywordCustomerScale:
+		db.Joins("left join clients on clients.id = service_fee_manage.client_id")
+		db = db.Where("clients.enterprise_scale_id = ?", slf.Keyword)
+	case constvar.ServiceFeeKeywordClientLevel:
+		db.Joins("left join clients on clients.id = service_fee_manage.client_id")
+		db = db.Where("clients.client_level_id = ?", slf.Keyword)
+	case constvar.ServiceFeeKeywordCustomerNo:
+		db.Joins("left join clients on clients.id = service_fee_manage.client_id")
+		db = db.Where("clients.number = ?", slf.Keyword)
+	case constvar.ServiceFeeKeywordCustomerStatus:
+		db.Joins("left join clients on clients.id = service_fee_manage.client_id")
+		db = db.Where("clients.client_status_id = ?", slf.Keyword)
+	case constvar.ServiceFeeKeywordServiceEndDate:
+		db = db.Where("latest_date = ?", slf.Keyword)
+	case constvar.ServiceFeeKeywordProductName:
+		//todo
+	}
+
 	return db
 }
 
@@ -70,6 +126,26 @@
 	return slf
 }
 
+func (slf *ServiceFeeManageSearch) SetMemberIds(ids []int) *ServiceFeeManageSearch {
+	slf.MemberIds = ids
+	return slf
+}
+
+func (slf *ServiceFeeManageSearch) SetKeywordType(keyword constvar.ServiceFeeKeywordType) *ServiceFeeManageSearch {
+	slf.KeywordType = keyword
+	return slf
+}
+
+func (slf *ServiceFeeManageSearch) SetQueryClass(queryClass constvar.ServiceFeeQueryClass) *ServiceFeeManageSearch {
+	slf.QueryClass = queryClass
+	return slf
+}
+
+func (slf *ServiceFeeManageSearch) SetKeyword(keyword string) *ServiceFeeManageSearch {
+	slf.Keyword = keyword
+	return slf
+}
+
 func (slf *ServiceFeeManageSearch) Find() (*ServiceFeeManage, error) {
 	var db = slf.build()
 	var record = new(ServiceFeeManage)
@@ -77,9 +153,35 @@
 	return record, err
 }
 
-func (slf *ServiceFeeManageSearch) FindAll() ([]*ServiceFeeManage, error) {
+func (slf *ServiceFeeManageSearch) FindAll() ([]*ServiceFeeManage, int64, error) {
 	var db = slf.build()
 	var records = make([]*ServiceFeeManage, 0)
-	err := db.Preload("Client").Find(&records).Error
-	return records, err
+	var total int64
+	if err := db.Count(&total).Error; err != nil {
+		return records, total, err
+	}
+	if slf.PageNum > 0 && slf.PageSize > 0 {
+		db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
+	}
+
+	if slf.PageNum > 0 && slf.PageSize > 0 {
+		db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
+	}
+
+	err := db.Preload("Client").Order("id desc").Find(&records).Error
+	return records, total, err
+}
+
+func (slf *ServiceFeeManageSearch) SetPage(page, size int) *ServiceFeeManageSearch {
+	slf.PageNum, slf.PageSize = page, size
+	return slf
+}
+
+func (slf *ServiceFeeManageSearch) SetOrder(order string) *ServiceFeeManageSearch {
+	slf.OrderBy = order
+	return slf
+}
+func (slf *ServiceFeeManageSearch) SetIds(ids []int) *ServiceFeeManageSearch {
+	slf.Orm = slf.Orm.Where("id in (?)", ids)
+	return slf
 }

--
Gitblit v1.8.0