Selaa lähdekoodia

新增客户来源

hongze 1 vuosi sitten
vanhempi
commit
fcb783d355

+ 93 - 69
controllers/overseas_custom/custom.go

@@ -11,74 +11,6 @@ import (
 	"time"
 )
 
-// @Title 海外客户统计数据
-// @Description 海外客户统计数据
-// @Param   Keywords	query	string	false	"关键词:客户名称/社会信用码/联系人手机号/邮箱"
-// @Param   SellerId	query	int		false	"销售ID"
-// @Success 200 {object} models.EnglishCompanyPageListResp
-// @router /custom/statistics [get]
-func (this *OverseasCustomController) CustomStatistics() {
-	br := new(models.BaseResponse).Init()
-	br.IsSendEmail = false
-	defer func() {
-		this.Data["json"] = br
-		this.ServeJSON()
-	}()
-	sysUser := this.SysUser
-	if sysUser == nil {
-		br.Msg = "请登录"
-		br.ErrMsg = "请登录,SysUser Is Empty"
-		br.Ret = 408
-		return
-	}
-
-	keywords := this.GetString("Keywords", "")
-	sellerId, _ := this.GetInt("SellerId", 0)
-
-	obj := new(overseas_custom.Custom)
-
-	var cond string
-	var pars []interface{}
-	if keywords != "" {
-		k := "%" + keywords + "%"
-		enCompanyIds, e := models.GetEnCompanyIdsByKeyword(k)
-		if e != nil {
-			br.Msg = "获取失败"
-			br.ErrMsg = "关键词获取英文客户IDs失败, Err: " + e.Error()
-			return
-		}
-
-		//获取中文客户
-
-		companyIds, err := obj.GetCompanyIdsByKeyword(k)
-		if err != nil {
-			br.Msg = "获取失败"
-			br.ErrMsg = "关键词获取客户IDs失败, Err: " + err.Error()
-			return
-		}
-
-		companyIds = append(companyIds, enCompanyIds...)
-
-		cond += fmt.Sprintf(` AND c.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
-		pars = append(pars, companyIds)
-	}
-	if sellerId > 0 {
-		cond = ` AND m.seller_id=? `
-		pars = append(pars, sellerId)
-	}
-
-	list, err := obj.GetCustomTotal(cond, pars)
-	if err != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取各状态总数失败, Err: " + err.Error()
-		return
-	}
-	br.Ret = 200
-	br.Success = true
-	br.Msg = "获取成功"
-	br.Data = list
-}
-
 // @Title 获取海外客户列表数据
 // @Description 获取海外客户列表数据
 // @Param   PageSize   query   int  true       "每页数据条数"
@@ -148,7 +80,7 @@ func (this *OverseasCustomController) CustomList() {
 
 		companyIds = append(companyIds, enCompanyIds...)
 
-		condition += fmt.Sprintf(` AND c.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
+		condition += fmt.Sprintf(` AND m.company_id IN (%s) `, utils.GetOrmInReplace(len(companyIds)))
 		pars = append(pars, companyIds)
 	}
 	if sellerId > 0 {
@@ -169,11 +101,26 @@ func (this *OverseasCustomController) CustomList() {
 		br.ErrMsg = "获取数据失败, Err: " + err.Error()
 		return
 	}
+
+	for _, v := range list {
+		if v.Source == 1 && v.OverseasStatus != "" {
+			v.CompanyStatus = v.OverseasStatus
+		}
+	}
+
+	StatisticsDataList, err := obj.GetCustomTotal(condition, pars)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取各状态总数失败, Err: " + err.Error()
+		return
+	}
+
 	page := paging.GetPaging(currentIndex, pageSize, total)
 
 	resp := new(overseas_custom.CustomListResp)
 	resp.Paging = page
 	resp.List = list
+	resp.StatisticsData = StatisticsDataList
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
@@ -256,3 +203,80 @@ func (this *OverseasCustomController) CustomHide() {
 	br.Success = true
 	br.Msg = "隐藏成功"
 }
+
+// @Title 客户状态设置
+// @Description 客户状态设置
+// @Param	request  body  overseas_custom.CustomHideReq  true  "type json string"
+// @Success 200 string "操作成功"
+// @router /custom/status_set [post]
+func (this *OverseasCustomController) CustomStatusSet() {
+	br := new(models.BaseResponse).Init()
+	br.IsSendEmail = false
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	var req overseas_custom.CustomHideReq
+	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	if req.CompanyId <= 0 {
+		br.Msg = "参数错误!"
+		return
+	}
+
+	obj := new(overseas_custom.Custom)
+	item, err := obj.GetCustomByCompanyId(req.CompanyId)
+	if err != nil {
+		br.Msg = "隐藏失败!"
+		br.ErrMsg = "隐藏失败,Err:" + err.Error()
+		return
+	}
+	//是否隐藏:0:不隐藏,1:隐藏
+	var overseasStatus string
+	if item.OverseasStatus == "" {
+		overseasStatus = "正式"
+	} else {
+		overseasStatus = ""
+	}
+
+	if req.CompanyId > 1000000 {
+		enCompanyObj := new(models.EnglishCompany)
+		// 更新客户
+		nowTime := time.Now().Local()
+		enCompanyObj.CompanyId = req.CompanyId - utils.EnCompanyIdStep
+		enCompanyObj.OverseasStatus = overseasStatus
+		enCompanyObj.ModifyTime = nowTime
+		updateCols := []string{"OverseasStatus", "ModifyTime"}
+		if err = enCompanyObj.Update(updateCols); err != nil {
+			br.Msg = "隐藏失败"
+			br.ErrMsg = "更新英文客户转正式状态失败, Err:" + err.Error()
+			return
+		}
+	} else {
+		companyObj := new(company.Company)
+		companyObj.CompanyId = req.CompanyId
+		companyObj.OverseasStatus = overseasStatus
+		updateCols := []string{"OverseasStatus"}
+		err = companyObj.Update(updateCols)
+		if err != nil {
+			br.Msg = "隐藏失败"
+			br.ErrMsg = "更新客户转正式状态失败, Err:" + err.Error()
+			return
+		}
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}

+ 1 - 1
models/company/company.go

@@ -43,7 +43,7 @@ type Company struct {
 	OpenCompanyCode string    `description:"开放给第三方的客户编码,不让第三方定位我们的客户信息"`
 	Nation          string    `description:"所属国家"`
 	IsHide          int       `description:"是否隐藏:0:不隐藏,1:隐藏"`
-	OverseasStatus  int       `description:"海外客户状态:'正式','试用','关闭'"`
+	OverseasStatus  string    `description:"海外客户状态:'正式','试用','关闭'"`
 }
 
 // 新增客户

+ 1 - 1
models/english_company.go

@@ -28,7 +28,7 @@ type EnglishCompany struct {
 	Status         int       `description:"1:正式,2:临时,3:终止"`
 	Nation         string    `description:"所属国家"`
 	IsHide         int       `description:"是否隐藏:0:不隐藏,1:隐藏"`
-	OverseasStatus int       `description:"海外客户状态:'正式','试用','关闭'"`
+	OverseasStatus string    `description:"海外客户状态:'正式','试用','关闭'"`
 }
 
 type EnglishCompanyListItem struct {

+ 9 - 5
models/overseas_custom/custom.go

@@ -19,7 +19,8 @@ type Custom struct {
 	LastViewTime   string `description:"最近阅读时间"`
 	CreateTime     string `description:"创建时间"`
 	IsHide         int    `description:"是否隐藏:0:不隐藏,1:隐藏"`
-	OverseasStatus int    `description:"海外客户状态:'正式','试用','关闭'"`
+	OverseasStatus string `description:"海外客户状态:'正式','试用','关闭'"`
+	Source         int    `description:"来源:1,英文客户,2:客户列表"`
 }
 
 type CustomTotal struct {
@@ -156,7 +157,8 @@ func (obj *Custom) GetCustomList(condition string, pars []interface{}, companySt
 				WHEN '永续' THEN '正式'
 				WHEN '试用' THEN '试用'
 				ELSE '关闭' END AS company_status,
-				b.view_total,b.road_show_total,a.created_time AS create_time,b.last_view_time,a.is_hide,a.overseas_status
+				b.view_total,b.road_show_total,a.created_time AS create_time,b.last_view_time,a.is_hide,a.overseas_status,
+				2 AS source
 				FROM company AS a
 				INNER JOIN company_product AS b ON a.company_id=b.company_id
 				INNER JOIN overseas_custom_seller AS c ON b.seller_id=c.seller_id
@@ -174,7 +176,8 @@ func (obj *Custom) GetCustomList(condition string, pars []interface{}, companySt
 				CASE t.enabled
 				WHEN 0 THEN '关闭'
 				ELSE '试用' END AS company_status,
-				t.view_total,0 AS road_show_total,t.create_time,'' AS last_view_time,a.is_hide,a.overseas_status
+				t.view_total,0 AS road_show_total,t.create_time,'' AS last_view_time,a.is_hide,a.overseas_status,
+				1 AS source
 				FROM %s.english_company AS t
 				INNER JOIN overseas_custom_seller AS n ON t.seller_id=n.seller_id
              WHERE 1=1 `
@@ -216,8 +219,9 @@ func (obj *Custom) GetCustomList(condition string, pars []interface{}, companySt
 }
 
 type CustomListResp struct {
-	Paging *paging.PagingItem
-	List   []*Custom
+	Paging         *paging.PagingItem
+	List           []*Custom
+	StatisticsData []*CustomTotal
 }
 
 // EnglishCompanySaveReq 英文客户-保存请求体