作者 陈志颖

合并分支 'dev' 到 'test'

Dev



查看合并请求 !47
... ... @@ -12,7 +12,7 @@ type UpdateCooperationContractCommand struct {
// 共创合约id
CooperationContractId string `cname:"共创合约id" json:"cooperationContractId" valid:"Required"`
// 共创合约描述
CooperationContractDescription string `cname:"共创合约描述" json:"cooperationContractDescription"`
CooperationContractDescription string `cname:"共创合约描述" json:"cooperationContractDescription,omitempty"`
// 共创项目编号
CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber"`
// 部门ID
... ... @@ -43,7 +43,7 @@ type UpdateCooperationContractCommand struct {
func (updateCooperationContractCommand *UpdateCooperationContractCommand) Valid(validation *validation.Validation) {
// 激励规则自定义校验
if len(updateCooperationContractCommand.DividendsIncentivesRules) <= 0 && len(updateCooperationContractCommand.MoneyIncentivesRules) <= 0 {
if len(updateCooperationContractCommand.DividendsIncentivesRules) < 1 && len(updateCooperationContractCommand.MoneyIncentivesRules) < 1 {
validation.Error("激励规则不能为空")
} else {
for i, _ := range updateCooperationContractCommand.DividendsIncentivesRules {
... ... @@ -58,7 +58,7 @@ func (updateCooperationContractCommand *UpdateCooperationContractCommand) Valid(
}
}
// 承接人列表校验
if len(updateCooperationContractCommand.Undertakers) <= 0 {
if len(updateCooperationContractCommand.Undertakers) < 1 {
validation.Error("承接人不能为空")
} else {
for i, _ := range updateCooperationContractCommand.Undertakers {
... ...
package service
import (
"crypto/md5"
"encoding/hex"
"fmt"
"strconv"
"time"
"unsafe"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
... ... @@ -746,7 +749,7 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
for _, cooperationContractOperated := range cooperationContractsOperated {
for _, cooperationContractOperated := range cooperationContracts {
// 新增共创合约变更记录
var operationType int32
if batchOperateCooperationContractCommand.Action == 1 {
... ... @@ -764,6 +767,7 @@ func (cooperationContractService *CooperationContractService) BatchOperateCooper
Org: cooperationContractOperated.Org,
Operator: operator,
CreatedAt: time.Now(),
OperatorTime: time.Now(),
}
// 保存共创合约变更记录
... ... @@ -939,24 +943,16 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
}
// 获取待更新的共创合约
cooperationContract, err8 := cooperationContractRepository.FindOne(map[string]interface{}{
cooperationContractFound, err8 := cooperationContractRepository.FindOne(map[string]interface{}{
"cooperationContractId": updateCooperationContractCommand.CooperationContractId,
})
if err8 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创合约不存在")
}
if cooperationContract == nil {
if cooperationContractFound == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractCommand.CooperationContractId)))
}
// 缓存共创合约
cooperationContractFound := cooperationContract
// 更新合约基础信息
if err9 := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err9 != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err9.Error())
}
// 用户REST服务初始化
var userService service.UserService
if value, err10 := factory.CreateUserService(map[string]interface{}{}); err10 != nil {
... ... @@ -985,6 +981,22 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
operator = data
}
// 获取待更新的共创合约
cooperationContract, err8 := cooperationContractRepository.FindOne(map[string]interface{}{
"cooperationContractId": updateCooperationContractCommand.CooperationContractId,
})
if err8 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创合约不存在")
}
if cooperationContract == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationContractCommand.CooperationContractId)))
}
// 更新合约基础信息
if err9 := cooperationContract.Update(tool_funs.SimpleStructToMap(updateCooperationContractCommand)); err9 != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err9.Error())
}
// 更新发起人
cooperationContract.CooperationContractSponsor = sponsor
... ... @@ -1195,10 +1207,10 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
var undertakerChange string
// 规则变更,原【(激励阶段:激励百分点,阶段有效期,推荐人抽点,关联业务员抽点),(激励阶段:激励百分点,阶段有效期,推荐人抽点,关联业务员抽点)】-->更新后【(激励阶段:激励百分点,阶段有效期,推荐人抽点,关联业务员抽点)】
if cooperationContractFound.IncentivesType != cooperationContractSaved.IncentivesType { // 1.激励规则类型变更
if cooperationContractFound.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES && cooperationContractSaved.IncentivesType == domain.TYPE_MONEY_INCENTIVES { // 业绩分红变更为金额激励
if cooperationContractFound.IncentivesType != cooperationContract.IncentivesType { // 1.激励规则类型变更
if cooperationContractFound.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES && cooperationContract.IncentivesType == domain.TYPE_MONEY_INCENTIVES { // 业绩分红变更为金额激励
// 业绩分红-->金额激励
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractSaved.IncentivesType))
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContract.IncentivesType))
//【第一阶段:20,2021-01-01~2021-12-31,,,;第二阶段:20,2021-01-01~2021-12-31,30,10】变更为【第一阶段:20,2021-01-01~2021-12-31,,,;】
// 原业绩分红激励规则
var dividendsIncentivesRuleOriginal string
... ... @@ -1214,10 +1226,10 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 变更后的金额激励规则
var moneyIncentivesRuleChanged string
for _, moneyIncentivesRule := range cooperationContractSaved.MoneyIncentivesRules {
for _, moneyIncentivesRule := range cooperationContract.MoneyIncentivesRules {
moneyIncentivesRuleChanged = moneyIncentivesRuleChanged + moneyIncentivesRule.MoneyIncentivesStageCN +
":" +
"," + moneyIncentivesRule.MoneyIncentivesStageStart.Format("2006-01-02") +
"," + moneyIncentivesRule.MoneyIncentivesTime.Format("2006-01-02") +
"," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
"," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
}
... ... @@ -1225,16 +1237,16 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 拼接规则变更
incentivesRuleChangeDetail = dividendsIncentivesRuleOriginalTmp + " 变更为 " + moneyIncentivesRuleOriginalTmp
} else if cooperationContractFound.IncentivesType == domain.TYPE_MONEY_INCENTIVES && cooperationContractSaved.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES { // 金额激励变更为业绩分红
} else if cooperationContractFound.IncentivesType == domain.TYPE_MONEY_INCENTIVES && cooperationContract.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES { // 金额激励变更为业绩分红
// 金额激励-->业绩分红
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractSaved.IncentivesType))
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContract.IncentivesType))
//【第一阶段:20,2021-01-01~2021-12-31,,,;第二阶段:20,2021-01-01~2021-12-31,30,10】变更为【第一阶段:20,2021-01-01~2021-12-31,,,;】
// 原金额激励规则
var moneyIncentivesRuleOriginal string
for _, moneyIncentivesRule := range cooperationContractFound.MoneyIncentivesRules {
moneyIncentivesRuleOriginal = moneyIncentivesRuleOriginal + moneyIncentivesRule.MoneyIncentivesStageCN +
":" +
"," + moneyIncentivesRule.MoneyIncentivesStageStart.Format("2006-01-02") +
"," + moneyIncentivesRule.MoneyIncentivesTime.Format("2006-01-02") +
"," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
"," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
}
... ... @@ -1242,7 +1254,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 变更后的业绩分红激励规则
var dividendsIncentivesRuleChanged string
for _, dividendsIncentivesRule := range cooperationContractSaved.DividendsIncentivesRules {
for _, dividendsIncentivesRule := range cooperationContract.DividendsIncentivesRules {
dividendsIncentivesRuleChanged = dividendsIncentivesRuleChanged + dividendsIncentivesRule.DividendsIncentivesStageCN +
":" + fmt.Sprint(dividendsIncentivesRule.DividendsIncentivesPercentage) +
"," + dividendsIncentivesRule.DividendsIncentivesStageStart.Format("2006-01-02") +
... ... @@ -1255,11 +1267,22 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 拼接规则变更
incentivesRuleChangeDetail = moneyIncentivesRuleOriginalTmp + " 变更为 " + dividendsIncentivesRuleOriginalTmp
}
} else if cooperationContractFound.IncentivesType == cooperationContractSaved.IncentivesType { // 2.激励规则内容变更
} else if cooperationContractFound.IncentivesType == cooperationContract.IncentivesType { // 2.激励规则内容变更
if cooperationContractFound.IncentivesType == domain.TYPE_DIVIDNEDS_INCENTIVES { // 业绩分红规则内容变更
if !cooperationContract.DividendsIncentivesRuleSliceEqualBCE(cooperationContractFound.DividendsIncentivesRules, cooperationContractSaved.DividendsIncentivesRules) {
// 计算原合约哈希值
cooperationContractFoundByte := *(*[]byte)(unsafe.Pointer(&cooperationContractFound.DividendsIncentivesRules))
cooperationContractFoundHashValue := md5.Sum(cooperationContractFoundByte)
cooperationContractFoundHashString := hex.EncodeToString(cooperationContractFoundHashValue[:])
// 计算更新后的合约哈希值
cooperationContractByte := *(*[]byte)(unsafe.Pointer(&cooperationContract.DividendsIncentivesRules))
cooperationContractHashValue := md5.Sum(cooperationContractByte)
cooperationContractHashString := hex.EncodeToString(cooperationContractHashValue[:])
if cooperationContractFoundHashString != cooperationContractHashString {
// 业绩分红-->业绩分红
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractSaved.IncentivesType))
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContract.IncentivesType))
//【第一阶段:20,2021-01-01~2021-12-31,,,;第二阶段:20,2021-01-01~2021-12-31,30,10】变更为【第一阶段:20,2021-01-01~2021-12-31,,,;】
// 原业绩分红激励规则
var dividendsIncentivesRuleOriginal string
... ... @@ -1274,7 +1297,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
dividendsIncentivesRuleOriginalTmp := "【" + dividendsIncentivesRuleOriginal + "】"
// 变更后的业绩分红激励规则
var dividendsIncentivesRuleChanged string
for _, dividendsIncentivesRule := range cooperationContractSaved.DividendsIncentivesRules {
for _, dividendsIncentivesRule := range cooperationContract.DividendsIncentivesRules {
dividendsIncentivesRuleChanged = dividendsIncentivesRuleChanged + dividendsIncentivesRule.DividendsIncentivesStageCN +
":" + fmt.Sprint(dividendsIncentivesRule.DividendsIncentivesPercentage) +
"," + dividendsIncentivesRule.DividendsIncentivesStageStart.Format("2006-01-02") +
... ... @@ -1286,26 +1309,36 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 拼接规则变更
incentivesRuleChangeDetail = dividendsIncentivesRuleOriginalTmp + " 变更为 " + dividendsIncentivesRuleChangedTmp
}
} else if cooperationContractFound.IncentivesType == domain.MONEY_INCENTIVES { // 金额激励规则内容变更
if !cooperationContract.MoneyIncentivesRuleSliceEqualBCE(cooperationContractFound.MoneyIncentivesRules, cooperationContractSaved.MoneyIncentivesRules) {
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractSaved.IncentivesType))
} else if cooperationContractFound.IncentivesType == domain.TYPE_MONEY_INCENTIVES { // 金额激励规则内容变更
// 计算原合约哈希值
cooperationContractFoundByte := *(*[]byte)(unsafe.Pointer(&cooperationContractFound.MoneyIncentivesRules))
cooperationContractFoundHashValue := md5.Sum(cooperationContractFoundByte)
cooperationContractFoundHashString := hex.EncodeToString(cooperationContractFoundHashValue[:])
// 计算更新后的合约哈希值
cooperationContractByte := *(*[]byte)(unsafe.Pointer(&cooperationContract.MoneyIncentivesRules))
cooperationContractHashValue := md5.Sum(cooperationContractByte)
cooperationContractHashString := hex.EncodeToString(cooperationContractHashValue[:])
if cooperationContractFoundHashString != cooperationContractHashString {
incentivesRuleChange = cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContractFound.IncentivesType)) + "-->" + cooperationContract.ReturnIncentivesName(domain.IncentivesType(cooperationContract.IncentivesType))
//【第一阶段:20,2021-01-01~2021-12-31,,,;第二阶段:20,2021-01-01~2021-12-31,30,10】变更为【第一阶段:20,2021-01-01~2021-12-31,,,;】
// 原金额激励规则
var moneyIncentivesRuleOriginal string
for _, moneyIncentivesRule := range cooperationContractFound.MoneyIncentivesRules {
moneyIncentivesRuleOriginal = moneyIncentivesRuleOriginal + moneyIncentivesRule.MoneyIncentivesStageCN +
":" +
"," + moneyIncentivesRule.MoneyIncentivesStageStart.Format("2006-01-02") +
"," + moneyIncentivesRule.MoneyIncentivesTime.Format("2006-01-02") +
"," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
"," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
}
moneyIncentivesRuleOriginalTmp := "【" + moneyIncentivesRuleOriginal + "】"
// 变更后的激励规则
var moneyIncentivesRuleChanged string
for _, moneyIncentivesRule := range cooperationContractSaved.MoneyIncentivesRules {
for _, moneyIncentivesRule := range cooperationContract.MoneyIncentivesRules {
moneyIncentivesRuleChanged = moneyIncentivesRuleChanged + moneyIncentivesRule.MoneyIncentivesStageCN +
":" +
"," + moneyIncentivesRule.MoneyIncentivesStageStart.Format("2006-01-02") +
"," + moneyIncentivesRule.MoneyIncentivesTime.Format("2006-01-02") +
"," + fmt.Sprint(moneyIncentivesRule.ReferrerPercentage) +
"," + fmt.Sprint(moneyIncentivesRule.SalesmanPercentage) + ";"
}
... ... @@ -1316,8 +1349,18 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
}
}
// 承接人变更
if !cooperationContract.UndertakerSliceEqualBCE(cooperationContractFound.Undertakers, cooperationContractSaved.Undertakers) { // 【1(张三,李四,王五)2(买买买,,)】变更为【1(张三,,)】
/*********************************************** 承接人变更 *****************************************************/
// 计算原合约哈希值
cooperationContractFoundByte := *(*[]byte)(unsafe.Pointer(&cooperationContractFound.Undertakers))
cooperationContractFoundHashValue := md5.Sum(cooperationContractFoundByte)
cooperationContractFoundHashString := hex.EncodeToString(cooperationContractFoundHashValue[:])
// 计算更新后的合约哈希值
cooperationContractByte := *(*[]byte)(unsafe.Pointer(&cooperationContract.Undertakers))
cooperationContractHashValue := md5.Sum(cooperationContractByte)
cooperationContractHashString := hex.EncodeToString(cooperationContractHashValue[:])
if cooperationContractFoundHashString != cooperationContractHashString { // 【1(张三,李四,王五)2(买买买,,)】变更为【1(张三,,)】
// 原承接人
var undertakersOriginal string
for i, undertaker := range cooperationContractFound.Undertakers {
... ... @@ -1357,7 +1400,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
// 变更承接人
var undertakersChanged string
for i, undertaker := range cooperationContractSaved.Undertakers {
for i, undertaker := range cooperationContract.Undertakers {
if undertaker.Referrer == nil {
undertaker.Referrer = &domain.Referrer{
UserId: 0,
... ... @@ -1401,7 +1444,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
IncentivesRuleDetail: incentivesRuleChangeDetail,
OperationType: domain.EDIT,
Undertakers: undertakerChange,
CooperationContractNumber: cooperationContractSaved.CooperationContractNumber,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
Company: company,
Org: organization,
Operator: operator,
... ...
... ... @@ -635,7 +635,7 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro
} else {
if count > 0 {
for _, cooperationApplication := range cooperationApplications {
applicantTypes[cooperationApplication.CooperationApplicationApplicant.UserType] = cooperationApplication.CooperationApplicationApplicant.UserType
applicantTypes[cooperationApplication.CooperationApplicationApplicant.UserType] = 1
}
}
}
... ... @@ -652,7 +652,7 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro
}
}
if k1 != 0 && k2 != 0 {
undertakerTypes = append(undertakerTypes, 4)
undertakerTypes = append(undertakerTypes, 3)
}
// 校验可以修改的承接人(申请人)类型
for _, t := range undertakerTypes {
... ...
... ... @@ -3,6 +3,7 @@ package dao
import (
"fmt"
"github.com/go-pg/pg/v10"
"github.com/go-pg/pg/v10/orm"
"github.com/linmadan/egglib-go/persistent/pg/sqlbuilder"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
... ... @@ -69,7 +70,11 @@ func (dao *CooperationContractDao) CheckUndertakerTypesUncheckedAvailable(queryO
query = query.Where(`cooperation_contract.org @> '{"orgId":"?"}'`, orgId)
}
if user, ok := queryOptions["user"]; ok && user.(bool) != false {
query = query.Where("user_type = ?", 1)
query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
q.WhereOr("user_type = ?", 1)
q.WhereOr("user_type = ?", 1025)
return q, nil
})
}
if partner, ok := queryOptions["partner"]; ok && partner.(bool) != false {
query = query.Where("user_type = ?", 2)
... ...
... ... @@ -2,6 +2,7 @@ package dao
import (
"fmt"
"github.com/go-pg/pg/v10/orm"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
... ... @@ -73,7 +74,11 @@ func (dao *CooperationProjectDao) CheckUndertakerTypesUncheckedAvailable(queryOp
queryUndertaker := tx.Model(&cooperationContractUndertakerModels)
queryUndertaker.Where("cooperation_contract_number = ?", cooperationContractModel.CooperationContractNumber)
if user, ok := queryOptions["user"]; ok && user.(bool) != false {
query = query.Where("user_type = ?", 1)
query.WhereGroup(func(q *orm.Query) (*orm.Query, error) {
q.WhereOr("user_type = ?", 1)
q.WhereOr("user_type = ?", 1025)
return q, nil
})
}
if partner, ok := queryOptions["partner"]; ok && partner.(bool) != false {
query = query.Where("user_type = ?", 2)
... ...
package utils
import (
"bytes"
"encoding/binary"
"fmt"
"github.com/shopspring/decimal"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
"strconv"
"strings"
)
... ... @@ -160,3 +163,13 @@ func IsContain64(items []int64, item int64) bool {
}
return false
}
func AnyToHex(any interface{}) []byte {
buff := new(bytes.Buffer)
//数据写入buff
err := binary.Write(buff, binary.BigEndian, any)
if err != nil {
log.Logger.Error(err.Error())
}
return buff.Bytes()
}
... ...