xingzai 6 bulan lalu
induk
melakukan
ad2c35adb1

+ 229 - 0
controllers/cygx/report_article.go

@@ -1976,3 +1976,232 @@ func (this *IndustrialSubjectController) ReportMappingAdd() {
 	br.Msg = "分类成功"
 	br.IsAddLog = true
 }
+
+//func init() {
+//	initart()
+//}
+
+func initart() {
+	//行业
+	var condition string
+	var pars []interface{}
+	condition += ` AND re.chart_permission_id  = 62  `
+	//报告匹配类型
+
+	condition += `	GROUP BY art.article_id  ORDER BY art.publish_date DESC `
+	listart, err := cygx.GetReportArticleList(condition, pars, 0, 200, 1)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+
+	//创建excel
+	dir, err := os.Executable()
+	exPath := filepath.Dir(dir)
+	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	xlsxFile := xlsx.NewFile()
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	style := xlsx.NewStyle()
+	alignment := xlsx.Alignment{
+		Horizontal: "center",
+		Vertical:   "center",
+		WrapText:   true,
+	}
+	style.Alignment = alignment
+	style.ApplyAlignment = true
+
+	redStyle := xlsx.NewStyle()
+	redStyle.Alignment = alignment
+	redStyle.ApplyAlignment = true
+	redStyle.Font.Color = "ff0000"
+	//定义底色需要标黄的 单元格颜色
+	redFill := xlsx.Fill{"solid", "ffff00", "ffff00"}
+	redStyle.Fill = redFill
+	//redStyle.Border = *border
+
+	var sheetName string
+	sheetName = "PV"
+	sheet, err := xlsxFile.AddSheet(sheetName)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	//标头
+	rowTitle := sheet.AddRow()
+	cellA := rowTitle.AddCell()
+	cellA.Value = "姓名"
+	cellB := rowTitle.AddCell()
+	cellB.Value = "手机号"
+	cellC := rowTitle.AddCell()
+	cellC.Value = "公司名称"
+	cellD := rowTitle.AddCell()
+	cellD.Value = "所属销售"
+
+	cellDCreatedTime := rowTitle.AddCell()
+	cellDCreatedTime.Value = "阅读时间(最后一次)"
+
+	cellE := rowTitle.AddCell()
+	cellE.Value = "停留时长(多次合计))"
+
+	cellF := rowTitle.AddCell()
+	cellF.Value = "阅读来源"
+
+	cellStatus := rowTitle.AddCell()
+	cellStatus.Value = "客户状态"
+
+	cellTc := rowTitle.AddCell()
+	cellTc.Value = "签约套餐"
+
+	for _, v := range listart {
+		articleId := v.ArticleId
+		condition = ` AND h.company_id != ` + strconv.Itoa(utils.HZ_COMPANY_ID) // 过滤弘则
+		list, err := cygx.GetArticleHistoryList(articleId, condition)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		listClPv, err := cygx.GetCygxCelueArticleHistoryRecordPvAll(strconv.Itoa(articleId))
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			fmt.Println(err)
+			return
+		}
+
+		var listDate []*cygx.ArticleHistoryRep
+		var mobiles []string
+
+		var mapMobileCy = make(map[string]bool)
+		var mapMobileCl = make(map[string]bool)
+		mapstopTime := make(map[string]int)
+		if len(list) > 0 {
+			for _, vPv := range list {
+				if !utils.ValidateMobileFormatat(vPv.Mobile) {
+					continue
+				}
+
+				mobiles = append(mobiles, vPv.Mobile)
+
+				stopTime, _ := strconv.Atoi(vPv.StopTime)
+				mapstopTime[vPv.Mobile] += stopTime
+			}
+		}
+
+		if len(listClPv) > 0 {
+			for _, vPv := range listClPv {
+				if !utils.ValidateMobileFormatat(vPv.Mobile) {
+					continue
+				}
+				vPv.Ly = "1"
+				//if vPv.Mobile != "" {
+				mobiles = append(mobiles, vPv.Mobile)
+				//}
+			}
+		}
+
+		listUser, err := models.GetWxUserRaiSllerListByUserMobile(mobiles)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+
+		mapuserMapbil := make(map[string]*models.WxUserSller)
+		var companyIds []int
+		for _, vuser := range listUser {
+			//mapuserMapbil[vuser.Mobile] = vuser
+			companyIds = append(companyIds, vuser.CompanyId)
+		}
+
+		//合并合同所对应的权限
+		mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapByIds(companyIds)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+		//fmt.Println(companyIds)
+		//for k, vuser := range mappermissionName {
+		//	fmt.Println(k, vuser)
+		//}
+
+		//fmt.Println(mappermissionName)
+		for _, vuser := range listUser {
+			vuser.ChartPermissionName = mappermissionName[vuser.CompanyId]
+			mapuserMapbil[vuser.Mobile] = vuser
+		}
+
+		if len(list) > 0 {
+			for _, vPv := range list {
+				if !utils.ValidateMobileFormatat(vPv.Mobile) || mapMobileCy[vPv.Mobile] {
+					continue
+				}
+				mapMobileCy[vPv.Mobile] = true
+				listDate = append(listDate, vPv)
+			}
+		}
+
+		if len(listClPv) > 0 {
+			for _, vPv := range listClPv {
+				if !utils.ValidateMobileFormatat(vPv.Mobile) || mapMobileCl[vPv.Mobile] {
+					continue
+				}
+				mapMobileCl[vPv.Mobile] = true
+				listDate = append(listDate, vPv)
+			}
+		}
+
+		rowtitleK := sheet.AddRow()
+		cellADatatitleK := rowtitleK.AddCell()
+		cellADatatitleK.Value = ""
+
+		rowtitle := sheet.AddRow()
+		cellADatatitle := rowtitle.AddCell()
+		cellADatatitle.Value = v.Title
+
+		for _, item := range listDate {
+			row := sheet.AddRow()
+			cellAData := row.AddCell()
+			cellAData.Value = item.RealName
+			//if item.Ly == "1" {
+			//	cellAData.SetStyle(redStyle)
+			//}
+			cellBData := row.AddCell()
+			cellBData.Value = item.Mobile
+			cellCData := row.AddCell()
+			//cellCData.Value = item.CompanyName
+			cellDData := row.AddCell()
+			//cellDData.Value = item.SellerName
+			cellEData := row.AddCell()
+			cellEData.Value = item.CreateTime
+			cellFData := row.AddCell()
+
+			if item.Ly == "" {
+				cellFData.Value = strconv.Itoa(mapstopTime[item.Mobile])
+			}
+			//fmt.Println(item.Source)
+			cellLyData := row.AddCell()
+			switch item.Source {
+			case "MOBILE":
+				cellLyData.Value = "小程序"
+			case "WEB":
+				cellLyData.Value = "网页版"
+			case "CELUE":
+				cellLyData.Value = "vmp"
+			}
+			cellStatusData := row.AddCell()
+			cellermissionNameData := row.AddCell()
+			if mapuserMapbil[item.Mobile] != nil {
+				cellCData.Value = mapuserMapbil[item.Mobile].CompanyName
+				cellDData.Value = mapuserMapbil[item.Mobile].SellerName
+				cellStatusData.Value = mapuserMapbil[item.Mobile].Status
+				cellermissionNameData.Value = mapuserMapbil[item.Mobile].ChartPermissionName
+			}
+		}
+
+		err = xlsxFile.Save(downLoadnFilePath)
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+	}
+}

+ 3 - 1
models/cygx/summary_manage.go

@@ -525,6 +525,8 @@ type ArticleHistoryRep struct {
 	SellerName  string `description:"所属销售"`
 	StopTime    string `description:"阅读停留时间"`
 	CreateTime  string `description:"创建时间"`
+	Ly          string `description:"创建时间"`
+	Source      string `description:"创建时间"`
 }
 
 // 列表
@@ -536,7 +538,7 @@ func GetArticleHistoryList(articleId int, condition string) (items []*ArticleHis
 				cygx_article_history_record_all AS h
 			WHERE
 				h.article_id = ?
-				AND h.platfor = 1  AND h.is_del = 0  `
+				AND h.platfor = 1  AND h.is_del = 0   `
 	if condition != "" {
 		sql = sql + condition + ` GROUP BY h.id`
 	}

+ 9 - 6
models/wx_user.go

@@ -530,12 +530,14 @@ func GetWxUserListCompanyId(companyId int) (list []*WxUserItem, err error) {
 }
 
 type WxUserSller struct {
-	UserId      int    `description:"用户id"`
-	RealName    string `description:"姓名"`
-	Mobile      string `description:"手机号"`
-	CompanyId   int    `description:"公司id"`
-	CompanyName string `description:"公司名称"`
-	SellerName  string `description:"所属销售"`
+	UserId              int    `description:"用户id"`
+	RealName            string `description:"姓名"`
+	Mobile              string `description:"手机号"`
+	CompanyId           int    `description:"公司id"`
+	CompanyName         string `description:"公司名称"`
+	SellerName          string `description:"所属销售"`
+	Status              string `description:"所属销售"`
+	ChartPermissionName string `description:"所属销售"`
 }
 
 // GetWxUserRaiSllerListByUserIds 根据用户id获取权益相关用户信息
@@ -576,6 +578,7 @@ func GetWxUserRaiSllerListByUserMobile(mobiles []string) (list []*WxUserSller, e
 				w.mobile,
 				c.company_name,
 				c.company_id,
+				p.status,
 				p.seller_name 
 			FROM
 				wx_user AS w

+ 138 - 1
services/cygx/contract_allocation.go

@@ -195,6 +195,143 @@ func GetCompanyContractPermissionNameMapById(companyContractIds []int) (mapContr
 	return
 }
 
+func GetCompanyContractPermissionNameMapByIds(companyIds []int) (mapContractResp map[int]string, err error) {
+	//return
+	lenArr := len(companyIds)
+	if lenArr == 0 {
+		return
+	}
+	var condition string
+	var pars []interface{}
+
+	condition += " AND  company_id IN (" + utils.GetOrmInReplace(lenArr) + ") AND product_id = 2  AND status = '正式' "
+	pars = append(pars, companyIds)
+
+	//获取所有开通买方研选正式试用的客户列表
+	listCompanyPermission, e := company.GetCompanyReportPermissionList(condition, pars, 0, 0)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCompanyReportPermissionList, Err: " + e.Error())
+		return
+	}
+
+	//companyContractList, e := company.GetCompanyContractList(condition, pars)
+	//if e != nil && e.Error() != utils.ErrNoRow() {
+	//	err = errors.New("GetCompanyContractList, Err: " + e.Error())
+	//	return
+	//}
+
+	permissionList, e := models.GetChartPermissionList()
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetChartPermissionList, Err: " + e.Error())
+		return
+	}
+	mappermissionName := make(map[int]string)
+	for _, v := range permissionList {
+		if v.ProductId == 2 {
+			mappermissionName[v.ChartPermissionId] = v.Remark
+		}
+	}
+
+	mapContractIdPerssion := make(map[int]string) //单个合同ID所对应的套餐或者权限名称
+	//for _, v := range companyContractList {
+	//	if v.RaiPackageType == 1 {
+	//		mapContractIdPerssion[v.CompanyContractId] = "70w套餐,"
+	//	}
+	//	if v.RaiPackageType == 2 {
+	//		mapContractIdPerssion[v.CompanyContractId] = "45w套餐,"
+	//	}
+	//}
+	//
+	//companyContractPermissionList, e := company.GetCompanyContractPermissionList(condition, pars)
+	//if e != nil && e.Error() != utils.ErrNoRow() {
+	//	err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
+	//	return
+	//}
+
+	mapIsUpgrade := make(map[string]bool) //合同ID对应的行业是否有升级
+	for _, v := range listCompanyPermission {
+		//如果开通的不是整个套餐,那么就做单独的子权限处理
+		if strings.Count(mapContractIdPerssion[(v.CompanyId)], "w套餐") == 0 {
+			if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
+				if v.ExpensiveYx == 1 {
+					mapContractIdPerssion[(v.CompanyId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(5w),"
+				} else if v.ExpensiveYx == 2 {
+					mapContractIdPerssion[(v.CompanyId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(10w),"
+				} else {
+					mapContractIdPerssion[(v.CompanyId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + ","
+				}
+			} else {
+				mapContractIdPerssion[(v.CompanyId)] += mappermissionName[v.ChartPermissionId] + ","
+				if v.IsUpgrade == 1 {
+					//合同ID,权限名称形成唯一的主键索引
+					perssionName := mappermissionName[v.ChartPermissionId]
+					perssionName = strings.Replace(perssionName, "(客观)", "", -1)
+					perssionName = strings.Replace(perssionName, "(主观)", "", -1)
+					mapIsUpgrade[fmt.Sprint(v.CompanyContractId, "perssionName", perssionName)] = true
+				}
+			}
+		} else {
+			if v.ChartPermissionId == utils.ZHUAN_JIA_ID {
+				mapContractIdPerssion[(v.CompanyId)] += utils.ZHUAN_JIA_NAME + ","
+			}
+			if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
+				if v.ExpensiveYx == 1 {
+					mapContractIdPerssion[(v.CompanyId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(5w),"
+				} else if v.ExpensiveYx == 2 {
+					mapContractIdPerssion[(v.CompanyId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(10w),"
+				} else {
+					mapContractIdPerssion[(v.CompanyId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + ","
+				}
+			}
+
+			if v.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
+				mapContractIdPerssion[(v.CompanyId)] += utils.YAN_XUAN_KOU_DIAN_BAO_NAME + ","
+			}
+		}
+	}
+	//合并客观权限
+	for k, v := range mapContractIdPerssion {
+		perssionName := v
+		if strings.Count(v, utils.YI_YAO_NAME) == 2 {
+			perssionName = strings.Replace(perssionName, "医药(主观)", "医药", -1)
+			perssionName = strings.Replace(perssionName, "医药(客观)", "", -1)
+		}
+		if strings.Count(v, utils.XIAO_FEI_NAME) == 2 {
+			perssionName = strings.Replace(perssionName, "消费(主观)", "消费", -1)
+			perssionName = strings.Replace(perssionName, "消费(客观)", "", -1)
+		}
+		if strings.Count(v, utils.KE_JI_NAME) == 2 {
+			perssionName = strings.Replace(perssionName, "科技(主观)", "科技", -1)
+			perssionName = strings.Replace(perssionName, "科技(客观)", "", -1)
+		}
+		if strings.Count(v, utils.ZHI_ZAO_NAME) == 2 {
+			perssionName = strings.Replace(perssionName, "智造(主观)", "智造", -1)
+			perssionName = strings.Replace(perssionName, "智造(客观)", "", -1)
+		}
+
+		perssionName = strings.TrimRight(perssionName, ",")
+		mapContractIdPerssion[k] = perssionName
+	}
+	mapContractResp = make(map[int]string, 0)
+
+	//过滤多余的","
+	for k, v := range mapContractIdPerssion {
+		sliceName := strings.Split(v, ",")
+		var nameArr []string
+		for _, vName := range sliceName {
+			if vName == "" {
+				continue
+			}
+			if mapIsUpgrade[fmt.Sprint(k, "perssionName", vName)] {
+				vName += "(升级)"
+			}
+			nameArr = append(nameArr, vName)
+		}
+		mapContractResp[k] = strings.Join(nameArr, ",")
+	}
+	return
+}
+
 // GetCompanyPermissionNameStatusMapByCompanyId 通过公司ID,获取公司当下所有权限的状态信息
 func GetCompanyPermissionNameStatusMapByCompanyId(companyIds []int) (mapResp map[string]string, err error) {
 	//return
@@ -205,7 +342,7 @@ func GetCompanyPermissionNameStatusMapByCompanyId(companyIds []int) (mapResp map
 	var condition string
 	var pars []interface{}
 
-	condition += " AND  company_id IN (" + utils.GetOrmInReplace(lenArr) + ") AND product_id = 2 "
+	condition += " AND  company_id IN (" + utils.GetOrmInReplace(lenArr) + ") AND product_id = 2  AND status = '正式' "
 	pars = append(pars, companyIds)
 
 	//获取所有开通买方研选正式试用的客户列表