Переглянути джерело

合同搜索-正式客户共享的处理

hsun 1 рік тому
батько
коміт
7d27af6ebd
3 змінених файлів з 137 додано та 22 видалено
  1. 50 7
      controllers/contract.go
  2. 53 2
      models/company.go
  3. 34 13
      models/tables/contract/contract.go

+ 50 - 7
controllers/contract.go

@@ -2,7 +2,9 @@ package controllers
 
 import (
 	"encoding/json"
+	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"hongze/hongze_mobile_admin/models"
 	contractReq "hongze/hongze_mobile_admin/models/request/contract"
 	contractResp "hongze/hongze_mobile_admin/models/response/contract"
 	"hongze/hongze_mobile_admin/models/tables/contract"
@@ -16,7 +18,7 @@ import (
 	"strings"
 )
 
-//合同模块
+// 合同模块
 type ContractCommon struct {
 	BaseAuth
 }
@@ -301,6 +303,25 @@ func (c *ContractCommon) CompanyListBySeal() {
 		companyNameList = append(companyNameList, v.CompanyName)
 	}
 
+	// 13.6正式共享客户的处理
+	{
+		// 通过关键词获取分配给当前销售的正式共享客户
+		kw := fmt.Sprint("%", keyword, "%")
+		cond := ` AND share_seller_id = ? AND is_share = 1 AND company_name LIKE ?`
+		pars := make([]interface{}, 0)
+		pars = append(pars, sysUser.AdminId, kw)
+		shares, e := models.GetCompanyListByCondition(cond, pars, []string{"company_id", "company_name"}, "")
+		if e != nil {
+			c.FailWithMessage("获取失败", "获取共享客户信息失败, Err: "+e.Error())
+			return
+		}
+		for _, v := range shares {
+			if !utils.InArrayByStr(companyNameList, v.CompanyName) {
+				companyNameList = append(companyNameList, v.CompanyName)
+			}
+		}
+	}
+
 	//审批列表中(跟自己有关联的)
 	//childCondition := ""
 	//condition := ""
@@ -350,6 +371,7 @@ func (c *ContractCommon) CompanyListBySeal() {
 // @Success 200 {object} contract.ContractListResp
 // @router /listBySeal [get]
 func (c *ContractCommon) ListBySeal() {
+	sysUser := c.AdminWx
 	//合同类型、产品类型、合同状态、更新时间、所选销售
 	//关键字:合同编号、客户名称,社会信用码
 
@@ -421,21 +443,42 @@ func (c *ContractCommon) ListBySeal() {
 	}
 	startSize = paging.StartIndex(currentIndex, pageSize)
 
-	total, err := contract.GetContractListCount(condition, pars)
+	//total, err := contract.GetContractListCount(condition, pars)
+	//if err != nil {
+	//	c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
+	//	return
+	//}
+	//
+	//list, err := contract.GetContractList(condition, pars, startSize, pageSize)
+	//if err != nil {
+	//	c.FailWithMessage("获取合同列表失败", "获取合同列表失败,Err:"+err.Error())
+	//	return
+	//}
+
+	// 13.6正式共享客户
+	joinStr := ` LEFT JOIN company AS b ON a.company_name = b.company_name `
+	// 非合规角色可查看自己的合同或是自己的共享客户下的非自己创建的合同
+	if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_COMPLIANCE {
+		condition += ` AND (a.seller_id = ? OR (b.is_share = 1 AND b.share_seller_id = ?))`
+		pars = append(pars, sysUser.AdminId, sysUser.AdminId)
+	}
+
+	total, err := contract.GetJoinContractListCount(condition, joinStr, pars)
 	if err != nil {
 		c.FailWithMessage("获取失败", "获取数据总数失败,Err:"+err.Error())
 		return
 	}
 
-	list, err := contract.GetContractList(condition, pars, startSize, pageSize)
-	if err != nil {
-		c.FailWithMessage("获取合同列表失败", "获取合同列表失败,Err:"+err.Error())
+	list, e := contract.GetJoinContractList(condition, joinStr, pars, startSize, pageSize)
+	if e != nil {
+		c.FailWithMessage("获取失败", "获取合同列表失败,Err:"+err.Error())
 		return
 	}
+
 	if len(list) > 0 {
 		// 代付合同查询代付用户名称
 		contractIdSlice := make([]string, 0)
-		for i := 0; i < len(list); i ++ {
+		for i := 0; i < len(list); i++ {
 			if list[i].ContractBusinessType == "代付合同" {
 				contractIdSlice = append(contractIdSlice, strconv.Itoa(list[i].ContractId))
 			}
@@ -448,7 +491,7 @@ func (c *ContractCommon) ListBySeal() {
 				return
 			}
 			userCompanyNameMap := make(map[int]string, 0)
-			for i := 0; i < len(contractList); i ++ {
+			for i := 0; i < len(contractList); i++ {
 				userCompanyNameMap[contractList[i].PaymentOnBehalfContractId] = contractList[i].CompanyName
 			}
 			for _, item := range list {

+ 53 - 2
models/company.go

@@ -1,10 +1,45 @@
 package models
 
 import (
+	"fmt"
 	"github.com/beego/beego/v2/client/orm"
+	"strings"
 	"time"
 )
 
+type Company struct {
+	CompanyId       int       `orm:"column(company_id);pk"`
+	CompanyName     string    `description:"客户名称"`
+	CompanyType     int       `orm:"column(type)"`
+	CreditCode      string    `description:"社会统一信用码"`
+	CompanyCode     string    `description:"客户编码"`
+	Sort            int       `description:"优先级"`
+	IsFeeCustomer   int       `description:"是否付费用户"`
+	Country         string    `description:"国家编码"`
+	Province        string    `description:"省"`
+	City            string    `description:"市"`
+	Address         string    `description:"详细地址"`
+	Enabled         int       `description:"用户状态"`
+	CreatedTime     time.Time `description:"创建时间"`
+	LastUpdatedTime time.Time `description:"最后一次阅读时间"`
+	Seller          string    `description:"销售员"`
+	SellsId         int       `description:"销售员id"`
+	ShareSeller     string    `description:"共享销售员"`
+	ShareSellerId   int       `description:"共享销售员id"`
+	CompanyBelong   string    `description:"客户所属,ficc:ficc客户,public_offering:公募客户,partner:合作伙伴"`
+	StartDate       string    `description:"合同开始日期"`
+	EndDate         string    `description:"合同结束日期"`
+	LastType        int       `description:"原客户标签"`
+	IsVip           int       `description:"0:普通用户,1:大客户"`
+	IsShare         int       `description:"0:非共享用户,1:共享客户"`
+	FirstStartDate  string    `description:"首次设置为试用客户开始时间"`
+	FirstEndDate    string    `description:"首次设置为试用客户结束时间"`
+	DateType        int       `description:"设置流失类型,1:1个月,2:2个月,3:3个月"`
+	Remark          string    `description:"备注信息"`
+	RegionType      string    `description:"地区类型,国内,国外"`
+	OpenCompanyCode string    `description:"开放给第三方的客户编码,不让第三方定位我们的客户信息"`
+}
+
 type CompanyProduct struct {
 	CompanyProductId    int       `orm:"column(company_product_id);pk" description:"客户产品id"`
 	CompanyId           int       `description:"客户id"`
@@ -51,7 +86,7 @@ func GetCompanyProductByCompanyIdAndProductId(companyId, productId int) (item *C
 	return
 }
 
-//客户授权产品结构体(包含产品名称)
+// 客户授权产品结构体(包含产品名称)
 type CompanyReportPermissionAndName struct {
 	CompanyReportPermissionId int `description:"客户授权产品id"`
 	CompanyId                 int
@@ -70,10 +105,26 @@ type CompanyReportPermissionAndName struct {
 	ModifyTime                time.Time `description:"修改时间"`
 }
 
-//根据企业用户id和产品id获取所有正式的权限
+// 根据企业用户id和产品id获取所有正式的权限
 func GetCompanyProductReportPermissionList(companyId, productId int) (items []*CompanyReportPermissionAndName, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT a.*,b.permission_name,b.classify_name FROM company_report_permission a left join chart_permission b on a.chart_permission_id=b.chart_permission_id WHERE a.company_id = ? and a.product_id=? `
 	_, err = o.Raw(sql, companyId, productId).QueryRows(&items)
 	return
 }
+
+// GetCompanyListByCondition 获取客户列表
+func GetCompanyListByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*Company, err error) {
+	o := orm.NewOrm()
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY created_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM company WHERE 1=1 %s %s`, fields, condition, order)
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 34 - 13
models/tables/contract/contract.go

@@ -9,7 +9,7 @@ import (
 	"time"
 )
 
-//合同
+// 合同
 type Contract struct {
 	ContractId           int       `orm:"column(contract_id);pk"`
 	ContractCode         string    `description:"合同编号,长度32位"`
@@ -52,14 +52,14 @@ type Contract struct {
 	CreateTime           time.Time `description:"合同添加时间"`
 }
 
-//更新合同基础信息
+// 更新合同基础信息
 func (contract *Contract) Update(cols []string) (err error) {
 	o := orm.NewOrm()
 	_, err = o.Update(contract, cols...)
 	return
 }
 
-//根据合同id获取合同信息
+// 根据合同id获取合同信息
 func GetContractById(contractId int) (contractInfo *Contract, err error) {
 	o := orm.NewOrm()
 	sql := `select * from contract where contract_id = ? `
@@ -67,7 +67,7 @@ func GetContractById(contractId int) (contractInfo *Contract, err error) {
 	return
 }
 
-//合同详情信息(包含服务信息等)
+// 合同详情信息(包含服务信息等)
 type ContractDetail struct {
 	ContractId           int       `description:"合同唯一id"`
 	ContractCode         string    `description:"合同编号,长度32位"`
@@ -132,7 +132,7 @@ func GetContractDetailById(contractId int) (contractInfo *ContractDetail, err er
 	return
 }
 
-//合同添加
+// 合同添加
 func AddContract(contractInfo *Contract, contractServiceAndDetailList []*contract.ContractServiceAndDetail) (newContract *Contract, err error) {
 	o := orm.NewOrm()
 	tx, err := o.Begin()
@@ -246,7 +246,7 @@ type ContractList struct {
 	Service              []*contract.ContractServiceAndDetail
 }
 
-//获取合同列表数据数量
+// 获取合同列表数据数量
 func GetContractListCount(condition string, pars []interface{}) (count int, err error) {
 	o := orm.NewOrm()
 	sql := "select count(*) AS COUNT from contract where 1=1 AND is_delete = 0 "
@@ -255,7 +255,7 @@ func GetContractListCount(condition string, pars []interface{}) (count int, err
 	return
 }
 
-//获取合同列表数据
+// 获取合同列表数据
 func GetContractList(condition string, pars []interface{}, startSize, pageSize int) (list []*ContractList, err error) {
 	o := orm.NewOrm()
 	sql := "select * from contract where 1=1 AND is_delete = 0 "
@@ -265,7 +265,28 @@ func GetContractList(condition string, pars []interface{}, startSize, pageSize i
 	return
 }
 
-//修改合同
+// GetJoinContractListCount 获取合同列表数据数量
+func GetJoinContractListCount(condition, joinStr string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sql := `select count(a.contract_id) AS COUNT from contract a ` + joinStr
+	sql += ` where a.is_delete = 0 `
+	sql += condition
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+// GetJoinContractList 获取合同列表数据
+func GetJoinContractList(condition, joinStr string, pars []interface{}, startSize, pageSize int) (list []*ContractList, err error) {
+	o := orm.NewOrm()
+	sql := "select a.* from contract a " + joinStr
+	sql += ` where a.is_delete = 0 `
+	sql += condition
+	sql += ` order by modify_time desc LIMIT ?,? `
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
+	return
+}
+
+// 修改合同
 func EditContract(contractInfo *Contract, contractServiceAndDetailList []*contract.ContractServiceAndDetail) (err error) {
 	o := orm.NewOrm()
 	tx, err := o.Begin()
@@ -334,7 +355,7 @@ func EditContract(contractInfo *Contract, contractServiceAndDetailList []*contra
 	return
 }
 
-//添加生成后的合同地址
+// 添加生成后的合同地址
 func AddContractPdf(contractId int, pdfUrl string) (err error) {
 	o := orm.NewOrm()
 
@@ -344,7 +365,7 @@ func AddContractPdf(contractId int, pdfUrl string) (err error) {
 	return
 }
 
-//删除合同
+// 删除合同
 func DeleteContract(contractInfo *Contract) (err error) {
 	o := orm.NewOrm()
 	tx, err := o.Begin()
@@ -369,7 +390,7 @@ func DeleteContract(contractInfo *Contract) (err error) {
 	return
 }
 
-//作废合同
+// 作废合同
 func InvalidContract(contractInfo *Contract) (err error) {
 	o := orm.NewOrm()
 	tx, err := o.Begin()
@@ -395,7 +416,7 @@ func InvalidContract(contractInfo *Contract) (err error) {
 	return
 }
 
-//生成合同编号
+// 生成合同编号
 func GetCompanyContractCode(productId int) (companyCode string, err error) {
 	var num int
 	o := orm.NewOrm()
@@ -421,7 +442,7 @@ type CompanyNameList struct {
 	CompanyName string `description:"客户名称,甲方名称,长度32位"`
 }
 
-//获取客户名称列表数据
+// 获取客户名称列表数据
 func GetCompanyNameList(sellerId int, keyword, status string) (list []*CompanyNameList, err error) {
 	o := orm.NewOrm()
 	sql := `select * from contract where is_delete=0 and (company_name like '%` + keyword + `%' or credit_code like '%` + keyword + `%') `