From de4bcd1dead50b05f716bc5718be5540bdb96783 Mon Sep 17 00:00:00 2001
From: liujiandao <274878379@qq.com>
Date: 星期日, 28 四月 2024 17:23:29 +0800
Subject: [PATCH] fix

---
 api/v1/test/supplier.go |  102 ++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 89 insertions(+), 13 deletions(-)

diff --git a/api/v1/test/supplier.go b/api/v1/test/supplier.go
index 5b9df26..6a2b489 100644
--- a/api/v1/test/supplier.go
+++ b/api/v1/test/supplier.go
@@ -1,15 +1,16 @@
 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/common/response"
-	"github.com/flipped-aurora/gin-vue-admin/server/model/test"
-	testReq "github.com/flipped-aurora/gin-vue-admin/server/model/test/request"
-	"github.com/flipped-aurora/gin-vue-admin/server/service"
-	"github.com/flipped-aurora/gin-vue-admin/server/utils"
 	"github.com/gin-gonic/gin"
 	"go.uber.org/zap"
+	"gorm.io/gorm"
+	"srm/global"
+	"srm/model/common/request"
+	"srm/model/common/response"
+	"srm/model/test"
+	testReq "srm/model/test/request"
+	"srm/service"
+	"srm/utils"
 )
 
 type SupplierApi struct {
@@ -33,12 +34,9 @@
 		response.FailWithMessage(err.Error(), c)
 		return
 	}
-	verify := utils.Rules{
-		"Name":                {utils.NotEmpty()},
-		"ResponsiblePersonId": {utils.NotEmpty()},
-	}
-	if err := utils.Verify(s, verify); err != nil {
-		response.FailWithMessage(err.Error(), c)
+	_, err = sService.GetSupplierByNumber(s.Number)
+	if err != gorm.ErrRecordNotFound {
+		response.FailWithMessage("缂栧彿閲嶅", c)
 		return
 	}
 	if err := sService.CreateSupplier(&s); err != nil {
@@ -153,6 +151,29 @@
 	}
 }
 
+// GetSupplierByNumber 鐢ㄧ紪鐮佹煡璇upplier
+// @Tags Supplier
+// @Summary 鐢ㄧ紪鐮佹煡璇upplier
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param     number  path string true  "渚涘簲鍟嗙紪鐮�"
+// @Success 200 {string} string "{"success":true,"data":{},"msg":"鏌ヨ鎴愬姛"}"
+// @Router /s/getSupplierByNumber/{number} [get]
+func (sApi *SupplierApi) GetSupplierByNumber(c *gin.Context) {
+	number := c.Param("number")
+	if number == "" {
+		response.FailWithMessage("缂栫爜鍙傛暟涓嶈兘涓虹┖", c)
+		return
+	}
+	if res, err := sService.GetSupplierByNumber(number); err != nil {
+		global.GVA_LOG.Error("鏌ヨ澶辫触!", zap.Error(err))
+		response.FailWithMessage("鏌ヨ澶辫触", c)
+	} else {
+		response.OkWithData(gin.H{"res": res}, c)
+	}
+}
+
 // GetSupplierList 鍒嗛〉鑾峰彇Supplier鍒楄〃
 // @Tags Supplier
 // @Summary 鍒嗛〉鑾峰彇Supplier鍒楄〃
@@ -181,3 +202,58 @@
 		}, "鑾峰彇鎴愬姛", c)
 	}
 }
+
+// ChangeSupplierStatus 淇敼Supplier鐘舵��
+// @Tags Supplier
+// @Summary 淇敼Supplier鐘舵��
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param data body testReq.SupplierStatus true "淇敼Supplier鐘舵��"
+// @Success 200 {string} string "{"success":true,"data":{},"msg":"淇敼鎴愬姛"}"
+// @Router /s/changeSupplierStatus [post]
+func (sApi *SupplierApi) ChangeSupplierStatus(c *gin.Context) {
+	var params testReq.SupplierStatus
+	err := c.ShouldBindJSON(&params)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	if err := sService.ChangeStatus(params.Id, params.Status); err != nil {
+		global.GVA_LOG.Error("淇敼澶辫触!", zap.Error(err))
+		response.FailWithMessage("淇敼澶辫触", c)
+	} else {
+		response.OkWithMessage("淇敼鎴愬姛", c)
+	}
+}
+
+// GetSupplierProductList 鑾峰彇渚涘簲鍟嗘彁渚涗骇鍝佸垪琛�
+// @Tags Supplier
+// @Summary 鑾峰彇渚涘簲鍟嗘彁渚涗骇鍝佸垪琛�
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce application/json
+// @Param data query testReq.SupplierProduct true "鑾峰彇渚涘簲鍟嗘彁渚涗骇鍝佸垪琛�"
+// @Param Authorization	header string true "token"
+// @Success 200 {string} string "{"success":true,"data":{},"msg":"鑾峰彇鎴愬姛"}"
+// @Router /s/getSupplierProductList [get]
+func (sApi *SupplierApi) GetSupplierProductList(c *gin.Context) {
+	var params testReq.SupplierProduct
+	err := c.ShouldBindQuery(&params)
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	list, total, err := sService.GetSupplierProduct(params)
+	if err != nil {
+		global.GVA_LOG.Error("鑾峰彇澶辫触!", zap.Error(err))
+		response.FailWithMessage("鑾峰彇澶辫触", c)
+		return
+	}
+	response.OkWithDetailed(response.PageResult{
+		List:     list,
+		Total:    total,
+		Page:     params.Page,
+		PageSize: params.PageSize,
+	}, "鑾峰彇鎴愬姛", c)
+}

--
Gitblit v1.8.0