From d182e581dd48d2e289f8cfa06405f8802a04573b Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 28 三月 2024 19:45:45 +0800
Subject: [PATCH] 运营商去掉必填

---
 controllers/order.go |   43 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/controllers/order.go b/controllers/order.go
index c527cf1..ffa4406 100644
--- a/controllers/order.go
+++ b/controllers/order.go
@@ -11,6 +11,7 @@
 	"outsourcing/pkg/logx"
 	"outsourcing/pkg/structx"
 	"outsourcing/request"
+	"outsourcing/response"
 	"outsourcing/service"
 	"outsourcing/service/outsourcing"
 	"outsourcing/utils/jwt"
@@ -203,10 +204,22 @@
 		params.Status == constvar.OutsourcingOrderStatusWaitProduce || //纭鎺ュ彈
 		params.Status == constvar.OutsourcingOrderStatusFinish || //鐢熶骇瀹屾垚
 		params.Status == constvar.OutsourcingOrderStatusDeliveryFinish { //鍙戣揣瀹屾垚
-		m := make(map[string]interface{})
-		m["status"] = params.Status
-		m["reason"] = params.Reason
-		err := models.NewOutsourcingOrderSearch().SetNumber(params.OutsourcingOrderNumber).UpdateByMap(m)
+		err = models.WithTransaction(func(db *gorm.DB) error {
+			m := make(map[string]interface{})
+			m["status"] = params.Status
+			m["reason"] = params.Reason
+			err := models.NewOutsourcingOrderSearch().SetNumber(params.OutsourcingOrderNumber).UpdateByMap(m)
+			if err != nil {
+				return err
+			}
+			if params.Status == constvar.OutsourcingOrderStatusCreate {
+				return models.NewOutsourcingOrderSearch().SetEnterpriseID(jwt.GetCompanyID(c)).SetNumber(params.OutsourcingOrderNumber).UpdateByMap(map[string]interface{}{
+					"enterprise_id": 0,
+				})
+			}
+			return nil
+		})
+
 		if err != nil {
 			util.ResponseFormat(c, code.RequestParamError, "鐘舵�佹洿鏂板け璐�")
 			return
@@ -274,7 +287,7 @@
 		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟瑙f瀽澶辫触锛屾暟鎹被鍨嬮敊璇�")
 		return
 	}
-	if params.OutsourcingOrderID == 0 || params.Number == "" || params.Carrier == "" || params.WaybillNumber == "" {
+	if params.OutsourcingOrderID == 0 || params.Number == "" {
 		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟缂哄け")
 		return
 	}
@@ -309,6 +322,7 @@
 				OutsourcingOrderDeliveryID: delivery.ID,
 				OutsourcingOrderProductID:  v.OutsourcingOrderProductID,
 				SendAmount:                 v.SendAmount,
+				IsReceived:                 2,
 			})
 		}
 		return models.NewOutsourcingOrderDeliveryDetailsSearch().SetOrm(db).CreateBatch(items)
@@ -358,7 +372,7 @@
 // @Summary   鐗╂枡鎼滅储
 // @Produce   application/json
 // @Param     object  body    request.MaterialSearch true  "鍙傛暟"
-// @Success   200   {object}  util.ResponseList{[]models.OutsourcingOrderDeliveryDetails}  "鎴愬姛"
+// @Success   200   {object}  util.ResponseList{[]response.Material}  "鎴愬姛"
 // @Router    /api-outsourcing/v1/order/materialSearch [post]
 func (slf *OrderController) MaterialSearch(c *gin.Context) {
 	var params request.MaterialSearch
@@ -367,15 +381,28 @@
 		return
 	}
 	client := outsourcing.NewOutsourcingServiceClient(service.ApsServiceConn)
-	list, err := client.GetMaterialList(c, &outsourcing.GetMaterialListRequest{
+	resp, err := client.GetMaterialList(c, &outsourcing.GetMaterialListRequest{
 		Page:     int32(params.Page),
 		PageSize: int32(params.PageSize),
 		Keyword:  params.Keyword,
 	})
+
 	if err != nil {
 		logx.Errorf("grpc outsourcing GetProductList err:%v", err)
 		util.ResponseFormat(c, code.RequestParamError, "鏌ヨ澶辫触")
 		return
 	}
-	util.ResponseFormat(c, code.Success, list)
+
+	data := make([]*response.Material, 0, len(resp.List))
+	for _, item := range resp.List {
+		data = append(data, &response.Material{
+			Number: item.ID,
+			Name:   item.Name,
+			Unit:   item.Unit,
+			Specs:  item.Specs,
+			Type:   item.Type,
+		})
+	}
+
+	util.ResponseFormat(c, code.Success, data)
 }

--
Gitblit v1.8.0