Browse Source

Merge branch 'seller_census'

zwxi 1 year ago
parent
commit
f0436c161f

File diff suppressed because it is too large
+ 737 - 252
controller/census/seller.go


+ 27 - 14
controller/crm/company_seller.go

@@ -106,27 +106,40 @@ func (rg *CompanySellerController) TeamList(c *gin.Context) {
 
 // 修复历史数据表中导入的销售seller_id
 func FIXIncomeHistorySellerId() (err error) {
-	adminCond := ``
-	adminPars := make([]interface{}, 0)
-	adminOB := new(crm.Admin)
-	adminList, e := adminOB.List(adminCond, adminPars)
-	if e != nil {
-		return
-	}
-	sellerMap := make(map[string]*crm.Admin)
-	for i := range adminList {
-		sellerMap[adminList[i].RealName] = adminList[i]
-	}
+	//adminCond := ``
+	//adminPars := make([]interface{}, 0)
+	//adminOB := new(crm.Admin)
+	//adminList, e := adminOB.List(adminCond, adminPars)
+	//if e != nil {
+	//	return
+	//}
+	//sellerMap := make(map[int]*crm.Admin)
+	//for i := range adminList {
+	//	sellerMap[adminList[i].AdminId] = adminList[i]
+	//}
 
 	list,err := fms.GetIncomeHistoryList()
 	if err != nil {
 		return
 	}
+	sellerList, e := crmService.GetSellerDepartmentListWithEnable()
+	if e != nil {
+		resp.FailData("获取销售失败", "Err:"+e.Error(), nil)
+		return
+	}
+	sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
+	for i := range sellerList {
+		sellerMap[sellerList[i].SellerId] = sellerList[i]
+	}
 	for _, v := range list {
 		fmt.Println("v:", v.IncomeId)
-		if seller, ok := sellerMap[v.SellerName]; ok{
-			v.SellerId = seller.AdminId
-			if e = v.Update([]string{"SellerId"}); e != nil {
+		if seller, ok := sellerMap[v.SellerId]; ok{
+			fmt.Println("更新销售:",v.SellerName)
+			v.SellerId = seller.SellerId
+			v.GroupId  = seller.GroupId
+			v.GroupName = seller.GroupName
+			v.DepartmentId = seller.DepartmentId
+			if e = v.Update([]string{"GroupId","GroupName","DepartmentId"}); e != nil {
 				fmt.Println("更新销售失败, Err: " + e.Error())
 				return
 			}

+ 1 - 0
init_serve/task.go

@@ -7,6 +7,7 @@ import (
 func InitTask() {
 	// TODO:执行一次
 	fmt.Println("task start")
+	//crm.FIXIncomeHistorySellerId()
 	//fmsService.FixContractInvoiceSellerInfo()
 	//fmsService.FixContractInvoicePaymentType()
 	//fmsService.FixContractSummaryData()

+ 13 - 10
models/fms/contract_income_history.go

@@ -6,13 +6,16 @@ import (
 )
 
 type ContractIncomeHistory struct {
-	IncomeId    int       `json:"income_id" gorm:"primaryKey;column:income_id"`       //
-	Amount      float64   `json:"amount" gorm:"column:amount"`             // 开票金额
-	InvoiceTime time.Time `json:"invoice_time" gorm:"column:invoice_time"` // 开票日期/到款月
-	SellerId    int       `json:"seller_id" gorm:"column:seller_id"`       // 销售ID
-	SellerName  string    `json:"seller_name" gorm:"column:seller_name"`   // 销售名称
-	NewCompany  int       `json:"new_company" gorm:"column:new_company"`   // 是否为新客户:0-否;1-是
-	CompanyName string    `json:"company_name" gorm:"column:company_name"` // 客户名称
+	IncomeId     int       `json:"income_id" gorm:"primaryKey;column:income_id"` //
+	Amount       float64   `json:"amount" gorm:"column:amount"`                  // 开票金额
+	InvoiceTime  time.Time `json:"invoice_time" gorm:"column:invoice_time"`      // 开票日期/到款月
+	SellerId     int       `json:"seller_id" gorm:"column:seller_id"`            // 销售ID
+	GroupId      int       `json:"group_id" gorm:"column:group_id"`              // 销售ID
+	SellerName   string    `json:"seller_name" gorm:"column:seller_name"`        // 销售名称
+	GroupName    string    `json:"group_name" gorm:"column:group_name"`          // 销售名称
+	NewCompany   int       `json:"new_company" gorm:"column:new_company"`        // 是否为新客户:0-否;1-是
+	CompanyName  string    `json:"company_name" gorm:"column:company_name"`      // 客户名称
+	DepartmentId int       `json:"department_id" gorm:"column:department_id"`    // 部门ID
 }
 
 func (c *ContractIncomeHistory) List(condition string, pars []interface{}) (list []*ContractIncomeHistory, err error) {
@@ -29,7 +32,7 @@ func (c *ContractIncomeHistory) TableName() string {
 
 // GetIncomeHistory
 func GetIncomeHistory(condition string, pars []interface{}) (results []*IncomeSummaryItem, err error) {
-	sql := `SELECT amount,seller_name,new_company AS contract_type,company_name,invoice_time AS invoice_date FROM contract_income_history WHERE  `
+	sql := `SELECT amount,seller_name,new_company AS contract_type,company_name,invoice_time AS invoice_date, seller_id as final_seller_id,group_id AS seller_group_id FROM contract_income_history WHERE  `
 	sql += condition
 	sql += ` ORDER BY invoice_date `
 	err = global.DEFAULT_MYSQL.Raw(sql, pars...).Find(&results).Error
@@ -38,7 +41,7 @@ func GetIncomeHistory(condition string, pars []interface{}) (results []*IncomeSu
 
 // GetIncomeHistoryList
 func GetIncomeHistoryList() (results []*ContractIncomeHistory, err error) {
-	sql := `SELECT * FROM contract_income_history WHERE seller_id=0 `
+	sql := `SELECT * FROM contract_income_history `
 	err = global.DEFAULT_MYSQL.Raw(sql).Find(&results).Error
 	return
 }
@@ -57,4 +60,4 @@ FROM
 	sql += ` ORDER BY invoice_time DESC  `
 	err = global.DEFAULT_MYSQL.Raw(sql, pars...).First(&result).Error
 	return
-}
+}

+ 1 - 1
models/fms/contract_invoice.go

@@ -818,4 +818,4 @@ func GetInvoiceCountByRegisterId(registerId int) (total int64, err error) {
 	err = global.DEFAULT_MYSQL.Table("contract_invoice as a ").
 		Where("is_deleted = 0 AND contract_register_id = ?", registerId).Count(&total).Error
 	return
-}
+}

+ 13 - 7
models/fms/invoice_payment_summary.go

@@ -192,17 +192,24 @@ func GetInvoicePaymentSummaryByRegisterIdAndInvoiceId(registerId, invocieId int)
 }
 
 type IncomeSummaryItem struct {
-	CompanyName  string    `json:"company_name" description:"客户名称"`
-	ContractType int       `json:"contract_type" description:"是否为新客户: 2-否; 1-是"`
-	InvoiceDate  time.Time `json:"invoice_time" description:"开票日期"`
-	Amount       float64   `json:"amount" description:"金额"`
-	SellerName   string    `json:"seller_name" description:"销售名称"`
+	CompanyName     string    `json:"company_name" description:"客户名称"`
+	ContractType    int       `json:"contract_type" description:"是否为新客户: 2-否; 1-是"`
+	InvoiceDate     time.Time `json:"invoice_time" description:"开票日期"`
+	Amount          float64   `json:"amount" description:"金额"`
+	SellerName      string    `json:"seller_name" description:"销售名称"`
+	FinalSellerId   int       `json:"final_seller_id" description:"最终销售ID"`
+	SellerGroupId   int       `json:"seller_group_id" description:"销售分组ID"`
+	SellerGroupName int       `json:"seller_group_name" description:"销售分组名称"`
 }
 
 // GetContractSummaryIncomeAmount 获取汇总金额合计信息
 func GetContractSummaryIncomeAmount(condition string, pars []interface{}) (results []*IncomeSummaryItem, err error) {
 	query := global.DEFAULT_MYSQL.Table("invoice_payment_summary AS a").
-		Select("IF(a.invoice_id=0,d.amount, b.amount) AS amount,IF(a.invoice_id=0,d.invoice_time, b.invoice_time) AS invoice_date, c.contract_type,c.company_name,IF(a.invoice_id=0,d.seller_name, b.seller_name) AS seller_name,IF(a.invoice_id=0,d.seller_id, b.seller_id) AS final_seller_id").
+		Select("IF(a.invoice_id=0,d.amount, b.amount) AS amount,IF(a.invoice_id=0,d.invoice_time, b.invoice_time) AS invoice_date,"+
+			" c.contract_type,c.company_name," +
+			"IF(a.invoice_id=0,d.seller_name, b.seller_name) AS seller_name,"+
+			"IF(a.invoice_id=0,d.seller_id, b.seller_id) AS final_seller_id,"+
+			"IF(a.invoice_id=0,d.seller_group_id, b.seller_group_id) AS seller_group_id").
 		Joins("LEFT JOIN contract_invoice AS b ON a.invoice_id = b.contract_invoice_id AND b.is_deleted = 0 ").
 		Joins("LEFT JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0").
 		Joins("JOIN contract_register AS c ON a.register_id = c.contract_register_id AND c.is_deleted = 0").
@@ -373,4 +380,3 @@ func UpdateInvoicePaymentSummaryByRegisterId(newId int, registerIds []int) (err
 	err = global.DEFAULT_MYSQL.Exec(sql, newId, registerIds).Error
 	return
 }
-

+ 2 - 2
routers/census.go

@@ -19,6 +19,6 @@ func InitCensus(rg *gin.RouterGroup) {
 	// 销售
 	sel := new(census.SellerController)
 	selGroup := rg.Group("seller/").Use(middleware.Token())
-	selGroup.GET("group_invoice_list", sel.GroupInvoiceList)
-	selGroup.GET("invoice_list", sel.InvoiceList)
+	selGroup.GET("group_invoice_list", sel.GroupInvoiceListV2)
+	selGroup.GET("invoice_list", sel.InvoiceListV2)
 }

+ 77 - 0
services/fms/seller.go

@@ -0,0 +1,77 @@
+package fms
+
+import (
+	"hongze/fms_api/models/fms"
+)
+
+type CensusSellerGroupList []*fms.CensusSellerGroupInvoiceItem
+
+func (c CensusSellerGroupList) Len() int {
+	return len(c)
+}
+
+func (c CensusSellerGroupList) Less(i, j int) bool {
+	return c[i].InvoiceAmount > c[j].InvoiceAmount
+}
+
+func (c CensusSellerGroupList) Swap(i, j int) {
+	c[i], c[j] = c[j], c[i]
+}
+
+
+type CensusSellerListByAmountAsc []*fms.CensusSellerInvoiceItem
+
+func (c CensusSellerListByAmountAsc) Len() int {
+	return len(c)
+}
+
+func (c CensusSellerListByAmountAsc) Less(i, j int) bool {
+	return c[i].InvoiceAmount > c[j].InvoiceAmount
+}
+
+func (c CensusSellerListByAmountAsc) Swap(i, j int) {
+	c[i], c[j] = c[j], c[i]
+}
+
+type CensusSellerListByAmountDesc []*fms.CensusSellerInvoiceItem
+
+func (c CensusSellerListByAmountDesc) Len() int {
+	return len(c)
+}
+
+func (c CensusSellerListByAmountDesc) Less(i, j int) bool {
+	return c[i].InvoiceAmount < c[j].InvoiceAmount
+}
+
+func (c CensusSellerListByAmountDesc) Swap(i, j int) {
+	c[i], c[j] = c[j], c[i]
+}
+
+type CensusSellerListByGroupRateAsc []*fms.CensusSellerInvoiceItem
+
+func (c CensusSellerListByGroupRateAsc) Len() int {
+	return len(c)
+}
+
+func (c CensusSellerListByGroupRateAsc) Less(i, j int) bool {
+	return c[i].GroupRate > c[j].GroupRate
+}
+
+func (c CensusSellerListByGroupRateAsc) Swap(i, j int) {
+	c[i], c[j] = c[j], c[i]
+}
+
+type CensusSellerListByGroupRateDesc []*fms.CensusSellerInvoiceItem
+
+func (c CensusSellerListByGroupRateDesc) Len() int {
+	return len(c)
+}
+
+func (c CensusSellerListByGroupRateDesc) Less(i, j int) bool {
+	return c[i].GroupRate < c[j].GroupRate
+}
+
+func (c CensusSellerListByGroupRateDesc) Swap(i, j int) {
+	c[i], c[j] = c[j], c[i]
+}
+

Some files were not shown because too many files changed in this diff