| | |
| | | "outsourcing/pkg/logx" |
| | | "outsourcing/pkg/structx" |
| | | "outsourcing/request" |
| | | "outsourcing/response" |
| | | "outsourcing/service" |
| | | "outsourcing/service/outsourcing" |
| | | "outsourcing/utils/jwt" |
| | | ) |
| | | |
| | | type OrderController struct{} |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | list, total, err := models.NewOutsourcingOrderSearch().SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetOrder("id desc").Find() |
| | | |
| | | companyId := jwt.GetCompanyID(c) |
| | | if companyId == 0 { |
| | | util.ResponseFormat(c, code.InternalError, "内部错误") |
| | | return |
| | | } |
| | | |
| | | list, total, err := models.NewOutsourcingOrderSearch().SetEnterpriseID(companyId).SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetOrder("id desc").Find() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, "查询错误") |
| | | return |
| | |
| | | // @Success 200 {object} util.ResponseList{data=request.OutsourcingOrderOverview} "成功" |
| | | // @Router /api-outsourcing/v1/order/overview [get] |
| | | func (slf *OrderController) OrderOverview(c *gin.Context) { |
| | | result, err := models.NewOutsourcingOrderSearch().CountGroupByStatus() |
| | | result, err := models.NewOutsourcingOrderSearch().SetEnterpriseID(jwt.GetCompanyID(c)).CountGroupByStatus() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, "查询错误") |
| | | return |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数缺失") |
| | | return |
| | | } |
| | | |
| | | _, err := models.NewOutsourcingOrderSearch().SetEnterpriseID(jwt.GetCompanyID(c)).SetID(params.OutsourcingOrderId).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "订单不存在") |
| | | return |
| | | } |
| | | |
| | | list, total, err := models.NewOutsourcingOrderProductSearch().SetPage(params.Page, params.PageSize).SetOutsourcingOrderID(params.OutsourcingOrderId).SetOrder("id desc").Find() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, "查询错误") |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "物料申请不能为空") |
| | | return |
| | | } |
| | | |
| | | _, err := models.NewOutsourcingOrderSearch().SetEnterpriseID(jwt.GetCompanyID(c)).SetNumber(params.ApplyList[0].OutsourcingOrderNumber).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "订单不存在") |
| | | return |
| | | } |
| | | |
| | | var apply []*models.OutsourcingMaterialApply |
| | | err := structx.AssignTo(params.ApplyList, &apply) |
| | | err = structx.AssignTo(params.ApplyList, &apply) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "数据转换失败") |
| | | return |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | |
| | | _, err := models.NewOutsourcingOrderSearch().SetEnterpriseID(jwt.GetCompanyID(c)).SetNumber(params.Number).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "订单不存在") |
| | | return |
| | | } |
| | | |
| | | find, err := models.NewOutsourcingMaterialApplySearch().SetOutsourcingOrderNumber(params.Number).FindNotTotal() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查询失败") |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | |
| | | _, err := models.NewOutsourcingOrderSearch().SetEnterpriseID(jwt.GetCompanyID(c)).SetNumber(params.OutsourcingOrderNumber).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "订单不存在") |
| | | return |
| | | } |
| | | |
| | | //限定状态参数 |
| | | if params.Status == constvar.OutsourcingOrderStatusCreate || //取消确认 |
| | | 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 |
| | |
| | | } |
| | | if params.OutsourcingOrderID == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数缺失") |
| | | return |
| | | } |
| | | |
| | | _, err := models.NewOutsourcingOrderSearch().SetEnterpriseID(jwt.GetCompanyID(c)).SetID(params.OutsourcingOrderID).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "订单不存在") |
| | | return |
| | | } |
| | | |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | if params.OutsourcingOrderID == 0 || params.Number == "" || params.Carrier == "" || params.WaybillNumber == "" { |
| | | if params.OutsourcingOrderID == 0 || params.Number == "" { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数缺失") |
| | | return |
| | | } |
| | | |
| | | _, err := models.NewOutsourcingOrderSearch().SetEnterpriseID(jwt.GetCompanyID(c)).SetID(params.OutsourcingOrderID).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "订单不存在") |
| | | return |
| | | } |
| | | |
| | | if len(params.DeliveryList) == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "发货列表不能为空") |
| | | return |
| | |
| | | WaybillNumber: params.WaybillNumber, |
| | | } |
| | | |
| | | err := models.WithTransaction(func(db *gorm.DB) error { |
| | | err := models.NewOutsourcingOrderDeliverySearch().SetOrm(db).Create(delivery) |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | err = models.NewOutsourcingOrderDeliverySearch().SetOrm(db).Create(delivery) |
| | | if err != nil { |
| | | return err |
| | | } |
| | |
| | | OutsourcingOrderDeliveryID: delivery.ID, |
| | | OutsourcingOrderProductID: v.OutsourcingOrderProductID, |
| | | SendAmount: v.SendAmount, |
| | | IsReceived: 2, |
| | | }) |
| | | } |
| | | return models.NewOutsourcingOrderDeliveryDetailsSearch().SetOrm(db).CreateBatch(items) |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | |
| | | _, err := models.NewOutsourcingOrderSearch().SetEnterpriseID(jwt.GetCompanyID(c)).SetID(params.OutsourcingOrderID).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "订单不存在") |
| | | return |
| | | } |
| | | |
| | | list, err := models.NewOutsourcingOrderDeliveryDetailsSearch(). |
| | | SetOutsourcingOrderID(params.OutsourcingOrderID). |
| | | SetPreload(true). |
| | |
| | | // @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 |
| | |
| | | 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) |
| | | } |