xingzai 1 an în urmă
părinte
comite
737a066d7f

+ 5 - 0
models/db_init.go

@@ -32,6 +32,7 @@ import (
 	"hongze/hongze_mobile_admin/models/tables/contract_service_detail"
 	"hongze/hongze_mobile_admin/models/tables/contract_service_template"
 	"hongze/hongze_mobile_admin/models/tables/contract_template"
+	"hongze/hongze_mobile_admin/models/tables/cygx_allocation_company_contract"
 	"hongze/hongze_mobile_admin/models/tables/cygx_company_user_type"
 	"hongze/hongze_mobile_admin/models/tables/english_company"
 	"hongze/hongze_mobile_admin/models/tables/h5_admin_session"
@@ -126,6 +127,10 @@ func init() {
 		new(english_company.EnglishCompany), // 英文客户表
 		new(cygx_company_user_type.CygxCompanyUserType), // 英文客户表
 		new(cygx.CygxActivitySpecialTripBill), // 专项调研确定行程活动报名流水表
+		new(cygx_allocation_company_contract.CygxAllocationCompanyContract), //权益合同派点(研究员)
+		new(cygx_allocation_company_contract.CygxAllocationCompanyContractLog), //权益合同派点日志(研究员)
+		new(cygx_allocation_company_contract.CygxAllocationCompanyContractPermission), //权益合同派点(行业)
+		new(cygx_allocation_company_contract.CygxAllocationCompanyContractPermissionLog), //权益合同派点日志(行业)
 
 	)
 

+ 32 - 0
models/tables/company_contract_permission/company_contract_permission.go

@@ -0,0 +1,32 @@
+package company_contract_permission
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+
+type CompanyContractPermission struct {
+	Id                int       `orm:"column(id);pk" description:"客户合同id"`
+	CompanyId         int       `description:"客户id"`
+	CompanyContractId int       `description:"合同id"`
+	ChartPermissionId int       `description:"权限id"`
+	IsUpgrade         int       `description:"是否升级,1是,0否"`
+	ExpensiveYx       int       `description:"权益研选: 0-3w; 1-5w"`
+	StartDate         string    `description:"开始日期"`
+	EndDate           string    `description:"结束日期"`
+	CreateTime        time.Time `description:"创建时间"`
+	ModifyTime        time.Time `description:"修改时间"`
+}
+
+// 获取合同对应的权限列表
+func GetCompanyContractPermissionList(condition string, pars []interface{}) (items []*CompanyContractPermission, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM company_contract_permission WHERE 1 = 1  `
+
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 155 - 0
models/tables/cygx_allocation_company_contract/cygx_allocation_company_contract.go

@@ -0,0 +1,155 @@
+package cygx_allocation_company_contract
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// 研究员派点
+type CygxAllocationCompanyContract struct {
+	AllocationCompanyContractId int       `orm:"column(allocation_company_contract_id);pk"`
+	CompanyContractId           int       `description:"合同id"`
+	CreateTime                  time.Time `description:"创建时间"`
+	ModifyTime                  time.Time `description:"更新时间"`
+	AdminId                     int       `description:"操作人ID"`
+	AdminName                   string    `description:"内容"`
+	Proportion                  float64   `description:"占比"`
+	Money                       float64   `description:"金额"`
+	RealName                    string    `description:"研究员姓名"`
+	ChartPermissionName         string    `description:"行业名称"`
+}
+
+// 研究员派点日志
+type CygxAllocationCompanyContractLog struct {
+	AllocationCompanyContractId int       `orm:"column(allocation_company_contract_id);pk"`
+	CompanyContractId           int       `description:"合同id"`
+	CreateTime                  time.Time `description:"创建时间"`
+	ModifyTime                  time.Time `description:"更新时间"`
+	AdminId                     int       `description:"操作人ID"`
+	AdminName                   string    `description:"内容"`
+	Proportion                  float64   `description:"占比"`
+	Money                       float64   `description:"金额"`
+	RealName                    string    `description:"研究员姓名"`
+	ChartPermissionName         string    `description:"行业名称"`
+}
+
+// 行业派点
+type CygxAllocationCompanyContractPermission struct {
+	AllocationCompanyContractId int       `orm:"column(allocation_company_contract_id);pk"`
+	CompanyContractId           int       `description:"合同id"`
+	CreateTime                  time.Time `description:"创建时间"`
+	ModifyTime                  time.Time `description:"更新时间"`
+	AdminId                     int       `description:"操作人ID"`
+	AdminName                   string    `description:"内容"`
+	Proportion                  float64   `description:"占比"`
+	Money                       float64   `description:"金额"`
+	MoneyAvg                    float64   `description:"行业所占合同的平均金额"`
+	ChartPermissionName         string    `description:"行业名称"`
+}
+
+// 行业派点日志
+type CygxAllocationCompanyContractPermissionLog struct {
+	AllocationCompanyContractId int       `orm:"column(allocation_company_contract_id);pk"`
+	CompanyContractId           int       `description:"合同id"`
+	CreateTime                  time.Time `description:"创建时间"`
+	ModifyTime                  time.Time `description:"更新时间"`
+	AdminId                     int       `description:"操作人ID"`
+	AdminName                   string    `description:"内容"`
+	Proportion                  float64   `description:"占比"`
+	Money                       float64   `description:"金额"`
+	MoneyAvg                    float64   `description:"行业所占合同的平均金额"`
+	ChartPermissionName         string    `description:"行业名称"`
+}
+
+
+// 更新派点信息
+func AddAndUpdateCygxAllocationCompanyContract(items []*CygxAllocationCompanyContract, itemsPermission []*CygxAllocationCompanyContractPermission, companyContractId int) (err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+
+	//组合研究员派点日志结构体
+	var itemsLog []*CygxAllocationCompanyContractLog
+	for _, v := range items {
+		item := new(CygxAllocationCompanyContractLog)
+		item.CompanyContractId = v.CompanyContractId
+		item.AdminId = v.AdminId
+		item.CompanyContractId = v.CompanyContractId
+		item.AdminName = v.AdminName
+		item.RealName = v.RealName
+		item.ChartPermissionName = v.ChartPermissionName
+		item.Proportion = v.Proportion
+		item.Money = v.Money
+		item.Money = v.Money
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		itemsLog = append(itemsLog, item)
+	}
+
+	//组合行业派点日志结构体
+	var itemsPermissionLog []*CygxAllocationCompanyContractPermissionLog
+	for _, v := range itemsPermission {
+		item := new(CygxAllocationCompanyContractPermissionLog)
+		item.CompanyContractId = v.CompanyContractId
+		item.AdminId = v.AdminId
+		item.CompanyContractId = v.CompanyContractId
+		item.AdminName = v.AdminName
+		item.ChartPermissionName = v.ChartPermissionName
+		item.Proportion = v.Proportion
+		item.Money = v.Money
+		item.MoneyAvg = v.MoneyAvg
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		itemsPermissionLog = append(itemsPermissionLog, item)
+	}
+
+	//删除原有的研究员派点信息
+	sql := `DELETE FROM cygx_allocation_company_contract WHERE company_contract_id = ?`
+	_, err = to.Raw(sql, companyContractId).Exec()
+	if err != nil {
+		return
+	}
+	//删除原有的行业派点信息
+	sql = `	DELETE FROM cygx_allocation_company_contract_permission WHERE company_contract_id = ?`
+	_, err = to.Raw(sql, companyContractId).Exec()
+	if err != nil {
+		return
+	}
+
+	//批量添加研究员派点信息
+	_, err = to.InsertMulti(len(items), items)
+	if err != nil {
+		return
+	}
+
+	_, err = to.InsertMulti(len(itemsLog), itemsLog)
+	if err != nil {
+		return
+	}
+
+	//批量添加行业派点信息
+	_, err = to.InsertMulti(len(itemsPermission), itemsPermission)
+	if err != nil {
+		return
+	}
+
+	_, err = to.InsertMulti(len(itemsPermissionLog), itemsPermissionLog)
+	if err != nil {
+		return
+	}
+
+	ow := orm.NewOrm()
+	sqlW := `UPDATE company_contract SET is_allocation=1   WHERE company_contract_id=? `
+	_, err = ow.Raw(sqlW, companyContractId).Exec()
+
+	return
+}

+ 3 - 2
services/company_approval/company_approval.go

@@ -407,7 +407,7 @@ func Approved(approvalRecord *contract_approval_record.ContractApprovalRecord, o
 				//处理权益客户的身份信息
 				cygxService.UpdateCygxCompanyUserType(recordInfo.CompanyContractId)
 
-				if recordInfo.ApplyMethod == 1{
+				if recordInfo.ApplyMethod == 1 {
 					//获取合同信息
 					contractInfo, tmpErr := company_contract.GetCompanyContractDetail(recordInfo.CompanyId, recordInfo.ProductId, recordInfo.CompanyContractId)
 					if tmpErr != nil {
@@ -436,7 +436,8 @@ func Approved(approvalRecord *contract_approval_record.ContractApprovalRecord, o
 				//客户研选行业转正时(王芳审批通过),模板消息提醒汪洋
 				services.AddCompanyApprovalMessageWangYang(recordInfo.CompanyId, recordInfo.CompanyContractId, recordInfo.ApplyRealName, companyInfo.CompanyName)
 
-				 cygxService.YanXuanCompanyApproval(recordInfo.CompanyId) //研选审批通过的时候研选扣点更新
+				cygxService.YanXuanCompanyApproval(recordInfo.CompanyId) //研选审批通过的时候研选扣点更新
+				cygxService.HandleAllocationCompanyContractByYanXuan(recordInfo.CompanyContractId)   //如果合同只有研选的时候,自动处理派点
 			}
 		}()
 	} else {

+ 87 - 0
services/cygx/contract_allocation.go

@@ -0,0 +1,87 @@
+package cygxService
+
+import (
+	"fmt"
+	"errors"
+	"hongze/hongze_mobile_admin/models/tables/company_contract_permission"
+	"hongze/hongze_mobile_admin/models/tables/cygx_allocation_company_contract"
+	"hongze/hongze_mobile_admin/services/alarm_msg"
+	"hongze/hongze_mobile_admin/utils"
+	"time"
+)
+
+// 如果合同只有研选的时候,自动处理派点
+func HandleAllocationCompanyContractByYanXuan(companyContractId int) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go alarm_msg.SendAlarmMsg(fmt.Sprint("如果合同只有研选的时候,自动处理派点失败,Err:", err.Error(), "companyContractId", companyContractId), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	pars = make([]interface{}, 0)
+	condition = " AND  company_contract_id = ?  "
+	pars = append(pars, companyContractId)
+	companyContractPermissionList, e := company_contract_permission.GetCompanyContractPermissionList(condition, pars)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
+		return
+	}
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCygxAllocationCompanyContractPermissionListById, Err: " + e.Error())
+		return
+	}
+
+	if len(companyContractPermissionList) > 1 {
+		return
+	}
+	var expensiveYxmoney float64
+	for _, v := range companyContractPermissionList {
+		if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
+			err = errors.New("没有发现研选权限: ")
+			return
+		}
+		if v.ExpensiveYx == 1 {
+			expensiveYxmoney = 5
+		} else {
+			expensiveYxmoney = 3
+		}
+	}
+
+	var items []*cygx_allocation_company_contract.CygxAllocationCompanyContract
+	var itemsPermission []*cygx_allocation_company_contract.CygxAllocationCompanyContractPermission
+
+	itemPermission := new(cygx_allocation_company_contract.CygxAllocationCompanyContractPermission)
+	itemPermission.CompanyContractId = companyContractId
+	//itemPermission.AdminId = sysUser.AdminId
+	//itemPermission.AdminName = sysUser.RealName
+	itemPermission.Proportion = 0
+	itemPermission.Money = expensiveYxmoney
+	itemPermission.MoneyAvg = 0
+	itemPermission.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
+	itemPermission.CreateTime = time.Now()
+	itemPermission.ModifyTime = time.Now()
+	itemsPermission = append(itemsPermission, itemPermission)
+
+	item := new(cygx_allocation_company_contract.CygxAllocationCompanyContract)
+	item.CompanyContractId = companyContractId
+	//item.AdminId = sysUser.AdminId
+	//item.AdminName = sysUser.RealName
+	item.Proportion = 0
+	item.Money = expensiveYxmoney
+	item.RealName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
+	item.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
+	item.CreateTime = time.Now()
+	item.ModifyTime = time.Now()
+	items = append(items, item)
+
+	e = cygx_allocation_company_contract.AddAndUpdateCygxAllocationCompanyContract(items, itemsPermission, companyContractId)
+	if e != nil {
+		err = errors.New("AddAndUpdateCygxAllocationCompanyContract, Err: " + e.Error())
+		return
+	}
+
+	return
+
+}

+ 14 - 13
utils/constants.go

@@ -158,19 +158,20 @@ const (
 )
 
 const (
-	LU_YAN_FU_WU                       = "路演服务"
-	CHART_PERMISSION_ID_YANXUAN        = 31
-	CE_LUE_NAME                 string = "策略"
-	YI_YAO_NAME                 string = "医药"
-	XIAO_FEI_NAME               string = "消费"
-	KE_JI_NAME                  string = "科技"
-	ZHI_ZAO_NAME                string = "智造"
-	ZHUAN_JIA_ID                int    = 29
-	CHART_PERMISSION_NAME_70W          = "70w大套餐"            // 权益70w大套餐名称
-	CHART_PERMISSION_ID_70W            = 2001                // 权益70w大套餐表示的权限ID(自定义)
-	CHART_PERMISSION_NAME_45W          = "45w大套餐"            // 权益45w大套餐名称
-	CHART_PERMISSION_ID_45W            = 2002                // 权益45w大套餐表示的权限ID(自定义)
-	TPL_MSG_WANG_YANG                  = "tpl_msg_wang_yang" //汪洋手机号地址参数
+	LU_YAN_FU_WU                            = "路演服务"
+	CHART_PERMISSION_ID_YANXUAN             = 31
+	CE_LUE_NAME                      string = "策略"
+	YI_YAO_NAME                      string = "医药"
+	XIAO_FEI_NAME                    string = "消费"
+	KE_JI_NAME                       string = "科技"
+	ZHI_ZAO_NAME                     string = "智造"
+	CHART_PERMISSION_NAME_MF_YANXUAN string = "买方研选"
+	ZHUAN_JIA_ID                     int    = 29
+	CHART_PERMISSION_NAME_70W               = "70w大套餐"            // 权益70w大套餐名称
+	CHART_PERMISSION_ID_70W                 = 2001                // 权益70w大套餐表示的权限ID(自定义)
+	CHART_PERMISSION_NAME_45W               = "45w大套餐"            // 权益45w大套餐名称
+	CHART_PERMISSION_ID_45W                 = 2002                // 权益45w大套餐表示的权限ID(自定义)
+	TPL_MSG_WANG_YANG                       = "tpl_msg_wang_yang" //汪洋手机号地址参数
 )
 
 const (