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/contract.go |   74 ++++++++++++++++++++++++++++++++----
 1 files changed, 65 insertions(+), 9 deletions(-)

diff --git a/model/contract.go b/model/contract.go
index 04c87a3..e437c6c 100644
--- a/model/contract.go
+++ b/model/contract.go
@@ -2,19 +2,27 @@
 
 import (
 	"aps_crm/pkg/mysqlx"
+	"fmt"
 	"gorm.io/gorm"
 )
 
 type (
 	Contract struct {
-		Id          int       `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
-		ClientId    int       `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"`
-		MemberId    int       `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
-		Number      string    `json:"number" gorm:"column:number;type:varchar(255);comment:鍚堝悓缂栧彿"`
-		QuotationId int       `json:"quotationId" gorm:"column:quotation_id;type:int;comment:鎶ヤ环鍗昳d"`
-		Quotation   Quotation `json:"quotation" gorm:"foreignKey:QuotationId;references:Id"`
-		StatusId    int       `json:"statusId" gorm:"column:status_id;type:int;comment:鍚堝悓鐘舵��"`
-		File        string    `json:"file" gorm:"column:file;type:varchar(255);comment:鍚堝悓鏂囦欢"`
+		Id                    int                   `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
+		ContractName          string                `json:"contractName" gorm:"column:contract_name;type:varchar(255);comment:鍚堝悓鍚嶇О"`
+		ClientId              int                   `json:"clientId" gorm:"column:client_id;type:int;comment:瀹㈡埛id"`
+		Client                Client                `json:"client" gorm:"foreignKey:ClientId"`
+		MemberId              int                   `json:"memberId" gorm:"column:member_id;type:int;comment:璐熻矗浜篿d"`
+		Member                User                  `json:"member" gorm:"foreignKey:MemberId"`
+		Number                string                `json:"number" gorm:"column:number;type:varchar(255);comment:鍚堝悓缂栧彿"`
+		QuotationId           int                   `json:"quotationId" gorm:"column:quotation_id;type:int;comment:鎶ヤ环鍗昳d"`
+		Quotation             Quotation             `json:"quotation" gorm:"foreignKey:QuotationId;references:Id"`
+		StatusId              int                   `json:"statusId" gorm:"column:status_id;type:int;comment:鍚堝悓鐘舵��"`
+		ServiceContractStatus ServiceContractStatus `json:"serviceContractStatus" gorm:"foreignKey:StatusId;references:Id"`
+		File                  string                `json:"file" gorm:"column:file;type:varchar(255);comment:鍚堝悓鏂囦欢"`
+		CreatedAt             *CustomTime           `json:"created_at" gorm:"column:created_at;type:datetime;comment:鍒涘缓鏃堕棿"`
+		CodeStandID           string                `json:"codeStandID" gorm:"column:code_stand_id;type:varchar(255);comment:缂栫爜id"`
+		SendTime              string                `json:"sendTime" gorm:"column:send_time;type:varchar(255);comment:鍙戣揣鏃堕棿"`
 		gormModel
 	}
 
@@ -45,6 +53,9 @@
 	if slf.Id != 0 {
 		db = db.Where("id = ?", slf.Id)
 	}
+	if slf.Number != "" {
+		db = db.Where("number = ?", slf.Number)
+	}
 
 	if len(slf.SearchMap) > 0 {
 		for key, value := range slf.SearchMap {
@@ -66,6 +77,13 @@
 					db = db.Where(key+"= ?", v)
 				}
 			case int:
+				if key == "member_id" {
+					db = db.Where(key+"= ?", v)
+				}
+			case []int:
+				if key == "member_ids" {
+					db = db.Where("contract.member_id in ?", v)
+				}
 			}
 		}
 	}
@@ -110,8 +128,32 @@
 		db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
 	}
 
-	err := db.Preload("Quotation").Order("id desc").Find(&records).Error
+	err := db.Preload("ServiceContractStatus").Preload("Client").Preload("Member").Preload("Quotation").Order("id desc").Find(&records).Error
 	return records, total, err
+}
+
+func (slf *ContractSearch) Count() (int64, error) {
+	var db = slf.build()
+	var total int64
+	err := db.Count(&total).Error
+	return total, err
+}
+
+func (slf *ContractSearch) 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 *ContractSearch) SetId(id int) *ContractSearch {
@@ -133,3 +175,17 @@
 	slf.SearchMap = data
 	return slf
 }
+func (slf *ContractSearch) SetIds(ids []int) *ContractSearch {
+	slf.Orm = slf.Orm.Where("id in (?)", ids)
+	return slf
+}
+
+func (slf *ContractSearch) SetNumber(number string) *ContractSearch {
+	slf.Number = number
+	return slf
+}
+
+func (slf *ContractSearch) UpdateByMap(data map[string]interface{}) error {
+	var db = slf.build()
+	return db.Updates(data).Error
+}

--
Gitblit v1.8.0