切换导航条
此项目
正在载入...
登录
mmm-go
/
partnermg
·
提交
转到一个项目
GitLab
转到群组
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
yangfu
5 years ago
提交
31f46aa78b041f9170d2f5c626a7213892ead2f8
1 个父辈
711a9d6e
分红编辑/详情修改
隐藏空白字符变更
内嵌
并排对比
正在显示
10 个修改的文件
包含
230 行增加
和
54 行删除
go.mod
pkg/application/factory/dao.go
pkg/application/order_payment/command/create_order_payment.go
pkg/application/order_payment/service/order_payment.go
pkg/infrastructure/dao/pg_order_dao.go
pkg/infrastructure/pg/models/order.go
pkg/infrastructure/repository/pg_order_payment_reponsitory.go
pkg/infrastructure/utils/math.go
pkg/port/beego/controllers/dividends_controller.go
pkg/port/beego/routers/router.go
go.mod
查看文件 @
31f46aa
...
...
@@ -20,9 +20,9 @@ require (
github.com/moul/http2curl v1.0.0 // indirect
github.com/onsi/ginkgo v1.13.0
github.com/onsi/gomega v1.10.1
github.com/prometheus/common v0.10.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
github.com/shopspring/decimal v1.2.0
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/valyala/fasthttp v1.14.0 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
...
...
pkg/application/factory/dao.go
查看文件 @
31f46aa
...
...
@@ -20,3 +20,11 @@ func CreatePartnerInfoDao(options map[string]interface{}) (*dao.PartnerInfoDao,
}
return
dao
.
NewPartnerInfoDao
(
transactionContext
)
}
func
CreateOrderDao
(
options
map
[
string
]
interface
{})
(
*
dao
.
OrderDao
,
error
)
{
var
transactionContext
*
transaction
.
TransactionContext
if
value
,
ok
:=
options
[
"transactionContext"
];
ok
{
transactionContext
=
value
.
(
*
transaction
.
TransactionContext
)
}
return
dao
.
NewOrderDao
(
transactionContext
)
}
...
...
pkg/application/order_payment/command/create_order_payment.go
查看文件 @
31f46aa
...
...
@@ -2,7 +2,12 @@ package command
type
CreateOrderPaymentCommand
struct
{
//订单编号
OrderId
int64
`json:"orderId"`
OrderId
int64
`json:"orderId"`
DivdendPaymentItem
[]
DivdendPyamentItem
`json:"dividendPayment"`
TotalPaymentAmount
float64
`json:"payment_amount"`
}
type
DivdendPyamentItem
struct
{
// 货款
PaymentForGoods
float64
`json:"paymentForGoods,omitempty"`
// 支付状态
...
...
pkg/application/order_payment/service/order_payment.go
查看文件 @
31f46aa
...
...
@@ -25,6 +25,7 @@ func NewOrderPaymentService(options map[string]interface{}) *OrderPaymentService
func
(
OrderPaymentService
*
OrderPaymentService
)
CreateOrderPayment
(
command
*
command
.
CreateOrderPaymentCommand
)
(
data
interface
{},
err
error
)
{
var
(
transactionContext
,
_
=
factory
.
CreateTransactionContext
(
nil
)
OrderDao
,
_
=
factory
.
CreateOrderDao
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
})
)
if
err
=
command
.
ValidateCommand
();
err
!=
nil
{
return
nil
,
application
.
ThrowError
(
application
.
ARG_ERROR
,
err
.
Error
())
...
...
@@ -33,7 +34,12 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm
return
nil
,
err
}
defer
func
()
{
transactionContext
.
RollbackTransaction
()
if
err
==
nil
{
err
=
transactionContext
.
CommitTransaction
()
}
if
err
!=
nil
{
transactionContext
.
RollbackTransaction
()
}
}()
//检查订单是否存在
...
...
@@ -43,34 +49,48 @@ func (OrderPaymentService *OrderPaymentService) CreateOrderPayment(command *comm
});
err
!=
nil
{
return
nil
,
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
dm
:=
&
domain
.
OrderPayment
{
OrderId
:
command
.
OrderId
,
PartnerId
:
0
,
PaymentAmount
:
0
,
BonusAmount
:
0
,
//计算分红金额
BonusStatus
:
0
,
CreateAt
:
time
.
Now
(),
PaymentSn
:
command
.
PaymentSn
,
UpdateAt
:
time
.
Now
(),
orderBase
,
e
:=
OrderDao
.
GetOrderBaseInfo
(
command
.
OrderId
)
if
e
!=
nil
{
err
=
e
return
}
//检查货款 已存在 / 未存在
if
findDm
,
e
:=
OrderPaymentRepository
.
FindOne
(
domain
.
OrderPaymentFindOneQuery
{
OrderId
:
command
.
OrderId
,
PaymentSn
:
command
.
PaymentSn
});
e
==
nil
{
if
dm
.
BonusStatus
==
domain
.
BonusPaid
{
return
for
i
:=
range
command
.
DivdendPaymentItem
{
paymentItem
:=
command
.
DivdendPaymentItem
[
i
]
dm
:=
&
domain
.
OrderPayment
{
OrderId
:
command
.
OrderId
,
PartnerId
:
0
,
PaymentAmount
:
0
,
BonusAmount
:
0
,
//计算分红金额
BonusStatus
:
0
,
CreateAt
:
time
.
Now
(),
PaymentSn
:
paymentItem
.
PaymentSn
,
UpdateAt
:
time
.
Now
(),
}
dm
=
findDm
}
dm
.
PaymentAmount
=
command
.
PaymentForGoods
dm
.
BonusStatus
=
command
.
StateOfPayment
dm
.
BonusAmount
=
0
//检查货款 已存在 / 未存在
if
findDm
,
e
:=
OrderPaymentRepository
.
FindOne
(
domain
.
OrderPaymentFindOneQuery
{
OrderId
:
command
.
OrderId
,
PaymentSn
:
paymentItem
.
PaymentSn
});
e
==
nil
{
if
findDm
.
BonusStatus
==
domain
.
BonusPaid
{
continue
}
dm
=
findDm
}
if
data
,
err
=
OrderPaymentRepository
.
Save
(
dm
);
err
!=
nil
{
return
nil
,
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
dm
.
PartnerId
=
orderBase
[
"PartnerId"
]
.
(
int64
)
bonousPercent
:=
orderBase
[
"PartnerBonusPercent"
]
.
(
float64
)
dm
.
BonusAmount
=
paymentItem
.
PaymentForGoods
*
(
bonousPercent
/
100.0
)
dm
.
PaymentAmount
=
paymentItem
.
PaymentForGoods
dm
.
BonusStatus
=
paymentItem
.
StateOfPayment
if
data
,
err
=
OrderPaymentRepository
.
Save
(
dm
);
err
!=
nil
{
return
nil
,
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
}
err
=
transactionContext
.
CommitTransaction
()
if
err
=
OrderDao
.
Update
(
map
[
string
]
interface
{}{
"id"
:
command
.
OrderId
,
"orderPaymentAmount"
:
command
.
TotalPaymentAmount
});
err
!=
nil
{
return
}
return
}
...
...
pkg/infrastructure/dao/pg_order_dao.go
0 → 100644
查看文件 @
31f46aa
package
dao
import
(
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type
OrderDao
struct
{
transactionContext
*
transaction
.
TransactionContext
}
func
(
dao
*
OrderDao
)
Update
(
options
map
[
string
]
interface
{})
(
err
error
)
{
tx
:=
dao
.
transactionContext
.
PgTx
order
:=
new
(
models
.
Order
)
q
:=
tx
.
Model
(
order
)
if
v
,
ok
:=
options
[
"orderPaymentAmount"
];
ok
{
q
.
Set
(
"order_payment_amount = ?"
,
v
)
}
if
v
,
ok
:=
options
[
"id"
];
ok
{
q
.
Where
(
"id = ?"
,
v
)
}
_
,
err
=
q
.
Update
()
return
}
func
(
dao
*
OrderDao
)
GetOrderBaseInfo
(
id
int64
)
(
data
map
[
string
]
interface
{},
err
error
)
{
tx
:=
dao
.
transactionContext
.
PgTx
order
:=
new
(
models
.
Order
)
data
=
make
(
map
[
string
]
interface
{})
q
:=
tx
.
Model
(
order
)
q
.
Column
(
"partner_id"
,
"partner_bonus_percent"
,
"order_payment_amount"
,
"buyer"
)
q
.
Where
(
"id = ?"
,
id
)
err
=
q
.
Select
()
if
err
==
nil
{
data
[
"PartnerId"
]
=
order
.
PartnerId
data
[
"PartnerBonusPercent"
]
=
order
.
PartnerBonusPercent
data
[
"OrderPaymentAmount"
]
=
order
.
OrderPaymentAmount
data
[
"Buyer"
]
=
order
.
Buyer
}
return
}
func
NewOrderDao
(
transactionContext
*
transaction
.
TransactionContext
)
(
*
OrderDao
,
error
)
{
if
transactionContext
==
nil
{
return
nil
,
fmt
.
Errorf
(
"transactionContext参数不能为nil"
)
}
else
{
return
&
OrderDao
{
transactionContext
:
transactionContext
,
},
nil
}
}
...
...
pkg/infrastructure/pg/models/order.go
0 → 100644
查看文件 @
31f46aa
package
models
import
(
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"time"
)
type
Order
struct
{
tableName
struct
{}
`pg:"order"`
//id
Id
int64
`pg:",pk"`
//订单类型 1:实际订单 2:意向订单
OrderType
int
`pg:",notnull,default:1"`
//订单编号
OrderCode
string
`pg:",notnull`
//订单名称
OrderName
string
//订单状态
OrderStatus
int
`pg:",notnull,default:1"`
//订单数量
OrderCount
int
//实际订单数量
OrderActualCount
int
//订单金额
OrderAmount
float64
//订单实际金额
OrderActualAmount
float64
//订单已支付金额(货款)
OrderPaymentAmount
float64
//订单区域信息
OrderRegionInfo
*
domain
.
RegionInfo
Buyer
*
domain
.
Buyer
//合伙人编号
PartnerId
int64
//合伙人分红百分比
PartnerBonusPercent
float64
//业务员分红百分比
SalesmanBonusPercent
float64
//创建时间
CreateAt
time
.
Time
//更新时间
UpdateAt
time
.
Time
//上一次查看时间 已读情况
LastViewTime
time
.
Time
}
...
...
pkg/infrastructure/repository/pg_order_payment_reponsitory.go
查看文件 @
31f46aa
...
...
@@ -24,6 +24,7 @@ func (repository *OrderPaymentRepository) Save(dm *domain.OrderPayment) (*domain
BonusAmount
:
dm
.
BonusAmount
,
BonusStatus
:
dm
.
BonusStatus
,
CreateAt
:
dm
.
CreateAt
,
PaymentSn
:
dm
.
PaymentSn
,
UpdateAt
:
dm
.
UpdateAt
,
}
if
m
.
Id
==
0
{
...
...
@@ -57,8 +58,11 @@ func (repository *OrderPaymentRepository) FindOne(queryOptions domain.OrderPayme
OrderPaymentModel
:=
new
(
models
.
OrderPayment
)
query
:=
tx
.
Model
(
OrderPaymentModel
)
if
queryOptions
.
Id
>
0
{
query
.
Where
(
"order_payment.id = ?"
,
"id"
)
if
queryOptions
.
OrderId
>
0
{
query
.
Where
(
"order_payment.order_id = ?"
,
queryOptions
.
OrderId
)
}
if
queryOptions
.
PaymentSn
>
0
{
query
.
Where
(
"order_payment.payment_sn = ?"
,
queryOptions
.
PaymentSn
)
}
if
err
:=
query
.
First
();
err
!=
nil
{
return
nil
,
err
...
...
@@ -73,7 +77,7 @@ func (repository *OrderPaymentRepository) Find(queryOptions domain.OrderPaymentQ
tx
:=
repository
.
transactionContext
.
PgTx
var
OrderPaymentModels
[]
*
models
.
OrderPayment
query
:=
tx
.
Model
(
&
OrderPaymentModels
)
query
.
Where
(
"order_payment.
partner_id = ?"
,
"partnerId"
)
query
.
Where
(
"order_payment.
order_id = ?"
,
queryOptions
.
OrderId
)
var
(
err
error
rsp
=
make
([]
*
domain
.
OrderPayment
,
0
)
...
...
@@ -117,6 +121,7 @@ func (repository *OrderPaymentRepository) transformPgModelToDomainModel(dm *mode
PaymentAmount
:
dm
.
PaymentAmount
,
BonusAmount
:
dm
.
BonusAmount
,
BonusStatus
:
dm
.
BonusStatus
,
PaymentSn
:
dm
.
PaymentSn
,
CreateAt
:
dm
.
CreateAt
,
UpdateAt
:
dm
.
UpdateAt
,
}
...
...
pkg/infrastructure/utils/math.go
0 → 100644
查看文件 @
31f46aa
package
utils
import
(
"github.com/shopspring/decimal"
"math"
"math/rand"
"time"
)
func
decimal1
(
value
float64
)
float64
{
return
math
.
Trunc
(
value
*
1e1
+
0.5
)
*
1e-1
}
func
Round
(
value
float64
,
places
int32
)
float64
{
quantity
:=
decimal
.
NewFromFloat
(
value
)
d
:=
quantity
.
Round
(
places
)
rsp
,
_
:=
d
.
Float64
()
return
rsp
}
func
Decimal
(
value
float64
)
float64
{
return
Round
(
value
,
2
)
}
func
DecimalToNumber
(
value
float64
)
float64
{
return
Round
(
value
,
2
)
}
func
GenerateRangeNum
(
min
,
max
int
)
int
{
rand
.
Seed
(
time
.
Now
()
.
Unix
())
randNum
:=
rand
.
Intn
(
max
-
min
)
+
min
return
randNum
}
...
...
pkg/port/beego/controllers/dividends_controller.go
查看文件 @
31f46aa
...
...
@@ -17,12 +17,12 @@ type DividendsController struct {
////Prepare 重写 BaseController 的Prepare方法
func
(
c
*
DividendsController
)
Prepare
()
{
c
.
BaseController
.
Prepare
()
if
ok
:=
c
.
ValidJWTToken
();
!
ok
{
return
}
if
ok
:=
c
.
ValidAdminPermission
(
domain
.
PERMINSSION_PARTNER
);
!
ok
{
return
}
//if ok := c.ValidJWTToken(); !ok {
// return
//}
//if ok := c.ValidAdminPermission(domain.PERMINSSION_PARTNER); !ok {
// return
//}
}
//Edit 编辑分红支付
...
...
@@ -37,38 +37,38 @@ func (c *DividendsController) Edit() {
DividendPayment
[]
DividendPaymentItem
`json:"dividendPayment"`
}
var
(
param
Parameter
err
error
totalPaymentAmount
float64
param
Parameter
err
error
)
if
err
=
c
.
BindJsonData
(
&
param
);
err
!=
nil
{
logs
.
Error
(
err
)
c
.
ResponseError
(
errors
.
New
(
"json数据解析失败"
))
return
}
cmd
:=
OrderPaymentCmd
.
CreateOrderPaymentCommand
{
OrderId
:
param
.
Id
,
DivdendPaymentItem
:
make
([]
OrderPaymentCmd
.
DivdendPyamentItem
,
0
),
}
//编辑
for
i
:=
range
param
.
DividendPayment
{
item
:=
param
.
DividendPayment
[
i
]
cmd
:=
OrderPaymentCmd
.
CreateOrderPaymentCommand
{
OrderId
:
param
.
Id
,
PaymentSn
:
i
,
}
cmd
.
PaymentForGoods
,
_
=
strconv
.
ParseFloat
(
item
.
PaymentForGoods
,
64
)
cmd
.
StateOfPayment
,
_
=
strconv
.
Atoi
(
item
.
StateOfPayment
)
serve
:=
OrderPaymentSvr
.
NewOrderPaymentService
(
nil
)
_
,
err
=
serve
.
CreateOrderPayment
(
&
cmd
)
if
err
!=
nil
{
c
.
ResponseError
(
err
)
return
}
if
cmd
.
StateOfPayment
==
domain
.
BonusPaid
{
totalPaymentAmount
+=
cmd
.
PaymentForGoods
paymentItem
:=
OrderPaymentCmd
.
DivdendPyamentItem
{}
paymentItem
.
PaymentForGoods
,
_
=
strconv
.
ParseFloat
(
item
.
PaymentForGoods
,
64
)
paymentItem
.
StateOfPayment
,
_
=
strconv
.
Atoi
(
item
.
StateOfPayment
)
paymentItem
.
PaymentSn
=
i
+
1
if
paymentItem
.
StateOfPayment
==
domain
.
BonusPaid
{
cmd
.
TotalPaymentAmount
+=
paymentItem
.
PaymentForGoods
}
cmd
.
DivdendPaymentItem
=
append
(
cmd
.
DivdendPaymentItem
,
paymentItem
)
}
serve
:=
OrderPaymentSvr
.
NewOrderPaymentService
(
nil
)
_
,
err
=
serve
.
CreateOrderPayment
(
&
cmd
)
if
err
!=
nil
{
c
.
ResponseError
(
err
)
return
}
//保存累计支付金额到订单里面
c
.
ResponseData
(
nil
)
return
}
...
...
pkg/port/beego/routers/router.go
查看文件 @
31f46aa
...
...
@@ -27,6 +27,10 @@ func init() {
beego
.
NSRouter
(
"/detail"
,
&
controllers
.
PartnerInfoController
{},
"POST:GetPartnerInfo"
),
beego
.
NSRouter
(
"/set-status"
,
&
controllers
.
PartnerInfoController
{},
"POST:PartnerInfoSetState"
),
),
beego
.
NSNamespace
(
"/dividends"
,
beego
.
NSRouter
(
"/edit"
,
&
controllers
.
DividendsController
{},
"POST:Edit"
),
beego
.
NSRouter
(
"/detail"
,
&
controllers
.
DividendsController
{},
"POST:Detail"
),
),
)
beego
.
AddNamespace
(
adminRouter
)
}
...
...
请
注册
或
登录
后发表评论