add
wangpengfei
2023-07-12 a32c022b30a30982358464ba0f68aab0b2a103c2
add

contract 合同管理
add, Delete, update, list
5个文件已添加
10个文件已修改
726 ■■■■■ 已修改文件
api/v1/contract.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 205 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 205 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 129 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
logs/aps-admin.err.log 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/contract.go 76 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/contract.go 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/response/response.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pkg/ecode/code.go 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/contract.go 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/index.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/contract.go 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/contract.go
New file
@@ -0,0 +1 @@
package v1
api/v1/index.go
@@ -37,6 +37,7 @@
    SalesDetailsApi
    SalesReturnApi
    SalesRefundApi
    ContractApi
}
var ApiGroup = new(Group)
@@ -73,4 +74,5 @@
    salesDetailsService      = service.ServiceGroup.SalesDetailsService
    salesReturnService       = service.ServiceGroup.SalesReturnService
    salesRefundService       = service.ServiceGroup.SalesRefundService
    contractService          = service.ServiceGroup.ContractService
)
docs/docs.go
@@ -952,6 +952,125 @@
                }
            }
        },
        "/api/contract/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Contract"
                ],
                "summary": "添加合同",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddContract"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/contract/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Contract"
                ],
                "summary": "删除合同",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/contract/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Contract"
                ],
                "summary": "获取合同列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.ContractResponse"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api/contract/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Contract"
                ],
                "summary": "更新合同",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateContract"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/country/add": {
            "post": {
                "produces": [
@@ -4272,6 +4391,32 @@
                }
            }
        },
        "model.Contract": {
            "type": "object",
            "properties": {
                "clientId": {
                    "type": "integer"
                },
                "file": {
                    "type": "string"
                },
                "id": {
                    "type": "integer"
                },
                "memberId": {
                    "type": "integer"
                },
                "number": {
                    "type": "string"
                },
                "quotationId": {
                    "type": "integer"
                },
                "statusId": {
                    "type": "integer"
                }
            }
        },
        "model.Country": {
            "type": "object",
            "properties": {
@@ -5135,6 +5280,29 @@
                "wechat": {
                    "description": "微信号",
                    "type": "string"
                }
            }
        },
        "request.AddContract": {
            "type": "object",
            "properties": {
                "client_id": {
                    "type": "integer"
                },
                "file": {
                    "type": "string"
                },
                "member_id": {
                    "type": "integer"
                },
                "number": {
                    "type": "string"
                },
                "quotation_id": {
                    "type": "integer"
                },
                "status_id": {
                    "type": "integer"
                }
            }
        },
@@ -6254,6 +6422,32 @@
                }
            }
        },
        "request.UpdateContract": {
            "type": "object",
            "properties": {
                "client_id": {
                    "type": "integer"
                },
                "file": {
                    "type": "string"
                },
                "id": {
                    "type": "integer"
                },
                "member_id": {
                    "type": "integer"
                },
                "number": {
                    "type": "string"
                },
                "quotation_id": {
                    "type": "integer"
                },
                "status_id": {
                    "type": "integer"
                }
            }
        },
        "request.UpdateCountry": {
            "type": "object",
            "properties": {
@@ -6986,6 +7180,17 @@
                }
            }
        },
        "response.ContractResponse": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.Contract"
                    }
                }
            }
        },
        "response.CountryResponse": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -940,6 +940,125 @@
                }
            }
        },
        "/api/contract/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Contract"
                ],
                "summary": "添加合同",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddContract"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/contract/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Contract"
                ],
                "summary": "删除合同",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/contract/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Contract"
                ],
                "summary": "获取合同列表",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/contextx.Response"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/definitions/response.ContractResponse"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api/contract/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "Contract"
                ],
                "summary": "更新合同",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateContract"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/country/add": {
            "post": {
                "produces": [
@@ -4260,6 +4379,32 @@
                }
            }
        },
        "model.Contract": {
            "type": "object",
            "properties": {
                "clientId": {
                    "type": "integer"
                },
                "file": {
                    "type": "string"
                },
                "id": {
                    "type": "integer"
                },
                "memberId": {
                    "type": "integer"
                },
                "number": {
                    "type": "string"
                },
                "quotationId": {
                    "type": "integer"
                },
                "statusId": {
                    "type": "integer"
                }
            }
        },
        "model.Country": {
            "type": "object",
            "properties": {
@@ -5123,6 +5268,29 @@
                "wechat": {
                    "description": "微信号",
                    "type": "string"
                }
            }
        },
        "request.AddContract": {
            "type": "object",
            "properties": {
                "client_id": {
                    "type": "integer"
                },
                "file": {
                    "type": "string"
                },
                "member_id": {
                    "type": "integer"
                },
                "number": {
                    "type": "string"
                },
                "quotation_id": {
                    "type": "integer"
                },
                "status_id": {
                    "type": "integer"
                }
            }
        },
@@ -6242,6 +6410,32 @@
                }
            }
        },
        "request.UpdateContract": {
            "type": "object",
            "properties": {
                "client_id": {
                    "type": "integer"
                },
                "file": {
                    "type": "string"
                },
                "id": {
                    "type": "integer"
                },
                "member_id": {
                    "type": "integer"
                },
                "number": {
                    "type": "string"
                },
                "quotation_id": {
                    "type": "integer"
                },
                "status_id": {
                    "type": "integer"
                }
            }
        },
        "request.UpdateCountry": {
            "type": "object",
            "properties": {
@@ -6974,6 +7168,17 @@
                }
            }
        },
        "response.ContractResponse": {
            "type": "object",
            "properties": {
                "list": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/model.Contract"
                    }
                }
            }
        },
        "response.CountryResponse": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -266,6 +266,23 @@
      wechat:
        type: string
    type: object
  model.Contract:
    properties:
      clientId:
        type: integer
      file:
        type: string
      id:
        type: integer
      memberId:
        type: integer
      number:
        type: string
      quotationId:
        type: integer
      statusId:
        type: integer
    type: object
  model.Country:
    properties:
      id:
@@ -846,6 +863,21 @@
      wechat:
        description: 微信号
        type: string
    type: object
  request.AddContract:
    properties:
      client_id:
        type: integer
      file:
        type: string
      member_id:
        type: integer
      number:
        type: string
      quotation_id:
        type: integer
      status_id:
        type: integer
    type: object
  request.AddCountry:
    properties:
@@ -1607,6 +1639,23 @@
        description: 微信号
        type: string
    type: object
  request.UpdateContract:
    properties:
      client_id:
        type: integer
      file:
        type: string
      id:
        type: integer
      member_id:
        type: integer
      number:
        type: string
      quotation_id:
        type: integer
      status_id:
        type: integer
    type: object
  request.UpdateCountry:
    properties:
      id:
@@ -2088,6 +2137,13 @@
      list:
        items:
          $ref: '#/definitions/model.ContactDetail'
        type: array
    type: object
  response.ContractResponse:
    properties:
      list:
        items:
          $ref: '#/definitions/model.Contract'
        type: array
    type: object
  response.CountryResponse:
@@ -2821,6 +2877,79 @@
      summary: 更新联系人
      tags:
      - Contact
  /api/contract/add:
    post:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.AddContract'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 添加合同
      tags:
      - Contract
  /api/contract/delete/{id}:
    delete:
      parameters:
      - description: 查询参数
        in: path
        name: id
        required: true
        type: integer
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 删除合同
      tags:
      - Contract
  /api/contract/list:
    get:
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            allOf:
            - $ref: '#/definitions/contextx.Response'
            - properties:
                data:
                  $ref: '#/definitions/response.ContractResponse'
              type: object
      summary: 获取合同列表
      tags:
      - Contract
  /api/contract/update:
    put:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.UpdateContract'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 更新合同
      tags:
      - Contract
  /api/country/add:
    post:
      parameters:
logs/aps-admin.err.log
@@ -345,3 +345,4 @@
[2023-07-11 11:33:55]    [error]    [gorm.io/gorm/migrator.Migrator.AutoMigrate:104]    failed to parse value model.SubOrder{Id:0, ClientId:0, MemberId:0, MasterOrderId:0, Number:"", ProductOrder:model.ProductOrder{Id:0, Products:[]model.Product(nil)}, Model:gorm.Model{ID:0x0, CreatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), UpdatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), DeletedAt:gorm.DeletedAt{Time:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Valid:false}}}, got error invalid field found for struct aps_crm/model.SubOrder's field ProductOrder: define a valid foreign key for relations or implement the Valuer/Scanner interface
[2023-07-11 11:33:55]    [error]    [gorm.io/gorm/migrator.Migrator.CreateTable:198]    failed to parse value model.SubOrder{Id:0, ClientId:0, MemberId:0, MasterOrderId:0, Number:"", ProductOrder:model.ProductOrder{Id:0, Products:[]model.Product(nil)}, Model:gorm.Model{ID:0x0, CreatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), UpdatedAt:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), DeletedAt:gorm.DeletedAt{Time:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Valid:false}}}, got error invalid field found for struct aps_crm/model.SubOrder's field ProductOrder: define a valid foreign key for relations or implement the Valuer/Scanner interface
[2023-07-11 11:33:55]    [error]    [main.main:29]    model Init err:invalid field found for struct aps_crm/model.SubOrder's field ProductOrder: define a valid foreign key for relations or implement the Valuer/Scanner interface
[2023-07-12 15:23:10]    [error]    [aps_crm/model.(*ContractSearch).Create:46]    trace    {"error": "Error 1146 (42S02): Table 'aps_crm.contract' doesn't exist", "elapsed": 0.003547, "rows": 0, "sql": "INSERT INTO `contract` (`client_id`,`member_id`,`number`,`quotation_id`,`status_id`,`file`) VALUES (11,11,'ZDYB02-2',0,0,'string')"}
model/contract.go
New file
@@ -0,0 +1,76 @@
package model
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
)
type (
    Contract struct {
        Id          int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        ClientId    int    `json:"clientId" gorm:"column:client_id;type:int;comment:客户id"`
        MemberId    int    `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"`
        Number      string `json:"number" gorm:"column:number;type:varchar(255);comment:合同编号"`
        QuotationId int    `json:"quotationId" gorm:"column:quotation_id;type:int;comment:报价单id"`
        StatusId    int    `json:"statusId" gorm:"column:status_id;type:int;comment:合同状态"`
        File        string `json:"file" gorm:"column:file;type:varchar(255);comment:合同文件"`
    }
    ContractSearch struct {
        Contract
        Orm *gorm.DB
    }
)
func (Contract) TableName() string {
    return "contract"
}
func NewContractSearch() *ContractSearch {
    return &ContractSearch{
        Orm: mysqlx.GetDB(),
    }
}
func (slf *ContractSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&Contract{})
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    return db
}
func (slf *ContractSearch) Create(record *Contract) error {
    var db = slf.build()
    return db.Create(record).Error
}
func (slf *ContractSearch) Delete() error {
    var db = slf.build()
    return db.Delete(&Contract{}).Error
}
func (slf *ContractSearch) Update(record *Contract) error {
    var db = slf.build()
    return db.Updates(record).Error
}
func (slf *ContractSearch) Find() (*Contract, error) {
    var db = slf.build()
    var record = &Contract{}
    err := db.First(record).Error
    return record, err
}
func (slf *ContractSearch) FindAll() ([]*Contract, error) {
    var db = slf.build()
    var records = make([]*Contract, 0)
    err := db.Find(&records).Error
    return records, err
}
func (slf *ContractSearch) SetId(id int) *ContractSearch {
    slf.Id = id
    return slf
}
model/index.go
@@ -53,6 +53,7 @@
        SalesDetails{},
        SalesReturn{},
        SalesRefund{},
        Contract{},
    )
    return err
}
model/request/contract.go
New file
@@ -0,0 +1,19 @@
package request
type AddContract struct {
    Contract
}
type Contract struct {
    ClientId    int    `json:"client_id"`
    MemberId    int    `json:"member_id"`
    Number      string `json:"number"`
    QuotationId int    `json:"quotation_id"`
    StatusId    int    `json:"status_id"`
    File        string `json:"file"`
}
type UpdateContract struct {
    Id int `json:"id"`
    Contract
}
model/response/response.go
@@ -145,4 +145,8 @@
    SalesRefundResponse struct {
        List []*model.SalesRefund `json:"list"`
    }
    ContractResponse struct {
        List []*model.Contract `json:"list"`
    }
)
pkg/ecode/code.go
@@ -218,4 +218,11 @@
    SalesRefundSetErr    = 3000004 // 设置销售退款单失败
    SalesRefundUpdateErr = 3000005 // 更新销售退款单失败
    SalesRefundDeleteErr = 3000006 // 删除销售退款单失败
    ContractExist     = 3100001 // 合同已存在
    ContractNotExist  = 3100002 // 合同不存在
    ContractListErr   = 3100003 // 获取合同列表失败
    ContractSetErr    = 3100004 // 设置合同失败
    ContractUpdateErr = 3100005 // 更新合同失败
    ContractDeleteErr = 3100006 // 删除合同失败
)
router/contract.go
New file
@@ -0,0 +1,19 @@
package router
import (
    v1 "aps_crm/api/v1"
    "github.com/gin-gonic/gin"
)
type ContractRouter struct{}
func (s *ContractRouter) InitContractRouter(router *gin.RouterGroup) {
    contractRouter := router.Group("contract")
    contractApi := v1.ApiGroup.ContractApi
    {
        contractRouter.POST("add", contractApi.Add)             // 添加合同
        contractRouter.DELETE("delete/:id", contractApi.Delete) // 删除合同
        contractRouter.PUT("update", contractApi.Update)        // 更新合同
        contractRouter.GET("list", contractApi.List)            // 获取合同列表
    }
}
router/index.go
@@ -43,6 +43,7 @@
    SalesDetailsRouter
    SalesReturnRouter
    SalesRefundRouter
    ContractRouter
}
func InitRouter() *gin.Engine {
@@ -103,6 +104,7 @@
        routerGroup.InitSalesDetailsRouter(PrivateGroup)      // 注册salesDetails路由
        routerGroup.InitSalesReturnRouter(PrivateGroup)       // 注册salesReturn路由
        routerGroup.InitSalesRefundRouter(PrivateGroup)       // 注册salesRefund路由
        routerGroup.InitContractRouter(PrivateGroup)          // 注册contract路由
    }
    return Router
}
service/contract.go
New file
@@ -0,0 +1,54 @@
package service
import (
    "aps_crm/model"
    "aps_crm/pkg/ecode"
)
type ContractService struct{}
func (ContractService) AddContract(contract *model.Contract) int {
    err := model.NewContractSearch().Create(contract)
    if err != nil {
        return ecode.ContractExist
    }
    return ecode.OK
}
func (ContractService) DeleteContract(id int) int {
    _, err := model.NewContractSearch().SetId(id).Find()
    if err != nil {
        return ecode.ContractNotExist
    }
    err = model.NewContractSearch().SetId(id).Delete()
    if err != nil {
        return ecode.ContractNotExist
    }
    return ecode.OK
}
func (ContractService) GetContractList() ([]*model.Contract, int) {
    list, err := model.NewContractSearch().FindAll()
    if err != nil {
        return nil, ecode.ContractListErr
    }
    return list, ecode.OK
}
func (ContractService) UpdateContract(contract *model.Contract) int {
    // check contract exist
    _, err := model.NewContractSearch().SetId(contract.Id).Find()
    if err != nil {
        return ecode.ContractNotExist
    }
    err = model.NewContractSearch().SetId(contract.Id).Update(contract)
    if err != nil {
        return ecode.ContractSetErr
    }
    return ecode.OK
}
service/index.go
@@ -32,6 +32,7 @@
    SalesDetailsService
    SalesReturnService
    SalesRefundService
    ContractService
}
var ServiceGroup = new(Group)