From c7e82fd1d76b9fb25497d5aba4372bbfe13a8468 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 28 三月 2024 20:00:21 +0800
Subject: [PATCH] 采购入库增加来源

---
 service/test/supplier.go |   53 ++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/service/test/supplier.go b/service/test/supplier.go
index 07110a2..27f4a39 100644
--- a/service/test/supplier.go
+++ b/service/test/supplier.go
@@ -1,52 +1,52 @@
 package test
 
 import (
-	"github.com/flipped-aurora/gin-vue-admin/server/global"
-	"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
-	"github.com/flipped-aurora/gin-vue-admin/server/model/test"
-	testReq "github.com/flipped-aurora/gin-vue-admin/server/model/test/request"
+	"srm/global"
+	"srm/model/common/request"
+	"srm/model/test"
+	testReq "srm/model/test/request"
 )
 
 type SupplierService struct {
 }
 
 // CreateSupplier 鍒涘缓Supplier璁板綍
-// Author [piexlmax](https://github.com/piexlmax)
 func (sService *SupplierService) CreateSupplier(s *test.Supplier) (err error) {
 	err = global.GVA_DB.Create(s).Error
 	return err
 }
 
 // DeleteSupplier 鍒犻櫎Supplier璁板綍
-// Author [piexlmax](https://github.com/piexlmax)
 func (sService *SupplierService) DeleteSupplier(s test.Supplier) (err error) {
 	err = global.GVA_DB.Delete(&s).Error
 	return err
 }
 
 // DeleteSupplierByIds 鎵归噺鍒犻櫎Supplier璁板綍
-// Author [piexlmax](https://github.com/piexlmax)
 func (sService *SupplierService) DeleteSupplierByIds(ids request.IdsReq) (err error) {
 	err = global.GVA_DB.Delete(&[]test.Supplier{}, "id in ?", ids.Ids).Error
 	return err
 }
 
 // UpdateSupplier 鏇存柊Supplier璁板綍
-// Author [piexlmax](https://github.com/piexlmax)
 func (sService *SupplierService) UpdateSupplier(s test.Supplier) (err error) {
-	err = global.GVA_DB.Save(&s).Error
+	err = global.GVA_DB.Updates(&s).Error
 	return err
 }
 
 // GetSupplier 鏍规嵁id鑾峰彇Supplier璁板綍
-// Author [piexlmax](https://github.com/piexlmax)
 func (sService *SupplierService) GetSupplier(id uint) (s test.Supplier, err error) {
-	err = global.GVA_DB.Where("id = ?", id).First(&s).Error
+	err = global.GVA_DB.Model(&test.Supplier{}).Where("id = ?", id).First(&s).Error
+	return
+}
+
+// GetSupplierByNumber 鏍规嵁缂栫爜鑾峰彇Supplier璁板綍
+func (sService *SupplierService) GetSupplierByNumber(number string) (s test.Supplier, err error) {
+	err = global.GVA_DB.Model(&test.Supplier{}).Where("number = ?", number).Preload("Contract").First(&s).Error
 	return
 }
 
 // GetSupplierInfoList 鍒嗛〉鑾峰彇Supplier璁板綍
-// Author [piexlmax](https://github.com/piexlmax)
 func (sService *SupplierService) GetSupplierInfoList(info testReq.SupplierSearch) (list []test.Supplier, total int64, err error) {
 	limit := info.PageSize
 	offset := info.PageSize * (info.Page - 1)
@@ -60,12 +60,33 @@
 	if info.Name != "" {
 		db = db.Where("name LIKE ?", "%"+info.Name+"%")
 	}
+	if info.Number != "" {
+		db = db.Where("number LIKE ?", "%"+info.Number+"%")
+	}
+	if info.SupplierType != "" {
+		db = db.Where("srm_supplier_type LIKE ?", "%"+info.SupplierType+"%")
+	}
+	if info.Industry != "" {
+		db = db.Where("industry LIKE ?", "%"+info.Industry+"%")
+	}
+	if info.Contact != "" {
+		db = db.Where("contact LIKE ?", "%"+info.Contact+"%")
+	}
+	if info.Phone != "" {
+		db = db.Where("phone LIKE ?", "%"+info.Phone+"%")
+	}
+	if info.CreatedAt != nil {
+		db = db.Where("created_at = ?", info.CreatedAt)
+	}
+	if info.Status != 0 {
+		db = db.Where("status = ?", info.Status)
+	}
 	err = db.Count(&total).Error
 	if err != nil {
 		return
 	}
 
-	err = db.Limit(limit).Offset(offset).Find(&ss).Error
+	err = db.Debug().Limit(limit).Offset(offset).Order("created_at desc").Preload("Contract").Find(&ss).Error
 	return ss, total, err
 }
 
@@ -74,3 +95,9 @@
 	err = global.GVA_DB.Model(&test.Supplier{}).Where("id = ?", id).Update("status", status).Error
 	return err
 }
+
+func (sService *SupplierService) MaxAutoIncr() (int, error) {
+	var total int64
+	err := global.GVA_DB.Model(&test.Supplier{}).Count(&total).Error
+	return int(total), err
+}

--
Gitblit v1.8.0