| | |
| | | package v1 |
| | | |
| | | import ( |
| | | "aps_crm/constvar" |
| | | "aps_crm/model" |
| | | "aps_crm/model/request" |
| | | "aps_crm/model/response" |
| | | "aps_crm/pkg/contextx" |
| | | "aps_crm/pkg/ecode" |
| | | "aps_crm/utils" |
| | | "github.com/gin-gonic/gin" |
| | | "strconv" |
| | | ) |
| | | |
| | | type ContractApi struct{} |
| | |
| | | return |
| | | } |
| | | |
| | | count, err := model.NewContractSearch().SetNumber(params.Number).Count() |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "编码验证失败") |
| | | return |
| | | } |
| | | if count > 0 { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "编码已存在") |
| | | return |
| | | } |
| | | |
| | | if contract.MemberId == 0 { |
| | | userInfo := utils.GetUserInfo(c) |
| | | if userInfo.UserType == constvar.UserTypeSub { |
| | | contract.MemberId = userInfo.CrmUserId |
| | | } |
| | | } |
| | | |
| | | errCode = contractService.AddContract(&contract) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | if params.CodeRule.Method == 1 { |
| | | autoCode := model.GetAutoCode(contract.Id, ¶ms.CodeRule) |
| | | m := map[string]interface{}{ |
| | | "number": autoCode, |
| | | } |
| | | _ = model.NewContractSearch().SetId(contract.Id).UpdateByMap(m) |
| | | } |
| | | |
| | | ctx.Ok() |
| | |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/contract/delete [delete] |
| | | func (s *ContractApi) Delete(c *gin.Context) { |
| | | var params request.DeleteContract |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | id := c.Param("id") |
| | | ctx, _ := contextx.NewContext(c, nil) |
| | | if id == "" { |
| | | ctx.Fail(ecode.ParamsErr) |
| | | return |
| | | } |
| | | |
| | | errCode := contractService.DeleteContract(params.Ids) |
| | | atoi, err := strconv.Atoi(id) |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "数据转换失败") |
| | | return |
| | | } |
| | | errCode := contractService.DeleteContract(atoi) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | |
| | | //} |
| | | |
| | | contractModel = model.Contract{ |
| | | ClientId: contract.ClientId, |
| | | MemberId: contract.MemberId, |
| | | Number: contract.Number, |
| | | QuotationId: contract.QuotationId, |
| | | StatusId: contract.StatusId, |
| | | File: contract.File, |
| | | CodeStandID: contract.CodeStandID, |
| | | ClientId: contract.ClientId, |
| | | MemberId: contract.MemberId, |
| | | Number: contract.Number, |
| | | QuotationId: contract.QuotationId, |
| | | StatusId: contract.StatusId, |
| | | File: contract.File, |
| | | CodeStandID: contract.CodeStandID, |
| | | ContractName: contract.ContractName, |
| | | SendTime: contract.SendTime, |
| | | } |
| | | |
| | | return ecode.OK, contractModel |
| | |
| | | return |
| | | } |
| | | |
| | | userInfo := utils.GetUserInfo(c) |
| | | if userInfo.UserType == constvar.UserTypeSub { |
| | | if params.SearchMap == nil { |
| | | params.SearchMap = make(map[string]interface{}, 0) |
| | | } |
| | | params.SearchMap["member_ids"] = userInfo.SubUserIds |
| | | } |
| | | |
| | | contracts, total, errCode := contractService.GetContractList(params.Page, params.PageSize, params.SearchMap) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |