作者 yangfu

修改分红订单列表

1 package query 1 package query
2 2
3 -type ListOrderPaymentQuery struct { 3 +type GetOrderPaymentQuery struct {
4 // 合伙人类别 4 // 合伙人类别
5 OrderId int64 `json:"orderId"` 5 OrderId int64 `json:"orderId"`
6 } 6 }
7 7
8 -func (q *ListOrderPaymentQuery) ValidateQuery() error { 8 +func (q *GetOrderPaymentQuery) ValidateQuery() error {
9 9
10 return nil 10 return nil
11 } 11 }
@@ -5,6 +5,8 @@ import ( @@ -5,6 +5,8 @@ import (
5 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" 5 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command" 6 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command"
7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query" 7 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query"
  8 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
  9 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils"
8 "time" 10 "time"
9 11
10 //"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query" 12 //"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query"
@@ -86,92 +88,31 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm @@ -86,92 +88,31 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm
86 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 88 return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
87 } 89 }
88 } 90 }
  91 + var bonusStatus int = 1
  92 + if len(command.DivdendPaymentItem) > 0 {
  93 + bonusStatus = command.DivdendPaymentItem[len(command.DivdendPaymentItem)-1].StateOfPayment
  94 + }
89 95
90 - if err = OrderDao.Update(map[string]interface{}{"id": command.OrderId, "orderPaymentAmount": command.TotalPaymentAmount}); err != nil { 96 + if err = OrderDao.Update(map[string]interface{}{"id": command.OrderId, "orderPaymentAmount": command.TotalPaymentAmount, "bonusStatus": bonusStatus}); err != nil {
91 return 97 return
92 } 98 }
93 99
94 return 100 return
95 } 101 }
96 102
97 -//// GetOrderPayment 返回合伙人  
98 -//func (OrderPaymentService *OrderPaymentService) GetOrderPayment(command query.GetOrderPaymentQuery) (data *domain.OrderPayment, err error) {  
99 -// var (  
100 -// transactionContext, _ = factory.CreateTransactionContext(nil)  
101 -// )  
102 -// if err = command.ValidateQuery(); err != nil {  
103 -// return nil, lib.ThrowError(lib.ARG_ERROR, err.Error())  
104 -// }  
105 -// if err := transactionContext.StartTransaction(); err != nil {  
106 -// return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
107 -// }  
108 -// defer func() {  
109 -// transactionContext.RollbackTransaction()  
110 -// }()  
111 -// var OrderPaymentRepository domain.OrderPaymentRepository  
112 -// if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{  
113 -// "transactionContext": transactionContext,  
114 -// }); err != nil {  
115 -// return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
116 -// }  
117 -// data, err = OrderPaymentRepository.FindOne(domain.PartnerFindOneQuery{UserId: command.Id})  
118 -// if err != nil {  
119 -// return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
120 -// }  
121 -// err = transactionContext.CommitTransaction()  
122 -// return  
123 -//}  
124 -//  
125 -//// 更新客户价值  
126 -//func (OrderPaymentService *OrderPaymentService) UpdateOrderPayment(updateOrderPaymentCommand *command.UpdateOrderPaymentCommand) (err error) {  
127 -// var (  
128 -// transactionContext, _ = factory.CreateTransactionContext(nil)  
129 -// )  
130 -// if err = updateOrderPaymentCommand.ValidateCommand(); err != nil {  
131 -// return application.ThrowError(application.ARG_ERROR, err.Error())  
132 -// }  
133 -// if err := transactionContext.StartTransaction(); err != nil {  
134 -// return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
135 -// }  
136 -// defer func() {  
137 -// transactionContext.RollbackTransaction()  
138 -// }()  
139 -// var OrderPaymentRepository domain.OrderPaymentRepository  
140 -// if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{  
141 -// "transactionContext": transactionContext,  
142 -// }); err != nil {  
143 -// return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())  
144 -// }  
145 -// OrderPayment, err := OrderPaymentRepository.FindOne(domain.PartnerFindOneQuery{  
146 -// UserId: updateOrderPaymentCommand.Id,  
147 -// })  
148 -// if err != nil {  
149 -// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
150 -// }  
151 -// OrderPayment.PartnerCategory = updateOrderPaymentCommand.PartnerCategory  
152 -// OrderPayment.Salesman = updateOrderPaymentCommand.Salesman  
153 -// OrderPayment.Status = updateOrderPaymentCommand.Status  
154 -// OrderPayment.RegionInfo = updateOrderPaymentCommand.RegionInfo  
155 -// if _, err = OrderPaymentRepository.Save(OrderPayment); err != nil {  
156 -// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())  
157 -// }  
158 -// transactionContext.CommitTransaction()  
159 -// return  
160 -//}  
161 -//  
162 // 返回订单支付列表 103 // 返回订单支付列表
163 -func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymentQuery *query.ListOrderPaymentQuery) (int, []*domain.OrderPayment, error) { 104 +func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymentQuery *query.GetOrderPaymentQuery) (map[string]interface{}, []*domain.OrderPayment, error) {
164 var ( 105 var (
165 transactionContext, _ = factory.CreateTransactionContext(nil) 106 transactionContext, _ = factory.CreateTransactionContext(nil)
  107 + OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
166 OrderPayments []*domain.OrderPayment 108 OrderPayments []*domain.OrderPayment
167 - count int  
168 err error 109 err error
169 ) 110 )
170 if err = listOrderPaymentQuery.ValidateQuery(); err != nil { 111 if err = listOrderPaymentQuery.ValidateQuery(); err != nil {
171 - return 0, nil, lib.ThrowError(lib.ARG_ERROR, err.Error()) 112 + return nil, nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
172 } 113 }
173 if err := transactionContext.StartTransaction(); err != nil { 114 if err := transactionContext.StartTransaction(); err != nil {
174 - return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 115 + return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
175 } 116 }
176 defer func() { 117 defer func() {
177 if err != nil { 118 if err != nil {
@@ -182,19 +123,99 @@ func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymen @@ -182,19 +123,99 @@ func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymen
182 if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{ 123 if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{
183 "transactionContext": transactionContext, 124 "transactionContext": transactionContext,
184 }); err != nil { 125 }); err != nil {
185 - return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 126 + return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
186 } 127 }
187 queryOption := domain.OrderPaymentQuery{ 128 queryOption := domain.OrderPaymentQuery{
188 OrderId: listOrderPaymentQuery.OrderId, 129 OrderId: listOrderPaymentQuery.OrderId,
189 } 130 }
  131 + orderBase, e := OrderDao.GetOrderBaseInfo(listOrderPaymentQuery.OrderId)
  132 + if e != nil {
  133 + return nil, nil, e
  134 + }
190 if OrderPayments, err = OrderPaymentRepository.Find(queryOption); err != nil { 135 if OrderPayments, err = OrderPaymentRepository.Find(queryOption); err != nil {
191 - return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 136 + return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  137 + }
  138 + //if count, err = OrderPaymentRepository.CountAll(queryOption); err != nil {
  139 + // return nil, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  140 + //}
  141 +
  142 + if err = transactionContext.CommitTransaction(); err != nil {
  143 + return nil, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
192 } 144 }
193 - if count, err = OrderPaymentRepository.CountAll(queryOption); err != nil { 145 + return orderBase, OrderPayments, nil
  146 +}
  147 +
  148 +// 返回分红管理列表
  149 +func (OrderPaymentService *OrderPaymentService) ListDividendOrders(listOrderPaymentQuery *query.ListDividendOrdersQuery) (int, interface{}, error) {
  150 + var (
  151 + transactionContext, _ = factory.CreateTransactionContext(nil)
  152 + //OrderPayments []*domain.OrderPayment
  153 + count int
  154 + err error
  155 + OrderDao, _ = factory.CreateOrderDao(map[string]interface{}{"transactionContext": transactionContext})
  156 + orders []*models.Order
  157 + )
  158 + if err = listOrderPaymentQuery.ValidateQuery(); err != nil {
  159 + return 0, nil, lib.ThrowError(lib.ARG_ERROR, err.Error())
  160 + }
  161 + if err := transactionContext.StartTransaction(); err != nil {
  162 + return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  163 + }
  164 + defer func() {
  165 + if err != nil {
  166 + transactionContext.RollbackTransaction()
  167 + }
  168 + }()
  169 + if count, orders, err = OrderDao.GetDividendOrders(map[string]interface{}{
  170 + "orderCode": listOrderPaymentQuery.OrderNumber,
  171 + "partnerName": listOrderPaymentQuery.PartnerName,
  172 + "orderType": 1,
  173 + "offset": (listOrderPaymentQuery.PageNumber - 1) * listOrderPaymentQuery.PageSize,
  174 + "limit": listOrderPaymentQuery.PageSize,
  175 + }); err != nil {
194 return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 176 return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
195 } 177 }
  178 +
  179 + type DividendOrderItem struct {
  180 + OrderNumber string `json:"orderNumber"` //订单号
  181 + OrderState int `json:"orderState"` //订单状态
  182 + StateOfPayment string `json:"stateOfPayment"` //支付状态
  183 + CreateTime string `json:"createTime"` //订单创建时间
  184 + PartnerName string `json:"partnerName"` //合伙人姓名
  185 + DividendProportion float64 `json:"dividendProportion"` //分红比例
  186 + DividendsReceivable float64 `json:"dividendsReceivable"` //应收分红
  187 + DividendSpending float64 `json:"dividendSpending"` //分红支出
  188 + ReceiveDividends float64 `json:"receiveDividends"` //实收分红
  189 + CommissionProportion float64 `json:"commissionProportion"` //业务员抽成比例
  190 + }
  191 + var list = make([]DividendOrderItem, 0)
  192 + for i := range orders {
  193 + order := orders[i]
  194 + item := DividendOrderItem{
  195 + OrderNumber: order.OrderCode,
  196 + OrderState: order.OrderStatus,
  197 + StateOfPayment: "",
  198 + CreateTime: order.CreateAt.Local().Format("2006-01-02 15:04:05"),
  199 + PartnerName: order.PartnerInfo.PartnerName,
  200 + DividendProportion: order.PartnerBonusPercent,
  201 + DividendsReceivable: utils.Decimal(order.OrderActualAmount * (order.PartnerBonusPercent / 100.0)),
  202 + DividendSpending: 0,
  203 + ReceiveDividends: utils.Decimal(order.OrderPaymentAmount * (order.PartnerBonusPercent / 100.0)),
  204 + CommissionProportion: order.SalesmanBonusPercent,
  205 + }
  206 + if order.BonusStatus == domain.BonusPaid {
  207 + item.StateOfPayment = "已支付分红"
  208 + } else {
  209 + item.StateOfPayment = "等待支付分红"
  210 + }
  211 + if order.OrderActualAmount < order.OrderAmount {
  212 + item.DividendSpending = utils.Decimal(order.OrderAmount - order.OrderActualAmount)
  213 + }
  214 + list = append(list, item)
  215 + }
  216 +
196 if err = transactionContext.CommitTransaction(); err != nil { 217 if err = transactionContext.CommitTransaction(); err != nil {
197 return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 218 return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
198 } 219 }
199 - return count, OrderPayments, nil 220 + return count, list, nil
200 } 221 }
@@ -26,6 +26,9 @@ type OrderPayment struct { @@ -26,6 +26,9 @@ type OrderPayment struct {
26 CreateAt time.Time `json:"createAt"` 26 CreateAt time.Time `json:"createAt"`
27 //更新时间 27 //更新时间
28 UpdateAt time.Time `json:"updateAt"` 28 UpdateAt time.Time `json:"updateAt"`
  29 +
  30 + //扩展
  31 + PartnerBonusPercent float64 `json:"-"`
29 } 32 }
30 33
31 func (m *OrderPayment) Identify() interface{} { 34 func (m *OrderPayment) Identify() interface{} {
@@ -17,6 +17,9 @@ func (dao *OrderDao) Update(options map[string]interface{}) (err error) { @@ -17,6 +17,9 @@ func (dao *OrderDao) Update(options map[string]interface{}) (err error) {
17 if v, ok := options["orderPaymentAmount"]; ok { 17 if v, ok := options["orderPaymentAmount"]; ok {
18 q.Set("order_payment_amount = ?", v) 18 q.Set("order_payment_amount = ?", v)
19 } 19 }
  20 + if v, ok := options["bonusStatus"]; ok {
  21 + q.Set("bonus_status = ?", v)
  22 + }
20 if v, ok := options["id"]; ok { 23 if v, ok := options["id"]; ok {
21 q.Where("id = ?", v) 24 q.Where("id = ?", v)
22 } 25 }
@@ -42,6 +45,31 @@ func (dao *OrderDao) GetOrderBaseInfo(id int64) (data map[string]interface{}, er @@ -42,6 +45,31 @@ func (dao *OrderDao) GetOrderBaseInfo(id int64) (data map[string]interface{}, er
42 return 45 return
43 } 46 }
44 47
  48 +func (dao *OrderDao) GetDividendOrders(options map[string]interface{}) (count int, orders []*models.Order, err error) {
  49 + tx := dao.transactionContext.PgTx
  50 + //Order:=new(models.Order)
  51 + q := tx.Model(&orders)
  52 + q.ColumnExpr(`"order".*`, `partner_info.partner_name`)
  53 + q.Relation("PartnerInfo")
  54 + if v, ok := options["orderCode"]; ok && len(v.(string)) > 0 {
  55 + q.Where(`"order".order_code like ?`, fmt.Sprintf("%%%v%%", v))
  56 + }
  57 + if v, ok := options["orderType"]; ok {
  58 + q.Where(`"order".order_type=?`, v)
  59 + }
  60 + if v, ok := options["partnerName"]; ok && len(v.(string)) > 0 {
  61 + q.Where(`partner_info.partner_name like ?`, "%"+v.(string)+"%")
  62 + }
  63 + if v, ok := options["offset"]; ok {
  64 + q.Offset(v.(int))
  65 + }
  66 + if v, ok := options["limit"]; ok {
  67 + q.Limit(v.(int))
  68 + }
  69 + count, err = q.SelectAndCount()
  70 + return
  71 +}
  72 +
45 func NewOrderDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) { 73 func NewOrderDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) {
46 if transactionContext == nil { 74 if transactionContext == nil {
47 return nil, fmt.Errorf("transactionContext参数不能为nil") 75 return nil, fmt.Errorf("transactionContext参数不能为nil")
@@ -27,12 +27,15 @@ type Order struct { @@ -27,12 +27,15 @@ type Order struct {
27 OrderActualAmount float64 27 OrderActualAmount float64
28 //订单已支付金额(货款) 28 //订单已支付金额(货款)
29 OrderPaymentAmount float64 29 OrderPaymentAmount float64
  30 + //最后分红状态
  31 + BonusStatus int
30 //订单区域信息 32 //订单区域信息
31 OrderRegionInfo *domain.RegionInfo 33 OrderRegionInfo *domain.RegionInfo
32 34
33 Buyer *domain.Buyer 35 Buyer *domain.Buyer
34 //合伙人编号 36 //合伙人编号
35 - PartnerId int64 37 + PartnerId int64
  38 + PartnerInfo PartnerInfo `pg:"fk:partner_id"`
36 //合伙人分红百分比 39 //合伙人分红百分比
37 PartnerBonusPercent float64 40 PartnerBonusPercent float64
38 //业务员分红百分比 41 //业务员分红百分比
@@ -88,12 +88,13 @@ func (c *DividendsController) Detail() { @@ -88,12 +88,13 @@ func (c *DividendsController) Detail() {
88 return 88 return
89 } 89 }
90 90
91 - cmd := OrderPaymentQuery.ListOrderPaymentQuery{ 91 + cmd := OrderPaymentQuery.GetOrderPaymentQuery{
92 OrderId: param.Id, 92 OrderId: param.Id,
93 } 93 }
94 serve := OrderPaymentSvr.NewOrderPaymentService(nil) 94 serve := OrderPaymentSvr.NewOrderPaymentService(nil)
95 var data []*domain.OrderPayment 95 var data []*domain.OrderPayment
96 - _, data, err = serve.ListOrderPayment(&cmd) 96 + var extral map[string]interface{}
  97 + extral, data, err = serve.ListOrderPayment(&cmd)
97 if err != nil { 98 if err != nil {
98 c.ResponseError(err) 99 c.ResponseError(err)
99 return 100 return
@@ -114,10 +115,10 @@ func (c *DividendsController) Detail() { @@ -114,10 +115,10 @@ func (c *DividendsController) Detail() {
114 item := data[i] 115 item := data[i]
115 payment := DividendPayment{ 116 payment := DividendPayment{
116 PaymentForGoods: item.PaymentAmount, 117 PaymentForGoods: item.PaymentAmount,
117 - UpdateTime: item.UpdateAt.Format("2006-01-02 15:04:05"), 118 + UpdateTime: item.UpdateAt.Local().Format("2006-01-02 15:04:05"),
118 StateOfPayment: item.BonusStatus, 119 StateOfPayment: item.BonusStatus,
119 Dividend: item.BonusAmount, 120 Dividend: item.BonusAmount,
120 - DividendProportion: 2, 121 + DividendProportion: extral["PartnerBonusPercent"].(float64),
121 } 122 }
122 rsp.DividendPayment = append(rsp.DividendPayment, payment) 123 rsp.DividendPayment = append(rsp.DividendPayment, payment)
123 } 124 }
@@ -125,3 +126,33 @@ func (c *DividendsController) Detail() { @@ -125,3 +126,33 @@ func (c *DividendsController) Detail() {
125 c.ResponseData(rsp) 126 c.ResponseData(rsp)
126 return 127 return
127 } 128 }
  129 +
  130 +//分红管理
  131 +func (c *DividendsController) List() {
  132 + var (
  133 + param OrderPaymentQuery.ListDividendOrdersQuery
  134 + err error
  135 + count int
  136 + )
  137 + if err = c.BindJsonData(&param); err != nil {
  138 + logs.Error(err)
  139 + c.ResponseError(errors.New("json数据解析失败"))
  140 + return
  141 + }
  142 +
  143 + if param.PageSize == 0 {
  144 + param.PageSize = 20
  145 + }
  146 + if param.PageNumber == 0 {
  147 + param.PageNumber = 1
  148 + }
  149 + serve := OrderPaymentSvr.NewOrderPaymentService(nil)
  150 + var data interface{}
  151 + count, data, err = serve.ListDividendOrders(&param)
  152 + if err != nil {
  153 + c.ResponseError(err)
  154 + return
  155 + }
  156 + c.ResponsePageList(data, count, param.PageNumber)
  157 + return
  158 +}
@@ -30,6 +30,7 @@ func init() { @@ -30,6 +30,7 @@ func init() {
30 beego.NSNamespace("/dividends", 30 beego.NSNamespace("/dividends",
31 beego.NSRouter("/edit", &controllers.DividendsController{}, "POST:Edit"), 31 beego.NSRouter("/edit", &controllers.DividendsController{}, "POST:Edit"),
32 beego.NSRouter("/detail", &controllers.DividendsController{}, "POST:Detail"), 32 beego.NSRouter("/detail", &controllers.DividendsController{}, "POST:Detail"),
  33 + beego.NSRouter("/list", &controllers.DividendsController{}, "POST:List"),
33 ), 34 ),
34 ) 35 )
35 beego.AddNamespace(adminRouter) 36 beego.AddNamespace(adminRouter)