New file |
| | |
| | | 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, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode := service.NewRefundTypeService().AddRefundType(¶ms.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, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | if params.Id == 0 { |
| | | ctx.Fail(ecode.ParamsErr) |
| | | } |
| | | params.RefundType.Id = params.Id |
| | | |
| | | errCode := service.NewRefundTypeService().UpdateRefundType(¶ms.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, ¶ms) |
| | | 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, |
| | | }) |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/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": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "model.RefundType": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "model.Region": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "type": "string" |
| | | }, |
| | | "status_id": { |
| | | "type": "integer" |
| | | "$ref": "#/definitions/model.Status" |
| | | }, |
| | | "threats": { |
| | | "type": "string" |
| | |
| | | "model.SalesRefund": { |
| | | "type": "object", |
| | | "properties": { |
| | | "RefundType": { |
| | | "description": "退款方式", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/model.RefundType" |
| | | } |
| | | ] |
| | | }, |
| | | "Source": { |
| | | "$ref": "#/definitions/model.SalesReturn" |
| | | }, |
| | |
| | | }, |
| | | "refundDate": { |
| | | "type": "string" |
| | | }, |
| | | "refundTypeId": { |
| | | "description": "退款方式ID", |
| | | "type": "integer" |
| | | }, |
| | | "sourceId": { |
| | | "description": "源单id", |
| | |
| | | "description": "所属公司ID", |
| | | "type": "integer" |
| | | }, |
| | | "codeRule": { |
| | | "$ref": "#/definitions/code.CodeStandard" |
| | | }, |
| | | "codeStandID": { |
| | | "description": "编码id", |
| | | "type": "string" |
| | | }, |
| | | "country_id": { |
| | | "description": "国家ID", |
| | | "type": "integer" |
| | |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddRefundType": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | |
| | | "description": "所属公司ID", |
| | | "type": "integer" |
| | | }, |
| | | "codeRule": { |
| | | "$ref": "#/definitions/code.CodeStandard" |
| | | }, |
| | | "codeStandID": { |
| | | "description": "编码id", |
| | | "type": "string" |
| | | }, |
| | | "country_id": { |
| | | "description": "国家ID", |
| | | "type": "integer" |
| | |
| | | }, |
| | | "keywordType": { |
| | | "$ref": "#/definitions/constvar.SalesDetailsKeywordType" |
| | | }, |
| | | "number": { |
| | | "description": "销售子单号", |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | |
| | | "description": "所属公司ID", |
| | | "type": "integer" |
| | | }, |
| | | "codeRule": { |
| | | "$ref": "#/definitions/code.CodeStandard" |
| | | }, |
| | | "codeStandID": { |
| | | "description": "编码id", |
| | | "type": "string" |
| | | }, |
| | | "country_id": { |
| | | "description": "国家ID", |
| | | "type": "integer" |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateRefundType": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateRegion": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/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": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "model.RefundType": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "model.Region": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "type": "string" |
| | | }, |
| | | "status_id": { |
| | | "type": "integer" |
| | | "$ref": "#/definitions/model.Status" |
| | | }, |
| | | "threats": { |
| | | "type": "string" |
| | |
| | | "model.SalesRefund": { |
| | | "type": "object", |
| | | "properties": { |
| | | "RefundType": { |
| | | "description": "退款方式", |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/model.RefundType" |
| | | } |
| | | ] |
| | | }, |
| | | "Source": { |
| | | "$ref": "#/definitions/model.SalesReturn" |
| | | }, |
| | |
| | | }, |
| | | "refundDate": { |
| | | "type": "string" |
| | | }, |
| | | "refundTypeId": { |
| | | "description": "退款方式ID", |
| | | "type": "integer" |
| | | }, |
| | | "sourceId": { |
| | | "description": "源单id", |
| | |
| | | "description": "所属公司ID", |
| | | "type": "integer" |
| | | }, |
| | | "codeRule": { |
| | | "$ref": "#/definitions/code.CodeStandard" |
| | | }, |
| | | "codeStandID": { |
| | | "description": "编码id", |
| | | "type": "string" |
| | | }, |
| | | "country_id": { |
| | | "description": "国家ID", |
| | | "type": "integer" |
| | |
| | | "name" |
| | | ], |
| | | "properties": { |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddRefundType": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | |
| | | "description": "所属公司ID", |
| | | "type": "integer" |
| | | }, |
| | | "codeRule": { |
| | | "$ref": "#/definitions/code.CodeStandard" |
| | | }, |
| | | "codeStandID": { |
| | | "description": "编码id", |
| | | "type": "string" |
| | | }, |
| | | "country_id": { |
| | | "description": "国家ID", |
| | | "type": "integer" |
| | |
| | | }, |
| | | "keywordType": { |
| | | "$ref": "#/definitions/constvar.SalesDetailsKeywordType" |
| | | }, |
| | | "number": { |
| | | "description": "销售子单号", |
| | | "type": "string" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | |
| | | "description": "所属公司ID", |
| | | "type": "integer" |
| | | }, |
| | | "codeRule": { |
| | | "$ref": "#/definitions/code.CodeStandard" |
| | | }, |
| | | "codeStandID": { |
| | | "description": "编码id", |
| | | "type": "string" |
| | | }, |
| | | "country_id": { |
| | | "description": "国家ID", |
| | | "type": "integer" |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateRefundType": { |
| | | "type": "object", |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "name": { |
| | | "type": "string" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateRegion": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | name: |
| | | type: string |
| | | type: object |
| | | model.RefundType: |
| | | properties: |
| | | id: |
| | | type: integer |
| | | name: |
| | | type: string |
| | | type: object |
| | | model.Region: |
| | | properties: |
| | | id: |
| | |
| | | solutions: |
| | | type: string |
| | | status_id: |
| | | type: integer |
| | | $ref: '#/definitions/model.Status' |
| | | threats: |
| | | type: string |
| | | whether_established: |
| | |
| | | type: object |
| | | model.SalesRefund: |
| | | properties: |
| | | RefundType: |
| | | allOf: |
| | | - $ref: '#/definitions/model.RefundType' |
| | | description: 退款方式 |
| | | Source: |
| | | $ref: '#/definitions/model.SalesReturn' |
| | | amountTotal: |
| | |
| | | type: string |
| | | refundDate: |
| | | type: string |
| | | refundTypeId: |
| | | description: 退款方式ID |
| | | type: integer |
| | | sourceId: |
| | | description: 源单id |
| | | type: integer |
| | |
| | | client_id: |
| | | description: 所属公司ID |
| | | type: integer |
| | | codeRule: |
| | | $ref: '#/definitions/code.CodeStandard' |
| | | codeStandID: |
| | | description: 编码id |
| | | type: string |
| | | country_id: |
| | | description: 国家ID |
| | | type: integer |
| | |
| | | type: string |
| | | required: |
| | | - name |
| | | type: object |
| | | request.AddRefundType: |
| | | properties: |
| | | id: |
| | | type: integer |
| | | name: |
| | | type: string |
| | | type: object |
| | | request.AddRegion: |
| | | properties: |
| | |
| | | client_id: |
| | | description: 所属公司ID |
| | | type: integer |
| | | codeRule: |
| | | $ref: '#/definitions/code.CodeStandard' |
| | | codeStandID: |
| | | description: 编码id |
| | | type: string |
| | | country_id: |
| | | description: 国家ID |
| | | type: integer |
| | |
| | | type: string |
| | | keywordType: |
| | | $ref: '#/definitions/constvar.SalesDetailsKeywordType' |
| | | number: |
| | | description: 销售子单号 |
| | | type: string |
| | | page: |
| | | description: 页码 |
| | | type: integer |
| | |
| | | client_id: |
| | | description: 所属公司ID |
| | | type: integer |
| | | codeRule: |
| | | $ref: '#/definitions/code.CodeStandard' |
| | | codeStandID: |
| | | description: 编码id |
| | | type: string |
| | | country_id: |
| | | description: 国家ID |
| | | type: integer |
| | |
| | | type: array |
| | | required: |
| | | - refund_method |
| | | type: object |
| | | request.UpdateRefundType: |
| | | properties: |
| | | id: |
| | | type: integer |
| | | name: |
| | | type: string |
| | | type: object |
| | | request.UpdateRegion: |
| | | properties: |
| | |
| | | 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: |
New file |
| | |
| | | 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 |
| | | } |
| | | } |
| | |
| | | InvoiceStatus{}, |
| | | InvoiceType{}, |
| | | Invoice{}, |
| | | RefundType{}, |
| | | ) |
| | | return err |
| | | } |
| | |
| | | NewStatusSearch(), |
| | | NewPaymentTypeSearch(), |
| | | NewBankAccountSearch(), |
| | | NewRefundTypeSearch(), |
| | | } |
| | | |
| | | for _, model := range models { |
| | |
| | | if total != 0 { |
| | | return |
| | | } |
| | | |
| | | records := []*PaymentType{ |
| | | {1, "原路返回"}, |
| | | {2, "线下"}, |
| | | {1, "对公转账"}, |
| | | {2, "线下付款"}, |
| | | {3, "支票"}, |
| | | {4, "其他"}, |
| | | } |
| | | err := slf.CreateBatch(records) |
| | | if err != nil { |
New file |
| | |
| | | package request |
| | | |
| | | import ( |
| | | "aps_crm/model" |
| | | ) |
| | | |
| | | type AddRefundType struct { |
| | | model.RefundType |
| | | } |
| | | |
| | | type UpdateRefundType struct { |
| | | Id int `json:"id"` |
| | | model.RefundType |
| | | } |
| | | |
| | | type GetRefundTypeList struct { |
| | | PageInfo |
| | | } |
| | |
| | | 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:是否开票"` |
New file |
| | |
| | | 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) // 获取退款方式列表 |
| | | } |
| | | } |
| | |
| | | InitReceiptRouter(PrivateGroup) |
| | | InitBankAccountRouter(PrivateGroup) |
| | | InitPaymentTypeRouter(PrivateGroup) |
| | | InitRefundTypeRouter(PrivateGroup) |
| | | InitFileRouter(PrivateGroup) |
| | | InitInvoiceRouter(PrivateGroup) |
| | | InitInvoiceStatusRouter(PrivateGroup) |
New file |
| | |
| | | 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 |
| | | } |