| | |
| | | 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 SaleChanceApi struct{} |
| | |
| | | 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) |
| | |
| | | // @Tags SaleChance |
| | | // @Summary 删除销售机会 |
| | | // @Produce application/json |
| | | // @Param id path int true "查询参数" |
| | | // @Param object body request.DeleteSaleChance true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/saleChance/delete/{id} [delete] |
| | | // @Router /api/saleChance/delete [delete] |
| | | func (s *SaleChanceApi) Delete(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | var params request.DeleteSaleChance |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | id, _ := strconv.Atoi(c.Param("id")) |
| | | errCode := saleChanceService.DeleteSaleChance(id) |
| | | errCode := saleChanceService.DeleteSaleChance(params.Ids) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |
| | | |
| | | // List |
| | | // |
| | | // @Tags SaleChance |
| | | // @Summary 获取销售机会列表 |
| | | // @Produce application/json |
| | | // @Success 200 {object} contextx.Response{data=response.SaleChanceResponse} |
| | | // @Router /api/saleChance/list [get] |
| | | func (s *SaleChanceApi) List(c *gin.Context) { |
| | | ctx, ok := contextx.NewContext(c, nil) |
| | | if !ok { |
| | | return |
| | | } |
| | | |
| | | errCode, list := saleChanceService.GetSaleChanceList() |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.OkWithDetailed(response.SaleChanceResponse{ |
| | | List: list, |
| | | }) |
| | | } |
| | | |
| | | // checkSaleChanceParams |
| | |
| | | sc.Address.CityId = saleChance.Address.CityId |
| | | sc.Address.CountryId = saleChance.Address.CountryId |
| | | sc.Address.ProvinceId = saleChance.Address.ProvinceId |
| | | sc.CodeStandID = saleChance.CodeStandID |
| | | sc.Products = saleChance.Products |
| | | |
| | | return ecode.OK, sc |
| | | } |
| | | |
| | | // List |
| | | // |
| | | // @Tags SaleChance |
| | | // @Summary 销售机会列表 |
| | | // @Produce application/json |
| | | // @Param object body request.GetSaleChanceList true "参数" |
| | | // |
| | | // @Success 200 {object} contextx.Response{data=response.SaleChanceResponse} |
| | | // |
| | | // @Router /api/saleChance/list [post] |
| | | func (con *SaleChanceApi) List(c *gin.Context) { |
| | | var params request.GetSaleChanceList |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | 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) |
| | | return |
| | | } |
| | | |
| | | ctx.OkWithDetailed(response.SaleChanceResponse{ |
| | | List: saleChances, |
| | | Count: int(total), |
| | | }) |
| | | } |
| | | |
| | | // Push |
| | | // |
| | | // @Tags SaleChance |
| | | // @Summary 推进销售机会 |
| | | // @Produce application/json |
| | | // @Param object body request.PushSaleChance true "查询参数" |
| | | // @Success 200 {object} contextx.Response{} |
| | | // @Router /api/saleChance/push [put] |
| | | func (s *SaleChanceApi) Push(c *gin.Context) { |
| | | var params request.PushSaleChance |
| | | ctx, ok := contextx.NewContext(c, ¶ms) |
| | | if !ok { |
| | | ctx.Fail(ecode.InvalidParams) |
| | | return |
| | | } |
| | | |
| | | errCode := saleChanceService.PushSaleChance(params.Id, params.Step) |
| | | if errCode != ecode.OK { |
| | | ctx.Fail(errCode) |
| | | return |
| | | } |
| | | |
| | | ctx.Ok() |
| | | } |