Bladeren bron

新增海外客户统计

hongze 1 jaar geleden
bovenliggende
commit
c5fed3f20e

+ 75 - 0
controllers/overseas_custom/custom.go

@@ -1 +1,76 @@
 package overseas_custom
+
+import (
+	"fmt"
+	"hongze/hz_crm_api/models"
+	"hongze/hz_crm_api/models/overseas_custom"
+	"hongze/hz_crm_api/utils"
+)
+
+// @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
+}

+ 2 - 2
models/english_report_email.go

@@ -288,7 +288,7 @@ func GetEnCompanyIdsByKeyword(keyword string) (companyIds []int, err error) {
 				english_report_email AS a
 			JOIN english_company AS b ON a.company_id = b.company_id AND b.is_deleted = 0
 			WHERE
-				a.is_deleted = 0 AND a.status = 1 AND (a.email LIKE ? OR a.mobile LIKE ? OR b.company_name LIKE ?)`
-	_, err = o.Raw(sql, keyword, keyword, keyword).QueryRows(&companyIds)
+				a.is_deleted = 0 AND a.status = 1 AND (a.email LIKE ? OR a.mobile LIKE ? OR b.company_name LIKE ? OR b.country_code LIKE ? )`
+	_, err = o.Raw(sql, keyword, keyword, keyword, keyword).QueryRows(&companyIds)
 	return
 }

+ 81 - 0
models/overseas_custom/custom.go

@@ -0,0 +1,81 @@
+package overseas_custom
+
+import (
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"hongze/hz_crm_api/utils"
+)
+
+type Custom struct {
+	CompanyId     int    `description:"客户id"`
+	CompanyName   string `description:"客户名称"`
+	Nation        string `description:"国家"`
+	SellerId      int    `description:"销售id"`
+	SellerName    string `description:"销售名称"`
+	CompanyStatus string `description:"状态"`
+	ViewTotal     int    `description:"累计点击量"`
+	RoadShowTotal int    `description:"路演数量"`
+	LastViewTime  string `description:"最近阅读时间"`
+	CreateTime    string `description:"创建时间"`
+}
+
+type CustomTotal struct {
+	CompanyStatus string `description:"状态"`
+	Total         int    `description:"总数"`
+}
+
+func (obj *Custom) GetCustomTotal(condition string, pars []interface{}) (list []*CustomTotal, err error) {
+	o := orm.NewOrm()
+	sql := ``
+	var databaseName string
+	if utils.RunMode == "debug" {
+		databaseName = "test_v2_hongze_rddp"
+	} else {
+		databaseName = "hongze_rddp"
+	}
+
+	sql = `SELECT company_status,COUNT(1) AS total FROM (
+				SELECT a.company_id,a.company_name,a.nation,b.seller_id,b.seller_name,
+				CASE b.status 
+				WHEN '正式' THEN '正式'
+				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
+				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
+				WHERE b.is_overseas = 0
+				UNION ALL
+				SELECT t.company_id+10000000,t.company_name,t.nation,t.seller_id,t.seller_name,
+				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
+				FROM %s.english_company AS t
+				INNER JOIN overseas_custom_seller AS n ON t.seller_id=n.seller_id
+				)AS m
+		WHERE 1=1                       
+`
+
+	if condition != "" {
+		sql += condition
+	}
+
+	sql += ` GROUP BY m.company_status `
+
+	sql = fmt.Sprintf(sql, databaseName)
+
+	_, err = o.Raw(sql, pars).QueryRows(&list)
+	return
+}
+
+// GetCompanyIdsByKeyword 关键词获取客户IDs
+func (obj *Custom) GetCompanyIdsByKeyword(keyword string) (companyIds []int, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT DISTINCT b.company_id FROM wx_user AS a
+INNER JOIN company AS b ON a.company_id=b.company_id
+WHERE 1=1 AND (a.email LIKE ? OR a.mobile LIKE ? OR b.company_name LIKE ? OR b.credit_code LIKE ? ) `
+	_, err = o.Raw(sql, keyword, keyword, keyword, keyword).QueryRows(&companyIds)
+	return
+}

+ 1 - 1
models/overseas_custom/overseas_custom_seller.go

@@ -69,7 +69,7 @@ func (m *OverseasCustomerSale) HandelOverseasCustomerSale(sellerId, isOverseas i
 		return err
 	}
 	if sellerItem.Mobile == "13065778668" {
-		sql = ` UPDATE company_product SET is_overseas = ? WHERE seller_id=? `
+		sql = ` UPDATE company_product SET is_overseas = ? WHERE seller_id=? AND company_id IN (SELECT company_id FROM company WHERE region_type='国内') `
 		_, err = o.Raw(sql, isOverseas, sellerId).Exec()
 		return err
 	}