add
salesRetrun 销售退货单
add, Delete, update, list
| | |
| | | MasterOrderApi |
| | | SubOrderApi |
| | | SalesDetailsApi |
| | | SalesReturnApi |
| | | } |
| | | |
| | | var ApiGroup = new(Group) |
| | |
| | | masterOrderService = service.ServiceGroup.MasterOrderService |
| | | subOrderService = service.ServiceGroup.SubOrderService |
| | | salesDetailsService = service.ServiceGroup.SalesDetailsService |
| | | salesReturnService = service.ServiceGroup.SalesReturnService |
| | | ) |
New file |
| | |
| | | package v1 |
| | | |
| | | import ( |
| | | "aps_crm/model" |
| | | "aps_crm/model/request" |
| | | "aps_crm/model/response" |
| | | "aps_crm/pkg/contextx" |
| | | "aps_crm/pkg/ecode" |
| | | "github.com/gin-gonic/gin" |
| | | "strconv" |
| | | ) |
| | | |
| | | type SalesReturnApi struct{} |
| | | |
| | | // Add |
| | | // |
| | | // @Tags SalesReturn |
| | | // @Summary 添加销售退货 |
| | | // @Produce application/json |
| | | // @Param object body request.AddSalesReturnRequest true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/salesReturn/add [post] |
| | | func (s *SalesReturnApi) Add(c *gin.Context) { |
| | | var params request.AddSalesReturnRequest |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode, salesReturn := checkSalesReturnParams(params.SalesReturn) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | errCode = salesReturnService.AddSalesReturn(&salesReturn) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Delete |
| | | // |
| | | // @Tags SalesReturn |
| | | // @Summary 删除销售退货 |
| | | // @Produce application/json |
| | | // @Param id path int true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/salesReturn/delete/{id} [delete] |
| | | func (s *SalesReturnApi) Delete(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | id, _ := strconv.Atoi(c.Param("id")) |
| | | errCode := salesReturnService.DeleteSalesReturn(id) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // Update |
| | | // |
| | | // @Tags SalesReturn |
| | | // @Summary 更新销售退货 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateSalesReturnRequest true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/salesReturn/update/{id} [put] |
| | | func (s *SalesReturnApi) Update(c *gin.Context) { |
| | | var params request.UpdateSalesReturnRequest |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode, salesReturn := checkSalesReturnParams(params.SalesReturn) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | errCode = salesReturnService.UpdateSalesReturn(&salesReturn) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | |
| | | } |
| | | |
| | | // List |
| | | // |
| | | // @Tags SalesReturn |
| | | // @Summary 获取销售退货列表 |
| | | // @Produce application/json |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/salesReturn/list [get] |
| | | func (s *SalesReturnApi) List(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | salesReturns, errCode := salesReturnService.GetSalesReturnList() |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.OkWithDetailed(response.SalesReturnResponse{ |
| | | List: salesReturns, |
| | | }) |
| | | } |
| | | |
| | | func checkSalesReturnParams(salesReturn request.SalesReturn) (errCode int, s model.SalesReturn) { |
| | | if salesReturn.Number == "" { |
| | | return ecode.InvalidParams, s |
| | | } |
| | | |
| | | if salesReturn.Repository == "" { |
| | | return ecode.InvalidParams, s |
| | | } |
| | | |
| | | if salesReturn.MemberId == 0 { |
| | | return ecode.InvalidParams, s |
| | | } |
| | | |
| | | t, err := checkTimeFormat(salesReturn.ReturnDate) |
| | | if err != nil { |
| | | return ecode.InvalidParams, s |
| | | } |
| | | |
| | | s.ClientId = salesReturn.ClientId |
| | | s.ReturnDate = t |
| | | s.Number = salesReturn.Number |
| | | s.Repository = salesReturn.Repository |
| | | s.MemberId = salesReturn.MemberId |
| | | s.Status = salesReturn.Status |
| | | s.Reason = salesReturn.Reason |
| | | s.Products = salesReturn.Products |
| | | |
| | | return ecode.OK, s |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/salesReturn/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "SalesReturn" |
| | | ], |
| | | "summary": "添加销售退货", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddSalesReturnRequest" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/salesReturn/delete/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "SalesReturn" |
| | | ], |
| | | "summary": "删除销售退货", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "查询参数", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/salesReturn/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "SalesReturn" |
| | | ], |
| | | "summary": "获取销售退货列表", |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/salesReturn/update/{id}": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "SalesReturn" |
| | | ], |
| | | "summary": "更新销售退货", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateSalesReturnRequest" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/salesSources/add": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.AddSalesReturnRequest": { |
| | | "type": "object", |
| | | "properties": { |
| | | "salesReturn": { |
| | | "$ref": "#/definitions/request.SalesReturn" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddSalesSources": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | "deliveryDate": { |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "memberId": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | "type": "string" |
| | | }, |
| | | "wechatOrderStatus": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.SalesReturn": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "type": "integer" |
| | | }, |
| | | "memberId": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "products": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Product" |
| | | } |
| | | }, |
| | | "reason": { |
| | | "type": "string" |
| | | }, |
| | | "repository": { |
| | | "type": "string" |
| | | }, |
| | | "returnDate": { |
| | | "type": "string" |
| | | }, |
| | | "status": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateSalesReturnRequest": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "type": "integer" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "memberId": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "products": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Product" |
| | | } |
| | | }, |
| | | "reason": { |
| | | "type": "string" |
| | | }, |
| | | "repository": { |
| | | "type": "string" |
| | | }, |
| | | "returnDate": { |
| | | "type": "string" |
| | | }, |
| | | "status": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateSalesSources": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "/api/salesReturn/add": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "SalesReturn" |
| | | ], |
| | | "summary": "添加销售退货", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.AddSalesReturnRequest" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/salesReturn/delete/{id}": { |
| | | "delete": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "SalesReturn" |
| | | ], |
| | | "summary": "删除销售退货", |
| | | "parameters": [ |
| | | { |
| | | "type": "integer", |
| | | "description": "查询参数", |
| | | "name": "id", |
| | | "in": "path", |
| | | "required": true |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/salesReturn/list": { |
| | | "get": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "SalesReturn" |
| | | ], |
| | | "summary": "获取销售退货列表", |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/salesReturn/update/{id}": { |
| | | "put": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "SalesReturn" |
| | | ], |
| | | "summary": "更新销售退货", |
| | | "parameters": [ |
| | | { |
| | | "description": "查询参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.UpdateSalesReturnRequest" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "OK", |
| | | "schema": { |
| | | "$ref": "#/definitions/contextx.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api/salesSources/add": { |
| | | "post": { |
| | | "produces": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.AddSalesReturnRequest": { |
| | | "type": "object", |
| | | "properties": { |
| | | "salesReturn": { |
| | | "$ref": "#/definitions/request.SalesReturn" |
| | | } |
| | | } |
| | | }, |
| | | "request.AddSalesSources": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | "deliveryDate": { |
| | | "type": "string" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "memberId": { |
| | | "type": "integer" |
| | | }, |
| | |
| | | "type": "string" |
| | | }, |
| | | "wechatOrderStatus": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.SalesReturn": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "type": "integer" |
| | | }, |
| | | "memberId": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "products": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Product" |
| | | } |
| | | }, |
| | | "reason": { |
| | | "type": "string" |
| | | }, |
| | | "repository": { |
| | | "type": "string" |
| | | }, |
| | | "returnDate": { |
| | | "type": "string" |
| | | }, |
| | | "status": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateSalesReturnRequest": { |
| | | "type": "object", |
| | | "properties": { |
| | | "clientId": { |
| | | "type": "integer" |
| | | }, |
| | | "id": { |
| | | "type": "integer" |
| | | }, |
| | | "memberId": { |
| | | "type": "integer" |
| | | }, |
| | | "number": { |
| | | "type": "string" |
| | | }, |
| | | "products": { |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/model.Product" |
| | | } |
| | | }, |
| | | "reason": { |
| | | "type": "string" |
| | | }, |
| | | "repository": { |
| | | "type": "string" |
| | | }, |
| | | "returnDate": { |
| | | "type": "string" |
| | | }, |
| | | "status": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.UpdateSalesSources": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | description: 商机来源ID |
| | | type: integer |
| | | type: object |
| | | request.AddSalesReturnRequest: |
| | | properties: |
| | | salesReturn: |
| | | $ref: '#/definitions/request.SalesReturn' |
| | | type: object |
| | | request.AddSalesSources: |
| | | properties: |
| | | name: |
| | |
| | | type: string |
| | | deliveryDate: |
| | | type: string |
| | | id: |
| | | type: integer |
| | | memberId: |
| | | type: integer |
| | | number: |
| | |
| | | signTime: |
| | | type: string |
| | | wechatOrderStatus: |
| | | type: integer |
| | | type: object |
| | | request.SalesReturn: |
| | | properties: |
| | | clientId: |
| | | type: integer |
| | | memberId: |
| | | type: integer |
| | | number: |
| | | type: string |
| | | products: |
| | | items: |
| | | $ref: '#/definitions/model.Product' |
| | | type: array |
| | | reason: |
| | | type: string |
| | | repository: |
| | | type: string |
| | | returnDate: |
| | | type: string |
| | | status: |
| | | type: integer |
| | | type: object |
| | | request.SetCity: |
| | |
| | | type: integer |
| | | sales_sources_id: |
| | | description: 商机来源ID |
| | | type: integer |
| | | type: object |
| | | request.UpdateSalesReturnRequest: |
| | | properties: |
| | | clientId: |
| | | type: integer |
| | | id: |
| | | type: integer |
| | | memberId: |
| | | type: integer |
| | | number: |
| | | type: string |
| | | products: |
| | | items: |
| | | $ref: '#/definitions/model.Product' |
| | | type: array |
| | | reason: |
| | | type: string |
| | | repository: |
| | | type: string |
| | | returnDate: |
| | | type: string |
| | | status: |
| | | type: integer |
| | | type: object |
| | | request.UpdateSalesSources: |
| | |
| | | summary: 更新销售线索 |
| | | tags: |
| | | - SalesLeads |
| | | /api/salesReturn/add: |
| | | post: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.AddSalesReturnRequest' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 添加销售退货 |
| | | tags: |
| | | - SalesReturn |
| | | /api/salesReturn/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: |
| | | - SalesReturn |
| | | /api/salesReturn/list: |
| | | get: |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 获取销售退货列表 |
| | | tags: |
| | | - SalesReturn |
| | | /api/salesReturn/update/{id}: |
| | | put: |
| | | parameters: |
| | | - description: 查询参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.UpdateSalesReturnRequest' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: OK |
| | | schema: |
| | | $ref: '#/definitions/contextx.Response' |
| | | summary: 更新销售退货 |
| | | tags: |
| | | - SalesReturn |
| | | /api/salesSources/add: |
| | | post: |
| | | parameters: |
| | |
| | | SubOrder{}, |
| | | Product{}, |
| | | SalesDetails{}, |
| | | SalesReturn{}, |
| | | ) |
| | | return err |
| | | } |
New file |
| | |
| | | package request |
| | | |
| | | import "aps_crm/model" |
| | | |
| | | type AddSalesReturnRequest struct { |
| | | SalesReturn SalesReturn |
| | | } |
| | | |
| | | type SalesReturn struct { |
| | | ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:客户id"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:退货单号"` |
| | | Repository string `json:"repository" gorm:"column:repository;type:varchar(255);comment:仓库"` |
| | | MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"` |
| | | ReturnDate string `json:"returnDate" gorm:"column:return_date;type:datetime;comment:退货日期"` |
| | | Status int `json:"status" gorm:"column:status;type:int;comment:退货状态"` |
| | | Reason string `json:"reason" gorm:"column:reason;type:varchar(255);comment:退货原因"` |
| | | Products []model.Product `json:"products" gorm:"many2many:salesReturn_product;"` |
| | | } |
| | | |
| | | type UpdateSalesReturnRequest struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | SalesReturn |
| | | } |
| | |
| | | SalesDetailsResponse struct { |
| | | List []*model.SalesDetails `json:"list"` |
| | | } |
| | | |
| | | SalesReturnResponse struct { |
| | | List []*model.SalesReturn `json:"list"` |
| | | } |
| | | ) |
New file |
| | |
| | | package model |
| | | |
| | | import ( |
| | | "aps_crm/pkg/mysqlx" |
| | | "gorm.io/gorm" |
| | | "time" |
| | | ) |
| | | |
| | | type ( |
| | | SalesReturn struct { |
| | | Id int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"` |
| | | ClientId int `json:"clientId" gorm:"column:client_id;type:int;comment:客户id"` |
| | | Number string `json:"number" gorm:"column:number;type:varchar(255);comment:退货单号"` |
| | | Repository string `json:"repository" gorm:"column:repository;type:varchar(255);comment:仓库"` |
| | | MemberId int `json:"memberId" gorm:"column:member_id;type:int;comment:负责人id"` |
| | | ReturnDate time.Time `json:"returnDate" gorm:"column:return_date;type:datetime;comment:退货日期"` |
| | | Status int `json:"status" gorm:"column:status;type:int;comment:退货状态"` |
| | | Reason string `json:"reason" gorm:"column:reason;type:varchar(255);comment:退货原因"` |
| | | Products []Product `json:"products" gorm:"many2many:salesReturn_product;"` |
| | | } |
| | | |
| | | SalesReturnSearch struct { |
| | | SalesReturn |
| | | Orm *gorm.DB |
| | | } |
| | | ) |
| | | |
| | | func (SalesReturn) TableName() string { |
| | | return "sales_return" |
| | | } |
| | | |
| | | func NewSalesReturnSearch() *SalesReturnSearch { |
| | | return &SalesReturnSearch{ |
| | | Orm: mysqlx.GetDB(), |
| | | } |
| | | } |
| | | |
| | | func (slf *SalesReturnSearch) build() *gorm.DB { |
| | | var db = slf.Orm.Model(&SalesReturn{}) |
| | | if slf.Id != 0 { |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | | func (slf *SalesReturnSearch) Create(record *SalesReturn) error { |
| | | var db = slf.build() |
| | | return db.Create(record).Error |
| | | } |
| | | |
| | | func (slf *SalesReturnSearch) Delete() error { |
| | | var db = slf.build() |
| | | return db.Delete(&SalesReturn{}).Error |
| | | } |
| | | |
| | | func (slf *SalesReturnSearch) Update(record *SalesReturn) error { |
| | | var db = slf.build() |
| | | return db.Updates(record).Error |
| | | } |
| | | |
| | | func (slf *SalesReturnSearch) Find() (*SalesReturn, error) { |
| | | var db = slf.build() |
| | | var record = new(SalesReturn) |
| | | err := db.First(record).Error |
| | | return record, err |
| | | } |
| | | |
| | | func (slf *SalesReturnSearch) FindAll() ([]*SalesReturn, error) { |
| | | var db = slf.build() |
| | | var record = make([]*SalesReturn, 0) |
| | | err := db.Preload("Products").Find(&record).Error |
| | | return record, err |
| | | } |
| | | |
| | | func (slf *SalesReturnSearch) SetId(id int) *SalesReturnSearch { |
| | | slf.Id = id |
| | | return slf |
| | | } |
| | |
| | | SalesDetailsUpdateErr = 2800005 // 更新销售明细失败 |
| | | SalesDetailsDeleteErr = 2800006 // 删除销售明细失败 |
| | | |
| | | SalesReturnExist = 2900001 // 销售退货单已存在 |
| | | SalesReturnNotExist = 2900002 // 销售退货单不存在 |
| | | SalesReturnListErr = 2900003 // 获取销售退货单列表失败 |
| | | SalesReturnSetErr = 2900004 // 设置销售退货单失败 |
| | | SalesReturnUpdateErr = 2900005 // 更新销售退货单失败 |
| | | SalesReturnDeleteErr = 2900006 // 删除销售退货单失败 |
| | | |
| | | ) |
| | |
| | | MasterOrderRouter |
| | | SubOrderRouter |
| | | SalesDetailsRouter |
| | | SalesReturnRouter |
| | | } |
| | | |
| | | func InitRouter() *gin.Engine { |
| | |
| | | routerGroup.InitMasterOrderRouter(PrivateGroup) // 注册masterOrder路由 |
| | | routerGroup.InitSubOrderRouter(PrivateGroup) // 注册subOrder路由 |
| | | routerGroup.InitSalesDetailsRouter(PrivateGroup) // 注册salesDetails路由 |
| | | routerGroup.InitSalesReturnRouter(PrivateGroup) // 注册salesReturn路由 |
| | | } |
| | | return Router |
| | | } |
New file |
| | |
| | | package router |
| | | |
| | | import ( |
| | | v1 "aps_crm/api/v1" |
| | | "github.com/gin-gonic/gin" |
| | | ) |
| | | |
| | | type SalesReturnRouter struct{} |
| | | |
| | | func (s *SalesReturnRouter) InitSalesReturnRouter(router *gin.RouterGroup) { |
| | | salesReturnRouter := router.Group("salesReturn") |
| | | salesReturnApi := v1.ApiGroup.SalesReturnApi |
| | | { |
| | | salesReturnRouter.POST("add", salesReturnApi.Add) // 添加销售退货 |
| | | salesReturnRouter.DELETE("delete/:id", salesReturnApi.Delete) // 删除销售退货 |
| | | salesReturnRouter.PUT("update", salesReturnApi.Update) // 更新销售退货 |
| | | salesReturnRouter.GET("list", salesReturnApi.List) // 获取销售退货列表 |
| | | } |
| | | } |
| | |
| | | MasterOrderService |
| | | SubOrderService |
| | | SalesDetailsService |
| | | SalesReturnService |
| | | } |
| | | |
| | | var ServiceGroup = new(Group) |
New file |
| | |
| | | package service |
| | | |
| | | import ( |
| | | "aps_crm/model" |
| | | "aps_crm/pkg/ecode" |
| | | ) |
| | | |
| | | type SalesReturnService struct{} |
| | | |
| | | func (SalesReturnService) AddSalesReturn(salesReturn *model.SalesReturn) int { |
| | | err := model.NewSalesReturnSearch().Create(salesReturn) |
| | | if err != nil { |
| | | return ecode.SalesReturnExist |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (SalesReturnService) DeleteSalesReturn(id int) int { |
| | | _, err := model.NewSalesReturnSearch().SetId(id).Find() |
| | | if err != nil { |
| | | return ecode.SalesReturnNotExist |
| | | } |
| | | |
| | | err = model.NewSalesReturnSearch().SetId(id).Delete() |
| | | if err != nil { |
| | | return ecode.SalesReturnNotExist |
| | | } |
| | | return ecode.OK |
| | | } |
| | | |
| | | func (SalesReturnService) GetSalesReturnList() ([]*model.SalesReturn, int) { |
| | | list, err := model.NewSalesReturnSearch().FindAll() |
| | | if err != nil { |
| | | return nil, ecode.SalesReturnListErr |
| | | } |
| | | |
| | | return list, ecode.OK |
| | | } |
| | | |
| | | func (SalesReturnService) UpdateSalesReturn(salesReturn *model.SalesReturn) int { |
| | | // check salesReturn exist |
| | | _, err := model.NewSalesReturnSearch().SetId(salesReturn.Id).Find() |
| | | if err != nil { |
| | | return ecode.SalesReturnNotExist |
| | | } |
| | | |
| | | err = model.NewSalesReturnSearch().SetId(salesReturn.Id).Update(salesReturn) |
| | | if err != nil { |
| | | return ecode.SalesReturnSetErr |
| | | } |
| | | |
| | | return ecode.OK |
| | | } |