liujiandao
2023-10-21 4b2c52b17abef8521f9211b4865e1cad0288b12a
Merge branch 'master' of http://192.168.5.5:10010/r/aps/crm
5个文件已添加
20个文件已修改
1317 ■■■■■ 已修改文件
api/v1/RefundType.go 112 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 183 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 183 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 114 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/RefundType.go 148 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/bankAccount.go 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/clientLevel.go 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/clientOrigin.go 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/clientType.go 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/contactInformation.go 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/enterpriseNature.go 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/enterpriseScale.go 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/index.go 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/industry.go 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/paymentType.go 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/possibilities.go 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/registeredCapital.go 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/request/RefundType.go 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/saleChance.go 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/saleType.go 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/salesRefund.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
model/status.go 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/RefundType.go 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/index.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/RefundType.go 64 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/v1/RefundType.go
New file
@@ -0,0 +1,112 @@
package v1
import (
    "aps_crm/model/request"
    "aps_crm/model/response"
    "aps_crm/pkg/contextx"
    "aps_crm/pkg/ecode"
    "aps_crm/service"
    "github.com/gin-gonic/gin"
    "strconv"
)
type RefundTypeApi struct{}
// Add
// @Tags        退款方式管理
// @Summary    添加退款方式
// @Produce    application/json
// @Param        object    body        request.AddRefundType    true    "查询参数"
// @Success    200        {object}    contextx.Response{}
// @Router        /api/refundType/add [post]
func (s *RefundTypeApi) Add(c *gin.Context) {
    var params request.AddRefundType
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    errCode := service.NewRefundTypeService().AddRefundType(&params.RefundType)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Delete
// @Tags        退款方式管理
// @Summary    删除退款方式
// @Produce    application/json
// @Param        id    path        int    true    "查询参数"
// @Success    200    {object}    contextx.Response{}
// @Router        /api/refundType/delete/{id} [delete]
func (s *RefundTypeApi) Delete(c *gin.Context) {
    ctx, ok := contextx.NewContext(c, nil)
    if !ok {
        return
    }
    id, _ := strconv.Atoi(c.Param("id"))
    errCode := service.NewRefundTypeService().DeleteRefundType(id)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// Update
// @Tags        退款方式管理
// @Summary    更新退款方式
// @Produce    application/json
// @Param        object    body        request.UpdateRefundType    true    "查询参数"
// @Success    200        {object}    contextx.Response{}
// @Router        /api/refundType/update [put]
func (s *RefundTypeApi) Update(c *gin.Context) {
    var params request.UpdateRefundType
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    if params.Id == 0 {
        ctx.Fail(ecode.ParamsErr)
    }
    params.RefundType.Id = params.Id
    errCode := service.NewRefundTypeService().UpdateRefundType(&params.RefundType)
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.Ok()
}
// List
// @Tags        退款方式管理
// @Summary    获取退款方式列表
// @Produce    application/json
// @Param        object    query        request.GetRefundTypeList    true    "参数"
// @Success    200    {object}    response.ListResponse{data=[]model.RefundType}
// @Router        /api/refundType/list [get]
func (s *RefundTypeApi) List(c *gin.Context) {
    var params request.GetRefundTypeList
    ctx, ok := contextx.NewContext(c, &params)
    if !ok {
        return
    }
    RefundType, total, errCode := service.NewRefundTypeService().GetRefundTypeList()
    if errCode != ecode.OK {
        ctx.Fail(errCode)
        return
    }
    ctx.OkWithDetailed(response.ListResponse{
        Data:  RefundType,
        Count: total,
    })
}
docs/docs.go
@@ -5689,6 +5689,142 @@
                }
            }
        },
        "/api/refundType/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "退款方式管理"
                ],
                "summary": "添加退款方式",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddRefundType"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/refundType/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "退款方式管理"
                ],
                "summary": "删除退款方式",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/refundType/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "退款方式管理"
                ],
                "summary": "获取退款方式列表",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "页码",
                        "name": "page",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "description": "每页大小",
                        "name": "pageSize",
                        "in": "query"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/response.ListResponse"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/model.RefundType"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api/refundType/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "退款方式管理"
                ],
                "summary": "更新退款方式",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateRefundType"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/region/add": {
            "post": {
                "produces": [
@@ -11699,6 +11835,17 @@
                }
            }
        },
        "model.RefundType": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "model.Region": {
            "type": "object",
            "properties": {
@@ -11902,7 +12049,7 @@
                    "type": "string"
                },
                "status_id": {
                    "type": "integer"
                    "$ref": "#/definitions/model.Status"
                },
                "threats": {
                    "type": "string"
@@ -12126,6 +12273,14 @@
        "model.SalesRefund": {
            "type": "object",
            "properties": {
                "RefundType": {
                    "description": "退款方式",
                    "allOf": [
                        {
                            "$ref": "#/definitions/model.RefundType"
                        }
                    ]
                },
                "Source": {
                    "$ref": "#/definitions/model.SalesReturn"
                },
@@ -12188,6 +12343,10 @@
                },
                "refundDate": {
                    "type": "string"
                },
                "refundTypeId": {
                    "description": "退款方式ID",
                    "type": "integer"
                },
                "sourceId": {
                    "description": "源单id",
@@ -13887,6 +14046,17 @@
                "name"
            ],
            "properties": {
                "name": {
                    "type": "string"
                }
            }
        },
        "request.AddRefundType": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
@@ -17073,6 +17243,17 @@
                }
            }
        },
        "request.UpdateRefundType": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "request.UpdateRegion": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -5677,6 +5677,142 @@
                }
            }
        },
        "/api/refundType/add": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "退款方式管理"
                ],
                "summary": "添加退款方式",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.AddRefundType"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/refundType/delete/{id}": {
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "退款方式管理"
                ],
                "summary": "删除退款方式",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "查询参数",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/refundType/list": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "退款方式管理"
                ],
                "summary": "获取退款方式列表",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "页码",
                        "name": "page",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "description": "每页大小",
                        "name": "pageSize",
                        "in": "query"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/response.ListResponse"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/model.RefundType"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api/refundType/update": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "退款方式管理"
                ],
                "summary": "更新退款方式",
                "parameters": [
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateRefundType"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/contextx.Response"
                        }
                    }
                }
            }
        },
        "/api/region/add": {
            "post": {
                "produces": [
@@ -11687,6 +11823,17 @@
                }
            }
        },
        "model.RefundType": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "model.Region": {
            "type": "object",
            "properties": {
@@ -11890,7 +12037,7 @@
                    "type": "string"
                },
                "status_id": {
                    "type": "integer"
                    "$ref": "#/definitions/model.Status"
                },
                "threats": {
                    "type": "string"
@@ -12114,6 +12261,14 @@
        "model.SalesRefund": {
            "type": "object",
            "properties": {
                "RefundType": {
                    "description": "退款方式",
                    "allOf": [
                        {
                            "$ref": "#/definitions/model.RefundType"
                        }
                    ]
                },
                "Source": {
                    "$ref": "#/definitions/model.SalesReturn"
                },
@@ -12176,6 +12331,10 @@
                },
                "refundDate": {
                    "type": "string"
                },
                "refundTypeId": {
                    "description": "退款方式ID",
                    "type": "integer"
                },
                "sourceId": {
                    "description": "源单id",
@@ -13875,6 +14034,17 @@
                "name"
            ],
            "properties": {
                "name": {
                    "type": "string"
                }
            }
        },
        "request.AddRefundType": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
@@ -17061,6 +17231,17 @@
                }
            }
        },
        "request.UpdateRefundType": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "request.UpdateRegion": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -1233,6 +1233,13 @@
      name:
        type: string
    type: object
  model.RefundType:
    properties:
      id:
        type: integer
      name:
        type: string
    type: object
  model.Region:
    properties:
      id:
@@ -1367,7 +1374,7 @@
      solutions:
        type: string
      status_id:
        type: integer
        $ref: '#/definitions/model.Status'
      threats:
        type: string
      whether_established:
@@ -1516,6 +1523,10 @@
    type: object
  model.SalesRefund:
    properties:
      RefundType:
        allOf:
        - $ref: '#/definitions/model.RefundType'
        description: 退款方式
      Source:
        $ref: '#/definitions/model.SalesReturn'
      amountTotal:
@@ -1559,6 +1570,9 @@
        type: string
      refundDate:
        type: string
      refundTypeId:
        description: 退款方式ID
        type: integer
      sourceId:
        description: 源单id
        type: integer
@@ -2705,6 +2719,13 @@
        type: string
    required:
    - name
    type: object
  request.AddRefundType:
    properties:
      id:
        type: integer
      name:
        type: string
    type: object
  request.AddRegion:
    properties:
@@ -4884,6 +4905,13 @@
        type: array
    required:
    - refund_method
    type: object
  request.UpdateRefundType:
    properties:
      id:
        type: integer
      name:
        type: string
    type: object
  request.UpdateRegion:
    properties:
@@ -9763,6 +9791,90 @@
      summary: 更新退款方式
      tags:
      - RefundMethod
  /api/refundType/add:
    post:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.AddRefundType'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 添加退款方式
      tags:
      - 退款方式管理
  /api/refundType/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:
      - 退款方式管理
  /api/refundType/list:
    get:
      parameters:
      - description: 页码
        in: query
        name: page
        type: integer
      - description: 每页大小
        in: query
        name: pageSize
        type: integer
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            allOf:
            - $ref: '#/definitions/response.ListResponse'
            - properties:
                data:
                  items:
                    $ref: '#/definitions/model.RefundType'
                  type: array
              type: object
      summary: 获取退款方式列表
      tags:
      - 退款方式管理
  /api/refundType/update:
    put:
      parameters:
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.UpdateRefundType'
      produces:
      - application/json
      responses:
        "200":
          description: OK
          schema:
            $ref: '#/definitions/contextx.Response'
      summary: 更新退款方式
      tags:
      - 退款方式管理
  /api/region/add:
    post:
      parameters:
model/RefundType.go
New file
@@ -0,0 +1,148 @@
package model
import (
    "aps_crm/pkg/mysqlx"
    "errors"
    "fmt"
    "gorm.io/gorm"
    "sync"
)
type (
    // RefundType 退款方式
    RefundType struct {
        Id   int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Name string `json:"name" gorm:"column:name"`
    }
    // RefundTypeSearch 支付方式搜索条件
    RefundTypeSearch struct {
        RefundType
        Orm      *gorm.DB
        PageNum  int
        PageSize int
    }
)
func (RefundType) TableName() string {
    return "refund_type"
}
func NewRefundTypeSearch() *RefundTypeSearch {
    return &RefundTypeSearch{
        Orm: mysqlx.GetDB(),
    }
}
func (slf *RefundTypeSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&RefundType{})
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    return db
}
func (slf *RefundTypeSearch) Create(record *RefundType) error {
    var db = slf.build()
    return db.Create(record).Error
}
func (slf *RefundTypeSearch) CreateBatch(records []*RefundType) error {
    var db = slf.build()
    return db.Create(records).Error
}
func (slf *RefundTypeSearch) Delete() error {
    var db = slf.build()
    return db.Delete(&RefundType{}).Error
}
func (slf *RefundTypeSearch) Update(record *RefundType) error {
    var db = slf.build()
    return db.Updates(record).Error
}
func (slf *RefundTypeSearch) FindAll() ([]*RefundType, error) {
    var db = slf.build()
    var record = make([]*RefundType, 0)
    err := db.Find(&record).Error
    return record, err
}
func (slf *RefundTypeSearch) SetId(id int) *RefundTypeSearch {
    slf.Id = id
    return slf
}
func (slf *RefundTypeSearch) SetOrm(tx *gorm.DB) *RefundTypeSearch {
    slf.Orm = tx
    return slf
}
func (slf *RefundTypeSearch) First() (*RefundType, error) {
    var db = slf.build()
    var record = new(RefundType)
    err := db.First(record).Error
    return record, err
}
func (slf *RefundTypeSearch) Updates(values interface{}) error {
    var db = slf.build()
    return db.Updates(values).Error
}
func (slf *RefundTypeSearch) Save(record *RefundType) error {
    if record.Id == 0 {
        return errors.New("id为空")
    }
    var db = slf.build()
    if err := db.Save(record).Error; err != nil {
        return fmt.Errorf("save err: %v, record: %+v", err, record)
    }
    return nil
}
func (slf *RefundTypeSearch) Find() ([]*RefundType, int64, error) {
    var db = slf.build()
    var records = make([]*RefundType, 0)
    var total int64
    if err := db.Count(&total).Error; err != nil {
        return records, total, err
    }
    if slf.PageNum > 0 && slf.PageSize > 0 {
        db = db.Limit(slf.PageSize).Offset((slf.PageNum - 1) * slf.PageSize)
    }
    err := db.Find(&records).Error
    return records, total, err
}
// InitDefaultData 初始化数据
func (slf *RefundTypeSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*RefundType{
        {1, "原路返回"},
        {2, "线下"},
        {3, "支票"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/bankAccount.go
@@ -6,24 +6,25 @@
    "errors"
    "fmt"
    "gorm.io/gorm"
    "sync"
)
type (
    // BankAccount 银行账户
    BankAccount struct {
        Id   int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Name   string    `json:"name" gorm:"column:name"`
        Name string `json:"name" gorm:"column:name"`
    }
    // BankAccountSearch 银行账户搜索条件
    BankAccountSearch struct {
        BankAccount
        Orm *gorm.DB
        QueryClass  constvar.BankAccountQueryClass
        KeywordType constvar.BankAccountKeywordType
        Keyword     string
        PageNum  int
        PageSize int
        Orm         *gorm.DB
        QueryClass  constvar.BankAccountQueryClass
        KeywordType constvar.BankAccountKeywordType
        Keyword     string
        PageNum     int
        PageSize    int
    }
)
@@ -124,17 +125,26 @@
}
// InitDefaultData 初始化数据
func (slf *BankAccountSearch) InitDefaultData() error {
func (slf *BankAccountSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        return err
        errCh <- err
        return
    }
    if total != 0 {
        return nil
        return
    }
    records := []*BankAccount{}
    return slf.CreateBatch(records)
    records := []*BankAccount{
        {1, "默认账户"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/clientLevel.go
@@ -3,6 +3,7 @@
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "sync"
)
type (
@@ -82,3 +83,36 @@
    var db = slf.build()
    return db.Updates(data).Error
}
func (slf *ClientLevelSearch) CreateBatch(records []*ClientLevel) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *ClientLevelSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*ClientLevel{
        {1, "重点关注客户"},
        {2, "优质客户"},
        {3, "普通客户"},
        {4, "其他"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/clientOrigin.go
@@ -3,6 +3,7 @@
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "sync"
)
type (
@@ -89,3 +90,38 @@
    var db = slf.build()
    return db.Updates(data).Error
}
func (slf *ClientOriginSearch) CreateBatch(records []*ClientOrigin) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *ClientOriginSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*ClientOrigin{
        {1, "供应商资源"},
        {2, "客户介绍"},
        {3, "现有客户"},
        {4, "展会"},
        {5, "外出拜访客户"},
        {6, "其他"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/clientType.go
@@ -3,6 +3,7 @@
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "sync"
)
type (
@@ -91,3 +92,36 @@
    var db = slf.build()
    return db.Updates(data).Error
}
func (slf *ClientTypeSearch) CreateBatch(records []*ClientType) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *ClientTypeSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*ClientType{
        {1, "代理商"},
        {2, "集成商"},
        {3, "合作伙伴"},
        {4, "其他"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/contactInformation.go
@@ -3,6 +3,7 @@
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "sync"
)
type (
@@ -78,3 +79,35 @@
    slf.Name = name
    return slf
}
func (slf *ContactInformationSearch) CreateBatch(records []*ContactInformation) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *ContactInformationSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*ContactInformation{
        {1, "线下拜访"},
        {2, "电话联系"},
        {3, "会议"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/enterpriseNature.go
@@ -3,6 +3,7 @@
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "sync"
)
type (
@@ -84,3 +85,39 @@
    var db = slf.build()
    return db.Updates(data).Error
}
func (slf *EnterpriseNatureSearch) CreateBatch(records []*EnterpriseNature) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *EnterpriseNatureSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*EnterpriseNature{
        {1, "国有企业"},
        {2, "集体企业"},
        {3, "私营企业"},
        {4, "个体工商户"},
        {5, "合伙企业"},
        {6, "联营企业"},
        {7, "股份合作制企业"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/enterpriseScale.go
@@ -3,6 +3,7 @@
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "sync"
)
type (
@@ -86,3 +87,38 @@
    slf.Id = id
    return slf
}
func (slf *EnterpriseScaleSearch) CreateBatch(records []*EnterpriseScale) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *EnterpriseScaleSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*EnterpriseScale{
        {1, "20人以下"},
        {2, "20-50人"},
        {3, "50-100人"},
        {4, "100-500人"},
        {5, "500-1000人"},
        {6, "1000人以上"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/index.go
@@ -94,6 +94,7 @@
        InvoiceStatus{},
        InvoiceType{},
        Invoice{},
        RefundType{},
    )
    return err
}
@@ -127,6 +128,20 @@
        NewQuotationStatusSearch(),
        NewSalesSourcesSearch(),
        NewClientStatusSearch(),
        NewClientTypeSearch(),
        NewClientOriginSearch(),
        NewClientLevelSearch(),
        NewIndustrySearch(),
        NewRegisteredCapitalSearch(),
        NewEnterpriseNatureSearch(),
        NewEnterpriseScaleSearch(),
        NewContactInformationSearch(),
        NewSaleTypeSearch(),
        NewPossibilitySearch(),
        NewStatusSearch(),
        NewPaymentTypeSearch(),
        NewBankAccountSearch(),
        NewRefundTypeSearch(),
    }
    for _, model := range models {
model/industry.go
@@ -3,6 +3,7 @@
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "sync"
)
type (
@@ -84,3 +85,38 @@
    var db = slf.build()
    return db.Updates(data).Error
}
func (slf *IndustrySearch) CreateBatch(records []*Industry) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *IndustrySearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*Industry{
        {1, "制造业"},
        {2, "交通运输"},
        {3, "建筑业"},
        {4, "环境和公共设施管理业"},
        {5, "批发和零售业"},
        {6, "其他"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/paymentType.go
@@ -6,24 +6,25 @@
    "errors"
    "fmt"
    "gorm.io/gorm"
    "sync"
)
type (
    // PaymentType 支付方式
    PaymentType struct {
        Id   int    `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Name   string    `json:"name" gorm:"column:name"`
        Name string `json:"name" gorm:"column:name"`
    }
    // PaymentTypeSearch 支付方式搜索条件
    PaymentTypeSearch struct {
        PaymentType
        Orm *gorm.DB
        QueryClass  constvar.PaymentTypeQueryClass
        KeywordType constvar.PaymentTypeKeywordType
        Keyword     string
        PageNum  int
        PageSize int
        Orm         *gorm.DB
        QueryClass  constvar.PaymentTypeQueryClass
        KeywordType constvar.PaymentTypeKeywordType
        Keyword     string
        PageNum     int
        PageSize    int
    }
)
@@ -124,17 +125,30 @@
}
// InitDefaultData 初始化数据
func (slf *PaymentTypeSearch) InitDefaultData() error {
func (slf *PaymentTypeSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        return err
        errCh <- err
        return
    }
    if total != 0 {
        return nil
        return
    }
    records := []*PaymentType{}
    return slf.CreateBatch(records)
    records := []*PaymentType{
        {1, "对公转账"},
        {2, "线下付款"},
        {3, "支票"},
        {4, "其他"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/possibilities.go
@@ -3,6 +3,7 @@
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "sync"
)
type (
@@ -84,3 +85,42 @@
    var db = slf.build()
    return db.Updates(data).Error
}
func (slf *PossibilitySearch) CreateBatch(records []*Possibility) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *PossibilitySearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*Possibility{
        {1, "100%"},
        {2, "90%"},
        {3, "80%"},
        {4, "70%"},
        {5, "60%"},
        {6, "50%"},
        {7, "40%"},
        {8, "30%"},
        {9, "20%"},
        {10, "10%"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/registeredCapital.go
@@ -3,6 +3,7 @@
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "sync"
)
type (
@@ -82,3 +83,37 @@
    slf.Name = name
    return slf
}
func (slf *RegisteredCapitalSearch) CreateBatch(records []*RegisteredCapital) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *RegisteredCapitalSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*RegisteredCapital{
        {1, "50万以下"},
        {2, "50-100万"},
        {3, "100-500万"},
        {4, "500-1000万"},
        {5, "1000万以上"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/request/RefundType.go
New file
@@ -0,0 +1,18 @@
package request
import (
    "aps_crm/model"
)
type AddRefundType struct {
    model.RefundType
}
type UpdateRefundType struct {
    Id int `json:"id"`
    model.RefundType
}
type GetRefundTypeList struct {
    PageInfo
}
model/saleChance.go
@@ -30,6 +30,7 @@
        Currency              int                    `json:"currency" gorm:"column:currency;type:int(11);comment:币种"`
        ExpectedTime          *CustomTime            `json:"expected_time" gorm:"column:expected_time;type:datetime;comment:预计成交时间"`
        StatusId              int                    `json:"status_id" gorm:"column:status_id;type:int(11);comment:状态ID"`
        Status                Status                 `json:"status"` //状态
        PainPoints            string                 `json:"pain_points" gorm:"column:pain_points;type:text;comment:痛点"`
        WhetherEstablished    string                 `json:"whether_established" gorm:"column:whether_established;type:text;comment:是否成立"`
        CapitalBudget         string                 `json:"capital_budget" gorm:"column:capital_budget;type:text;comment:资金预算"`
@@ -164,7 +165,7 @@
    err := db.Preload("SaleType").Preload("RegularCustomers").Preload("SalesSources").Preload("Products").
        Preload("Member").Preload("SaleStage").Preload("Possibility").
        Preload("CollectionProjections").Preload("Client").
        Preload("Province").Preload("City").Preload("Contact").Order("id desc").Find(&records).Error
        Preload("Province").Preload("City").Preload("Contact").Preload("Status").Order("id desc").Find(&records).Error
    return records, total, err
}
model/saleType.go
@@ -3,6 +3,7 @@
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "sync"
)
type (
@@ -82,3 +83,34 @@
    var db = slf.build()
    return db.Updates(data).Error
}
func (slf *SaleTypeSearch) CreateBatch(records []*SaleType) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *SaleTypeSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*SaleType{
        {1, "新业务"},
        {2, "传统业务"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
model/salesRefund.go
@@ -23,6 +23,8 @@
        RefundDate    string                    `json:"refundDate" gorm:"column:refund_date;type:varchar(255);comment:退款日期"`
        PaymentTypeId int                       `gorm:"column:payment_type_id;type:int;not null;default 0;comment:收款方式ID" json:"paymentTypeId"` // 收款方式ID
        PaymentType   PaymentType               `gorm:"foreignKey:PaymentTypeId" json:"paymentType"`
        RefundTypeId  int                       `gorm:"column:refund_type_id;type:int;not null;default 0;comment:收款方式ID" json:"refundTypeId"` // 退款方式ID
        RefundType    RefundType                `gorm:"foreignKey:RefundTypeId" json:"RefundType"`                                            //退款方式
        BankAccountId int                       `gorm:"column:bank_account_id;type:int;not null;default 0;comment:账户id" json:"bankAccountId"` // 账户id
        BankAccount   BankAccount               `gorm:"foreignKey:BankAccountId" json:"bankAccount"`
        IsInvoice     string                    `json:"isInvoice" gorm:"column:is_invoice;type:varchar(255);comment:是否开票"`
model/status.go
@@ -3,6 +3,7 @@
import (
    "aps_crm/pkg/mysqlx"
    "gorm.io/gorm"
    "sync"
)
type (
@@ -84,3 +85,34 @@
    var db = slf.build()
    return db.Updates(data).Error
}
func (slf *StatusSearch) CreateBatch(records []*Status) error {
    var db = slf.build()
    return db.Create(records).Error
}
// InitDefaultData 初始化数据
func (slf *StatusSearch) InitDefaultData(errCh chan<- error, wg *sync.WaitGroup) {
    var (
        db          = slf.Orm.Table(slf.TableName())
        total int64 = 0
    )
    defer wg.Done()
    if err := db.Count(&total).Error; err != nil {
        errCh <- err
        return
    }
    if total != 0 {
        return
    }
    records := []*Status{
        {1, "已成交"},
        {2, "未成交"},
    }
    err := slf.CreateBatch(records)
    if err != nil {
        errCh <- err
        return
    }
}
router/RefundType.go
New file
@@ -0,0 +1,17 @@
package router
import (
    v1 "aps_crm/api/v1"
    "github.com/gin-gonic/gin"
)
func InitRefundTypeRouter(router *gin.RouterGroup) {
    RefundTypeRouter := router.Group("refundType")
    RefundTypeApi := v1.RefundTypeApi{}
    {
        RefundTypeRouter.POST("add", RefundTypeApi.Add)             // 添加退款方式
        RefundTypeRouter.DELETE("delete/:id", RefundTypeApi.Delete) // 删除退款方式
        RefundTypeRouter.PUT("update", RefundTypeApi.Update)        // 更新退款方式
        RefundTypeRouter.GET("list", RefundTypeApi.List)            // 获取退款方式列表
    }
}
router/index.go
@@ -184,6 +184,7 @@
        InitReceiptRouter(PrivateGroup)
        InitBankAccountRouter(PrivateGroup)
        InitPaymentTypeRouter(PrivateGroup)
        InitRefundTypeRouter(PrivateGroup)
        InitFileRouter(PrivateGroup)
        InitInvoiceRouter(PrivateGroup)
        InitInvoiceStatusRouter(PrivateGroup)
service/RefundType.go
New file
@@ -0,0 +1,64 @@
package service
import (
    "aps_crm/model"
    "aps_crm/model/request"
    "aps_crm/pkg/ecode"
)
type RefundTypeService struct{}
func NewRefundTypeService() RefundTypeService {
    return RefundTypeService{}
}
func (RefundTypeService) AddRefundType(RefundType *model.RefundType) int {
    err := model.NewRefundTypeSearch().Create(RefundType)
    if err != nil {
        return ecode.DBErr
    }
    return ecode.OK
}
func (RefundTypeService) DeleteRefundType(id int) int {
    err := model.NewRefundTypeSearch().SetId(id).Delete()
    if err != nil {
        return ecode.DBErr
    }
    return ecode.OK
}
func (RefundTypeService) GetRefundTypeList() ([]*model.RefundType, int64, int) {
    list, total, err := model.NewRefundTypeSearch().Find()
    if err != nil {
        return nil, 0, ecode.DBErr
    }
    return list, total, ecode.OK
}
func (RefundTypeService) UpdateRefundTypes(RefundTypes []*request.UpdateRefundType) int {
    for _, v := range RefundTypes {
        // check RefundType exist
        _, err := model.NewRefundTypeSearch().SetId(v.Id).First()
        if err != nil {
            return ecode.DBErr
        }
        err = model.NewRefundTypeSearch().SetId(v.Id).Updates(map[string]interface{}{})
        if err != nil {
            return ecode.DBErr
        }
    }
    return ecode.OK
}
func (RefundTypeService) UpdateRefundType(RefundType *model.RefundType) int {
    err := model.NewRefundTypeSearch().SetId(RefundType.Id).Update(RefundType)
    if err != nil {
        return ecode.DBErr
    }
    return ecode.OK
}