作者 yangfu

分红预算列表

... ... @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
)
... ... @@ -14,6 +15,8 @@ const (
SearchContractDividends = "SearchContractDividends"
// 获取分红合约详情
GetContractDividends = "GetContractDividends"
// 分红统计(分红明细)
DividendsStatistics = "DividendsStatistics"
// 企业-商品统计
CooperationGoodsStatistics = "cooperationGoodsStatistics"
... ... @@ -45,13 +48,6 @@ func NewCooperationStatisticsService(transactionContext *pgTransaction.Transacti
// 分红合约搜索
//
// queryOptions 查询参数
// - pageNumber
// - pageSize
// 按组织
// - companyId
// - orgId
// 按个人
// - userBaseId
func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions map[string]interface{}) (interface{}, error) {
// 1.根据个人、企业查询合约列表
var contracts []*domain.CooperationContract
... ... @@ -165,14 +161,9 @@ type searchContractDividendsResult struct {
/*1.2 分红合约详情*/
// 分红合约搜索
//GetContractDividends 分红合约详情
//
// queryOptions 查询参数
// 按组织
// - companyId
// - orgId
// 按个人
// - userBaseId
func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[string]interface{}) (interface{}, error) {
// 1.合约详情
contractRepository, _ := repository.NewCooperationContractRepository(ptr.transactionContext)
... ... @@ -202,3 +193,80 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
res["dividends"] = []struct{}{}
return res, nil
}
// 分红统计(分红明细)
func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[string]interface{}) (interface{}, error) {
return nil, nil
}
// 分红预算列表
func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions map[string]interface{}) (interface{}, error) {
// 参数验证
var request = struct {
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
UserBaseId int64 `json:"userBaseId"`
DividendsAccountStatus int32 `json:"dividendsAccountStatus"` // 分红结算状态
Offset int64 `json:"offset"`
Limit int64 `json:"limit"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
_, estimates, err := dividendsEstimateRepository.Find(queryOptions)
if err != nil {
return nil, err
}
type response struct {
// 承接人分红预算记录ID
DividendsEstimateId int64 `json:"dividendsEstimateId,string"`
// 分红结算状态,1待结算,2已结算
DividendsAccountStatus int32 `json:"dividendsAccountStatus"`
// 分红金额
DividendsAmount float64 `json:"dividendsAmount"`
// 参与分红类型,1承接人,2推荐人,3关联业务员
DividendsParticipateType int32 `json:"dividendsParticipateType"`
// 分红类型,1订单分红,2退货冲销,3金额激励
DividendsType int32 `json:"dividendsType"`
// 分红用户(共创参与)
DividendsUser *domain.User `json:"dividendsUser"`
// 分红订单金额
DividendsOrderAmount float64 `json:"dividendsOrderAmount"`
//OrderGoodName string `json:"orderGoodName"`
CustomerName string `json:"customerName"`
}
var results = make([]response, 0)
dividendsOrderRepository, _ := repository.NewDividendsOrderRepository(ptr.transactionContext)
dividendsReturnedOrderRepository, _ := repository.NewDividendsReturnedOrderRepository(ptr.transactionContext)
for i := range estimates {
item := estimates[i]
result := response{
DividendsEstimateId: item.DividendsEstimateId,
DividendsAccountStatus: item.DividendsAccountStatus,
DividendsAmount: item.DividendsAmount,
DividendsParticipateType: item.DividendsParticipateType,
DividendsType: item.DividendsType,
DividendsUser: item.DividendsUser,
}
if item.DividendsType == 1 {
order, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": item.OrderOrReturnedOrderNum})
if err != nil {
return nil, err
}
result.DividendsOrderAmount = order.DividendsOrderAmount
result.CustomerName = order.CustomerName
} else if item.DividendsType == 2 {
order, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderNumber": item.OrderOrReturnedOrderNum})
if err != nil {
return nil, err
}
result.DividendsOrderAmount = order.DividendsReturnedOrderRefund
result.CustomerName = order.DividendsReturnedCustomerName
}
results = append(results, result)
}
return results, nil
}
... ...
... ... @@ -294,6 +294,7 @@ 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")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
... ...
... ... @@ -306,6 +306,7 @@ func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[str
dividendsReturnedOrderModel := new(models.DividendsReturnedOrder)
query := sqlbuilder.BuildQuery(tx.Model(dividendsReturnedOrderModel), queryOptions)
query.SetWhereByQueryOption("dividends_returned_order.dividends_returned_order_id = ?", "dividendsReturnedOrderId")
query.SetWhereByQueryOption("dividends_returned_order.dividends_returned_order_number = ?", "dividendsReturnedOrderNumber")
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("没有此资源")
... ...