zhangqian
2023-08-29 cd6940f07750c1e2cd3a5c0eeafa6cc0309ef2f6
新增和查询采购类型
2个文件已添加
8个文件已修改
861 ■■■■■ 已修改文件
api/v1/purchase/purchase.go 82 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 250 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 250 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 163 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/purchase/purchase.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/purchase/purchase_type.go 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/purchase/request/purchase.go 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/purchase/request/purchase_type.go 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/purchase/purchase.go 15 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/purchase/purchase.go 50 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/purchase/purchase.go
@@ -2,12 +2,16 @@
import (
    "github.com/gin-gonic/gin"
    "github.com/mitchellh/mapstructure"
    "go.uber.org/zap"
    "gorm.io/gorm"
    "srm/global"
    "srm/model/common/request"
    "srm/model/common/response"
    "srm/model/purchase"
    purchaserequest "srm/model/purchase/request"
    "strconv"
    "strings"
    //"srm/model/purchase"
@@ -35,8 +39,21 @@
        response.FailWithMessage(err.Error(), c)
        return
    }
    err = service.NewPurchaseService().CreatePurchase(params)
    var purchaseRecord purchase.Purchase
    if err := mapstructure.Decode(params.Purchase, &purchaseRecord); err != nil {
        response.FailWithMessage(err.Error(), c)
        return
    }
    purchaseRecord.ID = 0
    err = service.NewPurchaseService().CreatePurchase(&purchaseRecord, params.ProductList)
    if err != nil {
        if err == gorm.ErrDuplicatedKey || strings.Contains(err.Error(), "Duplicate entry") {
            response.FailWithMessage("编号重复", c)
            return
        }
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
        response.FailWithMessage("创建失败", c)
        return
@@ -74,22 +91,24 @@
// @Security  ApiKeyAuth
// @accept    application/json
// @Produce   application/json
// @Param     data  body      purchaserequest.AddPurchase            true  "采购单ID, 采购单信息"
// @Param     data  body      purchaserequest.UpdatePurchase            true  "采购单ID, 采购单信息"
// @Success   200   {object}  response.Response{msg=string}  "更新采购单信息"
// @Router    /purchase/purchase [put]
func (e *PurchaseApi) UpdatePurchase(c *gin.Context) {
    var params purchaserequest.AddPurchase
    var params purchaserequest.UpdatePurchase
    err := c.ShouldBindJSON(&params)
    if err != nil {
        response.FailWithMessage(err.Error(), c)
        return
    }
    err = utils.Verify(params.Purchase.GVA_MODEL, utils.IdVerify)
    if err != nil {
    var purchaseRecord purchase.Purchase
    if err := mapstructure.Decode(params.Purchase, &purchaseRecord); err != nil {
        response.FailWithMessage(err.Error(), c)
        return
    }
    err = service.NewPurchaseService().UpdatePurchase(&params)
    err = service.NewPurchaseService().UpdatePurchase(&purchaseRecord, params.ProductList)
    if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
        response.FailWithMessage("更新失败", c)
@@ -186,3 +205,54 @@
    }
    response.OkWithMessage("更新成功", c)
}
// SavePurchaseType
// @Tags      Purchase
// @Summary   创建采购类型
// @Security  ApiKeyAuth
// @accept    application/json
// @Produce   application/json
// @Param     data  body     []purchaserequest.PurchaseType   true  "采购类型list"
// @Success   200   {object}  response.Response{msg=string}  "创建采购类型"
// @Router    /purchase/purchaseType [post]
func (e *PurchaseApi) SavePurchaseType(c *gin.Context) {
    var params []*purchaserequest.PurchaseType
    err := c.ShouldBindJSON(&params)
    if err != nil {
        response.FailWithMessage(err.Error(), c)
        return
    }
    purchaseTypeList := make([]*purchase.PurchaseType, 0, len(params))
    if err := mapstructure.Decode(params, &purchaseTypeList); err != nil {
        response.FailWithMessage(err.Error(), c)
        return
    }
    err = service.NewPurchaseService().SavePurchaseType(purchaseTypeList)
    if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
        response.FailWithMessage("创建失败", c)
        return
    }
    response.OkWithMessage("创建成功", c)
}
// GetPurchaseTypeList
// @Tags      Purchase
// @Summary   获取采购类型列表
// @Security  ApiKeyAuth
// @accept    application/json
// @Produce   application/json
// @Success   200   {object}  response.Response{data=[]purchase.PurchaseType,msg=string}  "获取采购类型列表"
// @Router    /purchase/purchaseTypeList [get]
func (e *PurchaseApi) GetPurchaseTypeList(c *gin.Context) {
    list, err := service.NewPurchaseService().GetPurchaseTypeList()
    if err != nil {
        global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败"+err.Error(), c)
        return
    }
    response.OkWithDetailed(list, "获取成功", c)
}
docs/docs.go
@@ -4490,7 +4490,7 @@
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/purchaserequest.AddPurchase"
                            "$ref": "#/definitions/purchaserequest.UpdatePurchase"
                        }
                    }
                ],
@@ -4711,6 +4711,104 @@
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.PageResult"
                                        },
                                        "msg": {
                                            "type": "string"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/purchase/purchaseType": {
            "post": {
                "security": [
                    {
                        "ApiKeyAuth": []
                    }
                ],
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Purchase"
                ],
                "summary": "创建采购类型",
                "parameters": [
                    {
                        "description": "采购类型list",
                        "name": "data",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/purchaserequest.PurchaseType"
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "创建采购类型",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/response.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "msg": {
                                            "type": "string"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/purchase/purchaseTypeList": {
            "get": {
                "security": [
                    {
                        "ApiKeyAuth": []
                    }
                ],
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Purchase"
                ],
                "summary": "获取采购类型列表",
                "responses": {
                    "200": {
                        "description": "获取采购类型列表",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/response.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/purchase.PurchaseType"
                                            }
                                        },
                                        "msg": {
                                            "type": "string"
@@ -8123,6 +8221,27 @@
                }
            }
        },
        "purchase.OrderStatus": {
            "type": "integer",
            "enum": [
                1,
                2,
                3,
                4
            ],
            "x-enum-comments": {
                "OrderStatusCompleted": "已完成",
                "OrderStatusConfirmed": "已下单",
                "OrderStatusReceived": "已到货",
                "OrderStatusStored": "已入库"
            },
            "x-enum-varnames": [
                "OrderStatusConfirmed",
                "OrderStatusReceived",
                "OrderStatusStored",
                "OrderStatusCompleted"
            ]
        },
        "purchase.Purchase": {
            "type": "object",
            "properties": {
@@ -8142,9 +8261,16 @@
                    "description": "采购名称",
                    "type": "string"
                },
                "number": {
                    "description": "采购编号",
                    "type": "string"
                },
                "phone": {
                    "description": "联系人电话",
                    "type": "string"
                },
                "purchaseType": {
                    "$ref": "#/definitions/purchase.PurchaseType"
                },
                "purchaseTypeId": {
                    "description": "采购类型id",
@@ -8157,6 +8283,17 @@
                "signingDate": {
                    "description": "签约日期",
                    "type": "string"
                },
                "status": {
                    "description": "状态",
                    "allOf": [
                        {
                            "$ref": "#/definitions/purchase.OrderStatus"
                        }
                    ]
                },
                "supplier": {
                    "$ref": "#/definitions/test.Supplier"
                },
                "supplierId": {
                    "description": "供应商id",
@@ -8197,6 +8334,27 @@
                }
            }
        },
        "purchase.PurchaseType": {
            "type": "object",
            "properties": {
                "id": {
                    "description": "主键ID",
                    "type": "integer"
                },
                "name": {
                    "description": "采购类型",
                    "type": "string"
                },
                "pin": {
                    "description": "是否置顶",
                    "type": "boolean"
                },
                "sort": {
                    "description": "排序",
                    "type": "integer"
                }
            }
        },
        "purchaserequest.AddPurchase": {
            "type": "object",
            "properties": {
@@ -8207,7 +8365,95 @@
                    }
                },
                "purchase": {
                    "$ref": "#/definitions/purchase.Purchase"
                    "$ref": "#/definitions/purchaserequest.Purchase"
                }
            }
        },
        "purchaserequest.Purchase": {
            "type": "object",
            "properties": {
                "contact": {
                    "description": "联系人",
                    "type": "string"
                },
                "deliveryDate": {
                    "description": "交付日期",
                    "type": "string"
                },
                "id": {
                    "description": "主键ID",
                    "type": "integer"
                },
                "name": {
                    "description": "采购名称",
                    "type": "string"
                },
                "number": {
                    "description": "采购编号",
                    "type": "string"
                },
                "phone": {
                    "description": "联系人电话",
                    "type": "string"
                },
                "purchaseTypeId": {
                    "description": "采购类型id",
                    "type": "integer"
                },
                "remark": {
                    "description": "备注",
                    "type": "string"
                },
                "signingDate": {
                    "description": "签约日期",
                    "type": "string"
                },
                "status": {
                    "description": "状态",
                    "allOf": [
                        {
                            "$ref": "#/definitions/purchase.OrderStatus"
                        }
                    ]
                },
                "supplierId": {
                    "description": "供应商id",
                    "type": "integer"
                }
            }
        },
        "purchaserequest.PurchaseType": {
            "type": "object",
            "properties": {
                "id": {
                    "description": "主键ID",
                    "type": "integer"
                },
                "name": {
                    "description": "采购类型",
                    "type": "string"
                },
                "pin": {
                    "description": "是否置顶",
                    "type": "boolean"
                },
                "sort": {
                    "description": "排序",
                    "type": "integer"
                }
            }
        },
        "purchaserequest.UpdatePurchase": {
            "type": "object",
            "properties": {
                "productList": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/purchase.PurchaseProducts"
                    }
                },
                "purchase": {
                    "$ref": "#/definitions/purchaserequest.Purchase"
                }
            }
        },
docs/swagger.json
@@ -4481,7 +4481,7 @@
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/purchaserequest.AddPurchase"
                            "$ref": "#/definitions/purchaserequest.UpdatePurchase"
                        }
                    }
                ],
@@ -4702,6 +4702,104 @@
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.PageResult"
                                        },
                                        "msg": {
                                            "type": "string"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/purchase/purchaseType": {
            "post": {
                "security": [
                    {
                        "ApiKeyAuth": []
                    }
                ],
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Purchase"
                ],
                "summary": "创建采购类型",
                "parameters": [
                    {
                        "description": "采购类型list",
                        "name": "data",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/purchaserequest.PurchaseType"
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "创建采购类型",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/response.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "msg": {
                                            "type": "string"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/purchase/purchaseTypeList": {
            "get": {
                "security": [
                    {
                        "ApiKeyAuth": []
                    }
                ],
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Purchase"
                ],
                "summary": "获取采购类型列表",
                "responses": {
                    "200": {
                        "description": "获取采购类型列表",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/response.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/purchase.PurchaseType"
                                            }
                                        },
                                        "msg": {
                                            "type": "string"
@@ -8114,6 +8212,27 @@
                }
            }
        },
        "purchase.OrderStatus": {
            "type": "integer",
            "enum": [
                1,
                2,
                3,
                4
            ],
            "x-enum-comments": {
                "OrderStatusCompleted": "已完成",
                "OrderStatusConfirmed": "已下单",
                "OrderStatusReceived": "已到货",
                "OrderStatusStored": "已入库"
            },
            "x-enum-varnames": [
                "OrderStatusConfirmed",
                "OrderStatusReceived",
                "OrderStatusStored",
                "OrderStatusCompleted"
            ]
        },
        "purchase.Purchase": {
            "type": "object",
            "properties": {
@@ -8133,9 +8252,16 @@
                    "description": "采购名称",
                    "type": "string"
                },
                "number": {
                    "description": "采购编号",
                    "type": "string"
                },
                "phone": {
                    "description": "联系人电话",
                    "type": "string"
                },
                "purchaseType": {
                    "$ref": "#/definitions/purchase.PurchaseType"
                },
                "purchaseTypeId": {
                    "description": "采购类型id",
@@ -8148,6 +8274,17 @@
                "signingDate": {
                    "description": "签约日期",
                    "type": "string"
                },
                "status": {
                    "description": "状态",
                    "allOf": [
                        {
                            "$ref": "#/definitions/purchase.OrderStatus"
                        }
                    ]
                },
                "supplier": {
                    "$ref": "#/definitions/test.Supplier"
                },
                "supplierId": {
                    "description": "供应商id",
@@ -8188,6 +8325,27 @@
                }
            }
        },
        "purchase.PurchaseType": {
            "type": "object",
            "properties": {
                "id": {
                    "description": "主键ID",
                    "type": "integer"
                },
                "name": {
                    "description": "采购类型",
                    "type": "string"
                },
                "pin": {
                    "description": "是否置顶",
                    "type": "boolean"
                },
                "sort": {
                    "description": "排序",
                    "type": "integer"
                }
            }
        },
        "purchaserequest.AddPurchase": {
            "type": "object",
            "properties": {
@@ -8198,7 +8356,95 @@
                    }
                },
                "purchase": {
                    "$ref": "#/definitions/purchase.Purchase"
                    "$ref": "#/definitions/purchaserequest.Purchase"
                }
            }
        },
        "purchaserequest.Purchase": {
            "type": "object",
            "properties": {
                "contact": {
                    "description": "联系人",
                    "type": "string"
                },
                "deliveryDate": {
                    "description": "交付日期",
                    "type": "string"
                },
                "id": {
                    "description": "主键ID",
                    "type": "integer"
                },
                "name": {
                    "description": "采购名称",
                    "type": "string"
                },
                "number": {
                    "description": "采购编号",
                    "type": "string"
                },
                "phone": {
                    "description": "联系人电话",
                    "type": "string"
                },
                "purchaseTypeId": {
                    "description": "采购类型id",
                    "type": "integer"
                },
                "remark": {
                    "description": "备注",
                    "type": "string"
                },
                "signingDate": {
                    "description": "签约日期",
                    "type": "string"
                },
                "status": {
                    "description": "状态",
                    "allOf": [
                        {
                            "$ref": "#/definitions/purchase.OrderStatus"
                        }
                    ]
                },
                "supplierId": {
                    "description": "供应商id",
                    "type": "integer"
                }
            }
        },
        "purchaserequest.PurchaseType": {
            "type": "object",
            "properties": {
                "id": {
                    "description": "主键ID",
                    "type": "integer"
                },
                "name": {
                    "description": "采购类型",
                    "type": "string"
                },
                "pin": {
                    "description": "是否置顶",
                    "type": "boolean"
                },
                "sort": {
                    "description": "排序",
                    "type": "integer"
                }
            }
        },
        "purchaserequest.UpdatePurchase": {
            "type": "object",
            "properties": {
                "productList": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/purchase.PurchaseProducts"
                    }
                },
                "purchase": {
                    "$ref": "#/definitions/purchaserequest.Purchase"
                }
            }
        },
docs/swagger.yaml
@@ -665,6 +665,23 @@
        description: 文件地址
        type: string
    type: object
  purchase.OrderStatus:
    enum:
    - 1
    - 2
    - 3
    - 4
    type: integer
    x-enum-comments:
      OrderStatusCompleted: 已完成
      OrderStatusConfirmed: 已下单
      OrderStatusReceived: 已到货
      OrderStatusStored: 已入库
    x-enum-varnames:
    - OrderStatusConfirmed
    - OrderStatusReceived
    - OrderStatusStored
    - OrderStatusCompleted
  purchase.Purchase:
    properties:
      contact:
@@ -679,9 +696,14 @@
      name:
        description: 采购名称
        type: string
      number:
        description: 采购编号
        type: string
      phone:
        description: 联系人电话
        type: string
      purchaseType:
        $ref: '#/definitions/purchase.PurchaseType'
      purchaseTypeId:
        description: 采购类型id
        type: integer
@@ -691,6 +713,12 @@
      signingDate:
        description: 签约日期
        type: string
      status:
        allOf:
        - $ref: '#/definitions/purchase.OrderStatus'
        description: 状态
      supplier:
        $ref: '#/definitions/test.Supplier'
      supplierId:
        description: 供应商id
        type: integer
@@ -719,6 +747,21 @@
        description: 采购总价
        type: number
    type: object
  purchase.PurchaseType:
    properties:
      id:
        description: 主键ID
        type: integer
      name:
        description: 采购类型
        type: string
      pin:
        description: 是否置顶
        type: boolean
      sort:
        description: 排序
        type: integer
    type: object
  purchaserequest.AddPurchase:
    properties:
      productList:
@@ -726,7 +769,68 @@
          $ref: '#/definitions/purchase.PurchaseProducts'
        type: array
      purchase:
        $ref: '#/definitions/purchase.Purchase'
        $ref: '#/definitions/purchaserequest.Purchase'
    type: object
  purchaserequest.Purchase:
    properties:
      contact:
        description: 联系人
        type: string
      deliveryDate:
        description: 交付日期
        type: string
      id:
        description: 主键ID
        type: integer
      name:
        description: 采购名称
        type: string
      number:
        description: 采购编号
        type: string
      phone:
        description: 联系人电话
        type: string
      purchaseTypeId:
        description: 采购类型id
        type: integer
      remark:
        description: 备注
        type: string
      signingDate:
        description: 签约日期
        type: string
      status:
        allOf:
        - $ref: '#/definitions/purchase.OrderStatus'
        description: 状态
      supplierId:
        description: 供应商id
        type: integer
    type: object
  purchaserequest.PurchaseType:
    properties:
      id:
        description: 主键ID
        type: integer
      name:
        description: 采购类型
        type: string
      pin:
        description: 是否置顶
        type: boolean
      sort:
        description: 排序
        type: integer
    type: object
  purchaserequest.UpdatePurchase:
    properties:
      productList:
        items:
          $ref: '#/definitions/purchase.PurchaseProducts'
        type: array
      purchase:
        $ref: '#/definitions/purchaserequest.Purchase'
    type: object
  request.AddMenuAuthorityInfo:
    properties:
@@ -4308,7 +4412,7 @@
        name: data
        required: true
        schema:
          $ref: '#/definitions/purchaserequest.AddPurchase'
          $ref: '#/definitions/purchaserequest.UpdatePurchase'
      produces:
      - application/json
      responses:
@@ -4417,6 +4521,61 @@
      summary: 分页获取采购单列表
      tags:
      - Purchase
  /purchase/purchaseType:
    post:
      consumes:
      - application/json
      parameters:
      - description: 采购类型list
        in: body
        name: data
        required: true
        schema:
          items:
            $ref: '#/definitions/purchaserequest.PurchaseType'
          type: array
      produces:
      - application/json
      responses:
        "200":
          description: 创建采购类型
          schema:
            allOf:
            - $ref: '#/definitions/response.Response'
            - properties:
                msg:
                  type: string
              type: object
      security:
      - ApiKeyAuth: []
      summary: 创建采购类型
      tags:
      - Purchase
  /purchase/purchaseTypeList:
    get:
      consumes:
      - application/json
      produces:
      - application/json
      responses:
        "200":
          description: 获取采购类型列表
          schema:
            allOf:
            - $ref: '#/definitions/response.Response'
            - properties:
                data:
                  items:
                    $ref: '#/definitions/purchase.PurchaseType'
                  type: array
                msg:
                  type: string
              type: object
      security:
      - ApiKeyAuth: []
      summary: 获取采购类型列表
      tags:
      - Purchase
  /purchase/submit/{id}:
    post:
      consumes:
model/purchase/purchase.go
@@ -8,9 +8,10 @@
type Purchase struct {
    global.GVA_MODEL
    PurchaseTypeId int           `json:"purchaseTypeId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:采购类型id"` // 采购类型id
    SupplierId     int           `json:"supplierId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:供应商id"`        // 供应商id
    PurchaseType   PurchaseType  `json:"purchaseType" gorm:"foreignKey:PurchaseTypeId"`
    SupplierId     int           `json:"supplierId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:供应商id"` // 供应商id
    Supplier       test.Supplier `json:"supplier" gorm:"foreignKey:SupplierId"`
    Number         string        `json:"number" form:"number" gorm:"type:varchar(255);not null;default '';comment:采购编号"`             // 采购编号
    Number         string        `json:"number" form:"number" gorm:"unique;type:varchar(255);not null;default '';comment:采购编号"`      // 采购编号
    Name           string        `json:"name" form:"name" gorm:"type:varchar(255);not null;default '';comment:采购名称"`                 // 采购名称
    Contact        string        `json:"contact" form:"contact" gorm:"type:varchar(255);not null;default '';comment:联系人"`            // 联系人
    Phone          string        `json:"phone" form:"phone" gorm:"type:varchar(255);not null;default '';comment:联系人电话"`              // 联系人电话
model/purchase/purchase_type.go
New file
@@ -0,0 +1,13 @@
package purchase
import (
    "srm/global"
)
type PurchaseType struct {
    global.GVA_MODEL
    ID   uint   `gorm:"primarykey"`                                                                 // 主键ID
    Name string `json:"name" form:"name" gorm:"type:varchar(255);not null;default '';comment:采购类型"` // 采购类型
    Sort int    `json:"sort" form:"sort" gorm:"type:int(11);not null;default 0;comment:排序"`         // 排序
    Pin  bool   `json:"pin" form:"pin" gorm:"type:tinyint(1);not null;default 0;comment:采购名称"`      // 是否置顶
}
model/purchase/request/purchase.go
@@ -13,6 +13,25 @@
}
type AddPurchase struct {
    Purchase    purchase.Purchase
    Purchase    Purchase                     `json:"purchase"`
    ProductList []*purchase.PurchaseProducts `json:"productList"`
}
type UpdatePurchase struct {
    Purchase    Purchase                     `json:"purchase"`
    ProductList []*purchase.PurchaseProducts `json:"productList"`
}
type Purchase struct {
    ID             uint                 `gorm:"primarykey"`                                                                                 // 主键ID
    PurchaseTypeId int                  `json:"purchaseTypeId" form:"purchaseType" gorm:"type:int(11);not null;default 0;comment:采购类型id"`   // 采购类型id
    SupplierId     int                  `json:"supplierId" form:"supplierId" gorm:"type:int(11);not null;default 0;comment:供应商id"`          // 供应商id
    Number         string               `json:"number" form:"number" gorm:"unique;type:varchar(255);not null;default '';comment:采购编号"`      // 采购编号
    Name           string               `json:"name" form:"name" gorm:"type:varchar(255);not null;default '';comment:采购名称"`                 // 采购名称
    Contact        string               `json:"contact" form:"contact" gorm:"type:varchar(255);not null;default '';comment:联系人"`            // 联系人
    Phone          string               `json:"phone" form:"phone" gorm:"type:varchar(255);not null;default '';comment:联系人电话"`              // 联系人电话
    SigningDate    string               `json:"signingDate" form:"signingDate" gorm:"type:varchar(255);not null;default '';comment:签约日期"`   // 签约日期
    DeliveryDate   string               `json:"deliveryDate" form:"deliveryDate" gorm:"type:varchar(255);not null;default '';comment:交付日期"` //交付日期
    Remark         string               `json:"remark" form:"remark" gorm:"type:varchar(1000);not null;default '';comment:备注"`              //备注
    Status         purchase.OrderStatus `json:"status" form:"status" gorm:"type:tinyint(1);not null;default 0;comment:状态"`                  //状态
}
model/purchase/request/purchase_type.go
New file
@@ -0,0 +1,12 @@
package purchaserequest
type SavePurchaseType struct {
    List []*PurchaseType `json:"purchase"`
}
type PurchaseType struct {
    ID   uint   `gorm:"primarykey"`                                                                 // 主键ID
    Name string `json:"name" form:"name" gorm:"type:varchar(255);not null;default '';comment:采购类型"` // 采购类型
    Sort int    `json:"sort" form:"sort" gorm:"type:int(11);not null;default 0;comment:排序"`         // 排序
    Pin  bool   `json:"pin" form:"pin" gorm:"type:tinyint(1);not null;default 0;comment:采购名称"`      // 是否置顶
}
router/purchase/purchase.go
@@ -7,14 +7,15 @@
func InitPurchaseRouter(Router *gin.RouterGroup) {
    purchaseRouter := Router.Group("purchase")
    purchaseRouterWithoutRecord := Router.Group("purchase")
    PurchaseApi := purchase.PurchaseApi{}
    {
        purchaseRouter.POST("purchase", PurchaseApi.CreatePurchase)                  // 创建采购单
        purchaseRouter.PUT("purchase", PurchaseApi.UpdatePurchase)                   // 更新采购单
        purchaseRouter.DELETE("purchase/:id", PurchaseApi.DeletePurchase)            // 删除采购单
        purchaseRouterWithoutRecord.GET("purchase/:id", PurchaseApi.GetPurchase)     // 获取单一采购单信息
        purchaseRouterWithoutRecord.GET("purchaseList", PurchaseApi.GetPurchaseList) // 获取采购单列表
        purchaseRouterWithoutRecord.POST("submit/:id", PurchaseApi.Submit)           // 提交采购单
        purchaseRouter.POST("purchase", PurchaseApi.CreatePurchase)             // 创建采购单
        purchaseRouter.PUT("purchase", PurchaseApi.UpdatePurchase)              // 更新采购单
        purchaseRouter.DELETE("purchase/:id", PurchaseApi.DeletePurchase)       // 删除采购单
        purchaseRouter.GET("purchase/:id", PurchaseApi.GetPurchase)             // 获取单一采购单信息
        purchaseRouter.GET("purchaseList", PurchaseApi.GetPurchaseList)         // 获取采购单列表
        purchaseRouter.POST("submit/:id", PurchaseApi.Submit)                   // 提交采购单
        purchaseRouter.POST("purchaseType", PurchaseApi.SavePurchaseType)       // 保存采购类型
        purchaseRouter.GET("purchaseTypeList", PurchaseApi.GetPurchaseTypeList) // 查询采购类型
    }
}
service/purchase/purchase.go
@@ -7,7 +7,6 @@
    "srm/global"
    "srm/model/common/request"
    "srm/model/purchase"
    purchaserequest "srm/model/purchase/request"
    "srm/proto/qualityinspect"
    "srm/service/test"
)
@@ -23,16 +22,16 @@
//@param: params *purchaserequest.AddPurchase
//@return: err error
func (slf *PurchaseService) CreatePurchase(params purchaserequest.AddPurchase) (err error) {
func (slf *PurchaseService) CreatePurchase(params *purchase.Purchase, productList []*purchase.PurchaseProducts) (err error) {
    err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
        err = global.GVA_DB.Create(&params.Purchase).Error
        err = tx.Create(&params).Error
        if err != nil {
            return err
        }
        for _, product := range params.ProductList {
            product.PurchaseId = cast.ToInt(params.Purchase.ID)
        for _, product := range productList {
            product.PurchaseId = cast.ToInt(params.ID)
        }
        return global.GVA_DB.Create(params.ProductList).Error
        return tx.Create(productList).Error
    })
    return err
@@ -45,11 +44,11 @@
func (slf *PurchaseService) DeletePurchase(id uint) (err error) {
    err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
        err = global.GVA_DB.Where("id = ?", id).Delete(&purchase.Purchase{}).Error
        err = tx.Where("id = ?", id).Delete(&purchase.Purchase{}).Error
        if err != nil {
            return err
        }
        return global.GVA_DB.Where("purchase_id = ?", id).Delete(&purchase.PurchaseProducts{}).Error
        return tx.Where("purchase_id = ?", id).Delete(&purchase.PurchaseProducts{}).Error
    })
    return err
}
@@ -59,21 +58,21 @@
//@param: params *purchaserequest.AddPurchase
//@return: err error
func (slf *PurchaseService) UpdatePurchase(params *purchaserequest.AddPurchase) (err error) {
func (slf *PurchaseService) UpdatePurchase(params *purchase.Purchase, productList []*purchase.PurchaseProducts) (err error) {
    err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
        err = global.GVA_DB.Updates(params.Purchase).Error
        err = tx.Where("id = ?", params.ID).Updates(params).Error
        if err != nil {
            return err
        }
        err = global.GVA_DB.Where("purchase_id = ?", params.Purchase.ID).Delete(&purchase.PurchaseProducts{}).Error
        err = tx.Where("purchase_id = ?", params.ID).Delete(&purchase.PurchaseProducts{}).Error
        if err != nil {
            return err
        }
        for _, product := range params.ProductList {
        for _, product := range productList {
            product.ID = 0
            product.PurchaseId = cast.ToInt(params.Purchase.ID)
            product.PurchaseId = cast.ToInt(params.ID)
        }
        return global.GVA_DB.Create(params.ProductList).Error
        return tx.Create(productList).Error
    })
    return err
}
@@ -147,7 +146,7 @@
        targetStatus = purchase.OrderStatusCompleted
    }
    err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
        err = global.GVA_DB.Where("id = ?", id).Model(&purchase.Purchase{}).Updates(map[string]interface{}{"status": targetStatus}).Error
        err = tx.Where("id = ?", id).Model(&purchase.Purchase{}).Updates(map[string]interface{}{"status": targetStatus}).Error
        if err != nil {
            return err
        }
@@ -200,3 +199,24 @@
    _, err = qualityinspect.NewQualityInspectServiceClient(qualityinspect.Conn).SendPurchaseInspect(context.Background(), &inspectRequest)
    return err
}
func (slf *PurchaseService) SavePurchaseType(list []*purchase.PurchaseType) (err error) {
    err = global.GVA_DB.Transaction(func(tx *gorm.DB) error {
        err = tx.Where("1 = ?", 1).Delete(&purchase.PurchaseType{}).Error
        if err != nil {
            return err
        }
        for _, item := range list {
            item.ID = 0
        }
        return tx.Create(list).Error
    })
    return err
}
func (slf *PurchaseService) GetPurchaseTypeList() (list []*purchase.PurchaseType, err error) {
    db := global.GVA_DB.Model(&purchase.PurchaseType{})
    list = make([]*purchase.PurchaseType, 0)
    err = db.Order("pin desc, sort desc, id asc").Find(&list).Error
    return list, err
}