zhangchuanxing 4 giorni fa
parent
commit
6742d8d818
2 ha cambiato i file con 110 aggiunte e 9 eliminazioni
  1. 20 9
      controllers/statistic_company_merge.go
  2. 90 0
      models/company/company_contract.go

+ 20 - 9
controllers/statistic_company_merge.go

@@ -2342,7 +2342,7 @@ func init323() {
 }
 
 //func init() {
-//	init16_1_05()
+//	init16_1_06()
 //}
 
 func init16_1_01() {
@@ -2476,21 +2476,32 @@ func init16_1_06() {
 	var condition string
 	var pars []interface{}
 
-	condition = "  AND  product_id = 2    "
+	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
+	}
 
-	listProduct, e := company.GetCompanyProductList(condition, pars)
+	listContract, e := company.GetCompanyContracListInit_CRM_16_1(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
+	var updateId []string
+	for _, v := range listContract {
+		if maxId[v.CompanyContractId] > 0 {
+			continue
 		}
+		updateId = append(updateId, strconv.Itoa(v.CompanyContractId))
 	}
-	fmt.Println("end")
+
+	err := company.UpdateCompanyContracthide(updateId)
+	fmt.Println((err))
+	fmt.Println((updateId))
 }
 
 //更新权益销客户后一个正式的销售为当前销售

+ 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
+}