作者 陈志颖

合并分支 'dev' 到 'test'

Dev



查看合并请求 !8
@@ -175,11 +175,20 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro @@ -175,11 +175,20 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
175 "orgId": createCooperationProjectCommand.OrgId, 175 "orgId": createCooperationProjectCommand.OrgId,
176 "cooperationProjectNumber": projectNumber, 176 "cooperationProjectNumber": projectNumber,
177 }) 177 })
178 - // TODO 校验共创项目名称是否唯一  
179 -  
180 if !numberAvailable { 178 if !numberAvailable {
181 return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增共创项目异常") 179 return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增共创项目异常")
182 } 180 }
  181 +
  182 + // 校验共创项目名称是否唯一
  183 + nameAvailable, _ := cooperationProjectDao.CheckProjectNameAvailable(map[string]interface{}{
  184 + "companyId": createCooperationProjectCommand.CompanyId,
  185 + "orgId": createCooperationProjectCommand.OrgId,
  186 + "cooperationProjectName": createCooperationProjectCommand.CooperationProjectName,
  187 + })
  188 + if !nameAvailable {
  189 + return nil, application.ThrowError(application.TRANSACTION_ERROR, "共创项目名称重复")
  190 + }
  191 +
183 newCooperationProject := &domain.CooperationProject{ 192 newCooperationProject := &domain.CooperationProject{
184 CooperationProjectNumber: projectNumber, 193 CooperationProjectNumber: projectNumber,
185 CooperationProjectName: createCooperationProjectCommand.CooperationProjectName, 194 CooperationProjectName: createCooperationProjectCommand.CooperationProjectName,
@@ -489,6 +498,16 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro @@ -489,6 +498,16 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro
489 operator = data 498 operator = data
490 } 499 }
491 500
  501 + // 共创项目DAO初始化
  502 + var cooperationProjectDao *dao.CooperationProjectDao
  503 + if value, err := factory.CreateCooperationProjectDao(map[string]interface{}{
  504 + "transactionContext": transactionContext,
  505 + }); err != nil {
  506 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  507 + } else {
  508 + cooperationProjectDao = value
  509 + }
  510 +
492 // 获取发起人 511 // 获取发起人
493 var sponsor *domain.User 512 var sponsor *domain.User
494 // sponsorUid类型转换 513 // sponsorUid类型转换
@@ -520,6 +539,18 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro @@ -520,6 +539,18 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro
520 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationProjectCommand.CooperationProjectId))) 539 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationProjectCommand.CooperationProjectId)))
521 } 540 }
522 541
  542 + // 校验共创项目名称是否唯一
  543 + if cooperationProject.CooperationProjectName != updateCooperationProjectCommand.CooperationProjectName {
  544 + nameAvailable, _ := cooperationProjectDao.CheckProjectNameAvailable(map[string]interface{}{
  545 + "companyId": updateCooperationProjectCommand.CompanyId,
  546 + "orgId": updateCooperationProjectCommand.OrgId,
  547 + "cooperationProjectName": updateCooperationProjectCommand.CooperationProjectName,
  548 + })
  549 + if !nameAvailable {
  550 + return nil, application.ThrowError(application.TRANSACTION_ERROR, "共创项目名称重复")
  551 + }
  552 + }
  553 +
523 applicantTypes := make(map[int32]interface{}) 554 applicantTypes := make(map[int32]interface{})
524 555
525 // 获取所有申请人 556 // 获取所有申请人
@@ -104,6 +104,24 @@ func (dao *CooperationProjectDao) CheckProjectNumberAvailable(queryOptions map[s @@ -104,6 +104,24 @@ func (dao *CooperationProjectDao) CheckProjectNumberAvailable(queryOptions map[s
104 return !ok, err 104 return !ok, err
105 } 105 }
106 106
  107 +// CheckProjectNameAvailable 校验共创项目名称唯一
  108 +func (dao *CooperationProjectDao) CheckProjectNameAvailable(queryOptions map[string]interface{}) (bool, error) {
  109 + tx := dao.transactionContext.PgTx
  110 + var cooperationProjectModels []*models.CooperationProject
  111 + query := tx.Model(&cooperationProjectModels)
  112 + if cooperationProjectName, ok := queryOptions["cooperationProjectName"]; ok && cooperationProjectName != "" {
  113 + query = query.Where("cooperation_project_name = ?", cooperationProjectName)
  114 + }
  115 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  116 + query = query.Where(`cooperation_project.company @> '{"companyId":"?"}'`, companyId)
  117 + }
  118 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  119 + query = query.Where(`cooperation_project.org @> '{"orgId":"?"}'`, orgId)
  120 + }
  121 + ok, err := query.Exists()
  122 + return !ok, err
  123 +}
  124 +
107 func NewCooperationProjectDao(transactionContext *pgTransaction.TransactionContext) (*CooperationProjectDao, error) { 125 func NewCooperationProjectDao(transactionContext *pgTransaction.TransactionContext) (*CooperationProjectDao, error) {
108 if transactionContext == nil { 126 if transactionContext == nil {
109 return nil, fmt.Errorf("transactionContext参数不能为nil") 127 return nil, fmt.Errorf("transactionContext参数不能为nil")
@@ -229,6 +229,12 @@ func (ptr *CooperationStatisticsService) CompanyCooperationUsersStatistics(query @@ -229,6 +229,12 @@ func (ptr *CooperationStatisticsService) CompanyCooperationUsersStatistics(query
229 } 229 }
230 if user, e := userService.UserFrom(0, 0, responses[i].UserId); e == nil && user != nil { 230 if user, e := userService.UserFrom(0, 0, responses[i].UserId); e == nil && user != nil {
231 item["cooperationTime"] = user.CreatedAt.Unix() * 1000 231 item["cooperationTime"] = user.CreatedAt.Unix() * 1000
  232 + item["participator"] = map[string]interface{}{
  233 + "userId": user.UserId,
  234 + "userInfo": map[string]interface{}{
  235 + "userName": user.UserName,
  236 + },
  237 + }
232 } 238 }
233 retMap = append(retMap, item) 239 retMap = append(retMap, item)
234 } 240 }
@@ -515,6 +515,7 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m @@ -515,6 +515,7 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m
515 if item.DividendsType == 1 { 515 if item.DividendsType == 1 {
516 order, err := dividendsOrderRepository.FindOne(map[string]interface{}{ 516 order, err := dividendsOrderRepository.FindOne(map[string]interface{}{
517 "dividendsOrderNumber": item.OrderOrReturnedOrderNum, 517 "dividendsOrderNumber": item.OrderOrReturnedOrderNum,
  518 + "orgId": request.OrgId,
518 }) 519 })
519 if err != nil { 520 if err != nil {
520 return nil, err 521 return nil, err
@@ -522,7 +523,7 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m @@ -522,7 +523,7 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m
522 result.DividendsOrderAmount = order.DividendsOrderAmount 523 result.DividendsOrderAmount = order.DividendsOrderAmount
523 result.CustomerName = order.CustomerName 524 result.CustomerName = order.CustomerName
524 } else if item.DividendsType == 2 { 525 } else if item.DividendsType == 2 {
525 - order, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderNumber": item.OrderOrReturnedOrderNum}) 526 + order, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderNumber": item.OrderOrReturnedOrderNum, "orgId": request.OrgId})
526 if err != nil { 527 if err != nil {
527 return nil, err 528 return nil, err
528 } 529 }
@@ -584,7 +585,7 @@ func (ptr *CooperationStatisticsService) RelevantCooperationContractNumbers(quer @@ -584,7 +585,7 @@ func (ptr *CooperationStatisticsService) RelevantCooperationContractNumbers(quer
584 return nil, err 585 return nil, err
585 } 586 }
586 queryOptions = tool_funs.SimpleStructToMap(&request) 587 queryOptions = tool_funs.SimpleStructToMap(&request)
587 - 588 + queryOptions["limit"] = 999
588 contractNumbers, err := ptr.getRelevantContracts(queryOptions) 589 contractNumbers, err := ptr.getRelevantContracts(queryOptions)
589 return contractNumbers, err 590 return contractNumbers, err
590 } 591 }
@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 type CooperationContractUndertaker struct { 8 type CooperationContractUndertaker struct {
9 tableName string `comment:"共创合约承接人" pg:"cooperation_contract_undertakers,alias:cooperation_contract_undertaker"` 9 tableName string `comment:"共创合约承接人" pg:"cooperation_contract_undertakers,alias:cooperation_contract_undertaker"`
10 // 共创合约承接人id 10 // 共创合约承接人id
11 - CooperationContractUndertakerId int64 `comment:"共创合约承接人id" pg:",pk,unique"` 11 + CooperationContractUndertakerId int64 `comment:"共创合约承接人id" pg:",pk"`
12 // 共创合约编号 12 // 共创合约编号
13 CooperationContractNumber string `comment:"共创合约编号"` 13 CooperationContractNumber string `comment:"共创合约编号"`
14 // 共创合约承接人uid 14 // 共创合约承接人uid
@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 type DividendsIncentivesRule struct { 8 type DividendsIncentivesRule struct {
9 tableName string `comment:"金额激励规则实体" pg:"dividends_incentives_rules,alias:dividends_incentives_rule"` 9 tableName string `comment:"金额激励规则实体" pg:"dividends_incentives_rules,alias:dividends_incentives_rule"`
10 // 分红规则ID 10 // 分红规则ID
11 - DividendsIncentivesRuleId int64 `comment:"分红规则ID" pg:",pk,unique"` 11 + DividendsIncentivesRuleId int64 `comment:"分红规则ID" pg:",pk"`
12 // 关联的项目合约编号 12 // 关联的项目合约编号
13 CooperationContractNumber string `comment:"关联的项目合约编号"` 13 CooperationContractNumber string `comment:"关联的项目合约编号"`
14 // 推荐人抽成比例 14 // 推荐人抽成比例
@@ -10,7 +10,7 @@ type DividendsOrder struct { @@ -10,7 +10,7 @@ type DividendsOrder struct {
10 // 分红订单ID 10 // 分红订单ID
11 DividendsOrderId int64 `comment:"分红订单ID" pg:",pk"` 11 DividendsOrderId int64 `comment:"分红订单ID" pg:",pk"`
12 // 分红订单号 12 // 分红订单号
13 - DividendsOrderNumber string `comment:"分红订单号" pg:",unique"` 13 + DividendsOrderNumber string `comment:"分红订单号"`
14 // 分红订单原单号 14 // 分红订单原单号
15 DividendsOriginalOrderNum string `comment:"分红订单原单号"` 15 DividendsOriginalOrderNum string `comment:"分红订单原单号"`
16 // 分红订单金额 16 // 分红订单金额
@@ -10,7 +10,7 @@ type DividendsReturnedOrder struct { @@ -10,7 +10,7 @@ type DividendsReturnedOrder struct {
10 // 分红退货单记录ID 10 // 分红退货单记录ID
11 DividendsReturnedOrderId int64 `comment:"分红退货单记录ID" pg:",pk"` 11 DividendsReturnedOrderId int64 `comment:"分红退货单记录ID" pg:",pk"`
12 // 分红退货单号 12 // 分红退货单号
13 - DividendsReturnedOrderNumber string `comment:"分红退货单号" pg:",unique"` 13 + DividendsReturnedOrderNumber string `comment:"分红退货单号"`
14 // 退货金额 14 // 退货金额
15 DividendsReturnedOrderRefund float64 `comment:"退货金额"` 15 DividendsReturnedOrderRefund float64 `comment:"退货金额"`
16 // 源单号(原始订单号) 16 // 源单号(原始订单号)
@@ -8,7 +8,7 @@ import ( @@ -8,7 +8,7 @@ import (
8 type MoneyIncentivesRule struct { 8 type MoneyIncentivesRule struct {
9 tableName string `comment:"金额激励规则实体" pg:"money_incentives_rules,alias:money_incentives_rule"` 9 tableName string `comment:"金额激励规则实体" pg:"money_incentives_rules,alias:money_incentives_rule"`
10 // 金额激励规则ID 10 // 金额激励规则ID
11 - MoneyIncentivesRuleId int64 `comment:"金额激励规则ID" pg:",pk,unique"` 11 + MoneyIncentivesRuleId int64 `comment:"金额激励规则ID" pg:",pk"`
12 // 关联的共创合约编号 12 // 关联的共创合约编号
13 CooperationContractNumber string `comment:"关联的共创合约编号"` 13 CooperationContractNumber string `comment:"关联的共创合约编号"`
14 // 激励金额 14 // 激励金额
@@ -208,6 +208,9 @@ func (repository *CreditAccountRepository) Find(queryOptions map[string]interfac @@ -208,6 +208,9 @@ func (repository *CreditAccountRepository) Find(queryOptions map[string]interfac
208 if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" { 208 if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
209 query.Where(`cooperation_contract_number = ?`, fmt.Sprintf("%s", cooperationContractNumber)) 209 query.Where(`cooperation_contract_number = ?`, fmt.Sprintf("%s", cooperationContractNumber))
210 } 210 }
  211 + if v, ok := queryOptions["cooperationContractNumbers"]; ok && len(v.([]string)) > 0 {
  212 + query.Where("cooperation_contract_number in (?)", pg.In(v))
  213 + }
211 if paymentStatus, ok := queryOptions["paymentStatus"]; ok && paymentStatus.(int32) != 0 { 214 if paymentStatus, ok := queryOptions["paymentStatus"]; ok && paymentStatus.(int32) != 0 {
212 query.Where("payment_status = ?", paymentStatus) 215 query.Where("payment_status = ?", paymentStatus)
213 } 216 }