作者 陈志颖

fix:分红订单

... ... @@ -653,6 +653,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
}
... ... @@ -696,6 +698,8 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
}
... ...
... ... @@ -11,6 +11,8 @@ import (
type GetDividendsOrderQuery struct {
// 分红订单ID
DividendsOrderId int64 `cname:"分红订单ID" json:"dividendsOrderId" valid:"Required"`
// 分红订单编号
DividendsOrderNumber string `cname:"分红订单编号" json:"dividendsOrderNumber,omitempty"`
// 公司ID,通过集成REST上下文获取
CompanyId int64 `cname:"公司ID" json:"companyId" valid:"Required"`
// 组织机构ID
... ...
... ... @@ -41,7 +41,7 @@ type CreateDividendsReturnedOrderCommand struct {
// 退货日期
DividendsReturnedDate time.Time `cname:"退货日期" json:"dividendsReturnedDate" valid:"Required"`
// 订单日期
OrderTime time.Time `cname:"订单日期" json:"orderTime" valid:"Required"`
OrderTime string `cname:"订单日期" json:"orderTime" valid:"Required"`
// 退货区域名称
RegionName string `cname:"退货区域名称" json:"regionName,omitempty"`
// 订单产品列表
... ...
... ... @@ -5,7 +5,6 @@ import (
"github.com/beego/beego/v2/core/validation"
"reflect"
"strings"
"time"
)
type UpdateDividendsReturnedOrderCommand struct {
... ... @@ -24,7 +23,7 @@ type UpdateDividendsReturnedOrderCommand struct {
// 退货区域
RegionName string `cname:"退货区域" json:"regionName,omitempty"`
// 订单时间
OrderTime time.Time `cname:"订单日期" json:"orderTime" valid:"Required"`
OrderTime string `cname:"订单日期" json:"orderTime" valid:"Required"`
// 订单产品列表
OrderGoods []*OrderGoods `cname:"订单产品列表" json:"orderGoods,omitempty"`
// 公司ID,通过集成REST上下文获取
... ...
... ... @@ -99,15 +99,25 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 订单时间转换
orderTimeInt, err := strconv.ParseInt(createDividendsReturnedOrderCommand.OrderTime, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
}
orderTime := utils.TransformTimestampToTime(orderTimeInt)
// 校验分红退货单编号是否唯一
//numberAvailable, _ := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{
// "companyId": createDividendsOrderCommand.CompanyId,
// "orgId": createDividendsOrderCommand.OrgId,
// "dividendsReturnedOrderNumber": dividendsReturnedOrderNumber,
//})
//if !numberAvailable {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常")
//}
numberAvailable, err := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{
"companyId": createDividendsReturnedOrderCommand.CompanyId,
"orgId": createDividendsReturnedOrderCommand.OrgId,
"dividendsReturnedOrderNumber": dividendsReturnedOrderNumber,
})
if err != nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, err.Error())
}
if !numberAvailable {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单号已存在")
}
// 获取分红退货单产品
var orderGoods []*domain.OrderGood
... ... @@ -152,6 +162,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide
UpdatedAt: time.Time{},
Operator: operator,
OperateTime: time.Now(),
OrderTime: orderTime,
}
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
... ... @@ -563,6 +574,13 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide
}
dividendsReturnedDate := utils.TransformTimestampToTime(dividendsReturnedDateInt)
// 订单时间转换
orderTimeInt, err := strconv.ParseInt(updateDividendsReturnedOrderCommand.OrderTime, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
}
orderTime := utils.TransformTimestampToTime(orderTimeInt)
// 获取分红退货单
dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderId": updateDividendsReturnedOrderCommand.DividendsReturnedOrderId})
if err != nil {
... ... @@ -607,6 +625,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide
dividendsReturnedOrder.DividendsReturnedDate = dividendsReturnedDate
dividendsReturnedOrder.DividendsReturnedOrderRefund = dividendsReturnedOrderAmount
dividendsReturnedOrder.Goods = orderGoods
dividendsReturnedOrder.OrderTime = orderTime
// 保存分红退货单更新
if dividendsReturnedOrderSaved, err := dividendsReturnedOrderRepository.Save(dividendsReturnedOrder); err != nil {
... ...
... ... @@ -7,4 +7,8 @@ type AccountDetail struct {
DividendsType int32 `json:"dividendsType"`
// 分红金额
DividendsAmount float64 `json:"dividendsAmount"`
// 产品ID
OrderGoodId int64 `json:"orderGoodId"`
// 订单产品金额
OrderGoodAmount float64 `json:"orderGoodAmount"`
}
... ...
... ... @@ -42,6 +42,8 @@ type CooperationProject struct {
DeletedAt time.Time `json:"deletedAt"`
// 创建时间
CreatedAt time.Time `json:"createdAt"`
// 共创申请人计数
ApplicantCount int32 `json:"applicantCount"`
}
type CooperationProjectRepository interface {
... ...
... ... @@ -26,6 +26,8 @@ type CreditAccount struct {
ParticipateType string `json:"participateType"`
// 结算明细
AccountDetail []*AccountDetail `json:"accountDetail"`
// 产品金额统计
GoodAmountCount float64 `json:"goodAmountCount"`
// 支付凭证附件
PaymentDocumentAttachments []*Attachment `json:"paymentDocumentAttachments"`
// 数据所属组织机构
... ...
... ... @@ -61,6 +61,10 @@ type DividendsEstimate struct {
DeletedAt time.Time `json:"deletedAt"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt"`
// 订单产品ID
OrderGoodId int64 `json:"orderGoodId"`
// 订单产品金额
OrderGoodAmount float64 `json:"orderGoodAmount"`
}
type DividendsEstimateRepository interface {
... ...
... ... @@ -35,7 +35,25 @@ func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber() (st
}
}
// CalculateDividendsOrderAmount 计算分红订单金额
// CheckDividendsReturnedOrderNumberAvailable 校验分红订单是否唯一
func (dao *DividendsReturnedOrderDao) CheckDividendsReturnedOrderNumberAvailable(queryOptions map[string]interface{}) (bool, error) {
tx := dao.transactionContext.PgTx
var dividendsReturnedOrderModels []*models.DividendsReturnedOrder
query := tx.Model(&dividendsReturnedOrderModels)
if dividendsOrderNumber, ok := queryOptions["dividendsReturnedOrderNumber"]; ok && dividendsOrderNumber != "" {
query = query.Where("dividends_returned_order_number = ?", dividendsOrderNumber)
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`dividends_returned_order.company @> '{"companyId":"?"}'`, companyId)
}
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`dividends_returned_order.org @> '{"orgId":"?"}'`, orgId)
}
ok, err := query.Exists()
return !ok, err
}
// CalculateDividendsReturnedOrderAmount 计算分红订单金额
func (dao *DividendsReturnedOrderDao) CalculateDividendsReturnedOrderAmount(queryOptions map[string]interface{}) (float64, error) {
tx := dao.transactionContext.PgTx
var dividendsOrderModel = new(models.DividendsReturnedOrder)
... ...
... ... @@ -45,4 +45,6 @@ type CooperationProject struct {
DeletedAt time.Time `comment:"删除时间" pg:",soft_delete"`
// 创建时间
CreatedAt time.Time `comment:"创建时间"`
// 申请人统计
ApplicantCount int32 `comment:"申请人统计"`
}
... ...
... ... @@ -29,6 +29,8 @@ type CreditAccount struct {
ParticipateType string `comment:"参与类型,承接人,推荐人,业务员"`
// 结算明细
AccountDetail []*domain.AccountDetail `comment:"结算明细"`
// 产品金额统计
GoodAmountCount float64 `comment:"产品金额统计"`
// 支付凭证附件
PaymentDocumentAttachments []*domain.Attachment `comment:"支付凭证附件"`
// 数据所属组织机构
... ...
... ... @@ -41,5 +41,6 @@ func TransformToCooperationProjectDomainModelFromPgModels(
UpdatedAt: cooperationProjectModel.UpdatedAt,
DeletedAt: cooperationProjectModel.DeletedAt,
CreatedAt: cooperationProjectModel.CreatedAt,
ApplicantCount: cooperationProjectModel.ApplicantCount,
}, nil
}
... ...
... ... @@ -18,6 +18,7 @@ func TransformToCreditAccountDomainModelFromPgModels(creditAccountModel *models.
Participator: creditAccountModel.Participator,
ParticipateType: creditAccountModel.ParticipateType,
AccountDetail: creditAccountModel.AccountDetail,
GoodAmountCount: creditAccountModel.GoodAmountCount,
PaymentDocumentAttachments: creditAccountModel.PaymentDocumentAttachments,
Org: creditAccountModel.Org,
Company: creditAccountModel.Company,
... ...
... ... @@ -47,6 +47,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
"updated_at",
"deleted_at",
"created_at",
"applicant_account",
}
insertFieldsSnippet := sqlbuilder.SqlFieldsSnippet(sqlBuildFields)
insertPlaceHoldersSnippet := sqlbuilder.SqlPlaceHoldersSnippet(sqlBuildFields)
... ... @@ -82,6 +83,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
&cooperationProject.UpdatedAt,
&cooperationProject.DeletedAt,
&cooperationProject.CreatedAt,
&cooperationProject.ApplicantCount,
),
fmt.Sprintf("INSERT INTO cooperation_projects (%s) VALUES (%s) RETURNING %s", insertFieldsSnippet, insertPlaceHoldersSnippet, returningFieldsSnippet),
cooperationProject.CooperationProjectId,
... ... @@ -103,6 +105,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
cooperationProject.UpdatedAt,
nil,
cooperationProject.CreatedAt,
cooperationProject.ApplicantCount,
); err != nil {
return cooperationProject, err
}
... ... @@ -128,6 +131,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
&cooperationProject.UpdatedAt,
&cooperationProject.DeletedAt,
&cooperationProject.CreatedAt,
&cooperationProject.ApplicantCount,
),
fmt.Sprintf("UPDATE cooperation_projects SET %s WHERE cooperation_project_id=? RETURNING %s", updateFieldsSnippet, returningFieldsSnippet),
cooperationProject.CooperationProjectId,
... ... @@ -149,6 +153,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
cooperationProject.UpdatedAt,
nil,
cooperationProject.CreatedAt,
cooperationProject.ApplicantCount,
cooperationProject.Identify(),
); err != nil {
return cooperationProject, err
... ... @@ -181,6 +186,7 @@ func (repository *CooperationProjectRepository) UpdateMany(cooperationProjects [
UpdatedAt: time.Now(),
DeletedAt: cooperationProject.DeletedAt,
CreatedAt: cooperationProject.CreatedAt,
ApplicantCount: cooperationProject.ApplicantCount,
})
}
if _, err := tx.Model(&cooperationProjectModels).WherePK().Update(); err != nil {
... ...
... ... @@ -38,6 +38,7 @@ func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAcco
"participator",
"participate_type",
"account_detail",
"good_amount_count",
"payment_document_attachments",
"org",
"company",
... ... @@ -74,6 +75,7 @@ func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAcco
&creditAccount.Participator,
&creditAccount.ParticipateType,
&creditAccount.AccountDetail,
&creditAccount.GoodAmountCount,
&creditAccount.PaymentDocumentAttachments,
&creditAccount.Org,
&creditAccount.Company,
... ... @@ -96,6 +98,7 @@ func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAcco
creditAccount.Participator,
creditAccount.ParticipateType,
creditAccount.AccountDetail,
creditAccount.GoodAmountCount,
creditAccount.PaymentDocumentAttachments,
creditAccount.Org,
creditAccount.Company,
... ... @@ -122,6 +125,7 @@ func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAcco
&creditAccount.Participator,
&creditAccount.ParticipateType,
&creditAccount.AccountDetail,
&creditAccount.GoodAmountCount,
&creditAccount.PaymentDocumentAttachments,
&creditAccount.Org,
&creditAccount.Company,
... ... @@ -144,6 +148,7 @@ func (repository *CreditAccountRepository) Save(creditAccount *domain.CreditAcco
creditAccount.Participator,
creditAccount.ParticipateType,
creditAccount.AccountDetail,
creditAccount.GoodAmountCount,
creditAccount.PaymentDocumentAttachments,
creditAccount.Org,
creditAccount.Company,
... ...
... ... @@ -367,7 +367,10 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte
dividendsOrderModel := new(models.DividendsOrder)
query := sqlbuilder.BuildQuery(tx.Model(dividendsOrderModel), queryOptions)
query.SetWhereByQueryOption("dividends_order.dividends_order_id = ?", "dividendsOrderId")
query.SetWhereByQueryOption("dividends_order.dividends_order_number = ?", "dividendsOrderNumber")
//query.SetWhereByQueryOption("dividends_order.dividends_order_number = ?", "dividendsOrderNumber")
if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" {
query.Where("dividends_order.dividends_order_number = ?", dividendsOrderNumber)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
... ...
... ... @@ -61,6 +61,8 @@ func (controller *DividendsOrderController) GetDividendsOrder() {
getDividendsOrderQuery.UserBaseId = header.UserBaseId
dividendsOrderId, _ := controller.GetInt64(":dividendsOrderId")
getDividendsOrderQuery.DividendsOrderId = dividendsOrderId
dividendsOrderNumber := controller.GetString("dividendsOrderNumber")
getDividendsOrderQuery.DividendsOrderNumber = dividendsOrderNumber
data, err := dividendsOrderService.GetDividendsOrder(getDividendsOrderQuery)
controller.Response(data, err)
}
... ...