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/subOrder.go |   46 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/model/subOrder.go b/model/subOrder.go
index 175a6b6..765b112 100644
--- a/model/subOrder.go
+++ b/model/subOrder.go
@@ -2,6 +2,7 @@
 
 import (
 	"aps_crm/pkg/mysqlx"
+	"fmt"
 	"gorm.io/gorm"
 )
 
@@ -50,6 +51,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 {
@@ -70,12 +74,16 @@
 				if key == "member_name" {
 					db = db.Joins("Member").Where("User.username LIKE ?", "%"+v+"%")
 				}
-			case int:
-				if key == "master_order_id" {
-					db = db.Where("master_order_id = ?", v)
+			case int, float64:
+				if key == "client_id" || key == "master_order_id" {
+					db = db.Where(key+" = ?", v)
 				}
 				if key == "member_id" {
-					db = db.Where("member_id = ?", v)
+					db = db.Where("sub_order.member_id = ?", v)
+				}
+			case []int:
+				if key == "member_ids" {
+					db = db.Where("sub_order.member_id in ?", v)
 				}
 			}
 		}
@@ -120,6 +128,30 @@
 	return records, total, err
 }
 
+func (slf *SubOrderSearch) Count() (int64, error) {
+	var db = slf.build()
+	var total int64
+	err := db.Count(&total).Error
+	return total, err
+}
+
+func (slf *SubOrderSearch) 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 *SubOrderSearch) SetId(id int) *SubOrderSearch {
 	slf.Id = id
 	return slf
@@ -143,6 +175,12 @@
 	slf.Orm = slf.Orm.Where("id in (?)", ids)
 	return slf
 }
+
+func (slf *SubOrderSearch) SetNumber(number string) *SubOrderSearch {
+	slf.Number = number
+	return slf
+}
+
 func (slf *SubOrderSearch) UpdateByMap(data map[string]interface{}) error {
 	var db = slf.build()
 	return db.Updates(data).Error

--
Gitblit v1.8.0