正在显示
8 个修改的文件
包含
574 行增加
和
0 行删除
@@ -32,3 +32,12 @@ func CreateAdminPermissionRepository(options map[string]interface{}) (domain.Adm | @@ -32,3 +32,12 @@ func CreateAdminPermissionRepository(options map[string]interface{}) (domain.Adm | ||
32 | } | 32 | } |
33 | return repository.NewAdminPermissionRepository(transactionContext) | 33 | return repository.NewAdminPermissionRepository(transactionContext) |
34 | } | 34 | } |
35 | + | ||
36 | +//CreatePartnerInfoRepository 合伙人信息 | ||
37 | +func CreateOrderPaymentRepository(options map[string]interface{}) (domain.OrderPaymentRepository, error) { | ||
38 | + var transactionContext *transaction.TransactionContext | ||
39 | + if value, ok := options["transactionContext"]; ok { | ||
40 | + transactionContext = value.(*transaction.TransactionContext) | ||
41 | + } | ||
42 | + return repository.NewOrderPaymentRepository(transactionContext) | ||
43 | +} |
1 | +package command | ||
2 | + | ||
3 | +type CreateOrderPaymentCommand struct { | ||
4 | + //订单编号 | ||
5 | + OrderId int64 `json:"orderId"` | ||
6 | + // 货款 | ||
7 | + PaymentForGoods float64 `json:"paymentForGoods,omitempty"` | ||
8 | + // 支付状态 | ||
9 | + StateOfPayment int `json:"stateOfPayment,omitempty"` | ||
10 | + //支付批次 | ||
11 | + PaymentSn int `json:"paymentSn,omitempty"` | ||
12 | +} | ||
13 | + | ||
14 | +func (command CreateOrderPaymentCommand) ValidateCommand() error { | ||
15 | + return nil | ||
16 | +} |
1 | +package service | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query" | ||
8 | + "time" | ||
9 | + | ||
10 | + //"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query" | ||
11 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
12 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" | ||
13 | +) | ||
14 | + | ||
15 | +// 客户价值服务 | ||
16 | +type OrderPaymentService struct { | ||
17 | +} | ||
18 | + | ||
19 | +func NewOrderPaymentService(options map[string]interface{}) *OrderPaymentService { | ||
20 | + newOrderPaymentService := &OrderPaymentService{} | ||
21 | + return newOrderPaymentService | ||
22 | +} | ||
23 | + | ||
24 | +// 创建订单支付数据 | ||
25 | +func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *command.CreateOrderPaymentCommand) (data interface{}, err error) { | ||
26 | + var ( | ||
27 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
28 | + ) | ||
29 | + if err = command.ValidateCommand(); err != nil { | ||
30 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
31 | + } | ||
32 | + if err = transactionContext.StartTransaction(); err != nil { | ||
33 | + return nil, err | ||
34 | + } | ||
35 | + defer func() { | ||
36 | + transactionContext.RollbackTransaction() | ||
37 | + }() | ||
38 | + //检查订单是否存在 | ||
39 | + | ||
40 | + var OrderPaymentRepository domain.OrderPaymentRepository | ||
41 | + if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{ | ||
42 | + "transactionContext": transactionContext, | ||
43 | + }); err != nil { | ||
44 | + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
45 | + } | ||
46 | + | ||
47 | + dm := &domain.OrderPayment{ | ||
48 | + OrderId: command.OrderId, | ||
49 | + PartnerId: 0, | ||
50 | + PaymentAmount: 0, | ||
51 | + BonusAmount: 0, //计算分红金额 | ||
52 | + BonusStatus: 0, | ||
53 | + CreateAt: time.Now(), | ||
54 | + PaymentSn: command.PaymentSn, | ||
55 | + UpdateAt: time.Now(), | ||
56 | + } | ||
57 | + | ||
58 | + //检查货款 已存在 / 未存在 | ||
59 | + if findDm, e := OrderPaymentRepository.FindOne(domain.OrderPaymentFindOneQuery{OrderId: command.OrderId, PaymentSn: command.PaymentSn}); e == nil { | ||
60 | + if dm.BonusStatus == domain.BonusPaid { | ||
61 | + return | ||
62 | + } | ||
63 | + dm = findDm | ||
64 | + } | ||
65 | + | ||
66 | + dm.PaymentAmount = command.PaymentForGoods | ||
67 | + dm.BonusStatus = command.StateOfPayment | ||
68 | + dm.BonusAmount = 0 | ||
69 | + | ||
70 | + if data, err = OrderPaymentRepository.Save(dm); err != nil { | ||
71 | + return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
72 | + } | ||
73 | + err = transactionContext.CommitTransaction() | ||
74 | + return | ||
75 | +} | ||
76 | + | ||
77 | +//// GetOrderPayment 返回合伙人 | ||
78 | +//func (OrderPaymentService *OrderPaymentService) GetOrderPayment(command query.GetOrderPaymentQuery) (data *domain.OrderPayment, err error) { | ||
79 | +// var ( | ||
80 | +// transactionContext, _ = factory.CreateTransactionContext(nil) | ||
81 | +// ) | ||
82 | +// if err = command.ValidateQuery(); err != nil { | ||
83 | +// return nil, lib.ThrowError(lib.ARG_ERROR, err.Error()) | ||
84 | +// } | ||
85 | +// if err := transactionContext.StartTransaction(); err != nil { | ||
86 | +// return nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
87 | +// } | ||
88 | +// defer func() { | ||
89 | +// transactionContext.RollbackTransaction() | ||
90 | +// }() | ||
91 | +// var OrderPaymentRepository domain.OrderPaymentRepository | ||
92 | +// if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{ | ||
93 | +// "transactionContext": transactionContext, | ||
94 | +// }); err != nil { | ||
95 | +// return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
96 | +// } | ||
97 | +// data, err = OrderPaymentRepository.FindOne(domain.PartnerFindOneQuery{UserId: command.Id}) | ||
98 | +// if err != nil { | ||
99 | +// return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
100 | +// } | ||
101 | +// err = transactionContext.CommitTransaction() | ||
102 | +// return | ||
103 | +//} | ||
104 | +// | ||
105 | +//// 更新客户价值 | ||
106 | +//func (OrderPaymentService *OrderPaymentService) UpdateOrderPayment(updateOrderPaymentCommand *command.UpdateOrderPaymentCommand) (err error) { | ||
107 | +// var ( | ||
108 | +// transactionContext, _ = factory.CreateTransactionContext(nil) | ||
109 | +// ) | ||
110 | +// if err = updateOrderPaymentCommand.ValidateCommand(); err != nil { | ||
111 | +// return application.ThrowError(application.ARG_ERROR, err.Error()) | ||
112 | +// } | ||
113 | +// if err := transactionContext.StartTransaction(); err != nil { | ||
114 | +// return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
115 | +// } | ||
116 | +// defer func() { | ||
117 | +// transactionContext.RollbackTransaction() | ||
118 | +// }() | ||
119 | +// var OrderPaymentRepository domain.OrderPaymentRepository | ||
120 | +// if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{ | ||
121 | +// "transactionContext": transactionContext, | ||
122 | +// }); err != nil { | ||
123 | +// return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
124 | +// } | ||
125 | +// OrderPayment, err := OrderPaymentRepository.FindOne(domain.PartnerFindOneQuery{ | ||
126 | +// UserId: updateOrderPaymentCommand.Id, | ||
127 | +// }) | ||
128 | +// if err != nil { | ||
129 | +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
130 | +// } | ||
131 | +// OrderPayment.PartnerCategory = updateOrderPaymentCommand.PartnerCategory | ||
132 | +// OrderPayment.Salesman = updateOrderPaymentCommand.Salesman | ||
133 | +// OrderPayment.Status = updateOrderPaymentCommand.Status | ||
134 | +// OrderPayment.RegionInfo = updateOrderPaymentCommand.RegionInfo | ||
135 | +// if _, err = OrderPaymentRepository.Save(OrderPayment); err != nil { | ||
136 | +// return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
137 | +// } | ||
138 | +// transactionContext.CommitTransaction() | ||
139 | +// return | ||
140 | +//} | ||
141 | +// | ||
142 | +// 返回订单支付列表 | ||
143 | +func (OrderPaymentService *OrderPaymentService) ListOrderPayment(listOrderPaymentQuery *query.ListOrderPaymentQuery) (int, []*domain.OrderPayment, error) { | ||
144 | + var ( | ||
145 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
146 | + OrderPayments []*domain.OrderPayment | ||
147 | + count int | ||
148 | + err error | ||
149 | + ) | ||
150 | + if err = listOrderPaymentQuery.ValidateQuery(); err != nil { | ||
151 | + return 0, nil, lib.ThrowError(lib.ARG_ERROR, err.Error()) | ||
152 | + } | ||
153 | + if err := transactionContext.StartTransaction(); err != nil { | ||
154 | + return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
155 | + } | ||
156 | + defer func() { | ||
157 | + if err != nil { | ||
158 | + transactionContext.RollbackTransaction() | ||
159 | + } | ||
160 | + }() | ||
161 | + var OrderPaymentRepository domain.OrderPaymentRepository | ||
162 | + if OrderPaymentRepository, err = factory.CreateOrderPaymentRepository(map[string]interface{}{ | ||
163 | + "transactionContext": transactionContext, | ||
164 | + }); err != nil { | ||
165 | + return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
166 | + } | ||
167 | + queryOption := domain.OrderPaymentQuery{ | ||
168 | + OrderId: listOrderPaymentQuery.OrderId, | ||
169 | + } | ||
170 | + if OrderPayments, err = OrderPaymentRepository.Find(queryOption); err != nil { | ||
171 | + return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
172 | + } | ||
173 | + if count, err = OrderPaymentRepository.CountAll(queryOption); err != nil { | ||
174 | + return 0, nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) | ||
175 | + } | ||
176 | + if err = transactionContext.CommitTransaction(); err != nil { | ||
177 | + return 0, nil, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) | ||
178 | + } | ||
179 | + return count, OrderPayments, nil | ||
180 | +} |
pkg/domain/order_payment.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +const ( | ||
6 | + BonusWaitPay = iota + 1 //等待支付分红 | ||
7 | + BonusPaid //已经支付分红 | ||
8 | +) | ||
9 | + | ||
10 | +type OrderPayment struct { | ||
11 | + //编号 | ||
12 | + Id int64 `json:"id"` | ||
13 | + //订单编号 | ||
14 | + OrderId int64 `json:"orderId"` | ||
15 | + //合伙人编号 | ||
16 | + PartnerId int64 `json:"partnerId"` | ||
17 | + //支付序号 | ||
18 | + PaymentSn int `json:"paymentSn"` | ||
19 | + //支付货款 | ||
20 | + PaymentAmount float64 `json:"paymentAmount"` | ||
21 | + //分红金额 | ||
22 | + BonusAmount float64 `json:"bonusAmount"` | ||
23 | + //分红状态 1.等待支付分红 2.已支付分红 | ||
24 | + BonusStatus int `json:"bonusStatus"` | ||
25 | + //创建时间 | ||
26 | + CreateAt time.Time `json:"createAt"` | ||
27 | + //更新时间 | ||
28 | + UpdateAt time.Time `json:"updateAt"` | ||
29 | +} | ||
30 | + | ||
31 | +func (m *OrderPayment) Identify() interface{} { | ||
32 | + if m.Id == 0 { | ||
33 | + return nil | ||
34 | + } | ||
35 | + return m.Id | ||
36 | +} | ||
37 | + | ||
38 | +func (m *OrderPayment) Update(data map[string]interface{}) error { | ||
39 | + if m.BonusStatus != BonusWaitPay { | ||
40 | + return nil | ||
41 | + } | ||
42 | + if paymentAmount, ok := data["paymentAmount"]; ok && paymentAmount != 0 { | ||
43 | + m.PaymentAmount = paymentAmount.(float64) | ||
44 | + } | ||
45 | + if bonusAmount, ok := data["bonusAmount"]; ok && bonusAmount != 0 { | ||
46 | + m.BonusAmount = bonusAmount.(float64) | ||
47 | + } | ||
48 | + if bonusStatus, ok := data["bonusStatus"]; ok && bonusStatus != 0 { | ||
49 | + m.BonusStatus = bonusStatus.(int) | ||
50 | + } | ||
51 | + m.UpdateAt = time.Now() | ||
52 | + return nil | ||
53 | +} | ||
54 | + | ||
55 | +type OrderPaymentFindOneQuery struct { | ||
56 | + Id int64 | ||
57 | + OrderId int64 | ||
58 | + PaymentSn int | ||
59 | +} | ||
60 | +type OrderPaymentQuery struct { | ||
61 | + Offset int | ||
62 | + Limit int | ||
63 | + | ||
64 | + OrderId int64 | ||
65 | + //PartnerCategory []int //合伙人类型 | ||
66 | + //RegionInfo *RegionInfo //区域 | ||
67 | + //PartnerName string //合伙人姓名 | ||
68 | +} | ||
69 | + | ||
70 | +type OrderPaymentRepository interface { | ||
71 | + Save(dm *OrderPayment) (*OrderPayment, error) | ||
72 | + FindOne(queryOptions OrderPaymentFindOneQuery) (*OrderPayment, error) | ||
73 | + Find(queryOptions OrderPaymentQuery) ([]*OrderPayment, error) | ||
74 | + CountAll(queryOptions OrderPaymentQuery) (int, error) | ||
75 | +} |
1 | +package models | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +type OrderPayment struct { | ||
6 | + tableName struct{} `pg:"order_payment"` | ||
7 | + //编号 | ||
8 | + Id int64 `pg:",pk"` | ||
9 | + //订单编号 | ||
10 | + OrderId int64 | ||
11 | + //合伙人编号 | ||
12 | + PartnerId int64 | ||
13 | + //支付序号 | ||
14 | + PaymentSn int | ||
15 | + //支付货款 | ||
16 | + PaymentAmount float64 `pg:",notnull,default:0"` | ||
17 | + //分红金额 | ||
18 | + BonusAmount float64 | ||
19 | + //分红状态 1.等待支付分红 2.已支付分红 | ||
20 | + BonusStatus int `pg:",notnull,default:1"` | ||
21 | + //创建时间 | ||
22 | + CreateAt time.Time | ||
23 | + //更新时间 | ||
24 | + UpdateAt time.Time | ||
25 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction" | ||
8 | +) | ||
9 | + | ||
10 | +type OrderPaymentRepository struct { | ||
11 | + transactionContext *transaction.TransactionContext | ||
12 | +} | ||
13 | + | ||
14 | +func (repository *OrderPaymentRepository) Save(dm *domain.OrderPayment) (*domain.OrderPayment, error) { | ||
15 | + var ( | ||
16 | + err error | ||
17 | + tx = repository.transactionContext.PgTx | ||
18 | + ) | ||
19 | + m := &models.OrderPayment{ | ||
20 | + Id: dm.Id, | ||
21 | + OrderId: dm.OrderId, | ||
22 | + PartnerId: dm.PartnerId, | ||
23 | + PaymentAmount: dm.PaymentAmount, | ||
24 | + BonusAmount: dm.BonusAmount, | ||
25 | + BonusStatus: dm.BonusStatus, | ||
26 | + CreateAt: dm.CreateAt, | ||
27 | + UpdateAt: dm.UpdateAt, | ||
28 | + } | ||
29 | + if m.Id == 0 { | ||
30 | + err = tx.Insert(m) | ||
31 | + dm.Id = m.Id | ||
32 | + if err != nil { | ||
33 | + return nil, err | ||
34 | + } | ||
35 | + } else { | ||
36 | + err = tx.Update(m) | ||
37 | + if err != nil { | ||
38 | + return nil, err | ||
39 | + } | ||
40 | + } | ||
41 | + return dm, nil | ||
42 | +} | ||
43 | + | ||
44 | +func (repository *OrderPaymentRepository) Remove(OrderPayment *domain.OrderPayment) (*domain.OrderPayment, error) { | ||
45 | + var ( | ||
46 | + tx = repository.transactionContext.PgTx | ||
47 | + OrderPaymentModel = &models.OrderPayment{Id: OrderPayment.Identify().(int64)} | ||
48 | + ) | ||
49 | + if _, err := tx.Model(OrderPaymentModel).Where("id = ?", OrderPayment.Id).Delete(); err != nil { | ||
50 | + return OrderPayment, err | ||
51 | + } | ||
52 | + return OrderPayment, nil | ||
53 | +} | ||
54 | + | ||
55 | +func (repository *OrderPaymentRepository) FindOne(queryOptions domain.OrderPaymentFindOneQuery) (*domain.OrderPayment, error) { | ||
56 | + tx := repository.transactionContext.PgTx | ||
57 | + OrderPaymentModel := new(models.OrderPayment) | ||
58 | + query := tx.Model(OrderPaymentModel) | ||
59 | + | ||
60 | + if queryOptions.Id > 0 { | ||
61 | + query.Where("order_payment.id = ?", "id") | ||
62 | + } | ||
63 | + if err := query.First(); err != nil { | ||
64 | + return nil, err | ||
65 | + } | ||
66 | + if OrderPaymentModel.Id == 0 { | ||
67 | + return nil, nil | ||
68 | + } | ||
69 | + return repository.transformPgModelToDomainModel(OrderPaymentModel) | ||
70 | +} | ||
71 | + | ||
72 | +func (repository *OrderPaymentRepository) Find(queryOptions domain.OrderPaymentQuery) ([]*domain.OrderPayment, error) { | ||
73 | + tx := repository.transactionContext.PgTx | ||
74 | + var OrderPaymentModels []*models.OrderPayment | ||
75 | + query := tx.Model(&OrderPaymentModels) | ||
76 | + query.Where("order_payment.partner_id = ?", "partnerId") | ||
77 | + var ( | ||
78 | + err error | ||
79 | + rsp = make([]*domain.OrderPayment, 0) | ||
80 | + ) | ||
81 | + err = query.Select() | ||
82 | + if err != nil { | ||
83 | + return rsp, err | ||
84 | + } | ||
85 | + for i := range OrderPaymentModels { | ||
86 | + dm, err := repository.transformPgModelToDomainModel(OrderPaymentModels[i]) | ||
87 | + if err != nil { | ||
88 | + return rsp, err | ||
89 | + } | ||
90 | + rsp = append(rsp, dm) | ||
91 | + } | ||
92 | + return rsp, nil | ||
93 | +} | ||
94 | + | ||
95 | +func (repository OrderPaymentRepository) CountAll(queryOption domain.OrderPaymentQuery) (int, error) { | ||
96 | + db := repository.transactionContext.PgDd | ||
97 | + partnerModels := models.PartnerInfo{} | ||
98 | + query := db.Model(&partnerModels) | ||
99 | + //if len(queryOption.PartnerName) > 0 { | ||
100 | + // query = query.Where("partner_name like ?", "%"+queryOption.PartnerName+"%") | ||
101 | + //} | ||
102 | + //if queryOption.RegionInfo != nil { | ||
103 | + // query = query.Where("region_info::jsonb->>'regionName' like ?", "%"+queryOption.RegionInfo.RegionName+"%") | ||
104 | + //} | ||
105 | + //if len(queryOption.PartnerCategory) > 0 { | ||
106 | + // query = query.WhereIn("partner_category in(?)", queryOption.PartnerCategory) | ||
107 | + //} | ||
108 | + cnt, err := query.Count() | ||
109 | + return cnt, err | ||
110 | +} | ||
111 | + | ||
112 | +func (repository *OrderPaymentRepository) transformPgModelToDomainModel(dm *models.OrderPayment) (*domain.OrderPayment, error) { | ||
113 | + m := &domain.OrderPayment{ | ||
114 | + Id: dm.Id, | ||
115 | + OrderId: dm.OrderId, | ||
116 | + PartnerId: dm.PartnerId, | ||
117 | + PaymentAmount: dm.PaymentAmount, | ||
118 | + BonusAmount: dm.BonusAmount, | ||
119 | + BonusStatus: dm.BonusStatus, | ||
120 | + CreateAt: dm.CreateAt, | ||
121 | + UpdateAt: dm.UpdateAt, | ||
122 | + } | ||
123 | + return m, nil | ||
124 | +} | ||
125 | + | ||
126 | +func NewOrderPaymentRepository(transactionContext *transaction.TransactionContext) (*OrderPaymentRepository, error) { | ||
127 | + if transactionContext == nil { | ||
128 | + return nil, fmt.Errorf("transactionContext参数不能为nil") | ||
129 | + } | ||
130 | + return &OrderPaymentRepository{transactionContext: transactionContext}, nil | ||
131 | +} |
1 | +package controllers | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "github.com/astaxie/beego/logs" | ||
6 | + OrderPaymentCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/command" | ||
7 | + OrderPaymentQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/query" | ||
8 | + OrderPaymentSvr "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order_payment/service" | ||
9 | + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain" | ||
10 | + "strconv" | ||
11 | +) | ||
12 | + | ||
13 | +type DividendsController struct { | ||
14 | + BaseController | ||
15 | +} | ||
16 | + | ||
17 | +////Prepare 重写 BaseController 的Prepare方法 | ||
18 | +func (c *DividendsController) Prepare() { | ||
19 | + c.BaseController.Prepare() | ||
20 | + if ok := c.ValidJWTToken(); !ok { | ||
21 | + return | ||
22 | + } | ||
23 | + if ok := c.ValidAdminPermission(domain.PERMINSSION_PARTNER); !ok { | ||
24 | + return | ||
25 | + } | ||
26 | +} | ||
27 | + | ||
28 | +//Edit 编辑分红支付 | ||
29 | +func (c *DividendsController) Edit() { | ||
30 | + //用与适配前端定义的数据结构 | ||
31 | + type DividendPaymentItem struct { | ||
32 | + PaymentForGoods string `json:"paymentForGoods"` | ||
33 | + StateOfPayment string `json:"stateOfPayment"` | ||
34 | + } | ||
35 | + type Parameter struct { | ||
36 | + Id int64 `json:"id"` //订单编号 | ||
37 | + DividendPayment []DividendPaymentItem `json:"dividendPayment"` | ||
38 | + } | ||
39 | + var ( | ||
40 | + param Parameter | ||
41 | + err error | ||
42 | + totalPaymentAmount float64 | ||
43 | + ) | ||
44 | + if err = c.BindJsonData(¶m); err != nil { | ||
45 | + logs.Error(err) | ||
46 | + c.ResponseError(errors.New("json数据解析失败")) | ||
47 | + return | ||
48 | + } | ||
49 | + | ||
50 | + //编辑 | ||
51 | + for i := range param.DividendPayment { | ||
52 | + item := param.DividendPayment[i] | ||
53 | + cmd := OrderPaymentCmd.CreateOrderPaymentCommand{ | ||
54 | + OrderId: param.Id, | ||
55 | + PaymentSn: i, | ||
56 | + } | ||
57 | + cmd.PaymentForGoods, _ = strconv.ParseFloat(item.PaymentForGoods, 64) | ||
58 | + cmd.StateOfPayment, _ = strconv.Atoi(item.StateOfPayment) | ||
59 | + serve := OrderPaymentSvr.NewOrderPaymentService(nil) | ||
60 | + _, err = serve.CreateOrderPayment(&cmd) | ||
61 | + if err != nil { | ||
62 | + c.ResponseError(err) | ||
63 | + return | ||
64 | + } | ||
65 | + if cmd.StateOfPayment == domain.BonusPaid { | ||
66 | + totalPaymentAmount += cmd.PaymentForGoods | ||
67 | + } | ||
68 | + } | ||
69 | + | ||
70 | + //保存累计支付金额到订单里面 | ||
71 | + | ||
72 | + c.ResponseData(nil) | ||
73 | + return | ||
74 | +} | ||
75 | + | ||
76 | +//Edit 分红支付详情 | ||
77 | +func (c *DividendsController) Detail() { | ||
78 | + type Parameter struct { | ||
79 | + Id int64 `json:"id"` //订单编号 | ||
80 | + } | ||
81 | + var ( | ||
82 | + param Parameter | ||
83 | + err error | ||
84 | + ) | ||
85 | + if err = c.BindJsonData(¶m); err != nil { | ||
86 | + logs.Error(err) | ||
87 | + c.ResponseError(errors.New("json数据解析失败")) | ||
88 | + return | ||
89 | + } | ||
90 | + | ||
91 | + cmd := OrderPaymentQuery.ListOrderPaymentQuery{ | ||
92 | + OrderId: param.Id, | ||
93 | + } | ||
94 | + serve := OrderPaymentSvr.NewOrderPaymentService(nil) | ||
95 | + var data []*domain.OrderPayment | ||
96 | + _, data, err = serve.ListOrderPayment(&cmd) | ||
97 | + if err != nil { | ||
98 | + c.ResponseError(err) | ||
99 | + return | ||
100 | + } | ||
101 | + | ||
102 | + type DividendPayment struct { | ||
103 | + PaymentForGoods float64 `json:"paymentForGoods"` | ||
104 | + UpdateTime string `json:"updateTime"` | ||
105 | + StateOfPayment int `json:"stateOfPayment"` | ||
106 | + Dividend float64 `json:"dividend"` | ||
107 | + DividendProportion float64 `json:"dividendProportion"` | ||
108 | + } | ||
109 | + type Response struct { | ||
110 | + DividendPayment []DividendPayment `json:"dividendPayment"` | ||
111 | + } | ||
112 | + rsp := Response{DividendPayment: make([]DividendPayment, 0)} | ||
113 | + for i := range data { | ||
114 | + item := data[i] | ||
115 | + payment := DividendPayment{ | ||
116 | + PaymentForGoods: item.PaymentAmount, | ||
117 | + UpdateTime: item.UpdateAt.Format("2006-01-02 15:04:05"), | ||
118 | + StateOfPayment: item.BonusStatus, | ||
119 | + Dividend: item.BonusAmount, | ||
120 | + DividendProportion: 2, | ||
121 | + } | ||
122 | + rsp.DividendPayment = append(rsp.DividendPayment, payment) | ||
123 | + } | ||
124 | + | ||
125 | + c.ResponseData(rsp) | ||
126 | + return | ||
127 | +} |
-
请 注册 或 登录 后发表评论