作者 yangfu

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

…ion-cooperation into dev
正在显示 32 个修改的文件 包含 460 行增加207 行删除
... ... @@ -14,11 +14,11 @@ type ApplyForCooperationCommand struct {
// 共创申请描述
CooperationApplicationDescription string `cname:"共创申请描述" json:"cooperationApplicationDescription,omitempty"`
// 申请人ID
UserId int64 `cname:"申请人ID" json:"userId" valid:"Required"`
UserId int64 `cname:"申请人ID" json:"userId"`
// 用户基本id
UserBaseId int64 `cname:"用户基本数据ID" json:"userBaseId" valid:"Required"`
UserBaseId int64 `cname:"用户基本数据ID" json:"userBaseId"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId" valid:"Required"`
OrgId int64 `cname:"组织机构ID" json:"orgId"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId"`
// 共创项目ID
... ...
... ... @@ -10,6 +10,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"strconv"
"time"
... ... @@ -53,14 +54,6 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
userService = value
}
// 获取申请人
var applicant *domain.User
if data, err := userService.UserFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId, applyForCooperationCommand.UserId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取申请人失败")
} else {
applicant = data
}
// 公司REST服务初始化
var companyService service.CompanyService
if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
... ... @@ -69,14 +62,6 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
companyService = value
}
// 获取公司信息
var company *domain.Company
if data, err := companyService.CompanyFrom(applyForCooperationCommand.CompanyId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司信息失败")
} else {
company = data
}
// 组织机构REST服务初始化
var organizationService service.OrgService
if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {
... ... @@ -85,12 +70,24 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
organizationService = value
}
// 获取组织机构信息
var organization *domain.Org
if data, err := organizationService.OrgFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取组织机构数据失败")
// 共创申请仓储初始化
var cooperationApplicationRepository domain.CooperationApplicationRepository
if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
organization = data
cooperationApplicationRepository = value
}
// 共创申请DAO初始化
var cooperationApplicationDao *dao.CooperationApplicationDao
if value, err := factory.CreateCooperationApplicationDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
cooperationApplicationDao = value
}
// 获取共创项目
... ... @@ -102,36 +99,95 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(applyForCooperationCommand.CooperationProjectId, 10)))
}
// TODO 校验:同一个用户,不能多次申请同一个项目
var newCooperationApplication *domain.CooperationApplication
if applyForCooperationCommand.CompanyId == 0 && applyForCooperationCommand.OrgId == 0 && applyForCooperationCommand.UserId == 0 { // 游客操作
// TODO 获取申请人信息
// TODO 校验:同一个用户,不能多次申请同一个项目
// TODO 校验:判断用户类型是否属于承接对象
//if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
//}
newCooperationApplication = &domain.CooperationApplication{
CooperationApplicationApplicant: nil, // TODO 获取游客(申请人)信息
CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment,
CooperationApplicationDescription: applyForCooperationCommand.CooperationApplicationDescription,
CooperationApplicationStatus: 1,
CooperationApplicationVerifier: nil,
CooperationApplicationVerifyDescription: "",
CooperationApplicationVerifyTime: time.Time{},
CooperationApplyTime: time.Now(),
CooperationProject: cooperationProject,
Org: cooperationProject.Org,
IsCanceled: 1,
Company: cooperationProject.Company,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
}
} else {
// 获取申请人
var applicant *domain.User
if data, err := userService.UserFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId, applyForCooperationCommand.UserId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取申请人失败")
} else {
applicant = data
}
// TODO 校验:判断用户类型是否属于承接对象
// 获取公司信息
var company *domain.Company
if data, err := companyService.CompanyFrom(applyForCooperationCommand.CompanyId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司信息失败")
} else {
company = data
}
newCooperationApplication := &domain.CooperationApplication{
CooperationApplicationApplicant: applicant,
CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment,
CooperationApplicationDescription: applyForCooperationCommand.CooperationApplicationDescription,
CooperationApplicationStatus: 1,
CooperationApplicationVerifier: nil,
CooperationApplicationVerifyDescription: "",
CooperationApplicationVerifyTime: time.Time{},
CooperationApplyTime: time.Now(),
CooperationProject: cooperationProject,
Org: organization,
IsCanceled: 1,
Company: company,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
}
// 获取组织机构信息
var organization *domain.Org
if data, err := organizationService.OrgFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取组织机构数据失败")
} else {
organization = data
}
var cooperationApplicationRepository domain.CooperationApplicationRepository
if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationApplicationRepository = value
// 校验:同一个用户,不能多次申请同一个项目
applicationExist, _ := cooperationApplicationDao.CheckApplicationExist(map[string]interface{}{
"companyId": applyForCooperationCommand.CompanyId,
"orgId": applyForCooperationCommand.OrgId,
"cooperationApplicationId": cooperationProject.CooperationProjectId,
})
if applicationExist {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "抱歉,您已经申请过该项目")
}
// 校验:判断用户类型是否属于承接对象
if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
}
newCooperationApplication = &domain.CooperationApplication{
CooperationApplicationApplicant: applicant,
CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment,
CooperationApplicationDescription: applyForCooperationCommand.CooperationApplicationDescription,
CooperationApplicationStatus: 1,
CooperationApplicationVerifier: nil,
CooperationApplicationVerifyDescription: "",
CooperationApplicationVerifyTime: time.Time{},
CooperationApplyTime: time.Now(),
CooperationProject: cooperationProject,
Org: organization,
IsCanceled: 1,
Company: company,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
}
}
// 保存共创申请
if cooperationApplication, err := cooperationApplicationRepository.Save(newCooperationApplication); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -2,6 +2,9 @@ package service
import (
"fmt"
"strconv"
"time"
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationContract/command"
... ... @@ -13,8 +16,6 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
"strconv"
"time"
)
// CooperationContractService 共创合约服务
... ... @@ -269,7 +270,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
MoneyIncentivesStage: moneyIncentivesRule.MoneyIncentivesStage,
MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd,
MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart,
MoneyIncentivesTime: time.Now(),
MoneyIncentivesTime: moneyIncentivesRule.MoneyIncentivesTime,
ReferrerPercentage: moneyIncentivesRule.ReferrerPercentage,
SalesmanPercentage: moneyIncentivesRule.SalesmanPercentage,
Org: organization,
... ... @@ -828,7 +829,7 @@ func (cooperationContractService *CooperationContractService) SearchCooperationC
if count, cooperationContractByUndertakers, err := cooperationContractDao.SearchCooperationContractByUndertaker(tool_funs.SimpleStructToMap(searchCooperationContractByUndertakerQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
var cooperationContractByUndertakerDtos []*dto.CooperationContractByUndertakerDto
cooperationContractByUndertakerDtos := []*dto.CooperationContractByUndertakerDto{}
for _, cooperationContractByUndertaker := range cooperationContractByUndertakers {
cooperationContractByUndertakerDto := &dto.CooperationContractByUndertakerDto{}
if err := cooperationContractByUndertakerDto.LoadDto(cooperationContractByUndertaker); err != nil {
... ...
... ... @@ -75,12 +75,16 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive
for _, orderGood := range orderGoods {
dividendsIncentivesEstimateDto := &dto.DividendsIncentivesEstimateDto{}
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber})
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dividendsOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
}
if err := dividendsIncentivesEstimateDto.LoadDto(orderGood, dividendsOrder.DividendsOrderNumber, dividendsOrder.DividendsOriginalOrderNum, dividendsOrder.CustomerName, dividendsOrder.Region.RegionName, dividendsOrder.OrderTime); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -92,7 +96,7 @@ func (dividendsEstimateService *DividendsEstimateService) ListDividendsIncentive
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dividendsReturnedOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红退货单%s不存在", orderGood.DividendsReturnedOrderNumber))
}
if err := dividendsIncentivesEstimateDto.LoadDto(orderGood, dividendsReturnedOrder.DividendsReturnedOrderNumber, dividendsReturnedOrder.OriginalOrderNum, dividendsReturnedOrder.DividendsReturnedCustomerName, dividendsReturnedOrder.Region.RegionName, dividendsReturnedOrder.OrderTime); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -615,12 +619,16 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
for _, orderGood := range orderGoods {
dividendsEstimate := &domain.DividendsEstimate{}
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber})
dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err3 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
}
if dividendsOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
}
// 分红订单产品预算
if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
... ... @@ -665,7 +673,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dividendsReturnedOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红退货单%s不存在", orderGood.DividendsReturnedOrderNumber))
}
// 分红退货单产品预算
if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
... ... @@ -1098,7 +1106,11 @@ func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncenti
for _, orderGood := range orderGoods {
dividendsIncentivesEstimateDto := &dto.DividendsIncentivesEstimateDto{}
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber})
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -18,7 +18,7 @@ type OrderGoods struct {
// 订单产品单价
OrderGoodPrice float64 `json:"orderGoodPrice"`
// 订单产品数量
OrderGoodQuantity int64 `json:"orderGoodQuantity"`
OrderGoodQuantity float64 `json:"orderGoodQuantity"`
// 关联分红订单号
DividendsOrderNumber string `json:"dividendsOrderNumber"`
// 关联的共创合约编号
... ...
... ... @@ -141,7 +141,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
UpdatedAt: time.Time{},
})
// 计算分红订单金额
dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense)))).Float64()
dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense))).Float64()
}
// 订单时间转换
... ... @@ -488,7 +488,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
}
// 产品相关:产品名称,产品数量、产品价格、费用
quantity, err := strconv.ParseInt(dividendsOrder.OrderGoodQuantity, 10, 64)
quantity, err := strconv.ParseFloat(dividendsOrder.OrderGoodQuantity, 64)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -533,7 +533,7 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
}
} else { // 聚合同一笔订单产品
// 产品相关:产品名称,产品数量、产品价格、费用
quantity, err := strconv.ParseInt(dividendsOrder.OrderGoodQuantity, 10, 64)
quantity, err := strconv.ParseFloat(dividendsOrder.OrderGoodQuantity, 64)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -1096,6 +1096,7 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD
DividendsReturnedOrderNumber: "",
CooperationContractNumber: orderGood.CooperationContractNumber,
OrderGoodExpense: orderGood.OrderGoodExpense,
OrderGoodDividendsStatus: 0,
OrgId: updateDividendsOrderCommand.OrgId,
CompanyId: updateDividendsOrderCommand.CompanyId,
CreatedAt: time.Time{},
... ...
... ... @@ -17,7 +17,7 @@ type OrderGoods struct {
// 订单产品单价
OrderGoodPrice float64 `cname:"订单产品单价" json:"orderGoodPrice"`
// 订单产品数量
OrderGoodQuantity int64 `cname:"订单产品数量" json:"orderGoodQuantity"`
OrderGoodQuantity float64 `cname:"订单产品数量" json:"orderGoodQuantity"`
// 关联分红订单号
DividendsOrderNumber string `cname:"关联分红订单号" json:"dividendsOrderNumber"`
// 关联的共创合约编号
... ...
... ... @@ -10,14 +10,14 @@ import (
type UpdateDividendsReturnedOrderCommand struct {
// 分红退货单记录ID
DividendsReturnedOrderId string `cname:"分红退货单记录ID" json:"dividendsReturnedOrderId" valid:"Required"`
// 退货金额
DividendsReturnedOrderRefund float64 `cname:"退货金额" json:"dividendsReturnedOrderRefund" valid:"Required"`
// 退货客户名称
DividendsReturnedCustomerName string `cname:"退货客户名称" json:"dividendsReturnedCustomerName" valid:"Required"`
// 来源单号,源单号,订单号
OriginalOrderNum string `cname:"来源单号" json:"originalOrderNum" valid:"Required"`
// 分红单号
DividendsOrderNumber string `cname:"订单号" json:"dividendsOrderNumber"`
// 备注
Remarks string `cname:"备注" json:"remarks" valid:"Required"`
Remarks string `cname:"备注" json:"remarks"`
// 退货日期
DividendsReturnedDate string `cname:"退货日期" json:"dividendsReturnedDate" valid:"Required"`
// 退货区域
... ...
... ... @@ -524,7 +524,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
}
// 产品相关:产品名称,退货数量、退货价格
quantity, err := strconv.ParseInt(dividendsReturnedOrder.OrderGoodQuantity, 10, 64)
quantity, err := strconv.ParseFloat(dividendsReturnedOrder.OrderGoodQuantity, 64)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ... @@ -562,7 +562,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
}
} else { // 聚合同一笔订单产品
// 产品相关:产品名称,退货数量、退货价格
quantity, err := strconv.ParseInt(dividendsReturnedOrder.OrderGoodQuantity, 10, 64)
quantity, err := strconv.ParseFloat(dividendsReturnedOrder.OrderGoodQuantity, 64)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
... ...
... ... @@ -60,3 +60,11 @@ func CreateDividendsEstimateDao(options map[string]interface{}) (*dao.DividendsE
}
return dao.NewDividendsEstimateDao(transactionContext)
}
func CreateCooperationApplicationDao(options map[string]interface{}) (*dao.CooperationApplicationDao, error) {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return dao.NewCooperationApplicationDao(transactionContext)
}
... ...
... ... @@ -18,7 +18,7 @@ type OrderGood struct {
// 订单产品单价
OrderGoodPrice float64 `json:"orderGoodPrice"`
// 订单产品数量
OrderGoodQuantity int64 `json:"orderGoodQuantity,string"`
OrderGoodQuantity float64 `json:"orderGoodQuantity,string"`
// 关联分红订单号
DividendsOrderNumber string `json:"dividendsOrderNumber"`
// 关联的分红退货单号
... ... @@ -66,7 +66,7 @@ func (orderGood *OrderGood) Update(data map[string]interface{}) error {
orderGood.OrderGoodPrice = orderGoodPrice.(float64)
}
if orderGoodQuantity, ok := data["orderGoodQuantity"]; ok {
orderGood.OrderGoodQuantity = orderGoodQuantity.(int64)
orderGood.OrderGoodQuantity = orderGoodQuantity.(float64)
}
if cooperationContractNumber, ok := data["cooperationContractNumber"]; ok {
orderGood.CooperationContractNumber = cooperationContractNumber.(string)
... ...
... ... @@ -31,3 +31,10 @@ type Relevant struct {
// 公司
Company *Company `json:"company"`
}
func (relevant *Relevant) Identify() interface{} {
if relevant.RelevantId == 0 {
return nil
}
return relevant.RelevantId
}
... ...
... ... @@ -37,3 +37,10 @@ type Undertaker struct {
// 合同附件
ContractAttachment []*Attachment `json:"contractAttachment"`
}
func (undertaker *Undertaker) Identify() interface{} {
if undertaker.UndertakerId == 0 {
return nil
}
return undertaker.UndertakerId
}
... ...
package dao
import (
"fmt"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
type CooperationApplicationDao struct {
transactionContext *pgTransaction.TransactionContext
}
// CheckApplicationExist 判断该申请人是否提交过申请
func (dao *CooperationApplicationDao) CheckApplicationExist(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
var cooperationApplicationModels []*models.CooperationApplication
query := tx.Model(&cooperationApplicationModels)
if cooperationApplicationId, ok := queryOptions["cooperationApplicationId"]; ok && cooperationApplicationId != "" {
query = query.Where("cooperation_application_id = ?", cooperationApplicationId)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`cooperation_application.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`cooperation_application.org @> '{"orgId":"?"}'`, orgId)
}
if applicantId, ok := queryOptions["applicantId"]; ok && applicantId.(int64) != 0 {
query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userId":"?"}'`, applicantId)
}
if applicantBaseId, ok := queryOptions["applicantBaseId"]; ok && applicantBaseId.(int64) != 0 {
query = query.Where(`cooperation_application.cooperation_application_applicant @>'{"userBaseId":"?"}'`, applicantBaseId)
}
ok, err := query.Exists()
return ok, err
}
func NewCooperationApplicationDao(transactionContext *pgTransaction.TransactionContext) (*CooperationApplicationDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CooperationApplicationDao{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -47,18 +47,20 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创合约不存在")
}
if cooperationContract == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.CooperationContractNumber))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber))
}
if orderGood.DividendsOrderNumber != "" {
// 获取分红订单
dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
}
if dividendsOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber))
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
}
// 匹配分红规则
var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule
... ... @@ -77,7 +79,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
for _, undertaker := range cooperationContract.Undertakers {
// 添加承接人分红预算信息详情
// TODO 使用decimal提高精度
undertakerDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage / 100
undertakerDividendsAmount := orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage / 100
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.UserId,
... ... @@ -88,7 +90,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Roles: undertaker.Roles,
UserInfo: undertaker.UserInfo,
UserType: undertaker.UserType,
UserName: undertaker.UserName,
UserName: undertaker.UserInfo.UserName,
UserPhone: undertaker.UserPhone,
Status: undertaker.Status,
Company: undertaker.Company,
... ... @@ -99,7 +101,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
})
// 添加推荐人分红预算信息详情
if undertaker.Referrer != nil {
referrerDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.ReferrerPercentage / 100
referrerDividendsAmount := orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.ReferrerPercentage / 100
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.Referrer.UserId,
... ... @@ -110,7 +112,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Roles: undertaker.Referrer.Roles,
UserInfo: undertaker.Referrer.UserInfo,
UserType: undertaker.Referrer.UserType,
UserName: undertaker.Referrer.UserName,
UserName: undertaker.Referrer.UserInfo.UserName,
UserPhone: undertaker.Referrer.UserPhone,
Company: undertaker.Referrer.Company,
},
... ... @@ -121,7 +123,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
}
// 添加关联业务员分红预算信息详情
if undertaker.Salesman != nil {
salesmanDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.SalesmanPercentage / 100
salesmanDividendsAmount := orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.SalesmanPercentage / 100
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.Salesman.UserId,
... ... @@ -132,7 +134,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Roles: undertaker.Salesman.Roles,
UserInfo: undertaker.Salesman.UserInfo,
UserType: undertaker.Salesman.UserType,
UserName: undertaker.Salesman.UserName,
UserName: undertaker.Salesman.UserInfo.UserName,
UserPhone: undertaker.Salesman.UserPhone,
Company: undertaker.Salesman.Company,
},
... ... @@ -175,7 +177,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Roles: undertaker.Roles,
UserInfo: undertaker.UserInfo,
UserType: undertaker.UserType,
UserName: undertaker.UserName,
UserName: undertaker.UserInfo.UserName,
UserPhone: undertaker.UserPhone,
Status: undertaker.Status,
Company: undertaker.Company,
... ... @@ -197,7 +199,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Roles: undertaker.Referrer.Roles,
UserInfo: undertaker.Referrer.UserInfo,
UserType: undertaker.Referrer.UserType,
UserName: undertaker.Referrer.UserName,
UserName: undertaker.Referrer.UserInfo.UserName,
UserPhone: undertaker.Referrer.UserPhone,
Company: undertaker.Referrer.Company,
},
... ... @@ -219,7 +221,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Roles: undertaker.Salesman.Roles,
UserInfo: undertaker.Salesman.UserInfo,
UserType: undertaker.Salesman.UserType,
UserName: undertaker.Salesman.UserName,
UserName: undertaker.Salesman.UserInfo.UserName,
UserPhone: undertaker.Salesman.UserPhone,
Company: undertaker.Salesman.Company,
},
... ...
... ... @@ -440,7 +440,11 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m
DividendsUser: item.DividendsUser,
}
if item.DividendsType == 1 {
order, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": item.OrderOrReturnedOrderNum})
order, err := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": item.OrderOrReturnedOrderNum,
"companyId": item.Company.CompanyId,
"orgId": item.Org.OrgId,
})
if err != nil {
return nil, err
}
... ...
... ... @@ -13,7 +13,7 @@ type OrderGood struct {
// 订单产品单价
OrderGoodPrice float64 `comment:"订单产品单价"`
// 订单产品数量
OrderGoodQuantity int64 `comment:"订单产品数量"`
OrderGoodQuantity float64 `comment:"订单产品数量"`
// 关联分红订单号
DividendsOrderNumber string `comment:"关联分红订单号"`
// 关联的分红退货单号
... ...
... ... @@ -15,14 +15,11 @@ import (
type ContractUndertakerFeedbackRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *ContractUndertakerFeedbackRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -202,8 +199,13 @@ func NewContractUndertakerFeedbackRepository(transactionContext *pgTransaction.T
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &ContractUndertakerFeedbackRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -17,14 +17,11 @@ import (
type CooperationApplicationRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CooperationApplicationRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -322,8 +319,13 @@ func NewCooperationApplicationRepository(transactionContext *pgTransaction.Trans
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CooperationApplicationRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -15,14 +15,11 @@ import (
type CooperationContractChangeLogRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CooperationContractChangeLogRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -198,8 +195,13 @@ func NewCooperationContractChangeLogRepository(transactionContext *pgTransaction
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CooperationContractChangeLogRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -15,14 +15,11 @@ import (
type CooperationContractRelevantRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CooperationContractRelevantRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -210,8 +207,13 @@ func NewCooperationContractRelevantRepository(transactionContext *pgTransaction.
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CooperationContractRelevantRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -16,14 +16,11 @@ import (
type CooperationContractRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CooperationContractRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -108,21 +105,30 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 新增相关人
var relevantPeopleModel []*models.CooperationContractRelevant
for _, relevant := range cooperationContract.RelevantPeople {
if relevant.Identify() == nil {
orderGoodId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
relevant.RelevantId = orderGoodId
}
}
relevantPeopleModel = append(relevantPeopleModel, &models.CooperationContractRelevant{
CooperationContractNumber: cooperationContract.CooperationContractNumber,
UserId: relevant.UserId,
UserBaseId: relevant.UserBaseId,
Org: relevant.Org,
Orgs: relevant.Orgs,
Department: relevant.Department,
Roles: relevant.Roles,
UserInfo: relevant.UserInfo,
UserType: relevant.UserType,
Status: relevant.Status,
Company: relevant.Company,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
CooperationContractRelevantId: relevant.RelevantId,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
UserId: relevant.UserId,
UserBaseId: relevant.UserBaseId,
Org: relevant.Org,
Orgs: relevant.Orgs,
Department: relevant.Department,
Roles: relevant.Roles,
UserInfo: relevant.UserInfo,
UserType: relevant.UserType,
Status: relevant.Status,
Company: relevant.Company,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
})
}
if len(relevantPeopleModel) > 0 {
... ... @@ -169,7 +175,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 新增分红激励规则
var dividendsIncentivesRulesModel []*models.DividendsIncentivesRule
for _, rule := range cooperationContract.DividendsIncentivesRules {
if rule.Identify() == nil {
ruleId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
rule.DividendsIncentivesRuleId = ruleId
}
}
dividendsIncentivesRulesModel = append(dividendsIncentivesRulesModel, &models.DividendsIncentivesRule{
DividendsIncentivesRuleId: rule.DividendsIncentivesRuleId,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
ReferrerPercentage: rule.ReferrerPercentage,
SalesmanPercentage: rule.SalesmanPercentage,
... ... @@ -197,7 +212,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 新增金额激励规则
var moneyIncentivesRulesModel []*models.MoneyIncentivesRule
for _, rule := range cooperationContract.MoneyIncentivesRules {
if rule.Identify() == nil {
ruleId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
rule.MoneyIncentivesRuleId = ruleId
}
}
moneyIncentivesRulesModel = append(moneyIncentivesRulesModel, &models.MoneyIncentivesRule{
MoneyIncentivesRuleId: rule.MoneyIncentivesRuleId,
CooperationContractNumber: cooperationContract.CooperationContractNumber,
MoneyIncentivesAmount: rule.MoneyIncentivesAmount,
MoneyIncentivesStage: rule.MoneyIncentivesStage,
... ... @@ -302,21 +326,30 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 将待添加的相关人领域模型转换为数据模型
var cooperationContractRelevantPeopleToAddModels []*models.CooperationContractRelevant
for _, relevantDomain := range cooperationContractRelevantPeopleToAdd {
if relevantDomain.Identify() == nil {
relevantId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
relevantDomain.RelevantId = relevantId
}
}
cooperationContractRelevantPeopleToAddModels = append(cooperationContractRelevantPeopleToAddModels, &models.CooperationContractRelevant{
CooperationContractNumber: relevantDomain.CooperationContractNumber,
UserId: relevantDomain.UserId,
UserBaseId: relevantDomain.UserBaseId,
Org: relevantDomain.Org,
Orgs: relevantDomain.Orgs,
Department: relevantDomain.Department,
Roles: relevantDomain.Roles,
UserInfo: relevantDomain.UserInfo,
UserType: relevantDomain.UserType,
Status: relevantDomain.Status,
Company: relevantDomain.Company,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
CooperationContractRelevantId: relevantDomain.RelevantId,
CooperationContractNumber: relevantDomain.CooperationContractNumber,
UserId: relevantDomain.UserId,
UserBaseId: relevantDomain.UserBaseId,
Org: relevantDomain.Org,
Orgs: relevantDomain.Orgs,
Department: relevantDomain.Department,
Roles: relevantDomain.Roles,
UserInfo: relevantDomain.UserInfo,
UserType: relevantDomain.UserType,
Status: relevantDomain.Status,
Company: relevantDomain.Company,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
})
}
... ... @@ -401,24 +434,33 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 将待添加的相关人领域模型转换为数据模型
var cooperationContractUndertakersToAddModels []*models.CooperationContractUndertaker
for _, undertakerDomain := range cooperationContractUndertakersToAdd {
if undertakerDomain.Identify() == nil {
undertakerId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
undertakerDomain.UndertakerId = undertakerId
}
}
cooperationContractUndertakersToAddModels = append(cooperationContractUndertakersToAddModels, &models.CooperationContractUndertaker{
CooperationContractNumber: undertakerDomain.CooperationContractNumber,
UserId: undertakerDomain.UserId,
UserBaseId: undertakerDomain.UserBaseId,
Org: undertakerDomain.Org,
Orgs: undertakerDomain.Orgs,
Department: undertakerDomain.Department,
Roles: undertakerDomain.Roles,
UserInfo: undertakerDomain.UserInfo,
UserType: undertakerDomain.UserType,
Referrer: undertakerDomain.Referrer,
Salesman: undertakerDomain.Salesman,
Status: undertakerDomain.Status,
Company: undertakerDomain.Company,
ContractAttachment: undertakerDomain.ContractAttachment,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
CooperationContractUndertakerId: undertakerDomain.UndertakerId,
CooperationContractNumber: undertakerDomain.CooperationContractNumber,
UserId: undertakerDomain.UserId,
UserBaseId: undertakerDomain.UserBaseId,
Org: undertakerDomain.Org,
Orgs: undertakerDomain.Orgs,
Department: undertakerDomain.Department,
Roles: undertakerDomain.Roles,
UserInfo: undertakerDomain.UserInfo,
UserType: undertakerDomain.UserType,
Referrer: undertakerDomain.Referrer,
Salesman: undertakerDomain.Salesman,
Status: undertakerDomain.Status,
Company: undertakerDomain.Company,
ContractAttachment: undertakerDomain.ContractAttachment,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
})
}
log.Logger.Info("待添加的承接人", map[string]interface{}{
... ... @@ -534,7 +576,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 将待添加的分红激励规则领域模型转换为数据模型
var dividendsIncentivesRulesToAddModels []*models.DividendsIncentivesRule
for _, dividendsIncentivesRuleDomain := range dividendsIncentivesRulesToAdd {
if dividendsIncentivesRuleDomain.Identify() == nil {
ruleId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
dividendsIncentivesRuleDomain.DividendsIncentivesRuleId = ruleId
}
}
dividendsIncentivesRulesToAddModels = append(dividendsIncentivesRulesToAddModels, &models.DividendsIncentivesRule{
DividendsIncentivesRuleId: dividendsIncentivesRuleDomain.DividendsIncentivesRuleId,
CooperationContractNumber: dividendsIncentivesRuleDomain.CooperationContractNumber,
ReferrerPercentage: dividendsIncentivesRuleDomain.ReferrerPercentage,
SalesmanPercentage: dividendsIncentivesRuleDomain.SalesmanPercentage,
... ... @@ -657,7 +708,16 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
// 将待添加的金额激励规则领域模型转换为数据模型
var moneyIncentivesRulesToAddModels []*models.MoneyIncentivesRule
for _, moneyIncentivesRuleDomain := range moneyIncentivesRulesToAdd {
if moneyIncentivesRuleDomain.Identify() == nil {
ruleId, err := repository.nextIdentify()
if err != nil {
return nil, err
} else {
moneyIncentivesRuleDomain.MoneyIncentivesRuleId = ruleId
}
}
moneyIncentivesRulesToAddModels = append(moneyIncentivesRulesToAddModels, &models.MoneyIncentivesRule{
MoneyIncentivesRuleId: moneyIncentivesRuleDomain.MoneyIncentivesRuleId,
CooperationContractNumber: moneyIncentivesRuleDomain.CooperationContractNumber,
MoneyIncentivesAmount: moneyIncentivesRuleDomain.MoneyIncentivesAmount,
MoneyIncentivesStage: moneyIncentivesRuleDomain.MoneyIncentivesStage,
... ... @@ -1175,8 +1235,13 @@ func NewCooperationContractRepository(transactionContext *pgTransaction.Transact
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CooperationContractRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -15,14 +15,11 @@ import (
type CooperationContractUndertakerRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CooperationContractUndertakerRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -225,8 +222,13 @@ func NewCooperationContractUndertakerRepository(transactionContext *pgTransactio
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CooperationContractUndertakerRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -14,14 +14,11 @@ import (
type CooperationModeRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CooperationModeRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -221,8 +218,13 @@ func NewCooperationModeRepository(transactionContext *pgTransaction.TransactionC
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CooperationModeRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -17,14 +17,11 @@ import (
type CooperationProjectRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CooperationProjectRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -317,8 +314,13 @@ func NewCooperationProjectRepository(transactionContext *pgTransaction.Transacti
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CooperationProjectRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -15,14 +15,11 @@ import (
type CreditAccountRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *CreditAccountRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -249,8 +246,13 @@ func NewCreditAccountRepository(transactionContext *pgTransaction.TransactionCon
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &CreditAccountRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -16,14 +16,11 @@ import (
type DividendsEstimateRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *DividendsEstimateRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -332,8 +329,13 @@ func NewDividendsEstimateRepository(transactionContext *pgTransaction.Transactio
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &DividendsEstimateRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -15,14 +15,11 @@ import (
type DividendsIncentivesRuleRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *DividendsIncentivesRuleRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -202,8 +199,13 @@ func NewDividendsIncentivesRuleRepository(transactionContext *pgTransaction.Tran
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &DividendsIncentivesRuleRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -122,7 +122,7 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
CompanyId: good.CompanyId,
OrgId: good.OrgId,
OrderGoodExpense: good.OrderGoodExpense,
OrderGoodDividendsStatus: good.OrderGoodDividendsStatus,
OrderGoodDividendsStatus: 1,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
... ... @@ -178,7 +178,11 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
// 更新分红订单产品
var orderGoodsFetched []*models.OrderGood
orderGoodsQuery := tx.Model(&orderGoodsFetched)
if err := orderGoodsQuery.Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Select(); err != nil {
if err := orderGoodsQuery.
Where("company_id = ?", dividendsOrder.Company.CompanyId).
Where("org_id = ?", dividendsOrder.Org.OrgId).
Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).
Select(); err != nil {
return nil, err
}
... ... @@ -190,6 +194,7 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
// 待更新分红产品
var orderGoodsToUpdate []*domain.OrderGood
// 待添加分红产品
var orderGoodsToAdd []*domain.OrderGood
for _, good := range dividendsOrder.Goods {
... ... @@ -223,17 +228,17 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
OrderGoodExpense: goodDomain.OrderGoodExpense,
OrgId: goodDomain.OrgId,
CompanyId: goodDomain.CompanyId,
OrderGoodDividendsStatus: goodDomain.OrderGoodDividendsStatus,
OrderGoodDividendsStatus: 1,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
})
}
// 添加分红订单产品
log.Logger.Info("待添加的分红订单产品", map[string]interface{}{
"orderGoodsToAddModels": orderGoodsToAddModels,
})
if len(orderGoodsToAddModels) > 0 {
log.Logger.Info("待添加的分红订单产品", map[string]interface{}{
"orderGoodsToAddModels": orderGoodsToAddModels,
})
if _, err := tx.Model(&orderGoodsToAddModels).Insert(); err != nil {
return nil, err
}
... ... @@ -262,16 +267,16 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend
if orderGood.OrderGoodId == orderGoodModelToUpdate.OrderGoodId {
orderGoodModelsToUpdate[i] = &models.OrderGood{
OrderGoodId: orderGoodModelToUpdate.OrderGoodId,
OrderGoodAmount: orderGoodModelToUpdate.OrderGoodAmount,
OrderGoodName: orderGoodModelToUpdate.OrderGoodName,
OrderGoodPrice: orderGoodModelToUpdate.OrderGoodPrice,
OrderGoodQuantity: orderGoodModelToUpdate.OrderGoodQuantity,
DividendsOrderNumber: orderGoodModelToUpdate.DividendsOrderNumber,
DividendsReturnedOrderNumber: orderGoodModelToUpdate.DividendsReturnedOrderNumber,
CooperationContractNumber: orderGoodModelToUpdate.CooperationContractNumber,
OrderGoodAmount: orderGood.OrderGoodAmount,
OrderGoodName: orderGood.OrderGoodName,
OrderGoodPrice: orderGood.OrderGoodPrice,
OrderGoodQuantity: orderGood.OrderGoodQuantity,
DividendsOrderNumber: orderGood.DividendsOrderNumber,
DividendsReturnedOrderNumber: "",
CooperationContractNumber: orderGood.CooperationContractNumber,
OrgId: orderGoodModelToUpdate.OrgId,
CompanyId: orderGoodModelToUpdate.CompanyId,
OrderGoodExpense: orderGoodModelToUpdate.OrderGoodExpense,
OrderGoodExpense: orderGood.OrderGoodExpense,
OrderGoodDividendsStatus: orderGoodModelToUpdate.OrderGoodDividendsStatus,
CreatedAt: orderGoodModelToUpdate.CreatedAt,
DeletedAt: orderGoodModelToUpdate.DeletedAt,
... ... @@ -491,6 +496,12 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte
if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" {
query.Where("dividends_order.dividends_order_number = ?", dividendsOrderNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query.Where("org->>'orgId' = '?'", orgId)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("分红订单不存在")
... ...
... ... @@ -475,7 +475,8 @@ func (repository *DividendsReturnedOrderRepository) BatchRemove(dividendsReturne
if _, err := tx.Model(&orderGoodModels).
Where("company_id = ?", dividendsReturnedOrder.Company.CompanyId).
Where("org_id = ?", dividendsReturnedOrder.Org.OrgId).
Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Delete(); err != nil {
Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).
Delete(); err != nil {
return nil, err
}
}
... ... @@ -505,7 +506,8 @@ func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[str
if err := orderGoodModelQuery.
Where("company_id = ?", dividendsReturnedOrderModel.Company.CompanyId).
Where("org_id = ?", dividendsReturnedOrderModel.Org.OrgId).
Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).Select(); err != nil {
Where("dividends_returned_order_number = ?", dividendsReturnedOrderModel.DividendsReturnedOrderNumber).
Select(); err != nil {
return nil, fmt.Errorf("分红退货单关联的产品不存在")
}
// 聚合分红退货单
... ...
... ... @@ -15,14 +15,11 @@ import (
type MoneyIncentivesRuleRepository struct {
transactionContext *pgTransaction.TransactionContext
IdWorker *snowflake.IdWorker
}
func (repository *MoneyIncentivesRuleRepository) nextIdentify() (int64, error) {
IdWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return 0, err
}
id, err := IdWorker.NextId()
id, err := repository.IdWorker.NextId()
return id, err
}
... ... @@ -202,8 +199,13 @@ func NewMoneyIncentivesRuleRepository(transactionContext *pgTransaction.Transact
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
idWorker, err := snowflake.NewIdWorker(1)
if err != nil {
return nil, err
}
return &MoneyIncentivesRuleRepository{
transactionContext: transactionContext,
IdWorker: idWorker,
}, nil
}
}
... ...
... ... @@ -125,3 +125,13 @@ func RemoveDuplication(arr []string) []string {
}
return arr[:j]
}
// IsContain 判断int32数组是否包含
func IsContain(items []int32, item int32) bool {
for _, eachItem := range items {
if eachItem == item {
return true
}
}
return false
}
... ...