zhangchuanxing il y a 1 mois
Parent
commit
1ca71ccc49
2 fichiers modifiés avec 170 ajouts et 15 suppressions
  1. 126 14
      controllers/statistic_company_merge.go
  2. 44 1
      models/statistic_report.go

+ 126 - 14
controllers/statistic_company_merge.go

@@ -44,6 +44,7 @@ type StatisticCompanyMergerController struct {
 // @Param   IsConfirm   query   int  false       "是否确认续约: -1-默认全部; 0-待确认; 1-已确认 ;2-到期合同"
 // @Param   CompanyAscribeId   query   int  false       "归因ID"
 // @Param   PackageDifference   query   string  false       "和上一份合同的区别,枚举值:`增加套餐`,`减少套餐`,`维持套餐`"
+// @Param   Operation   query   string  false       "新增类型 ,枚举值:`新建`,`领取`"
 // @Success 200 {object} response.IncrementalCompanyListResp
 // @router /merge_company_list [get]
 func (this *StatisticCompanyMergerController) MergeCompanyList() {
@@ -71,6 +72,7 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
 	tryOutType := this.GetString("TryOutType")
 	keyword := this.GetString("Keyword")
 	packageDifference := this.GetString("PackageDifference")
+	operation := this.GetString("Operation")
 
 	startDate := this.GetString("StartDate")
 	endDate := this.GetString("EndDate")
@@ -214,19 +216,27 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
 
 	//试用客户数
 	{
+		var operationSql string
+		if operation == "新建" {
+			operationSql = ` "add" `
+		} else if operation == "领取" {
+			operationSql = ` "add","receive"  `
+		} else {
+			operationSql = ` "add","receive","apply_receive"  `
+		}
 		condition1 := condition
 		pars1 := pars
 		//销售筛选条件
 		if adminId != "" {
-			condition1 += ` AND c.seller_id in  (` + adminId + `) `
+			condition1 += ` AND a.sys_user_id in  (` + adminId + `) `
 		} else {
 			condition1, pars1 = getQueryParams(condition1, pars1, sysUser, "c.")
 		}
-		condition1 += ` AND a.create_time >= ? AND a.create_time <= ? AND a.operation in ("add","receive")  	AND b.company_id  NOT IN  (	SELECT  company_id  FROM company_operation_record WHERE   product_id = 2 	AND  operation  ="loss"   GROUP BY company_id )  AND c.status = '试用' `
+		condition1 += ` AND a.create_time >= ? AND a.create_time <= ? AND a.operation in (` + operationSql + `)  	AND b.company_id  NOT IN  (	SELECT  company_id  FROM company_operation_record WHERE   product_id = 2 	AND  operation  ="loss"   GROUP BY company_id ) 	AND a.sys_user_id IN ( SELECT  admin_id FROM admin  WHERE  role_type_code IN ( 'rai_seller', 'rai_group' , 'rai_admin') ) `
 		pars1 = append(pars1, startDate, endDate)
 
-		total, err := models.GetIncrementalCompanyCountByOperationRecord(condition1, pars1)
-		if err != nil && err.Error() != utils.ErrNoRow() {
+		total, err := models.GetIncrementalCompanyCountByOperationRecordRai(condition1, pars1)
+		if err != nil {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取失败,Err:" + err.Error()
 			return
@@ -235,25 +245,32 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
 
 		if dataType == "新增试用" {
 			//列表数据数量
-			total, err := models.GetIncrementalCompanyProductCountByOperationRecord(condition1, pars1)
-			if err != nil && err.Error() != utils.ErrNoRow() {
-				br.Msg = "获取失败"
-				br.ErrMsg = "获取失败,Err:" + err.Error()
-				return
-			}
+			//total, err := models.GetIncrementalCompanyProductCountByOperationRecord(condition1, pars1)
+			//if err != nil {
+			//	br.Msg = "获取失败"
+			//	br.ErrMsg = "获取失败,Err:" + err.Error()
+			//	return
+			//}
+
+			//total = trialTotal
 
 			//列表页数据
-			tmpList, err := models.GetIncrementalCompanyListByOperationRecord(condition1, pars1, startSize, pageSize)
+			tmpList, err := models.GetIncrementalCompanyListByOperationRecordRai(condition1, pars1, startSize, pageSize)
 			if err != nil {
 				br.Msg = "获取失败"
 				br.ErrMsg = "获取失败,Err:" + err.Error()
 				return
 			}
 			for _, v := range tmpList {
-				v.SellerName = v.SellerNameInit
+				v.SellerName = v.SysRealName
+				if v.Operation == "add" {
+					v.Operation = "新建"
+				} else if v.Operation == "receive" || v.Operation == "apply_receive" {
+					v.Operation = "领取"
+				}
 			}
 			list = tmpList
-			dataTotal = total
+			dataTotal = trialTotal
 		}
 	}
 
@@ -534,7 +551,11 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
 	//fmt.Println()
 	//导出excel
 	if isExport {
-		MergeCompanyListListExport(this, dataType, resp, br)
+		if dataType == "新增试用" {
+			MergeCompanyListListTrialExport(this, dataType, resp, br)
+		} else {
+			MergeCompanyListListExport(this, dataType, resp, br)
+		}
 		return
 	}
 	br.Ret = 200
@@ -719,6 +740,97 @@ func MergeCompanyListListExport(this *StatisticCompanyMergerController, dataType
 	br.Msg = "导出成功"
 }
 
+// MergeCompanyListListTrialExport 导出增量客户新增试用模块数据报表excel
+func MergeCompanyListListTrialExport(this *StatisticCompanyMergerController, dataType string, resp response.IncrementalCompanyListResp, br *models.BaseResponse) {
+	dir, err := os.Executable()
+	exPath := filepath.Dir(dir)
+	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	xlsxFile := xlsx.NewFile()
+	if err != nil {
+		br.Msg = "生成文件失败"
+		br.ErrMsg = "生成文件失败"
+		return
+	}
+	style := xlsx.NewStyle()
+	alignment := xlsx.Alignment{
+		Horizontal: "center",
+		Vertical:   "center",
+		WrapText:   true,
+	}
+
+	style.Alignment = alignment
+	style.ApplyAlignment = true
+
+	sheel, err := xlsxFile.AddSheet("新增试用客户数据")
+	if err != nil {
+		br.Msg = "新增Sheet失败"
+		br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
+		return
+	}
+	sheel.SetColWidth(0, 0, 30)
+	sheel.SetColWidth(1, 1, 15)
+	sheel.SetColWidth(2, 2, 15)
+	sheel.SetColWidth(3, 3, 18)
+	sheel.SetColWidth(4, 4, 40)
+	sheel.SetColWidth(5, 5, 18)
+
+	//统计数据
+	statisticRow := sheel.AddRow()
+
+	cell1 := statisticRow.AddCell()
+	cell1.SetStyle(style)
+	cell1.SetValue("客户名称")
+
+	cell2 := statisticRow.AddCell()
+	cell2.SetStyle(style)
+	cell2.SetValue("所属销售")
+
+	cell3 := statisticRow.AddCell()
+	cell3.SetStyle(style)
+	cell3.SetValue("新增类型")
+
+	cell4 := statisticRow.AddCell()
+	cell4.SetStyle(style)
+	cell4.SetValue("新增时间")
+	//表头
+
+	for _, v := range resp.List {
+		dataRow := sheel.AddRow()
+		dataRow.SetHeight(20)
+
+		cellDataName := dataRow.AddCell()
+		cellDataName.SetStyle(style)
+		cellDataName.SetValue(v.CompanyName)
+
+		cellDataSellerName := dataRow.AddCell()
+		cellDataSellerName.SetStyle(style)
+		cellDataSellerName.SetValue(v.SellerName)
+
+		cellDataOperation := dataRow.AddCell()
+		cellDataOperation.SetStyle(style)
+		cellDataOperation.SetValue(v.Operation)
+
+		cellDataTime := dataRow.AddCell()
+		cellDataTime.SetStyle(style)
+		cellDataTime.SetValue(v.CreateTime)
+	}
+	err = xlsxFile.Save(downLoadnFilePath)
+	if err != nil {
+		br.Msg = "保存文件失败"
+		br.ErrMsg = "保存文件失败"
+		return
+	}
+	randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
+	downloadFileName := "新增试用客户数据_" + randStr + ".xlsx"
+	this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
+	defer func() {
+		os.Remove(downLoadnFilePath)
+	}()
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "导出成功"
+}
+
 // @Title 上一份合同详情
 // @Description 上一份合同详情接口
 // @Param   CompanyContractId   query   int  true       "合同ID"

+ 44 - 1
models/statistic_report.go

@@ -414,6 +414,8 @@ type IncrementalList struct {
 	SellerIdInit    int    `description:"权益初始化销售ID"`
 	SellerIdLast    int    `description:"合同到期之前最后所属销售ID"`
 	ShareSellerInit string `description:"共享销售员"`
+	SysRealName     string `description:"操作者名称"`
+	Operation       string `description:"操作"`
 }
 
 // GetIncrementalNewCompanyCount 获取增量客户报表列表统计数据(根据合同来展示)
@@ -748,6 +750,23 @@ a.product_id,a.product_name,b.region_type,c.renewal_reason FROM company_operatio
 	return
 }
 
+// 获取试用客户报表列表统计数据(根据新增客户时间来展示)
+func GetIncrementalCompanyCountByOperationRecordRai(condition string, pars []interface{}) (total int, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT a.id,a.company_id,b.company_name,c.seller_id,c.seller_name,
+a.product_id,a.product_name,b.region_type,c.renewal_reason FROM company_operation_record a
+		RIGHT JOIN company b ON a.company_id = b.company_id 
+		 JOIN company_product c ON b.company_id = c.company_id and a.product_id=c.product_id WHERE 1 = 1 `
+
+	if condition != "" {
+		sql += condition
+	}
+	//sql += " order by a.start_date desc "
+	sql = `select count(1) count from (` + sql + ` group by a.id ) f `
+	err = o.Raw(sql, pars).QueryRow(&total)
+	return
+}
+
 // 获取试用客户报表列表统计数据(根据新增客户和对应的产品时间来展示)
 func GetIncrementalCompanyProductCountByOperationRecord(condition string, pars []interface{}) (total int, err error) {
 	o := orm.NewOrm()
@@ -802,7 +821,31 @@ func GetIncrementalCompanyListByOperationRecord(condition string, pars []interfa
 	sql1 += ` GROUP BY a.company_id, a.product_id `
 
 	//查询真正的数据
-	sql := `SELECT a.id, a.company_id, b.company_name, c.seller_id, c.seller_name, c.seller_name_init, a.product_id, a.product_name, a.create_time, b.region_type, c.renewal_reason, c.renewal_todo, c.status FROM company_operation_record a
+	sql := `SELECT a.id, a.company_id, b.company_name, c.seller_id, c.seller_name, c.seller_name_init, a.product_id, a.product_name, a.create_time, b.region_type, c.renewal_reason, c.renewal_todo, c.status , a.sys_real_name, a.operation FROM company_operation_record a
+		RIGHT JOIN company b ON a.company_id = b.company_id
+		JOIN company_product c ON b.company_id = c.company_id 
+		AND a.product_id = c.product_id
+where a.id in (` + sql1 + `) order by  create_time DESC,company_id DESC limit ?,?`
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+// GetIncrementalCompanyListByOperationRecord 获取试用客户报表列表数据(根据新增客户时间来展示)
+func GetIncrementalCompanyListByOperationRecordRai(condition string, pars []interface{}, startSize, pageSize int) (items []*IncrementalList, err error) {
+	o := orm.NewOrm()
+	//查询出最大id
+	sql1 := `SELECT max(id) id FROM company_operation_record a
+		RIGHT JOIN company b ON a.company_id = b.company_id
+		JOIN company_product c ON b.company_id = c.company_id 
+		AND a.product_id = c.product_id 
+	WHERE 1 = 1 `
+	if condition != "" {
+		sql1 += condition
+	}
+	sql1 += ` GROUP BY a.id `
+
+	//查询真正的数据
+	sql := `SELECT a.id, a.company_id, b.company_name, c.seller_id, c.seller_name, c.seller_name_init, a.product_id, a.product_name, a.create_time, b.region_type, c.renewal_reason, c.renewal_todo, c.status , a.sys_real_name, a.operation FROM company_operation_record a
 		RIGHT JOIN company b ON a.company_id = b.company_id
 		JOIN company_product c ON b.company_id = c.company_id 
 		AND a.product_id = c.product_id