作者 陈志颖

fix:合约增加激励类型查询,分红订单增加合约激励类型校验

... ... @@ -17,6 +17,8 @@ type SearchCooperationContractQuery struct {
CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber,omitempty"`
// 发起人姓名
SponsorName string `cname:"发起人姓名" json:"sponsorName,omitempty"`
// 激励类型
IncentivesType int32 `cname:"激励类型" json:"incentivesType,omitempty"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId"`
// 组织机构ID
... ... @@ -30,7 +32,6 @@ type SearchCooperationContractQuery struct {
}
func (searchCooperationContractQuery *SearchCooperationContractQuery) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (searchCooperationContractQuery *SearchCooperationContractQuery) ValidateQuery() error {
... ...
... ... @@ -126,7 +126,9 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
}
// 生成共创合约编号
contractNumber, err2 := cooperationContractDao.GenerateContractNumber()
contractNumber, err2 := cooperationContractDao.GenerateContractNumber(map[string]interface{}{
"companyId": createCooperationContractCommand.CompanyId,
})
if err2 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err2.Error())
}
... ... @@ -134,7 +136,6 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
// 校验共创合约编号是否唯一
numberAvailable, _ := cooperationContractDao.CheckContractNumberAvailable(map[string]interface{}{
"companyId": createCooperationContractCommand.CompanyId,
"orgId": createCooperationContractCommand.OrgId,
"cooperationContractNumber": contractNumber,
})
if !numberAvailable {
... ...
... ... @@ -163,7 +163,9 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
cooperationProjectDao = value
}
// 生成共创项目编号
projectNumber, err2 := cooperationProjectDao.GenerateProjectNumber()
projectNumber, err2 := cooperationProjectDao.GenerateProjectNumber(map[string]interface{}{
"companyId": createCooperationProjectCommand.CompanyId,
})
if err2 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -158,7 +158,9 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred
}
// 生成账期结算单号
creditAccountNumber, err12 := creditAccountDao.GenerateCreditAccountNumber()
creditAccountNumber, err12 := creditAccountDao.GenerateCreditAccountNumber(map[string]interface{}{
"companyId": createCreditAccountCommand.CompanyId,
})
if err12 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "生成账期结算单号错误")
}
... ...
... ... @@ -625,7 +625,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
// 统计当前分红预算单数
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
"orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -697,7 +696,9 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
} else {
for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
// 生成分红预算单号
dividendsEstimateOrderNumber, err := dividendsEstimateDao.GenerateDividendsEstimateNumber()
dividendsEstimateOrderNumber, err := dividendsEstimateDao.GenerateDividendsEstimateNumber(map[string]interface{}{
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -859,7 +860,9 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
} else {
for _, dividendsEstimateDetail := range dividendsEstimateDetails {
// 生成分红预算单号
dividendsEstimateOrderNumber, err := dividendsEstimateDao.GenerateDividendsEstimateNumber()
dividendsEstimateOrderNumber, err := dividendsEstimateDao.GenerateDividendsEstimateNumber(map[string]interface{}{
"companyId": confirmMoneyIncentivesEstimateCommand.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
... ... @@ -100,7 +100,9 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
}
// 生成分红订单号
dividendsOrderNumber, err := dividendsOrderDao.GenerateDividendsOrderNumber()
dividendsOrderNumber, err := dividendsOrderDao.GenerateDividendsOrderNumber(map[string]interface{}{
"companyId": createDividendsOrderCommand.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -108,7 +110,6 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
// 校验分红订单编号是否唯一
numberAvailable, err := dividendsOrderDao.CheckDividendsOrderNumberAvailable(map[string]interface{}{
"companyId": createDividendsOrderCommand.CompanyId,
"orgId": createDividendsOrderCommand.OrgId,
"dividendsOrderNumber": dividendsOrderNumber,
})
if err != nil {
... ... @@ -118,11 +119,44 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常")
}
// 合约仓储初始化
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
// 查找合约
var cooperationContractsMap map[string]*domain.CooperationContract
if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"companyId": createDividendsOrderCommand.CompanyId,
"orgId": createDividendsOrderCommand.OrgId,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
for _, cooperationContract := range cooperationContracts {
cooperationContractsMap[cooperationContract.CooperationContractNumber] = cooperationContract
}
}
}
// 新增订单产品
var orderGoods []*domain.OrderGood
var dividendsOrderAmount float64
for _, orderGood := range createDividendsOrderCommand.OrderGoods {
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Float64()
// 计算订单产品金额
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
// 校验共创合约
if orderGood.CooperationContractNumber != "" {
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单产品不能关联金额激励规则")
}
}
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: 0,
OrderGoodAmount: orderGoodAmount,
... ... @@ -141,7 +175,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(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense))).Float64()
}
// 订单时间转换
... ... @@ -269,13 +303,20 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
}
// 查找合约
_, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
var cooperationContractsMap map[string]*domain.CooperationContract
countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"offsetLimit": false,
"companyId": importDividendsOrderCommand.CompanyId,
"orgId": importDividendsOrderCommand.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if countContracts > 0 {
for _, cooperationContract := range cooperationContracts {
cooperationContractsMap[cooperationContract.CooperationContractNumber] = cooperationContract
}
}
}
// 分红订单DAO初始化
... ... @@ -673,7 +714,14 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
}
// 计算产品金额
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Float64()
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
// 校验共创合约激励类型是否正确
if orderGood.CooperationContractNumber != "" {
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则")
}
}
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: 0,
... ...
... ... @@ -24,6 +24,8 @@ type OrderGoods struct {
CooperationContractNumber string `cname:"关联的共创合约编号" json:"cooperationContractNumber"`
// 订单产品费用
OrderGoodExpense float64 `cname:"订单产品费用" json:"orderGoodExpense"`
//行号-错误信息返回
LineNumber int `json:"lineNumber"`
}
type CreateDividendsReturnedOrderCommand struct {
... ...
... ... @@ -99,7 +99,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
}
// 生成分红订单号
dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber()
dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber(map[string]interface{}{
"companyId": createDividendsReturnedOrderCommand.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -121,7 +123,6 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
// 校验分红退货单编号是否唯一
numberAvailable, err := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{
"companyId": createDividendsReturnedOrderCommand.CompanyId,
"orgId": createDividendsReturnedOrderCommand.OrgId,
"dividendsReturnedOrderNumber": dividendsReturnedOrderNumber,
})
if err != nil {
... ... @@ -131,13 +132,46 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单号已存在")
}
// 合约仓储初始化
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
// 查找合约
var cooperationContractsMap map[string]*domain.CooperationContract
if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"companyId": createDividendsReturnedOrderCommand.CompanyId,
"orgId": createDividendsReturnedOrderCommand.OrgId,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
for _, cooperationContract := range cooperationContracts {
cooperationContractsMap[cooperationContract.CooperationContractNumber] = cooperationContract
}
}
}
// 退货金额
var dividendsReturnedOrderRefund float64
// 获取分红退货单产品
// 新增分红退货单产品
var orderGoods []*domain.OrderGood
for _, orderGood := range createDividendsReturnedOrderCommand.OrderGoods {
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Float64()
// 退货产品金额计算
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
// 校验合约激励类型是否正确
if orderGood.CooperationContractNumber != "" {
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则")
}
}
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: 0,
OrderGoodAmount: orderGoodAmount,
... ... @@ -321,6 +355,33 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
dividendsReturnedOrderRepository = value
}
// 合约仓储初始化
var cooperationContractRepository domain.CooperationContractRepository
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationContractRepository = value
}
// 查找合约
var cooperationContractsMap map[string]*domain.CooperationContract
countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
"offsetLimit": false,
"companyId": importDividendsReturnedOrderCommand.CompanyId,
"orgId": importDividendsReturnedOrderCommand.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if countContracts > 0 {
for _, cooperationContract := range cooperationContracts {
cooperationContractsMap[cooperationContract.CooperationContractNumber] = cooperationContract
}
}
}
// 返回信息表头定义
var tableHeader = map[string]interface{}{
"failReason": "错误详情",
... ... @@ -664,7 +725,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
// 批量导入创建退货单
for _, dividendsReturnedOrder := range createDividendsReturnedOrderCommands {
// 生成退货订单号
dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber()
dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber(map[string]interface{}{
"companyId": importDividendsReturnedOrderCommand.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ... @@ -672,7 +735,6 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
// 校验退货订单编号是否唯一
numberAvailable, err3 := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{
"companyId": importDividendsReturnedOrderCommand.CompanyId,
"orgId": importDividendsReturnedOrderCommand.OrgId,
"dividendsReturnedOrderNumber": dividendsReturnedOrderNumber,
})
if err3 != nil {
... ... @@ -685,10 +747,32 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide
// 新增订单产品
var orderGoods []*domain.OrderGood
var dividendsReturnedOrderAmount float64
for _, orderGood := range dividendsReturnedOrder.OrderGoods {
orderGoodErrMap := make(map[int]interface{}, 0)
for i, orderGood := range dividendsReturnedOrder.OrderGoods {
// 校验共创合约是否合法
contractNumberExist := false
for _, cooperationContract := range cooperationContracts {
if orderGood.CooperationContractNumber == cooperationContract.CooperationContractNumber {
contractNumberExist = true
break
}
}
if !contractNumberExist {
orderGoodErrMap[dividendsReturnedOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("共创合约编号不存在:%s", err))
}
// 计算产品金额
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
// 校验合约激励类型是否正确
if orderGood.CooperationContractNumber != "" {
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
orderGoodErrMap[dividendsReturnedOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则")
}
}
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: 0,
OrderGoodAmount: orderGood.OrderGoodAmount,
OrderGoodAmount: orderGoodAmount,
OrderGoodName: orderGood.OrderGoodName,
OrderGoodPrice: orderGood.OrderGoodPrice,
OrderGoodQuantity: orderGood.OrderGoodQuantity,
... ...
... ... @@ -13,7 +13,7 @@ type CooperationContractDao struct {
}
// GenerateContractNumber 生成共创合约编号
func (dao *CooperationContractDao) GenerateContractNumber() (string, error) {
func (dao *CooperationContractDao) GenerateContractNumber(queryOptions map[string]interface{}) (string, error) {
tx := dao.transactionContext.PgTx
var cooperationContractModels []*models.CooperationContract
query := tx.Model(&cooperationContractModels)
... ... @@ -22,16 +22,30 @@ func (dao *CooperationContractDao) GenerateContractNumber() (string, error) {
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("cooperation_contract.created_at >= ?", todayZeroTime)
query.Where("cooperation_contract.created_at < ?", nextDayZeroTime)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`cooperation_contract.company @> '{"companyId":"?"}'`, companyId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
contractNumber := "HY" + timeString + "#" + countStr
return contractNumber, nil
if count < 1000 {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
contractNumber := "HY" + timeString + "#" + countStr
return contractNumber, nil
} else {
countStr := fmt.Sprintf("%d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsOrderNumber := "HY" + timeString + "#" + countStr
return dividendsOrderNumber, nil
}
}
}
... ...
... ... @@ -13,7 +13,7 @@ type CooperationProjectDao struct {
}
// GenerateProjectNumber 生成共创项目编码
func (dao *CooperationProjectDao) GenerateProjectNumber() (string, error) {
func (dao *CooperationProjectDao) GenerateProjectNumber(queryOptions map[string]interface{}) (string, error) {
tx := dao.transactionContext.PgTx
var cooperationProjectModels []*models.CooperationProject
query := tx.Model(&cooperationProjectModels)
... ... @@ -22,16 +22,29 @@ func (dao *CooperationProjectDao) GenerateProjectNumber() (string, error) {
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("cooperation_project.created_at >= ?", todayZeroTime)
query.Where("cooperation_project.created_at < ?", nextDayZeroTime)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`cooperation_contract.company @> '{"companyId":"?"}'`, companyId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
contractNumber := "XM" + timeString + "#" + countStr
return contractNumber, nil
if count < 1000 {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
contractNumber := "XM" + timeString + "#" + countStr
return contractNumber, nil
} else {
countStr := fmt.Sprintf("%d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
contractNumber := "XM" + timeString + "#" + countStr
return contractNumber, nil
}
}
}
... ...
... ... @@ -13,7 +13,7 @@ type CreditAccountDao struct {
}
// GenerateCreditAccountNumber 生成账期结算单号
func (dao *CreditAccountDao) GenerateCreditAccountNumber() (string, error) {
func (dao *CreditAccountDao) GenerateCreditAccountNumber(queryOptions map[string]interface{}) (string, error) {
tx := dao.transactionContext.PgTx
var creditAccountModels []*models.CreditAccount
query := tx.Model(&creditAccountModels)
... ... @@ -22,16 +22,29 @@ func (dao *CreditAccountDao) GenerateCreditAccountNumber() (string, error) {
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("credit_account.created_at >= ?", todayZeroTime)
query.Where("credit_account.created_at < ?", nextDayZeroTime)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`credit_account.company @> '{"companyId":"?"}'`, companyId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
creditAccountNumber := "JS" + timeString + "#" + countStr
return creditAccountNumber, nil
if count < 1000 {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
creditAccountNumber := "JS" + timeString + "#" + countStr
return creditAccountNumber, nil
} else {
countStr := fmt.Sprintf("%d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
creditAccountNumber := "JS" + timeString + "#" + countStr
return creditAccountNumber, nil
}
}
}
... ...
... ... @@ -13,7 +13,7 @@ type DividendsEstimateDao struct {
}
// GenerateDividendsEstimateNumber 生成分红预算单号
func (dao *DividendsEstimateDao) GenerateDividendsEstimateNumber() (string, error) {
func (dao *DividendsEstimateDao) GenerateDividendsEstimateNumber(queryOptions map[string]interface{}) (string, error) {
tx := dao.transactionContext.PgTx
var dividendsEstimateModels []*models.DividendsEstimate
query := tx.Model(&dividendsEstimateModels)
... ... @@ -22,16 +22,30 @@ func (dao *DividendsEstimateDao) GenerateDividendsEstimateNumber() (string, erro
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("dividends_estimate.created_at >= ?", todayZeroTime)
query.Where("dividends_estimate.created_at < ?", nextDayZeroTime)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsOrderNumber := "FH" + timeString + "#" + countStr
return dividendsOrderNumber, nil
if count < 1000 {
countStr := fmt.Sprintf("%03d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsOrderNumber := "FH" + timeString + "#" + countStr
return dividendsOrderNumber, nil
} else {
countStr := fmt.Sprintf("%d", count+1)
timestamp := currentTime.Unix()
timeNow := time.Unix(timestamp, 0)
timeString := timeNow.Format("20060102")
timeString = timeString[2:len(timeString)]
dividendsOrderNumber := "FH" + timeString + "#" + countStr
return dividendsOrderNumber, nil
}
}
}
... ...
... ... @@ -13,7 +13,7 @@ type DividendsOrderDao struct {
}
// GenerateDividendsOrderNumber 生成分红订单号
func (dao *DividendsOrderDao) GenerateDividendsOrderNumber() (string, error) {
func (dao *DividendsOrderDao) GenerateDividendsOrderNumber(queryOptions map[string]interface{}) (string, error) {
tx := dao.transactionContext.PgTx
var dividendsOrderModels []*models.DividendsOrder
query := tx.Model(&dividendsOrderModels)
... ... @@ -22,6 +22,9 @@ func (dao *DividendsOrderDao) GenerateDividendsOrderNumber() (string, error) {
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("dividends_order.created_at >= ?", todayZeroTime)
query.Where("dividends_order.created_at < ?", nextDayZeroTime)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_order.company @> '{"companyId":"?"}'`, companyId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
... ...
... ... @@ -13,7 +13,7 @@ type DividendsReturnedOrderDao struct {
}
// GenerateDividendsReturnedOrderNumber 生成分红退货单号
func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber() (string, error) {
func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber(queryOptions map[string]interface{}) (string, error) {
tx := dao.transactionContext.PgTx
var dividendsReturnedOrderModels []*models.DividendsReturnedOrder
query := tx.Model(&dividendsReturnedOrderModels)
... ... @@ -22,6 +22,9 @@ func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber() (st
nextDayZeroTime := utils.GetNextDayZeroTime(currentTime)
query.Where("dividends_returned_order.created_at >= ?", todayZeroTime)
query.Where("dividends_returned_order.created_at < ?", nextDayZeroTime)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_returned_order.company @> '{"companyId":"?"}'`, companyId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
} else {
... ...
... ... @@ -1159,6 +1159,9 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in
if cooperationContractNumbers, ok := queryOptions["cooperationContractNumbers"]; ok && len(cooperationContractNumbers.([]string)) != 0 {
query.Where("cooperation_contract_number in (?)", pg.In(cooperationContractNumbers))
}
if incentivesType, ok := queryOptions["incentivesType"]; ok && incentivesType.(int32) != 0 {
query.Where("incentives_type = ?", incentivesType)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
... ...