浏览代码

fix:修复数据同步问题

Roc 2 年之前
父节点
当前提交
bfff27a477
共有 2 个文件被更改,包括 23 次插入2 次删除
  1. 8 0
      models/tables/company/company.go
  2. 15 2
      services/yb/activity.go

+ 8 - 0
models/tables/company/company.go

@@ -41,6 +41,14 @@ type CompanyList struct {
 	Status      string `description:"客户状态" json:"status"`
 }
 
+// GetCompanyById 根据企业id获取企业信息
+func GetCompanyById(companyId int) (items *Company, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM company where company_id= ? `
+	err = o.Raw(sql, companyId).QueryRow(&items)
+	return
+}
+
 // GetList 获取客户列表
 func GetList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*CompanyList, err error) {
 	o := orm.NewOrm()

+ 15 - 2
services/yb/activity.go

@@ -2,6 +2,7 @@ package yb
 
 import (
 	"fmt"
+	"hongze/hongze_open_api/models/tables/company"
 	"hongze/hongze_open_api/models/tables/company_product"
 	"hongze/hongze_open_api/models/tables/qs_event"
 	"hongze/hongze_open_api/models/tables/qs_event_user"
@@ -30,6 +31,7 @@ func SyncUser(qsEventId int) (err error) {
 	}
 
 	companyProductMap := make(map[string]*company_product.CompanyProduct)
+	companyMap := make(map[string]*company.Company)
 	people := len(qsData.Summary) //参与人数
 	if qsData.Summary != nil && people > 0 {
 		for _, v := range qsData.Summary {
@@ -37,6 +39,7 @@ func SyncUser(qsEventId int) (err error) {
 			trimMobile := mobile
 			countryCode := "86"
 			var companyProductInfo *company_product.CompanyProduct
+			var companyInfo *company.Company
 			var wxUserInfo *wx_user.WxUser
 			if mobile != "" {
 				trimMobileSlice := strings.Split(v.Mobile, "-")
@@ -46,7 +49,7 @@ func SyncUser(qsEventId int) (err error) {
 					countryCode = strings.Replace(trimMobileSlice[0], "+", "", -1)
 				}
 				wxUserInfo, _ = wx_user.GetWxUserByMobileCountryCode(trimMobile, countryCode)
-				if wxUserInfo != nil {
+				if wxUserInfo != nil && wxUserInfo.CompanyId != 1 {
 					//获取客户产品信息
 					key := fmt.Sprint(wxUserInfo.CompanyId, "_", 1)
 					if tmpCompanyProductInfo, ok := companyProductMap[key]; ok {
@@ -56,6 +59,16 @@ func SyncUser(qsEventId int) (err error) {
 						if companyProductInfo != nil {
 							companyProductMap[key] = companyProductInfo
 						}
+
+					}
+
+					if tmpCompanyInfo, ok := companyMap[key]; ok {
+						companyInfo = tmpCompanyInfo
+					} else {
+						companyInfo, _ = company.GetCompanyById(wxUserInfo.CompanyId)
+						if companyProductInfo != nil {
+							companyMap[key] = companyInfo
+						}
 					}
 				}
 			}
@@ -93,7 +106,7 @@ func SyncUser(qsEventId int) (err error) {
 				qsEventUserInfo.Name = wxUserInfo.RealName
 				qsEventUserInfo.CompanyId = companyProductInfo.CompanyId
 				qsEventUserInfo.ProductId = companyProductInfo.ProductId
-				qsEventUserInfo.CompanyName = companyProductInfo.ProductName
+				qsEventUserInfo.CompanyName = companyInfo.CompanyName
 				qsEventUserInfo.Status = companyProductInfo.Status
 				qsEventUserInfo.SellerId = companyProductInfo.SellerId
 				qsEventUserInfo.SellerName = companyProductInfo.SellerName