作者 yangfu

1.短信 权限认证修改

... ... @@ -8,7 +8,7 @@ COPY ./go.mod go.mod
COPY ./main.go main.go
RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"]
ENV GO111MODULE on
ENV GOPROXY https://goproxy.cn
ENV GOPROXY https://goproxy.cn,direct
RUN ["go","mod","tidy"]
RUN ["go","build"]
ENTRYPOINT ["./partner"]
\ No newline at end of file
... ...
... ... @@ -31,5 +31,3 @@ require (
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
)
replace gitlab.fjmaimaimai.com/mmm-go/partner => ../partner
... ...
package dividend
import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
"time"
)
//分红统计
func DividendStatistics(header *protocol.RequestHeader, request *protocol.DividendStatisticsRequest) (rsp *protocol.DividendStatisticsResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderResponsitory, _ = factory.CreateOrderRepository(transactionContext)
beginTime = time.Unix(request.StartTime/1000, 0)
endTime = time.Unix(request.EndTime/1000, 0)
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
}()
_, orderAll, e := OrderResponsitory.Find(utils.ObjectJsonToMap(domain.OrderQueryOption{PartnerId: header.UserId, EndTime: time.Now(), SortByCreateTime: domain.DESC}))
if e != nil {
log.Error(e, beginTime, endTime)
}
var orderBetween []*domain.Order
for i := range orderAll {
if orderAll[i].CreateAt.After(beginTime) && orderAll[i].CreateAt.Before(endTime) {
orderBetween = append(orderBetween, orderAll[i])
}
}
bonusAll := AllBonusStatics(orderAll, request.DividendAction)
bonusQuarters := QuartersBonusStatics(orderBetween, request.DividendAction)
rsp = &protocol.DividendStatisticsResponse{}
rsp.Statistics = protocol.DividendStatistics{
Received: bonusAll.Received,
Outstanding: bonusAll.Outstanding,
Quarters: bonusQuarters,
}
err = transactionContext.CommitTransaction()
return
}
//累计分红
func AllBonusStatics(orders []*domain.Order, action int) (bonus protocol.Bonus) {
bonus = protocol.Bonus{}
for i := range orders {
o := orders[i]
if action == protocol.BonusTotal {
bonus.Received += o.OrderBonusReceive()
bonus.Outstanding += o.OrderBonusWait()
}
if action == protocol.BonusOutstanding {
bonus.Outstanding += o.OrderBonusOutstanding()
}
}
return
}
//订单-季度分红统计
func QuartersBonusStatics(orders []*domain.Order, action int) (bonus []protocol.Bonus) {
bonus = make([]protocol.Bonus, 4)
for i := range orders {
o := orders[i]
quarter := o.CreateAt.Month() / 4
if action == protocol.BonusTotal {
bonus[quarter].Received += o.OrderBonusReceive()
bonus[quarter].Outstanding += o.OrderBonusWait()
}
if action == protocol.BonusOutstanding {
bonus[quarter].Outstanding += o.OrderBonusOutstanding()
}
}
return
}
//分红订单
func DividendOrders(header *protocol.RequestHeader, request *protocol.DividendOrdersRequest) (rsp *protocol.DividendOrdersResponse, err error) {
var ()
rsp = &protocol.DividendOrdersResponse{}
return
}
... ...
... ... @@ -54,3 +54,17 @@ func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRe
err = transactionContext.CommitTransaction()
return
}
func OrderStatistics(header *protocol.RequestHeader, request *protocol.OrderStatisticsRequest) (rsp *protocol.OrderStatisticsResponse, err error) {
var (
//beginTime =time.Unix(request)
)
rsp = &protocol.OrderStatisticsResponse{}
return
}
func OrderList(header *protocol.RequestHeader, request *protocol.OrderListRequest) (rsp *protocol.OrderListResponse, err error) {
var ()
rsp = &protocol.OrderListResponse{}
return
}
... ...
package domain
//查询参数
const (
ASC = "ASC"
DESC = "DESC"
)
... ...
package domain
import "time"
import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
"time"
)
const (
OrderStatusReserve = iota + 1 //预定中
... ... @@ -8,6 +11,11 @@ const (
OrderStatusDeliverAll //全部发货
)
const (
OrderReal = iota + 1 //实发订单
OrderIntention //意向订单
)
type OrderRepository interface {
Save(dm *Order) (*Order, error)
Remove(dm *Order) (*Order, error)
... ... @@ -83,3 +91,35 @@ func (m *Order) Update(data map[string]interface{}) error {
m.UpdateAt = time.Now()
return nil
}
//合伙人
//订单累计分红
func (m *Order) OrderTotalBonus() float64 {
return utils.Decimal(m.OrderAmount * (m.PartnerBonusPercent / 100.0))
}
//订单已收分红
func (m *Order) OrderBonusReceive() float64 {
return utils.Decimal(m.OrderPaymentAmount * (m.PartnerBonusPercent / 100.0))
}
//订单未收分红
func (m *Order) OrderBonusWait() float64 {
return m.OrderTotalBonus() - m.OrderBonusReceive()
}
//分红支出
func (m *Order) OrderBonusOutstanding() float64 {
if m.OrderAmount <= m.OrderActualAmount {
return 0
}
return utils.Decimal((m.OrderAmount - m.OrderActualAmount) * (m.PartnerBonusPercent / 100.0))
}
type OrderQueryOption struct {
PartnerId int64 `json:"partnerId,omitempty"`
BeginTime time.Time `json:"beginTime,omitempty"`
EndTime time.Time `json:"endTime,omitempty"`
SortByCreateTime string `json:"sortByCreateTime,omitempty"`
SortByUpdateTime string `json:"sortByUpdateTime,omitempty"`
}
... ...
package domain
type OrderStatic struct {
TodayIntentionQuantity int `json:"todayIntentionQuantity"` //今日新增意向订单
TodayIntentionMoney int `json:"todayIntentionMoney"` //今日新增意向订单金额
TodayRealQuantity int `json:"todayRealQuantity"` //今日新增实发订单
TodayRealMoney int `json:"todayRealMoney"` //今日新增实发订单金额
CumulativeQuantity int `json:"cumulativeQuantity"` //累计实发订单
CumulativeMoney int `json:"cumulativeMoney"` //累计实发订单金额
}
... ...
... ... @@ -20,7 +20,7 @@ type PartnerInfo struct {
Password string `json:"password"`
// 状态(1:启用或者0:禁用)
Status int `json:"status"`
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业
// 合伙类别 (1.事业合伙人 2.业务合伙人 3.研发合伙人
PartnerCategory int `json:"partnerCategory"`
//所属区域信息
... ...
... ... @@ -9,6 +9,14 @@ type OrderDao struct {
transactionContext *transaction.TransactionContext
}
func (dao *OrderDao) OrderStatics() (count int, amount float64, err error) {
//tx :=dao.transactionContext.PgTx
//order :=new(models.Order)
//sql :=fmt.Sprintf(``,)
//q:=tx.Model(order).QueryOne()
return
}
func NewEmployeeDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
... ...
... ... @@ -67,12 +67,12 @@ func (repository *OrderRepository) Find(queryOptions map[string]interface{}) (in
Orders := make([]*domain.Order, 0)
query := NewQuery(tx.Model(&OrderModels), queryOptions)
query.
SetWhere("order.partner_id= ?", "partnerId").
SetWhere(`order.create_at >= ?`, "beginTime").
SetWhere(`order.create_at < ?`, "endTime").
SetWhere(`"order".partner_id= ?`, "partnerId").
SetWhere(`"order".create_at >= ?`, "beginTime").
SetWhere(`"order".create_at < ?`, "endTime").
SetLimit().
SetOrder("order.create_at", "sortByCreateTime").
SetOrder("order.update_at", "sortByUpdateTime")
SetOrder(`order.create_at`, "sortByCreateTime").
SetOrder(`order.update_at`, "sortByUpdateTime")
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, Orders, err
... ...
... ... @@ -6,6 +6,7 @@ import (
"fmt"
"github.com/go-pg/pg/v10/orm"
"github.com/linmadan/egglib-go/utils/snowflake"
"time"
)
var (
... ... @@ -28,6 +29,11 @@ func NewQuery(query *orm.Query, queryOptions map[string]interface{}) *Query {
func (query *Query) SetWhere(condition, key string) *Query {
if v, ok := query.queryOptions[key]; ok {
if t, e := time.Parse(time.RFC3339, fmt.Sprintf("%v", v)); e == nil {
if t.IsZero() {
return query
}
}
query.Where(condition, v)
}
return query
... ...
package utils
import (
"fmt"
"math"
"strconv"
)
func decimal(value float64) float64 {
return math.Trunc(value*1e1+0.5) * 1e-2
}
func Decimal(value float64) float64 {
value = decimal(value)
value, _ = strconv.ParseFloat(fmt.Sprintf("%.1f", value), 64)
return value
}
func DecimalToNumber(value float64) float64 {
value = decimal(value)
value, _ = strconv.ParseFloat(fmt.Sprintf("%.f", value), 64)
return value
}
... ...
package utils
import "testing"
func TestDecimal(t *testing.T) {
t.Log(Decimal(1.7999999))
t.Log(Decimal(1.7444444))
t.Log(Decimal(1.7555555))
t.Log(Decimal(1.3555555))
t.Log(Decimal(1.3000001))
t.Log(DecimalToNumber(1.0))
t.Log(DecimalToNumber(1.4))
t.Log(DecimalToNumber(1.5))
t.Log(DecimalToNumber(1.6))
t.Log(DecimalToNumber(99.0))
}
... ...
package controllers
import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/dividend"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
)
type DividendController struct {
BaseController
}
//DividendStatistics
func (this *DividendController) DividendStatistics() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.DividendStatisticsRequest
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := this.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(dividend.DividendStatistics(header, request))
}
//DividendOrders 分红订单
func (this *DividendController) DividendOrders() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.DividendOrdersRequest
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := this.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(dividend.DividendOrders(header, request))
}
... ...
... ... @@ -9,6 +9,26 @@ type OrderController struct {
BaseController
}
//OrderStatistics 订单统计
// @router /orderStatistics [post]
func (this *OrderController) OrderStatistics() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.OrderStatisticsRequest
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := this.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(order.OrderStatistics(header, request))
}
//OrderDetail 订单详情
// @router /orderDetail [post]
func (this *OrderController) OrderDetail() {
... ... @@ -28,3 +48,22 @@ func (this *OrderController) OrderDetail() {
header := this.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(order.OrderDetail(header, request))
}
//OrderList
func (this *OrderController) OrderList() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.OrderListRequest
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := this.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(order.OrderList(header, request))
}
... ...
... ... @@ -23,5 +23,7 @@ func init() {
nsV1.Router("user/changePassword", &controllers.UserController{}, "Post:ChangePassword")
nsV1.Router("order/details", &controllers.OrderController{}, "Post:OrderDetail")
nsV1.Router("dividend/statistics", &controllers.DividendController{}, "Post:DividendStatistics")
beego.AddNamespace(nsV1)
}
... ...
package protocol
const (
BonusTotal = iota //0 累计分红
BonusOutstanding //1 分红支出
)
/*DividendStatistics 分红统计*/
type DividendStatisticsRequest struct {
StartTime int64 `json:"startTime" valid:"Required"`
EndTime int64 `json:"endTime" valid:"Required"`
//分红类型(0累计分红、1分红支出)
DividendAction int `json:"dividendAction"`
}
type DividendStatisticsResponse struct {
Statistics DividendStatistics `json:"statistics"`
}
type DividendStatistics struct {
Received float64 `json:"received"` //总已收分红
Outstanding float64 `json:"outstanding"` //总未收分红/分红支出
Quarters []Bonus `json:"quarters"`
}
type Bonus struct {
Received float64 `json:"received"` //已收分红
Outstanding float64 `json:"outstanding"` //未收分红/分红支出
}
/*DividendOrders 分红订单*/
type DividendOrdersRequest struct {
DetailAction int `json:"detailAction"` //明细类型(0已收明细、1未收明细)
DividendAction int `json:"dividendAction"` //分红类型(0累计分红、1分红支出)
StartTime int64 `json:"startTime" valid:"Required"`
EndTime int64 `json:"endTime" valid:"Required"`
}
type DividendOrdersResponse struct {
}
... ...
... ... @@ -8,3 +8,17 @@ type OrderDetailResponse struct {
Order interface{} `json:"order"`
Partner interface{} `json:"partner"`
}
/*OrderStatistics */
type OrderStatisticsRequest struct {
Xxx string `json:"xxx" valid:"Required"`
}
type OrderStatisticsResponse struct {
}
/*OrderList */
type OrderListRequest struct {
Xxx string `json:"xxx" valid:"Required"`
}
type OrderListResponse struct {
}
... ...