作者 yangfu

1.短信 权限认证修改

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