Browse Source

Merge branch 'crm_15.4' of http://8.136.199.33:3000/hongze/hongze_mobile_admin into debug

xingzai 11 months ago
parent
commit
b9ab7eac54

+ 14 - 1
controllers/company_contract.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	companyContractResp "hongze/hongze_mobile_admin/models/response/company_contract"
 	"hongze/hongze_mobile_admin/models/tables/company_contract"
+	"hongze/hongze_mobile_admin/models/tables/company_product"
 	"hongze/hongze_mobile_admin/models/tables/company_report_permission"
 	"hongze/hongze_mobile_admin/services"
 	"hongze/hongze_mobile_admin/services/contract"
@@ -128,8 +129,20 @@ func (c *CompanyContractCommon) ApplyContractDetail() {
 		// 未选大套餐, 走老逻辑
 		var points float64
 		if detail.RaiPackageType == 0 {
-			mapUpgrade := make(map[int]bool) // 通过合同获取所勾选的升级行业权限
+			mapUpgrade := make(map[int]bool)                                                 // 通过合同获取所勾选的升级行业权限
+			totalForever, err := company_product.GetCompanyProductRaiForeverCount(companyId) //判断是否是权益的永续客户
+			if err != nil {
+				c.FailWithMessage("获取失败", "判断是否是权益的永续客户失败,Err:"+err.Error())
+				return
+			}
 
+			if totalForever > 0 {
+				detail.Quarter, err = utils.GetQuarterStrStartDatesInRange(detail.StartDate, detail.EndDate) //通过开始时间,结束时间,获取对应季度的拼接字符串
+				if err != nil {
+					c.FailWithMessage("获取失败", "获取季度息失败,Err:"+err.Error())
+					return
+				}
+			}
 			for _, v := range permissionList {
 				if v.IsUpgrade == 1 {
 					mapUpgrade[v.ChartPermissionId] = true

+ 1 - 0
models/tables/company_contract/company_contract.go

@@ -36,6 +36,7 @@ type CompanyContractDetail struct {
 	ContractType      string    `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"`
 	StartDate         string    `description:"合同开始时间"`
 	EndDate           string    `description:"合同结束时间"`
+	Quarter           string    `description:"季度(X类试用客户使用)"`
 	Money             float64   `description:"合同金额"`
 	PayMethod         string    `description:"支付方式"`
 	PayChannel        string    `description:"支付渠道"`

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

@@ -116,3 +116,11 @@ func GetCompanyProductItemByCompanyId(companyId int, productId int) (items *Comp
 
 	return
 }
+
+// 获取权益用户客户数量
+func GetCompanyProductRaiForeverCount(companyId int) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM company_product  WHERE 1= 1  AND product_id  = 2  AND   status = '永续' AND company_id  = ?  `
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, companyId).QueryRow(&count)
+	return
+}

+ 38 - 0
utils/common.go

@@ -959,3 +959,41 @@ func GetDaysBetween2Date(format, date1Str, date2Str string) (int, error) {
 	//计算相差天数
 	return int(date1.Sub(date2).Hours() / 24), nil
 }
+
+// 通过开始时间,结束时间,获取对应季度的拼接字符串
+func GetQuarterStrStartDatesInRange(startTimeStr, endTimeStr string) (quartersStar string, err error) {
+	startTime, err := time.Parse("2006-01-02", startTimeStr)
+	if err != nil {
+		return
+	}
+
+	endTime, err := time.Parse("2006-01-02", endTimeStr)
+	if err != nil {
+		return
+	}
+
+	adjustedStartTime := startTime.AddDate(0, -int(startTime.Month()-1)%3, -startTime.Day()+1)
+
+	startYear, _, _ := adjustedStartTime.Date()
+	endYear, _, _ := endTime.Date()
+
+	var quarters []string
+	//quarters := []string
+	for year := startYear; year <= endYear; year++ {
+		for quarter := 1; quarter <= 4; quarter++ {
+			firstMonth := (quarter-1)*3 + 1
+			quarterStartDate := time.Date(year, time.Month(firstMonth), 1, 0, 0, 0, 0, time.UTC)
+			if quarterStartDate.After(endTime) || quarterStartDate.AddDate(0, 3, -1).Before(adjustedStartTime) {
+				continue
+			}
+			quartersYear := quarterStartDate.Year()
+			yearStr := strconv.Itoa(quartersYear)
+			yearStr = yearStr[len(yearStr)-2:]
+
+			quarters = append(quarters, fmt.Sprint(yearStr, "Q", quarter))
+		}
+	}
+
+	quartersStar = strings.Join(quarters, "+")
+	return quartersStar, nil
+}