作者 yangfu

分红预算列表

@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 "fmt" 5 "fmt"
6 "github.com/go-pg/pg/v10" 6 "github.com/go-pg/pg/v10"
7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 7 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  8 + "github.com/linmadan/egglib-go/utils/tool_funs"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
10 ) 11 )
@@ -14,6 +15,8 @@ const ( @@ -14,6 +15,8 @@ const (
14 SearchContractDividends = "SearchContractDividends" 15 SearchContractDividends = "SearchContractDividends"
15 // 获取分红合约详情 16 // 获取分红合约详情
16 GetContractDividends = "GetContractDividends" 17 GetContractDividends = "GetContractDividends"
  18 + // 分红统计(分红明细)
  19 + DividendsStatistics = "DividendsStatistics"
17 20
18 // 企业-商品统计 21 // 企业-商品统计
19 CooperationGoodsStatistics = "cooperationGoodsStatistics" 22 CooperationGoodsStatistics = "cooperationGoodsStatistics"
@@ -45,13 +48,6 @@ func NewCooperationStatisticsService(transactionContext *pgTransaction.Transacti @@ -45,13 +48,6 @@ func NewCooperationStatisticsService(transactionContext *pgTransaction.Transacti
45 // 分红合约搜索 48 // 分红合约搜索
46 // 49 //
47 // queryOptions 查询参数 50 // queryOptions 查询参数
48 -// - pageNumber  
49 -// - pageSize  
50 -// 按组织  
51 -// - companyId  
52 -// - orgId  
53 -// 按个人  
54 -// - userBaseId  
55 func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions map[string]interface{}) (interface{}, error) { 51 func (ptr *CooperationStatisticsService) SearchContractDividends(queryOptions map[string]interface{}) (interface{}, error) {
56 // 1.根据个人、企业查询合约列表 52 // 1.根据个人、企业查询合约列表
57 var contracts []*domain.CooperationContract 53 var contracts []*domain.CooperationContract
@@ -165,14 +161,9 @@ type searchContractDividendsResult struct { @@ -165,14 +161,9 @@ type searchContractDividendsResult struct {
165 161
166 /*1.2 分红合约详情*/ 162 /*1.2 分红合约详情*/
167 163
168 -// 分红合约搜索 164 +//GetContractDividends 分红合约详情
169 // 165 //
170 // queryOptions 查询参数 166 // queryOptions 查询参数
171 -// 按组织  
172 -// - companyId  
173 -// - orgId  
174 -// 按个人  
175 -// - userBaseId  
176 func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[string]interface{}) (interface{}, error) { 167 func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[string]interface{}) (interface{}, error) {
177 // 1.合约详情 168 // 1.合约详情
178 contractRepository, _ := repository.NewCooperationContractRepository(ptr.transactionContext) 169 contractRepository, _ := repository.NewCooperationContractRepository(ptr.transactionContext)
@@ -202,3 +193,80 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s @@ -202,3 +193,80 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
202 res["dividends"] = []struct{}{} 193 res["dividends"] = []struct{}{}
203 return res, nil 194 return res, nil
204 } 195 }
  196 +
  197 +// 分红统计(分红明细)
  198 +func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[string]interface{}) (interface{}, error) {
  199 + return nil, nil
  200 +}
  201 +
  202 +// 分红预算列表
  203 +func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions map[string]interface{}) (interface{}, error) {
  204 + // 参数验证
  205 + var request = struct {
  206 + CompanyId int64 `json:"companyId"`
  207 + OrgId int64 `json:"orgId"`
  208 + UserBaseId int64 `json:"userBaseId"`
  209 + DividendsAccountStatus int32 `json:"dividendsAccountStatus"` // 分红结算状态
  210 + Offset int64 `json:"offset"`
  211 + Limit int64 `json:"limit"`
  212 + }{}
  213 + if err := LoadQueryObject(queryOptions, &request); err != nil {
  214 + return nil, err
  215 + }
  216 + queryOptions = tool_funs.SimpleStructToMap(&request)
  217 +
  218 + dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
  219 + _, estimates, err := dividendsEstimateRepository.Find(queryOptions)
  220 + if err != nil {
  221 + return nil, err
  222 + }
  223 + type response struct {
  224 + // 承接人分红预算记录ID
  225 + DividendsEstimateId int64 `json:"dividendsEstimateId,string"`
  226 + // 分红结算状态,1待结算,2已结算
  227 + DividendsAccountStatus int32 `json:"dividendsAccountStatus"`
  228 + // 分红金额
  229 + DividendsAmount float64 `json:"dividendsAmount"`
  230 + // 参与分红类型,1承接人,2推荐人,3关联业务员
  231 + DividendsParticipateType int32 `json:"dividendsParticipateType"`
  232 + // 分红类型,1订单分红,2退货冲销,3金额激励
  233 + DividendsType int32 `json:"dividendsType"`
  234 + // 分红用户(共创参与)
  235 + DividendsUser *domain.User `json:"dividendsUser"`
  236 + // 分红订单金额
  237 + DividendsOrderAmount float64 `json:"dividendsOrderAmount"`
  238 + //OrderGoodName string `json:"orderGoodName"`
  239 + CustomerName string `json:"customerName"`
  240 + }
  241 + var results = make([]response, 0)
  242 + dividendsOrderRepository, _ := repository.NewDividendsOrderRepository(ptr.transactionContext)
  243 + dividendsReturnedOrderRepository, _ := repository.NewDividendsReturnedOrderRepository(ptr.transactionContext)
  244 + for i := range estimates {
  245 + item := estimates[i]
  246 + result := response{
  247 + DividendsEstimateId: item.DividendsEstimateId,
  248 + DividendsAccountStatus: item.DividendsAccountStatus,
  249 + DividendsAmount: item.DividendsAmount,
  250 + DividendsParticipateType: item.DividendsParticipateType,
  251 + DividendsType: item.DividendsType,
  252 + DividendsUser: item.DividendsUser,
  253 + }
  254 + if item.DividendsType == 1 {
  255 + order, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": item.OrderOrReturnedOrderNum})
  256 + if err != nil {
  257 + return nil, err
  258 + }
  259 + result.DividendsOrderAmount = order.DividendsOrderAmount
  260 + result.CustomerName = order.CustomerName
  261 + } else if item.DividendsType == 2 {
  262 + order, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderNumber": item.OrderOrReturnedOrderNum})
  263 + if err != nil {
  264 + return nil, err
  265 + }
  266 + result.DividendsOrderAmount = order.DividendsReturnedOrderRefund
  267 + result.CustomerName = order.DividendsReturnedCustomerName
  268 + }
  269 + results = append(results, result)
  270 + }
  271 + return results, nil
  272 +}
@@ -294,6 +294,7 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte @@ -294,6 +294,7 @@ func (repository *DividendsOrderRepository) FindOne(queryOptions map[string]inte
294 dividendsOrderModel := new(models.DividendsOrder) 294 dividendsOrderModel := new(models.DividendsOrder)
295 query := sqlbuilder.BuildQuery(tx.Model(dividendsOrderModel), queryOptions) 295 query := sqlbuilder.BuildQuery(tx.Model(dividendsOrderModel), queryOptions)
296 query.SetWhereByQueryOption("dividends_order.dividends_order_id = ?", "dividendsOrderId") 296 query.SetWhereByQueryOption("dividends_order.dividends_order_id = ?", "dividendsOrderId")
  297 + query.SetWhereByQueryOption("dividends_order.dividends_order_number = ?", "dividendsOrderNumber")
297 if err := query.First(); err != nil { 298 if err := query.First(); err != nil {
298 if err.Error() == "pg: no rows in result set" { 299 if err.Error() == "pg: no rows in result set" {
299 return nil, fmt.Errorf("没有此资源") 300 return nil, fmt.Errorf("没有此资源")
@@ -306,6 +306,7 @@ func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[str @@ -306,6 +306,7 @@ func (repository *DividendsReturnedOrderRepository) FindOne(queryOptions map[str
306 dividendsReturnedOrderModel := new(models.DividendsReturnedOrder) 306 dividendsReturnedOrderModel := new(models.DividendsReturnedOrder)
307 query := sqlbuilder.BuildQuery(tx.Model(dividendsReturnedOrderModel), queryOptions) 307 query := sqlbuilder.BuildQuery(tx.Model(dividendsReturnedOrderModel), queryOptions)
308 query.SetWhereByQueryOption("dividends_returned_order.dividends_returned_order_id = ?", "dividendsReturnedOrderId") 308 query.SetWhereByQueryOption("dividends_returned_order.dividends_returned_order_id = ?", "dividendsReturnedOrderId")
  309 + query.SetWhereByQueryOption("dividends_returned_order.dividends_returned_order_number = ?", "dividendsReturnedOrderNumber")
309 if err := query.First(); err != nil { 310 if err := query.First(); err != nil {
310 if err.Error() == "pg: no rows in result set" { 311 if err.Error() == "pg: no rows in result set" {
311 return nil, fmt.Errorf("没有此资源") 312 return nil, fmt.Errorf("没有此资源")