zhangchuanxing 1 месяц назад
Родитель
Сommit
cc04bf1a74

+ 129 - 0
controllers/cygx/report_article.go

@@ -6662,3 +6662,132 @@ func initCommpanyList() {
 	}
 	fmt.Println("end")
 }
+
+//func init() {
+//	initCommpanyNum()
+//}
+
+// 公司研选剩余点数
+func initCommpanyNum() {
+	//行业
+
+	listContract, e := company.CompanyContractListNum()
+	if e != nil {
+		fmt.Println(e)
+		return
+	}
+	var companyIds []int
+
+	for _, v := range listContract {
+		companyIds = append(companyIds, v.CompanyId)
+	}
+
+	mapNum := make(map[int]int)
+	mapYearNum := make(map[string]bool)
+
+	for _, v := range listContract {
+		year := v.StartDate[:4]
+		keyMap := fmt.Sprint("CID", v.CompanyId, "Year", year)
+		if mapYearNum[keyMap] {
+			continue
+		}
+		mapNum[v.CompanyId]++
+		mapYearNum[keyMap] = true
+	}
+
+	listCompanyProduct, err := company.GetCompanyProductsByCompanyIdsAndProductIdinit(companyIds)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+
+	listCompany, err := company.GetOverseasCompanysByCompanyIds(companyIds)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+
+	mapCompamyName := make(map[int]string)
+	mapInteractionNum := make(map[int]int)
+
+	for _, v := range listCompany {
+		mapCompamyName[v.CompanyId] = v.CompanyName
+		mapInteractionNum[v.CompanyId] = v.InteractionNum
+	}
+
+	//创建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 = "正式、试用客户明细"
+	sheet, err := xlsxFile.AddSheet(sheetName)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	//标头
+	rowTitle := sheet.AddRow()
+
+	cellB := rowTitle.AddCell()
+	cellB.Value = "客户名称"
+
+	cellPd := rowTitle.AddCell()
+	cellPd.Value = "次数 "
+
+	cellAt := rowTitle.AddCell()
+	cellAt.Value = "所属销售"
+
+	cellPerssion := rowTitle.AddCell()
+	cellPerssion.Value = "状态"
+
+	for _, v := range listCompanyProduct {
+		if mapNum[v.CompanyId] < 3 {
+			continue
+		}
+
+		row := sheet.AddRow()
+		cellADatatitle := row.AddCell()
+		cellADatatitle.Value = mapCompamyName[v.CompanyId]
+
+		cellADataPd := row.AddCell()
+		cellADataPd.Value = fmt.Sprint(mapNum[v.CompanyId])
+
+		cellCompanyData := row.AddCell()
+		cellCompanyData.Value = fmt.Sprint(v.StartDate, " / ", v.EndDate)
+
+		cellBData := row.AddCell()
+		cellBData.Value = v.Status
+
+	}
+
+	err = xlsxFile.Save(downLoadnFilePath)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	fmt.Println("end")
+}

+ 23 - 0
models/company/company_contract.go

@@ -102,6 +102,29 @@ WHERE
 	return
 }
 
+func CompanyContractListNum() (items []*CompanyContract, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+				* 
+			FROM
+				company_contract 
+			WHERE
+				product_id = 2 
+				AND status = 1 
+				AND company_id IN (
+				SELECT
+					company_id 
+				FROM
+					company_product 
+				WHERE
+					product_id = 2 
+				AND status IN ( '正式', '试用' )) 
+			GROUP BY
+				start_date ASC `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
 // 新增客户合同
 func AddCompanyContract(item *CompanyContract) (lastId int64, err error) {
 	o := orm.NewOrm()

+ 1 - 1
models/company/company_product.go

@@ -737,7 +737,7 @@ func GetCompanyProductsByCompanyIdsAndProductIdinit(companyIds []int) (items []*
 	if lenCompanyId == 0 {
 		return
 	}
-	sql := `SELECT * FROM  company_product  WHERE company_id in (` + utils.GetOrmInReplace(lenCompanyId) + `) AND product_id = 2 `
+	sql := `SELECT * FROM  company_product  WHERE company_id in (` + utils.GetOrmInReplace(lenCompanyId) + `) AND product_id = 2 ORDER BY status ASC  `
 	o := orm.NewOrm()
 	_, err = o.Raw(sql, companyIds).QueryRows(&items)
 	return