ソースを参照

Merge branch 'crm/crm_16.7' of http://8.136.199.33:3000/hongze/hz_crm_api into debug

zhangchuanxing 1 週間 前
コミット
b1cf666d8c

+ 159 - 4
controllers/statistic/rai_data_summary.go

@@ -2,6 +2,7 @@ package statistic
 
 import (
 	"fmt"
+	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hz_crm_api/controllers"
 	"hongze/hz_crm_api/models"
 	"hongze/hz_crm_api/models/company"
@@ -96,13 +97,13 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 	}
 
 	//拼接起始时间查询
-	startData := fmt.Sprintf("%d-01-01", startYear)
-	endData := fmt.Sprintf("%d-12-31", endYear)
+	startDate := fmt.Sprintf("%d-01-01", startYear)
+	endDate := fmt.Sprintf("%d-12-31", endYear)
 
 	var conditionRai string
 	var parsRai []interface{}
 	conditionRai = " AND  a.product_id = 2  AND  a.status = 1  AND  a.start_date >= ?  AND  a.start_date <= ? "
-	parsRai = append(parsRai, startData, endData)
+	parsRai = append(parsRai, startDate, endDate)
 	listRaiData, err := statistic_report.GetRaiDataSummaryList(conditionRai, parsRai)
 	if err != nil {
 		br.Msg = "获取数据信息失败"
@@ -124,6 +125,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		mapNoRenewedcompanyContractIds[v.CompanyContractId] = true
 	}
 
+	mapAddTrialNum := make(map[string]float64)                  // 新增试用-(数据)
 	mapNewContractMoney := make(map[string]float64)             // 新签合同(金额)
 	mapNewContractNum := make(map[string]int)                   // 新签合同(数量)
 	mapExpiredContractMoney := make(map[string]float64)         // 到期合同(金额)
@@ -181,6 +183,42 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		mapSignedClientNum[keyMap]++
 	}
 
+	conditionTry := ` AND a.create_time >= ? AND a.create_time <= ? AND a.operation in ( "add","receive","apply_receive" )  AND a.sys_user_id IN ( SELECT  admin_id FROM admin  WHERE  role_type_code IN ( 'rai_seller', 'rai_group' , 'rai_admin') ) `
+	var parsTry []interface{}
+	parsTry = append(parsTry, startDate, endDate)
+	//列表页数据
+	tryList, err := models.GetIncrementalCompanyListByOperationRecordRai(conditionTry, parsTry, 0, 9999)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	for _, v := range tryList {
+		startDateTime := utils.StrTimeToTime(v.CreateTime)
+		monthNum := startDateTime.Month()
+		yearStr := strconv.Itoa(startDateTime.Year())
+		if dataType == "季度" {
+			if monthNum < 4 {
+				yearStr += "Q1"
+			} else if monthNum > 3 && monthNum < 7 {
+				yearStr += "Q2"
+			} else if monthNum > 6 && monthNum < 10 {
+				yearStr += "Q3"
+			} else if monthNum > 9 {
+				yearStr += "Q4"
+			}
+		} else if dataType == "半年度" {
+			if monthNum < 7 {
+				yearStr += "H1"
+			} else {
+				yearStr += "H2"
+			}
+		}
+
+		keyMap := fmt.Sprint(yearStr, "_", v.SysUserId)
+		mapAddTrialNum[keyMap]++
+	}
+
 	//fmt.Println(time.Now().AddDate(0, 0, -1))
 	//return
 	var sellerDevelop []*system.AdminItem // 开拓组销售
@@ -209,8 +247,9 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 			for _, vS := range sellerDevelop {
 				keyMap := fmt.Sprint(item.DataType, "_", vS.AdminId)
 				sellerItem := new(statistic_report.RaiDataSummaryDetail)
+				sellerItem.SellerId = vS.AdminId
 				sellerItem.SellerName = vS.RealName
-				sellerItem.AddTrialCount = "新增试用-(数据)"
+				sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMap])
 				sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoney[keyMap], 2), " / ", mapNewContractNum[keyMap])             // 新签合同(金额/数量)-(数据)
 				sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoney[keyMap], 2), " / ", mapExpiredContractNum[keyMap]) //"到期合同(金额/数量)-(数据)"
 				sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoney[keyMap], 2), " / ", mapRenewedContractNum[keyMap]) // "续约合同(金额/数量)-(数据)"
@@ -297,3 +336,119 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// MergeCompanyList
+// @Title 权益数据汇总弹窗详情
+// @Description 权益数据汇总弹窗详情接口
+// @Param   SellerId   query   int  true       "销售ID"
+// @Param   DataType   query   string  false       "报表类型,枚举值:`季度`,`年度`,`半年度`"
+// @Param   PopupType   query   string	  false       "弹窗数据类型,枚举值:"
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Success 200 {object} statistic_report.RaiDataSummaryPopupTypeResp
+// @router /rai_data_summary/detail [get]
+func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
+	br := new(models.BaseResponse).Init()
+	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
+	}
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	dataType := this.GetString("DataType")
+	sellerId, _ := this.GetInt("SellerId")
+	popupType := this.GetString("PopupType")
+
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+
+	var startDate string
+	var endDate string
+	year := (dataType[:4])
+	if strings.Contains(dataType, "Q1") {
+		startDate = year + "-01-01"
+		endDate = year + "-03-31"
+	} else if strings.Contains(dataType, "Q2") {
+		startDate = year + "-04-01"
+		endDate = year + "-06-30"
+	} else if strings.Contains(dataType, "Q3") {
+		startDate = year + "-07-01"
+		endDate = year + "-09-30"
+	} else if strings.Contains(dataType, "Q4") {
+		startDate = year + "-10-01"
+		endDate = year + "-12-31"
+	} else if strings.Contains(dataType, "H1") {
+		startDate = year + "-01-01"
+		endDate = year + "-06-31"
+	} else if strings.Contains(dataType, "H2") {
+		startDate = year + "-07-01"
+		endDate = year + "-12-31"
+	} else {
+		startDate = year + "-01-01"
+		endDate = year + "-12-31"
+	}
+	fmt.Println(startDate)
+	fmt.Println(endDate)
+	resp := new(statistic_report.RaiDataSummaryPopupTypeResp)
+	var trialTotal int
+	switch popupType {
+	case "新增试用":
+		var parsTry []interface{}
+		var conditionTry string
+		if sellerId > 0 {
+			conditionTry += ` AND a.sys_user_id = ? `
+			parsTry = append(parsTry, sellerId)
+		}
+		conditionTry += ` AND a.create_time >= ? AND a.create_time <= ? AND a.operation in ( "add","receive","apply_receive" )  AND a.sys_user_id IN ( SELECT  admin_id FROM admin  WHERE  role_type_code IN ( 'rai_seller', 'rai_group' , 'rai_admin') ) `
+
+		parsTry = append(parsTry, startDate, endDate)
+		total, err := models.GetIncrementalCompanyCountByOperationRecordRai(conditionTry, parsTry)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取新增试用客户数量失败,Err:" + err.Error()
+			return
+		}
+		trialTotal = total
+
+		//列表页数据
+		tryList, err := models.GetIncrementalCompanyListByOperationRecordRai(conditionTry, parsTry, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		if len(tryList) > 0 {
+			for _, v := range tryList {
+				v.SellerName = v.SysRealName
+				if v.Operation == "add" {
+					v.Operation = "新建"
+				} else if v.Operation == "receive" || v.Operation == "apply_receive" {
+					v.Operation = "领取"
+				}
+			}
+			resp.AddTrialItem.List = tryList
+		} else {
+			resp.AddTrialItem.List = make([]*models.IncrementalList, 0)
+		}
+	}
+	page := paging.GetPaging(currentIndex, pageSize, trialTotal)
+	resp.Paging = page
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 2 - 1
models/statistic_report.go

@@ -415,6 +415,7 @@ type IncrementalList struct {
 	SellerIdLast    int    `description:"合同到期之前最后所属销售ID"`
 	ShareSellerInit string `description:"共享销售员"`
 	SysRealName     string `description:"操作者名称"`
+	SysUserId       string `description:"操作者Id"`
 	Operation       string `description:"操作"`
 }
 
@@ -845,7 +846,7 @@ func GetIncrementalCompanyListByOperationRecordRai(condition string, pars []inte
 	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
+	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 ,a.sys_user_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

+ 11 - 2
models/statistic_report/rai_data_summary.go

@@ -2,6 +2,8 @@ package statistic_report
 
 import (
 	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"hongze/hz_crm_api/models"
 	"hongze/hz_crm_api/models/company"
 )
 
@@ -37,8 +39,6 @@ type RaiDataSummaryDetail struct {
 	UnpaidRatioCount                 string `description:"未到款比例"`
 	NewCustomerInvoicingCount        string `description:"新客开票"`
 	NewCustomerPaymentsReceivedCount string `description:"新客到款"`
-	StartDate                        string `description:"合同开始日期"`
-	EndDate                          string `description:"合同结束日期"`
 }
 
 // 增量客户统计报表列表数据结构
@@ -117,3 +117,12 @@ func GetRaiDataSummaryList(condition string, pars []interface{}) (items []*Incre
 	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
 }
+
+type RaiDataSummaryPopupTypeResp struct {
+	Paging       *paging.PagingItem `description:"分页数据"`
+	AddTrialItem AddTrialItem       `description:"新增试用"`
+}
+
+type AddTrialItem struct {
+	List []*models.IncrementalList
+}

+ 9 - 0
routers/commentsRouter.go

@@ -8134,6 +8134,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/statistic:StatisticRaiDataSummaryController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/statistic:StatisticRaiDataSummaryController"],
+        beego.ControllerComments{
+            Method: "RaiDataSummaryDetail",
+            Router: `/rai_data_summary/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/statistic:StatisticRaiDataSummaryController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/statistic:StatisticRaiDataSummaryController"],
         beego.ControllerComments{
             Method: "RaiDataSummaryList",