Selaa lähdekoodia

Merge branch 'cygx/cygx_13.9' of http://8.136.199.33:3000/hongze/hz_crm_api into debug

zhangchuanxing 1 päivä sitten
vanhempi
commit
db69e9756d

+ 85 - 3
controllers/statistic_company_merge.go

@@ -222,7 +222,7 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
 		} 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 ) `
+		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 = '试用' `
 		pars1 = append(pars1, startDate, endDate)
 
 		total, err := models.GetIncrementalCompanyCountByOperationRecord(condition1, pars1)
@@ -360,7 +360,7 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
 		condition1 += condition
 		pars1 = append(pars1, pars)
 
-		condition1 += ` AND a.end_date >= ? AND a.end_date  <= ? `
+		condition1 += `  AND a.not_renewal_hide = 0  AND a.status = 1 AND a.start_date >= '2020-01-01' AND  a.end_date >= ? AND a.end_date  <= ? `
 		pars1 = append(pars1, startDate, endDate)
 		//condition1 += ` AND a.operation = ? `
 		//pars1 = append(pars1, "try_out")
@@ -2342,7 +2342,7 @@ func init323() {
 }
 
 //func init() {
-//	init16_1_03()
+//	init16_1_06()
 //}
 
 func init16_1_01() {
@@ -2422,6 +2422,88 @@ func init16_1_03() {
 	}
 }
 
+func init16_1_04() {
+	var condition string
+	var pars []interface{}
+
+	condition = "  AND  product_id = 2  AND  seller_id_init = 0    "
+
+	CompanyApprovalList, e := company.GetCompanyContracList(condition, pars)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		fmt.Println(e)
+		return
+	}
+
+	for _, v := range CompanyApprovalList {
+		productItem, e := company.GetCompanyProductByCompanyIdAndProductId(v.CompanyId, 2)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			fmt.Println(e)
+			return
+		}
+		if productItem == nil {
+			continue
+		}
+		e = company.UpdateCompanyContractTypeinit16_1_02(productItem.SellerName, productItem.SellerId, v.CompanyContractId)
+		if e != nil {
+			fmt.Println(e)
+			return
+		}
+	}
+}
+
+//func init16_1_05() {
+//	var condition string
+//	var pars []interface{}
+//
+//	condition = "  AND  product_id = 2    "
+//
+//	listProduct, e := company.GetCompanyProductList(condition, pars)
+//	if e != nil {
+//		fmt.Println(e)
+//		return
+//	}
+//	for _, v := range listProduct {
+//		e = company.UpdateCompanyProductSellerUnexpiredInitinit16_1_05(v.SellerId, v.SellerName, v.CompanyId)
+//		if e != nil {
+//			fmt.Println(e)
+//			return
+//		}
+//	}
+//	fmt.Println("end")
+//}
+
+func init16_1_06() {
+	var condition string
+	var pars []interface{}
+
+	listContractMax, e := company.GetCompanyContracListInit(condition, pars)
+	if e != nil {
+		fmt.Println(e)
+		return
+	}
+	maxId := make(map[int]int)
+	for _, v := range listContractMax {
+		maxId[v.MaxCompanyContractId] = v.MaxCompanyContractId
+	}
+
+	listContract, e := company.GetCompanyContracListInit_CRM_16_1(condition, pars)
+	if e != nil {
+		fmt.Println(e)
+		return
+	}
+	var updateId []string
+	for _, v := range listContract {
+		if maxId[v.CompanyContractId] > 0 {
+			continue
+		}
+		updateId = append(updateId, strconv.Itoa(v.CompanyContractId))
+	}
+
+	err := company.UpdateCompanyContracthide(updateId)
+	fmt.Println((err))
+	fmt.Println((updateId))
+}
+
 //更新权益销客户后一个正式的销售为当前销售
 //func init(){
 //	SELECT * FROM company_product  WHERE 1= 1  AND  product_id =2   AND  share_seller_id > 0 ;

+ 90 - 0
models/company/company_contract.go

@@ -3,6 +3,7 @@ package company
 import (
 	"fmt"
 	"github.com/beego/beego/v2/client/orm"
+	"strings"
 	"time"
 )
 
@@ -406,3 +407,92 @@ func UpdateCompanyContractSellerUnexpired(sellerId, shareSellerInit int, sellerN
 	_, err = o.Raw(sql, sellerId, sellerName, shareSellerInit, shareSeller, companyContractId).Exec()
 	return
 }
+
+type CompanyContractRespInit struct {
+	MaxCompanyContractId int
+	CompanyContractId    int       `orm:"column(company_contract_id);pk" description:"客户合同id"`
+	ContractType         string    `description:"合同类型:枚举值:'新签合同','续约合同','补充协议'"`
+	ProductId            int       `description:"产品id"`
+	ProductName          string    `description:"产品名称"`
+	CompanyId            int       `description:"客户id"`
+	CompanyProductId     int       `description:"客户产品id"`
+	ContractCode         string    `description:"合同编码"`
+	StartDate            string    `description:"合同开始时间"`
+	EndDate              string    `description:"合同结束时间"`
+	Money                float64   `description:"合同金额"`
+	PayMethod            string    `description:"支付方式"`
+	PayChannel           string    `description:"支付渠道"`
+	ImgUrl               string    `description:"合同图片,多个用#隔开"`
+	CreateTime           time.Time `description:"合同创建时间"`
+	ModifyTime           time.Time `description:"合同修改时间"`
+	Status               int       `description:"状态"`
+	Source               string    `description:"合同来源,枚举值:上传附件、系统合同,默认上传附件"`
+	PackageType          int       `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
+	RaiPackageType       int       `description:"权益套餐类型: 0-无; 1-70w大套餐; 2-45w大套餐"`
+	PermissionName       string    `description:"权限名"`
+}
+
+// 通过ID获取详情
+func GetCompanyContracListInit(condition string, pars []interface{}) (items []*CompanyContractRespInit, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	MAX( company_contract_id ) AS max_company_contract_id,
+	COUNT(a.company_id) AS cc ,
+	a.* 
+FROM
+	company_contract a
+	JOIN company b ON a.company_id = b.company_id
+	JOIN company_product c ON a.company_id = c.company_id 
+	AND a.product_id = c.product_id 
+WHERE
+	1 = 1 -- 		AND b.company_name LIKE "%上海亘%"
+	
+	AND c.product_id = 2 -- 		AND b.company_name LIKE "%上海亘%"
+	
+	AND c.product_id = 2 
+	AND a.not_renewal_hide = 0 
+	AND a.STATUS = 1 
+	AND c.STATUS NOT IN ( "永续", "正式", "关闭" ) 
+	
+	AND a.company_contract_id  NOT IN (SELECT company_contract_id FROM company_contract_no_renewed_ascribe )
+GROUP BY
+	a.company_id
+ ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+// 通过ID获取详情
+func GetCompanyContracListInit_CRM_16_1(condition string, pars []interface{}) (items []*CompanyContractRespInit, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+	a.* 
+FROM
+	company_contract a
+	JOIN company b ON a.company_id = b.company_id
+	JOIN company_product c ON a.company_id = c.company_id 
+	AND a.product_id = c.product_id 
+WHERE
+	1 = 1 -- 		AND b.company_name LIKE "%上海亘%"
+	
+	AND c.product_id = 2 -- 		AND b.company_name LIKE "%上海亘%"
+	
+	AND c.product_id = 2 
+	AND a.not_renewal_hide = 0 
+	AND a.STATUS = 1 
+	AND c.STATUS NOT IN ( "永续", "正式", "关闭" ) 
+
+	AND a.company_contract_id  NOT IN (SELECT company_contract_id FROM company_contract_no_renewed_ascribe )
+ ` + condition
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+// 合同未生效更新对应销售的信息
+func UpdateCompanyContracthide(companyContractId []string) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE company_contract SET not_renewal_hide = 1                                
+                            WHERE company_contract_id  IN  (` + strings.Join(companyContractId, ",") + `) `
+	_, err = o.Raw(sql).Exec()
+	return
+}

+ 11 - 0
models/company/company_product.go

@@ -731,3 +731,14 @@ func UpdateCompanyProductSellerUnexpired(sellerId, shareSellerInit int, sellerNa
 	_, err = o.Raw(sql, sellerId, sellerName, shareSellerInit, shareSeller, companyId).Exec()
 	return
 }
+
+// 合同未到期更新对应销售的信息
+func UpdateCompanyProductSellerUnexpiredInitinit16_1_05(sellerId int, sellerName string, companyId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE company_product SET
+                            seller_id_last = ? , 
+                            seller_name_last = ? 
+                            WHERE company_id = ?  AND product_id= 2 `
+	_, err = o.Raw(sql, sellerId, sellerName, companyId).Exec()
+	return
+}

+ 1 - 1
models/cygx/chart.go

@@ -167,7 +167,7 @@ type ChartCollectReq struct {
 // 获取图表列表
 func GetChartList(condition string, pars []interface{}, startSize, pageSize int) (items []*HomeChartListResp, err error) {
 	o := orm.NewOrmUsingDB("hz_cygx")
-	sql := ` SELECT * FROM cygx_chart AS a WHERE a.publish_status=1 `
+	sql := ` SELECT * FROM cygx_chart AS a WHERE 1=1 `
 	if condition != "" {
 		sql += condition
 	}

+ 1 - 3
models/cygx/gushou_time_line_history.go

@@ -2,8 +2,6 @@ package cygx
 
 import (
 	"github.com/beego/beego/v2/client/orm"
-	"hongze/hz_crm_api/utils"
-	"strconv"
 	"time"
 )
 
@@ -25,7 +23,7 @@ type CygxGushouTimeLineHistory struct {
 func GetCygxGushouTimeLineHistoryList(condition string, pars []interface{}) (items []*CygxGushouTimeLineHistory, err error) {
 	o := orm.NewOrmUsingDB("hz_cygx")
 	sql := `SELECT * FROM cygx_gushou_time_line_history as art WHERE 1= 1 `
-	condition += `  AND company_id != ` + strconv.Itoa(utils.HZ_COMPANY_ID) // 过滤弘则来源
+	//condition += `  AND company_id != ` + strconv.Itoa(utils.HZ_COMPANY_ID) // 过滤弘则来源
 	if condition != "" {
 		sql += condition
 	}