| | |
| | | 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" |
| | | ) |
| | | |
| | |
| | | return |
| | | } |
| | | |
| | | count, err := model.NewSaleChanceSearch().SetNumber(saleChance.Number).Count() |
| | | if err != nil { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "编码验证失败") |
| | | return |
| | | } |
| | | if count > 0 { |
| | | ctx.FailWithMsg(ecode.UnknownErr, "销售机会编码已存在") |
| | | return |
| | | } |
| | | |
| | | if saleChance.MemberId == 0 { |
| | | userInfo := utils.GetUserInfo(c) |
| | | if userInfo.UserType == constvar.UserTypeSub { |
| | | saleChance.MemberId = userInfo.CrmUserId |
| | | } |
| | | } |
| | | |
| | | errCode = saleChanceService.AddSaleChance(&saleChance) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | if params.CodeRule.Method == 1 { |
| | | autoCode := model.GetAutoCode(saleChance.Id, ¶ms.CodeRule) |
| | | m := map[string]interface{}{ |
| | | "number": autoCode, |
| | | } |
| | | _ = model.NewSaleChanceSearch().SetId(saleChance.Id).UpdateByMap(m) |
| | | } |
| | | |
| | | ctx.Ok() |
| | |
| | | sc.Address.CountryId = saleChance.Address.CountryId |
| | | sc.Address.ProvinceId = saleChance.Address.ProvinceId |
| | | sc.CodeStandID = saleChance.CodeStandID |
| | | sc.Products = saleChance.Products |
| | | |
| | | return ecode.OK, sc |
| | | } |
| | |
| | | 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 |
| | | } |
| | | |
| | | saleChances, total, errCode := saleChanceService.GetSaleChanceList(params.Page, params.PageSize, params.SearchMap) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |