From 115bd9b51f5d8eade4658f844de37516486c60e7 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期六, 18 十一月 2023 17:25:25 +0800
Subject: [PATCH] crm获取aps项目模块信息

---
 model/salesDetails.go |  128 ++++++++++++++++++++++++++++++++----------
 1 files changed, 98 insertions(+), 30 deletions(-)

diff --git a/model/salesDetails.go b/model/salesDetails.go
index fe13d5e..5ae20b0 100644
--- a/model/salesDetails.go
+++ b/model/salesDetails.go
@@ -11,35 +11,41 @@
 
 type (
 	SalesDetails struct {
-		Id                  int               `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
-		ClientId            int               `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"`
-		Client              Client            `json:"client" gorm:"foreignKey:ClientId"`
-		Number              string            `json:"number" gorm:"column:number;type:varchar(255);comment:閿�鍞瓙鍗曞彿"`
-		SaleChanceId        int               `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:閿�鍞満浼歩d"`
-		SaleChance          SaleChance        `json:"saleChance" gorm:"foreignKey:SaleChanceId"`
-		SaleType            int               `json:"saleType" gorm:"column:sale_type;type:int;comment:閿�鍞被鍨�"`
-		SignTime            string            `json:"signTime" gorm:"column:sign_time;type:varchar(255);comment:绛惧崟鏃堕棿"`
-		MemberId            int               `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
-		Member              User              `json:"Member"  gorm:"foreignKey:MemberId"`
-		DeliveryDate        string            `json:"deliveryDate" gorm:"column:delivery_date;type:varchar(255);comment:浜よ揣鏃ユ湡"`
-		WechatOrderStatusId int               `json:"wechatOrderStatusId" gorm:"column:wechat_order_status;type:int;comment:寰俊璁㈠崟鐘舵��"`
-		WechatOrderStatus   WechatOrderStatus `json:"wechatOrderStatus" gorm:"foreignKey:WechatOrderStatusId"`
-		Address             string            `json:"address" gorm:"column:address;type:varchar(255);comment:鍦板潃"`
-		Phone               string            `json:"phone" gorm:"column:phone;type:varchar(255);comment:鐢佃瘽"`
-		Addressee           string            `json:"addressee" gorm:"column:addressee;type:varchar(255);comment:鏀朵欢浜�"`
-		Conditions          string            `json:"conditions" gorm:"column:conditions;type:text;comment:鏉′欢"`
-		CreatorId           int               `json:"creatorId" gorm:"column:creator_id;type:int;comment:鍒涘缓浜篿d"`
-		Remark              string            `json:"remark" gorm:"column:remark;type:text;comment:澶囨敞"`
-		Products            []*Product        `json:"products" gorm:"many2many:SalesDetails_Product;"`
-		LogisticCompany     string            `json:"logisticCompany" gorm:"column:logistic_company;type:varchar(255);comment:鐗╂祦鍏徃"`
-		LogisticNumber      string            `json:"logisticNumber" gorm:"column:logistic_number;type:varchar(255);comment:鐗╂祦鍗曞彿"`
-		LogisticCost        float64           `json:"logisticCost" gorm:"column:logistic_cost;type:decimal(10,2);comment:鐗╂祦璐圭敤"`
-		AmountReceivable    decimal.Decimal   `gorm:"column:amount_receivable;type:decimal(12,2);comment:搴旀敹閲戦" json:"amountReceivable"`    // 搴旀敹閲戦
-		AmountReceived      decimal.Decimal   `gorm:"column:amount_received;type:decimal(12,2);comment:宸叉敹閲戦" json:"amountReceived"`        // 宸叉敹閲戦
-		AmountInvoiced      decimal.Decimal   `gorm:"column:amount_invoiced;type:decimal(12,2);comment:宸插紑绁ㄩ噾棰�" json:"amountInvoiced"`       // 宸插紑绁ㄩ噾棰�
-		AmountUnInvoiced    decimal.Decimal   `gorm:"column:amount_not_invoiced;type:decimal(12,2);comment:鏈紑绁ㄩ噾棰�" json:"amountUnInvoiced"` // 鏈紑绁ㄩ噾棰�
-		AmountTotal         decimal.Decimal   `gorm:"column:amount_total;type:decimal(12,2);comment:浠风◣鍚堣" json:"amountTotal"`              // 浠风◣鍚堣
-		CodeStandID         string            `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:缂栫爜id"`
+		Id                  int                         `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+		ClientId            int                         `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"`
+		Client              Client                      `json:"client" gorm:"foreignKey:ClientId"`
+		Number              string                      `json:"number" gorm:"column:number;type:varchar(255);comment:閿�鍞槑缁嗗崟鍙�"`
+		SaleChanceId        int                         `json:"saleChanceId" gorm:"column:sale_chance_id;type:int;comment:閿�鍞満浼歩d"`
+		SaleChance          SaleChance                  `json:"saleChance" gorm:"foreignKey:SaleChanceId"`
+		SaleType            int                         `json:"saleType" gorm:"column:sale_type;type:int;comment:閿�鍞被鍨�"`
+		SignTime            string                      `json:"signTime" gorm:"column:sign_time;type:varchar(255);comment:绛惧崟鏃堕棿"`
+		MemberId            int                         `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
+		Member              User                        `json:"Member"  gorm:"foreignKey:MemberId"`
+		DeliveryDate        string                      `json:"deliveryDate" gorm:"column:delivery_date;type:varchar(255);comment:浜よ揣鏃ユ湡"`
+		WechatOrderStatusId int                         `json:"wechatOrderStatusId" gorm:"column:wechat_order_status;type:int;comment:寰俊璁㈠崟鐘舵��"`
+		WechatOrderStatus   WechatOrderStatus           `json:"wechatOrderStatus" gorm:"foreignKey:WechatOrderStatusId"`
+		Address             string                      `json:"address" gorm:"column:address;type:varchar(255);comment:鍦板潃"`
+		Phone               string                      `json:"phone" gorm:"column:phone;type:varchar(255);comment:鐢佃瘽"`
+		Addressee           string                      `json:"addressee" gorm:"column:addressee;type:varchar(255);comment:鏀朵欢浜�"`
+		Conditions          string                      `json:"conditions" gorm:"column:conditions;type:text;comment:鏉′欢"`
+		CreatorId           int                         `json:"creatorId" gorm:"column:creator_id;type:int;comment:鍒涘缓浜篿d"`
+		Remark              string                      `json:"remark" gorm:"column:remark;type:text;comment:澶囨敞"`
+		Products            []*Product                  `json:"products" gorm:"many2many:SalesDetails_Product;"`
+		LogisticCompany     string                      `json:"logisticCompany" gorm:"column:logistic_company;type:varchar(255);comment:鐗╂祦鍏徃"`
+		LogisticNumber      string                      `json:"logisticNumber" gorm:"column:logistic_number;type:varchar(255);comment:鐗╂祦鍗曞彿"`
+		LogisticCost        float64                     `json:"logisticCost" gorm:"column:logistic_cost;type:decimal(10,2);comment:鐗╂祦璐圭敤"`
+		AmountReceivable    decimal.Decimal             `gorm:"column:amount_receivable;type:decimal(12,2);comment:搴旀敹閲戦" json:"amountReceivable"`    // 搴旀敹閲戦
+		AmountReceived      decimal.Decimal             `gorm:"column:amount_received;type:decimal(12,2);comment:宸叉敹閲戦" json:"amountReceived"`        // 宸叉敹閲戦
+		AmountInvoiced      decimal.Decimal             `gorm:"column:amount_invoiced;type:decimal(12,2);comment:宸插紑绁ㄩ噾棰�" json:"amountInvoiced"`       // 宸插紑绁ㄩ噾棰�
+		AmountUnInvoiced    decimal.Decimal             `gorm:"column:amount_not_invoiced;type:decimal(12,2);comment:鏈紑绁ㄩ噾棰�" json:"amountUnInvoiced"` // 鏈紑绁ㄩ噾棰�
+		AmountTotal         decimal.Decimal             `gorm:"column:amount_total;type:decimal(12,2);comment:浠风◣鍚堣" json:"amountTotal"`              // 浠风◣鍚堣
+		CodeStandID         string                      `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:缂栫爜id"`
+		DeliverType         int                         `json:"deliverType" gorm:"column:deliver_type;type:int;comment:浜や粯绫诲瀷(1.涓�娆″彂璐�,2.澶氭鍙戣揣)"`
+		QuotationId         int                         `json:"quotationId" gorm:"column:quotation_id;type:int;comment:鎶ヤ环鍗昳d"`
+		Quotation           Quotation                   `json:"quotation" gorm:"foreignKey:QuotationId"`
+		Status              constvar.SalesDetailsStatus `json:"status" gorm:"column:status;type:int;comment:鐘舵��"`
+		Source              string                      `json:"source" gorm:"column:source;type:varchar(255);comment:璁㈠崟鏉ユ簮"`
+		ProjectId           string                      `json:"projectId" gorm:"column:project_id;type:varchar(255);comment:aps椤圭洰id"`
 		CrmModel
 	}
 
@@ -52,6 +58,7 @@
 		PageNum     int
 		PageSize    int
 		Preload     bool
+		MemberIds   []int
 	}
 )
 
@@ -71,6 +78,17 @@
 		db = db.Where("id = ?", slf.Id)
 	}
 
+	if slf.SaleChanceId != 0 {
+		db = db.Where("sale_chance_id = ?", slf.SaleChanceId)
+	}
+
+	if slf.ClientId != 0 {
+		db = db.Where("client_id = ?", slf.ClientId)
+	}
+	if slf.Number != "" {
+		db = db.Where("number = ?", slf.Number)
+	}
+
 	switch slf.KeywordType {
 	case constvar.SalesDetailsKeywordTypeCustomerName:
 		db = db.Joins("Client", clause.LeftJoin).Where("Client.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword))
@@ -84,12 +102,18 @@
 		db = db.Joins("left join sales_details_product sdp on sdp.sales_details_id = sales_details.id left join products on sdp.product_id = products.id").Where("products.name like ?", fmt.Sprintf("%%%s%%", slf.Keyword))
 
 	}
+
+	if len(slf.MemberIds) > 0 {
+		db = db.Where("sales_details.member_id in ?", slf.MemberIds)
+	}
+
 	if slf.Preload {
 		db = db.Preload("Products").
 			Preload("Member").
 			Preload("SaleChance").
 			Preload("WechatOrderStatus").
-			Preload("Client")
+			Preload("Client").
+			Preload("Quotation")
 	}
 
 	return db
@@ -116,8 +140,42 @@
 	return db.Updates(record).Error
 }
 
+func (slf *SalesDetailsSearch) Count() (int64, error) {
+	var db = slf.build()
+	var total int64
+	err := db.Count(&total).Error
+	return total, err
+}
+
+func (slf *SalesDetailsSearch) MaxAutoIncr() (int, error) {
+	type Result struct {
+		Max int
+	}
+
+	var (
+		result Result
+		db     = slf.build()
+	)
+
+	err := db.Select("MAX(id) as max").Scan(&result).Error
+	if err != nil {
+		return result.Max, fmt.Errorf("max err: %v", err)
+	}
+	return result.Max, nil
+}
+
 func (slf *SalesDetailsSearch) SetId(id int) *SalesDetailsSearch {
 	slf.Id = id
+	return slf
+}
+
+func (slf *SalesDetailsSearch) SetClientId(clientId int) *SalesDetailsSearch {
+	slf.ClientId = clientId
+	return slf
+}
+
+func (slf *SalesDetailsSearch) SetSaleChanceId(saleChanceId int) *SalesDetailsSearch {
+	slf.SaleChanceId = saleChanceId
 	return slf
 }
 
@@ -157,6 +215,11 @@
 	return slf
 }
 
+func (slf *SalesDetailsSearch) SetMemberIds(memberIds []int) *SalesDetailsSearch {
+	slf.MemberIds = memberIds
+	return slf
+}
+
 func (slf *SalesDetailsSearch) SetPreload(preload bool) *SalesDetailsSearch {
 	slf.Preload = preload
 	return slf
@@ -172,6 +235,11 @@
 	return slf
 }
 
+func (slf *SalesDetailsSearch) SetNumber(number string) *SalesDetailsSearch {
+	slf.Number = number
+	return slf
+}
+
 func (slf *SalesDetailsSearch) UpdateByMap(upMap map[string]interface{}) error {
 	var (
 		db = slf.build()

--
Gitblit v1.8.0