作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…

…ion-cooperation into dev
@@ -9,59 +9,84 @@ import ( @@ -9,59 +9,84 @@ import (
9 "github.com/beego/beego/v2/core/validation" 9 "github.com/beego/beego/v2/core/validation"
10 ) 10 )
11 11
  12 +// CreateDividendsIncentivesRulesCommand 业绩分红激励规则
12 type CreateDividendsIncentivesRulesCommand struct { 13 type CreateDividendsIncentivesRulesCommand struct {
13 - DividendsIncentivesRuleId string `cname:"分红激励规则ID" json:"dividendsIncentivesRuleId"`  
14 - CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber"` 14 + // 分红激励规则ID
  15 + DividendsIncentivesRuleId string `cname:"分红激励规则ID" json:"dividendsIncentivesRuleId,omitempty"`
  16 + // 共创合约编号
  17 + CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber,omitempty"`
  18 + // 推荐人抽成
15 ReferrerPercentage float64 `cname:"推荐人抽成" json:"referrerPercentage"` 19 ReferrerPercentage float64 `cname:"推荐人抽成" json:"referrerPercentage"`
  20 + // 业务员抽成
16 SalesmanPercentage float64 `cname:"业务员抽成" json:"salesmanPercentage"` 21 SalesmanPercentage float64 `cname:"业务员抽成" json:"salesmanPercentage"`
  22 + // 分红规则激励百分点
17 DividendsIncentivesPercentage float64 `cname:"分红规则激励百分点" json:"dividendsIncentivesPercentage"` 23 DividendsIncentivesPercentage float64 `cname:"分红规则激励百分点" json:"dividendsIncentivesPercentage"`
  24 + // 分红激励阶段
18 DividendsIncentivesStage int32 `cname:"分红激励阶段" json:"dividendsIncentivesStage"` 25 DividendsIncentivesStage int32 `cname:"分红激励阶段" json:"dividendsIncentivesStage"`
19 - DividendsIncentivesStageEnd time.Time `cname:"业绩分红阶段结束时间" json:"dividendsIncentivesStageEnd"` 26 + // 业绩分红阶段开始时间
20 DividendsIncentivesStageStart time.Time `cname:"业绩分红阶段开始时间" json:"dividendsIncentivesStageStart"` 27 DividendsIncentivesStageStart time.Time `cname:"业绩分红阶段开始时间" json:"dividendsIncentivesStageStart"`
  28 + // 业绩分红阶段结束时间
  29 + DividendsIncentivesStageEnd time.Time `cname:"业绩分红阶段结束时间" json:"dividendsIncentivesStageEnd"`
21 } 30 }
22 31
  32 +// CreateMoneyIncentivesRulesCommand 金额激励规则
23 type CreateMoneyIncentivesRulesCommand struct { 33 type CreateMoneyIncentivesRulesCommand struct {
  34 + // 金额激励规则ID
24 MoneyIncentivesRuleId string `cname:"金额激励规则ID" json:"moneyIncentivesRuleId"` 35 MoneyIncentivesRuleId string `cname:"金额激励规则ID" json:"moneyIncentivesRuleId"`
  36 + // 共创合约编号
25 CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber"` 37 CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber"`
  38 + // 激励金额
26 MoneyIncentivesAmount float64 `cname:"激励金额" json:"moneyIncentivesAmount"` 39 MoneyIncentivesAmount float64 `cname:"激励金额" json:"moneyIncentivesAmount"`
  40 + // 金额激励阶段
27 MoneyIncentivesStage int32 `cname:"金额激励阶段" json:"moneyIncentivesStage"` 41 MoneyIncentivesStage int32 `cname:"金额激励阶段" json:"moneyIncentivesStage"`
28 - MoneyIncentivesStageEnd time.Time `cname:"" json:"moneyIncentivesStageEnd"`  
29 - MoneyIncentivesStageStart time.Time `cname:"金额激励时间" json:"moneyIncentivesStageStart"`  
30 - MoneyIncentivesTime time.Time `cname:"" json:"moneyIncentivesTime"` 42 + // 金额激励结束时间
  43 + MoneyIncentivesStageEnd time.Time `cname:"金额激励结束时间" json:"moneyIncentivesStageEnd"`
  44 + // 金额激励开始时间
  45 + MoneyIncentivesStageStart time.Time `cname:"金额激励开始时间" json:"moneyIncentivesStageStart"`
  46 + // 金额激励时间
  47 + MoneyIncentivesTime time.Time `cname:"金额激励时间" json:"moneyIncentivesTime"`
  48 + // 推荐人抽成
31 ReferrerPercentage float64 `cname:"推荐人抽成" json:"referrerPercentage"` 49 ReferrerPercentage float64 `cname:"推荐人抽成" json:"referrerPercentage"`
  50 + // 业务员抽成
32 SalesmanPercentage float64 `cname:"业务员抽成" json:"salesmanPercentage"` 51 SalesmanPercentage float64 `cname:"业务员抽成" json:"salesmanPercentage"`
33 } 52 }
34 53
  54 +// CreateUndertakersCommand 承接人
35 type CreateUndertakersCommand struct { 55 type CreateUndertakersCommand struct {
  56 + // 承接人ID
36 UndertakerId string `cname:"承接人ID" json:"undertakerId"` 57 UndertakerId string `cname:"承接人ID" json:"undertakerId"`
  58 + // 承接人用户ID
37 UserId string `cname:"承接人UID" json:"userId"` 59 UserId string `cname:"承接人UID" json:"userId"`
  60 + // 附件
38 ContractAttachment []struct { 61 ContractAttachment []struct {
  62 + // 文件类型
39 FileType string `cname:"文件类型" json:"fileType"` 63 FileType string `cname:"文件类型" json:"fileType"`
  64 + // 文件名称
40 Name string `cname:"文件名称" json:"name"` 65 Name string `cname:"文件名称" json:"name"`
  66 + // 文件路径
41 Url string `cname:"文件路径" json:"url"` 67 Url string `cname:"文件路径" json:"url"`
  68 + // 文件大小
42 FileSize int64 `cname:"文件大小" json:"fileSize"` 69 FileSize int64 `cname:"文件大小" json:"fileSize"`
43 } `cname:"附件" json:"contractAttachment"` 70 } `cname:"附件" json:"contractAttachment"`
  71 + // 推荐人用户ID
44 ReferrerId string `cname:"推荐UID" json:"referrerId"` 72 ReferrerId string `cname:"推荐UID" json:"referrerId"`
  73 + // 业务员用户ID
45 SalesmanId string `cname:"业务员UID" json:"salesmanId"` 74 SalesmanId string `cname:"业务员UID" json:"salesmanId"`
46 } 75 }
47 76
48 -type CreateRelevantPeopleCommand struct {  
49 - UserId string `cname:"相关人UID" json:"userId"`  
50 -}  
51 -  
52 type CreateCooperationContractCommand struct { 77 type CreateCooperationContractCommand struct {
53 // 共创合约描述 78 // 共创合约描述
54 CooperationContractDescription string `cname:"共创合约描述" json:"cooperationContractDescription" valid:"Required"` 79 CooperationContractDescription string `cname:"共创合约描述" json:"cooperationContractDescription" valid:"Required"`
55 // 共创项目编号 80 // 共创项目编号
56 - CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber" valid:"Required"`  
57 - // 共创合约发起部门编码 81 + CooperationProjectNumber string `cname:"共创项目编号" json:"cooperationProjectNumber,omitempty"`
  82 + // 共创合约发起部门ID
58 DepartmentId string `cname:"共创合约发起部门ID" json:"departmentId" valid:"Required"` 83 DepartmentId string `cname:"共创合约发起部门ID" json:"departmentId" valid:"Required"`
59 // 共创合约承接对象,1员工,2共创用户,3公开 84 // 共创合约承接对象,1员工,2共创用户,3公开
60 CooperationContractUndertakerTypes []int32 `cname:"共创合约承接对象" json:"cooperationContractUndertakerTypes" valid:"Required"` 85 CooperationContractUndertakerTypes []int32 `cname:"共创合约承接对象" json:"cooperationContractUndertakerTypes" valid:"Required"`
61 // 共创合约名称 86 // 共创合约名称
62 CooperationContractName string `cname:"共创合约名称" json:"cooperationContractName" valid:"Required"` 87 CooperationContractName string `cname:"共创合约名称" json:"cooperationContractName" valid:"Required"`
63 // 共创模式编码 88 // 共创模式编码
64 - CooperationModeNumber string `cname:"共创模式编码" json:"cooperationModeNumber" valid:"Required"` 89 + CooperationModeNumber string `cname:"共创模式编码" json:"cooperationModeNumber,omitempty"`
65 // 共创合约发起人uid 90 // 共创合约发起人uid
66 SponsorUid string `cname:"共创合约发起人uid" json:"sponsorUid,omitempty"` 91 SponsorUid string `cname:"共创合约发起人uid" json:"sponsorUid,omitempty"`
67 // 业绩分红激励规则列表 92 // 业绩分红激励规则列表
@@ -94,6 +94,26 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -94,6 +94,26 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
94 organization = data 94 organization = data
95 } 95 }
96 96
  97 + // 部门REST服务初始化
  98 + var departmentService service.DepartmentService
  99 + if value, err := factory.CreateDepartmentService(map[string]interface{}{}); err != nil {
  100 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  101 + } else {
  102 + departmentService = value
  103 + }
  104 +
  105 + // 获取部门
  106 + var department *domain.Department
  107 + departmentId, err := strconv.ParseInt(createCooperationContractCommand.DepartmentId, 10, 64)
  108 + if err != nil {
  109 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  110 + }
  111 + if data, err := departmentService.DepartmentFrom(createCooperationContractCommand.CompanyId, departmentId); err != nil {
  112 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  113 + } else {
  114 + department = data
  115 + }
  116 +
97 // 共创合约DAO初始化 117 // 共创合约DAO初始化
98 var cooperationContractDao *dao.CooperationContractDao 118 var cooperationContractDao *dao.CooperationContractDao
99 if value, err := factory.CreateCooperationContractDao(map[string]interface{}{ 119 if value, err := factory.CreateCooperationContractDao(map[string]interface{}{
@@ -103,11 +123,13 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -103,11 +123,13 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
103 } else { 123 } else {
104 cooperationContractDao = value 124 cooperationContractDao = value
105 } 125 }
  126 +
106 // 生成共创合约编号 127 // 生成共创合约编号
107 contractNumber, err2 := cooperationContractDao.GenerateContractNumber() 128 contractNumber, err2 := cooperationContractDao.GenerateContractNumber()
108 if err2 != nil { 129 if err2 != nil {
109 return nil, application.ThrowError(application.TRANSACTION_ERROR, err2.Error()) 130 return nil, application.ThrowError(application.TRANSACTION_ERROR, err2.Error())
110 } 131 }
  132 +
111 // 校验共创合约编号是否唯一 133 // 校验共创合约编号是否唯一
112 numberAvailable, _ := cooperationContractDao.CheckContractNumberAvailable(map[string]interface{}{ 134 numberAvailable, _ := cooperationContractDao.CheckContractNumberAvailable(map[string]interface{}{
113 "companyId": createCooperationContractCommand.CompanyId, 135 "companyId": createCooperationContractCommand.CompanyId,
@@ -122,7 +144,10 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -122,7 +144,10 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
122 var undertakers []*domain.Undertaker 144 var undertakers []*domain.Undertaker
123 for _, undertaker := range createCooperationContractCommand.Undertakers { 145 for _, undertaker := range createCooperationContractCommand.Undertakers {
124 var undertakerDomain *domain.Undertaker 146 var undertakerDomain *domain.Undertaker
125 - undertakerUid, _ := strconv.ParseInt(undertaker.UserId, 10, 64) 147 + undertakerUid, err := strconv.ParseInt(undertaker.UserId, 10, 64)
  148 + if err != nil {
  149 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "承接人UID错误")
  150 + }
126 if data, err := userService.UndertakerFrom(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId, undertakerUid); err != nil { 151 if data, err := userService.UndertakerFrom(createCooperationContractCommand.CompanyId, createCooperationContractCommand.OrgId, undertakerUid); err != nil {
127 log.Logger.Error(err.Error()) 152 log.Logger.Error(err.Error())
128 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 153 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -268,6 +293,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -268,6 +293,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
268 Status: 1, 293 Status: 1,
269 Org: organization, 294 Org: organization,
270 Company: company, 295 Company: company,
  296 + Department: department,
271 Operator: operator, 297 Operator: operator,
272 DividendsIncentivesRules: dividendsIncentivesRules, 298 DividendsIncentivesRules: dividendsIncentivesRules,
273 MoneyIncentivesRules: moneyIncentivesRules, 299 MoneyIncentivesRules: moneyIncentivesRules,
@@ -339,14 +365,39 @@ func (cooperationContractService *CooperationContractService) GetCooperationCont @@ -339,14 +365,39 @@ func (cooperationContractService *CooperationContractService) GetCooperationCont
339 } else { 365 } else {
340 cooperationContractDao = value 366 cooperationContractDao = value
341 } 367 }
342 - // 获取可删除的承接对象类型  
343 - undertakerTypesUncheckedAvailable, err := cooperationContractDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{ 368 +
  369 + // 可以去除勾选的承接人对象列表
  370 + var undertakerTypesUncheckedAvailable []int32
  371 +
  372 + // 判断承接对象是否存在员工
  373 + gotUser, err := cooperationContractDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
  374 + "cooperationContractNumber": cooperationContract.CooperationContractNumber,
  375 + "user": true,
  376 + })
  377 + if err != nil {
  378 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  379 + }
  380 + if !gotUser {
  381 + undertakerTypesUncheckedAvailable = append(undertakerTypesUncheckedAvailable, 1)
  382 + }
  383 +
  384 + // 判断承接对象是否存在共创用户
  385 + gotPartner, err := cooperationContractDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
344 "cooperationContractNumber": cooperationContract.CooperationContractNumber, 386 "cooperationContractNumber": cooperationContract.CooperationContractNumber,
345 - "cooperationContractUndertakerTypes": cooperationContract.CooperationContractUndertakerTypes, 387 + "partner": true,
346 }) 388 })
347 if err != nil { 389 if err != nil {
348 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 390 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
349 } 391 }
  392 + if !gotPartner {
  393 + undertakerTypesUncheckedAvailable = append(undertakerTypesUncheckedAvailable, 2)
  394 + }
  395 +
  396 + // 判断承接人是否存在公开用户
  397 + if !gotUser && !gotPartner {
  398 + undertakerTypesUncheckedAvailable = append(undertakerTypesUncheckedAvailable, 3)
  399 + }
  400 +
350 cooperationContractDto := &dto.CooperationContractDto{} 401 cooperationContractDto := &dto.CooperationContractDto{}
351 if err := cooperationContractDto.LoadDto(cooperationContract, undertakerTypesUncheckedAvailable); err != nil { 402 if err := cooperationContractDto.LoadDto(cooperationContract, undertakerTypesUncheckedAvailable); err != nil {
352 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 403 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -21,7 +21,7 @@ type DividendsIncentivesEstimateDto struct { @@ -21,7 +21,7 @@ type DividendsIncentivesEstimateDto struct {
21 // 订单金额 21 // 订单金额
22 OrderAmount float64 `json:"orderAmount"` 22 OrderAmount float64 `json:"orderAmount"`
23 // 订单/退货单日期 23 // 订单/退货单日期
24 - OrderDate string `json:"orderDate"` 24 + OrderDate time.Time `json:"orderDate"`
25 } 25 }
26 26
27 func (dto *DividendsIncentivesEstimateDto) LoadDto(orderGood *domain.OrderGood, orderNumber string, originalOrderNum string, customerName string, regionName string, orderDate time.Time) error { 27 func (dto *DividendsIncentivesEstimateDto) LoadDto(orderGood *domain.OrderGood, orderNumber string, originalOrderNum string, customerName string, regionName string, orderDate time.Time) error {
@@ -32,6 +32,6 @@ func (dto *DividendsIncentivesEstimateDto) LoadDto(orderGood *domain.OrderGood, @@ -32,6 +32,6 @@ func (dto *DividendsIncentivesEstimateDto) LoadDto(orderGood *domain.OrderGood,
32 dto.CustomerName = customerName 32 dto.CustomerName = customerName
33 dto.RegionName = regionName 33 dto.RegionName = regionName
34 dto.OrderAmount = orderGood.OrderGoodAmount 34 dto.OrderAmount = orderGood.OrderGoodAmount
35 - dto.OrderDate = orderDate.String() 35 + dto.OrderDate = orderDate
36 return nil 36 return nil
37 } 37 }
@@ -35,10 +35,28 @@ func (dao *CooperationContractDao) GenerateContractNumber() (string, error) { @@ -35,10 +35,28 @@ func (dao *CooperationContractDao) GenerateContractNumber() (string, error) {
35 } 35 }
36 } 36 }
37 37
38 -// CheckUndertakerTypesUncheckedAvailable TODO 校验合约承接对象是否可以删除  
39 -func (dao *CooperationContractDao) CheckUndertakerTypesUncheckedAvailable(queryOptions map[string]interface{}) ([]int32, error) {  
40 -  
41 - return []int32{}, nil 38 +// CheckUndertakerTypesUncheckedAvailable 校验合约承接对象是否可以删除
  39 +func (dao *CooperationContractDao) CheckUndertakerTypesUncheckedAvailable(queryOptions map[string]interface{}) (bool, error) {
  40 + tx := dao.transactionContext.PgTx
  41 + var cooperationContractUndertakerModels []*models.CooperationContractUndertaker
  42 + query := tx.Model(&cooperationContractUndertakerModels)
  43 + if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
  44 + query = query.Where("cooperation_contract_number = ?", cooperationContractNumber)
  45 + }
  46 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  47 + query = query.Where(`cooperation_contract.company @> '{"companyId":"?"}'`, companyId)
  48 + }
  49 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  50 + query = query.Where(`cooperation_contract.org @> '{"orgId":"?"}'`, orgId)
  51 + }
  52 + if user, ok := queryOptions["user"]; ok && user.(bool) != false {
  53 + query = query.Where("user_type = ?", 1)
  54 + }
  55 + if partner, ok := queryOptions["partner"]; ok && partner.(bool) != false {
  56 + query = query.Where("user_type = ?", 2)
  57 + }
  58 + ok, err := query.Exists()
  59 + return !ok, err
42 } 60 }
43 61
44 // CheckContractNumberAvailable 检验合约编号唯一性 62 // CheckContractNumberAvailable 检验合约编号唯一性
@@ -150,6 +150,9 @@ func (repository *CooperationModeRepository) FindOne(queryOptions map[string]int @@ -150,6 +150,9 @@ func (repository *CooperationModeRepository) FindOne(queryOptions map[string]int
150 cooperationModeModel := new(models.CooperationMode) 150 cooperationModeModel := new(models.CooperationMode)
151 query := sqlbuilder.BuildQuery(tx.Model(cooperationModeModel), queryOptions) 151 query := sqlbuilder.BuildQuery(tx.Model(cooperationModeModel), queryOptions)
152 query.SetWhereByQueryOption("cooperation_mode.cooperation_mode_id = ?", "cooperationModeId") 152 query.SetWhereByQueryOption("cooperation_mode.cooperation_mode_id = ?", "cooperationModeId")
  153 + if cooperationModeNumber, ok := queryOptions["cooperationModeNumber"]; ok && cooperationModeNumber != "" {
  154 + query.Where("cooperation_mode_number = ?", cooperationModeNumber)
  155 + }
153 if err := query.First(); err != nil { 156 if err := query.First(); err != nil {
154 if err.Error() == "pg: no rows in result set" { 157 if err.Error() == "pg: no rows in result set" {
155 return nil, fmt.Errorf("没有此资源") 158 return nil, fmt.Errorf("没有此资源")
@@ -272,7 +272,7 @@ func (repository *DividendsReturnedOrderRepository) Remove(dividendsReturnedOrde @@ -272,7 +272,7 @@ func (repository *DividendsReturnedOrderRepository) Remove(dividendsReturnedOrde
272 } else { 272 } else {
273 // 删除分红退货单产品 273 // 删除分红退货单产品
274 var orderGoodModels []*models.OrderGood 274 var orderGoodModels []*models.OrderGood
275 - if _, err := tx.Model(&orderGoodModels).Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsOrderNumber).Delete(); err != nil { 275 + if _, err := tx.Model(&orderGoodModels).Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Delete(); err != nil {
276 return nil, err 276 return nil, err
277 } 277 }
278 } 278 }