正在显示
18 个修改的文件
包含
335 行增加
和
43 行删除
| @@ -52,6 +52,8 @@ spec: | @@ -52,6 +52,8 @@ spec: | ||
| 52 | - mountPath: /opt/logs | 52 | - mountPath: /opt/logs |
| 53 | name: accesslogs | 53 | name: accesslogs |
| 54 | env: | 54 | env: |
| 55 | + - name: RUN_MODE | ||
| 56 | + value: 8082 | ||
| 55 | - name: POSTGRESQL_DB_NAME | 57 | - name: POSTGRESQL_DB_NAME |
| 56 | value: "mmmpartner_dev" | 58 | value: "mmmpartner_dev" |
| 57 | - name: POSTGRESQL_USER | 59 | - name: POSTGRESQL_USER |
| @@ -52,6 +52,8 @@ spec: | @@ -52,6 +52,8 @@ spec: | ||
| 52 | - mountPath: /opt/logs | 52 | - mountPath: /opt/logs |
| 53 | name: accesslogs | 53 | name: accesslogs |
| 54 | env: | 54 | env: |
| 55 | + - name: RUN_MODE | ||
| 56 | + value: 8082 | ||
| 55 | - name: POSTGRESQL_DB_NAME | 57 | - name: POSTGRESQL_DB_NAME |
| 56 | value: "partner" | 58 | value: "partner" |
| 57 | - name: POSTGRESQL_USER | 59 | - name: POSTGRESQL_USER |
| @@ -62,6 +62,8 @@ spec: | @@ -62,6 +62,8 @@ spec: | ||
| 62 | configMapKeyRef: | 62 | configMapKeyRef: |
| 63 | name: suplus-config | 63 | name: suplus-config |
| 64 | key: redis.port | 64 | key: redis.port |
| 65 | + - name: RUN_MODE | ||
| 66 | + value: 8082 | ||
| 65 | - name: POSTGRESQL_DB_NAME | 67 | - name: POSTGRESQL_DB_NAME |
| 66 | value: "partner_test" | 68 | value: "partner_test" |
| 67 | - name: POSTGRESQL_USER | 69 | - name: POSTGRESQL_USER |
| @@ -8,5 +8,6 @@ require ( | @@ -8,5 +8,6 @@ require ( | ||
| 8 | github.com/go-pg/pg/v10 v10.0.0-beta.2 | 8 | github.com/go-pg/pg/v10 v10.0.0-beta.2 |
| 9 | github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 | 9 | github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 |
| 10 | github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect | 10 | github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect |
| 11 | + github.com/shopspring/decimal v1.2.0 | ||
| 11 | github.com/tiptok/gocomm v0.0.0-20190919092013-c230743f8095 | 12 | github.com/tiptok/gocomm v0.0.0-20190919092013-c230743f8095 |
| 12 | ) | 13 | ) |
| 1 | package factory | 1 | package factory |
| 2 | 2 | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/dao" | ||
| 5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | ||
| 6 | +) | ||
| 7 | + | ||
| 3 | //func CreateTaskDao(options map[string]interface{}) (*dao.TaskDao, error) { | 8 | //func CreateTaskDao(options map[string]interface{}) (*dao.TaskDao, error) { |
| 4 | // var transactionContext *pg.TransactionContext | 9 | // var transactionContext *pg.TransactionContext |
| 5 | // if value, ok := options["transactionContext"]; ok { | 10 | // if value, ok := options["transactionContext"]; ok { |
| @@ -7,3 +12,7 @@ package factory | @@ -7,3 +12,7 @@ package factory | ||
| 7 | // } | 12 | // } |
| 8 | // return dao.NewTaskDao(transactionContext) | 13 | // return dao.NewTaskDao(transactionContext) |
| 9 | //} | 14 | //} |
| 15 | + | ||
| 16 | +func CreateOrderDao(ctx *transaction.TransactionContext) (*dao.OrderDao, error) { | ||
| 17 | + return dao.NewOrderDao(ctx) | ||
| 18 | +} |
| @@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
| 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" |
| 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" | 6 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" |
| 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" | 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" |
| 8 | + "time" | ||
| 8 | ) | 9 | ) |
| 9 | 10 | ||
| 10 | func Template(header *protocol.RequestHeader, request *protocol.OrderDetailRequest) (rsp *protocol.OrderDetailResponse, err error) { | 11 | func Template(header *protocol.RequestHeader, request *protocol.OrderDetailRequest) (rsp *protocol.OrderDetailResponse, err error) { |
| @@ -25,13 +26,13 @@ func Template(header *protocol.RequestHeader, request *protocol.OrderDetailReque | @@ -25,13 +26,13 @@ func Template(header *protocol.RequestHeader, request *protocol.OrderDetailReque | ||
| 25 | return | 26 | return |
| 26 | } | 27 | } |
| 27 | 28 | ||
| 29 | +//订单详情 | ||
| 28 | func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRequest) (rsp *protocol.OrderDetailResponse, err error) { | 30 | func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRequest) (rsp *protocol.OrderDetailResponse, err error) { |
| 29 | var ( | 31 | var ( |
| 30 | transactionContext, _ = factory.CreateTransactionContext(nil) | 32 | transactionContext, _ = factory.CreateTransactionContext(nil) |
| 31 | OrderResponsitory, _ = factory.CreateOrderRepository(transactionContext) | 33 | OrderResponsitory, _ = factory.CreateOrderRepository(transactionContext) |
| 32 | - PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) | 34 | + //PartnerInfoRepository, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) |
| 33 | order *domain.Order | 35 | order *domain.Order |
| 34 | - partner *domain.PartnerInfo | ||
| 35 | ) | 36 | ) |
| 36 | if err = transactionContext.StartTransaction(); err != nil { | 37 | if err = transactionContext.StartTransaction(); err != nil { |
| 37 | return nil, err | 38 | return nil, err |
| @@ -46,25 +47,163 @@ func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRe | @@ -46,25 +47,163 @@ func OrderDetail(header *protocol.RequestHeader, request *protocol.OrderDetailRe | ||
| 46 | if order, err = OrderResponsitory.FindOne(utils.ObjectJsonToMap(request)); err != nil { | 47 | if order, err = OrderResponsitory.FindOne(utils.ObjectJsonToMap(request)); err != nil { |
| 47 | return | 48 | return |
| 48 | } | 49 | } |
| 49 | - if partner, err = PartnerInfoRepository.FindOne(map[string]interface{}{"partnerId": order.PartnerId}); err != nil { | ||
| 50 | - return | 50 | + //if partner, err = PartnerInfoRepository.FindOne(map[string]interface{}{"partnerId": order.PartnerId}); err != nil { |
| 51 | + // return | ||
| 52 | + //} | ||
| 53 | + rsp.Order = protocol.OrderDetail{ | ||
| 54 | + Id: order.Id, | ||
| 55 | + OrderNo: order.OrderCode, | ||
| 56 | + OrderName: order.OrderName, | ||
| 57 | + OrderStatus: order.OrderStatus, | ||
| 58 | + CreateTime: order.CreateAt.Unix() * 1000, | ||
| 59 | + UpdateTime: order.UpdateAt.Unix() * 1000, | ||
| 60 | + OrderQuantity: order.OrderCount, | ||
| 61 | + OrderAmount: order.OrderAmount, | ||
| 62 | + OrderAmountCancel: order.OrderAmountCancel(), | ||
| 63 | + OrderDistrict: map[string]interface{}{"id": order.OrderRegionInfo.RegionId, "name": order.OrderRegionInfo.RegionName}, | ||
| 64 | + Customer: protocol.Customer{Uname: order.Buyer.BuyerName, Phone: order.Buyer.ContactInfo}, | ||
| 65 | + MyDividend: order.OrderTotalBonus(), | ||
| 66 | + MyDividendPercent: order.PartnerBonusPercent, | ||
| 51 | } | 67 | } |
| 52 | - rsp.Order = order | ||
| 53 | - rsp.Partner = partner | ||
| 54 | err = transactionContext.CommitTransaction() | 68 | err = transactionContext.CommitTransaction() |
| 55 | return | 69 | return |
| 56 | } | 70 | } |
| 57 | 71 | ||
| 72 | +//订单统计 | ||
| 58 | func OrderStatistics(header *protocol.RequestHeader, request *protocol.OrderStatisticsRequest) (rsp *protocol.OrderStatisticsResponse, err error) { | 73 | func OrderStatistics(header *protocol.RequestHeader, request *protocol.OrderStatisticsRequest) (rsp *protocol.OrderStatisticsResponse, err error) { |
| 59 | var ( | 74 | var ( |
| 60 | - //beginTime =time.Unix(request) | 75 | + transactionContext, _ = factory.CreateTransactionContext(nil) |
| 76 | + OrderDao, _ = factory.CreateOrderDao(transactionContext) | ||
| 61 | ) | 77 | ) |
| 62 | - rsp = &protocol.OrderStatisticsResponse{} | 78 | + if err = transactionContext.StartTransaction(); err != nil { |
| 79 | + return nil, err | ||
| 80 | + } | ||
| 81 | + defer func() { | ||
| 82 | + if err != nil { | ||
| 83 | + transactionContext.RollbackTransaction() | ||
| 84 | + } | ||
| 85 | + }() | ||
| 86 | + rsp = &protocol.OrderStatisticsResponse{Statistics: protocol.OrderStatics{}} | ||
| 87 | + if rsp.Statistics.TodayIntentionQuantity, rsp.Statistics.TodayIntentionMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 88 | + BeginTime: utils.GetDayBegin().Unix() * 1000, | ||
| 89 | + EndTime: utils.GetDayEnd().Unix() * 1000, | ||
| 90 | + OrderType: domain.OrderIntention, | ||
| 91 | + PartnerId: header.UserId, | ||
| 92 | + }); err != nil { | ||
| 93 | + return | ||
| 94 | + } | ||
| 95 | + if rsp.Statistics.TodayRealQuantity, rsp.Statistics.TodayRealMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 96 | + BeginTime: utils.GetDayBegin().Unix() * 1000, | ||
| 97 | + EndTime: utils.GetDayEnd().Unix() * 1000, | ||
| 98 | + OrderType: domain.OrderReal, | ||
| 99 | + PartnerId: header.UserId, | ||
| 100 | + }); err != nil { | ||
| 101 | + return | ||
| 102 | + } | ||
| 103 | + if rsp.Statistics.CumulativeQuantity, rsp.Statistics.CumulativeMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 104 | + EndTime: time.Now().Unix() * 1000, | ||
| 105 | + OrderType: domain.OrderReal, | ||
| 106 | + PartnerId: header.UserId, | ||
| 107 | + }); err != nil { | ||
| 108 | + return | ||
| 109 | + } | ||
| 110 | + err = transactionContext.CommitTransaction() | ||
| 63 | return | 111 | return |
| 64 | } | 112 | } |
| 65 | 113 | ||
| 114 | +//订单列表 | ||
| 66 | func OrderList(header *protocol.RequestHeader, request *protocol.OrderListRequest) (rsp *protocol.OrderListResponse, err error) { | 115 | func OrderList(header *protocol.RequestHeader, request *protocol.OrderListRequest) (rsp *protocol.OrderListResponse, err error) { |
| 67 | - var () | ||
| 68 | - rsp = &protocol.OrderListResponse{} | 116 | + var ( |
| 117 | + transactionContext, _ = factory.CreateTransactionContext(nil) | ||
| 118 | + OrderResponsitory, _ = factory.CreateOrderRepository(transactionContext) | ||
| 119 | + OrderDao, _ = factory.CreateOrderDao(transactionContext) | ||
| 120 | + orders []*domain.Order | ||
| 121 | + ) | ||
| 122 | + | ||
| 123 | + rsp = &protocol.OrderListResponse{ | ||
| 124 | + List: make([]*protocol.OrderListItem, 0), | ||
| 125 | + Statistics: make(map[string]interface{}), | ||
| 126 | + } | ||
| 127 | + if err = transactionContext.StartTransaction(); err != nil { | ||
| 128 | + return nil, err | ||
| 129 | + } | ||
| 130 | + defer func() { | ||
| 131 | + err = transactionContext.CommitTransaction() | ||
| 132 | + if err != nil { | ||
| 133 | + transactionContext.RollbackTransaction() | ||
| 134 | + } | ||
| 135 | + }() | ||
| 136 | + queryOption := &domain.OrderQueryOption{ | ||
| 137 | + PartnerId: header.UserId, | ||
| 138 | + OrderType: request.OrderAction, | ||
| 139 | + Limit: request.PageSize, | ||
| 140 | + Offset: request.PageSize * request.PageIndex, | ||
| 141 | + SortByUpdateTime: domain.DESC, | ||
| 142 | + } | ||
| 143 | + if request.StartTime > 0 { | ||
| 144 | + queryOption.BeginTime = time.Unix(request.StartTime/1000, 0) | ||
| 145 | + } | ||
| 146 | + if request.EndTime > 0 { | ||
| 147 | + queryOption.EndTime = time.Unix(request.EndTime/1000, 0) | ||
| 148 | + } | ||
| 149 | + _, orders, _ = OrderResponsitory.Find(utils.ObjectJsonToMap(queryOption)) | ||
| 150 | + //统计数据 | ||
| 151 | + if request.PageIndex == 0 { | ||
| 152 | + //部分发货的订单数量 | ||
| 153 | + rsp.Statistics["partShipmentQuantity"], _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 154 | + EndTime: time.Now().Unix() * 1000, | ||
| 155 | + OrderType: domain.OrderReal, | ||
| 156 | + PartnerId: header.UserId, | ||
| 157 | + OrderStatus: domain.OrderStatusDeliverSome, | ||
| 158 | + }) | ||
| 159 | + //全部发货的订单数量 | ||
| 160 | + rsp.Statistics["allShipmentQuantity"], _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 161 | + EndTime: time.Now().Unix() * 1000, | ||
| 162 | + OrderType: domain.OrderReal, | ||
| 163 | + PartnerId: header.UserId, | ||
| 164 | + OrderStatus: domain.OrderStatusDeliverAll, | ||
| 165 | + }) | ||
| 166 | + var ( | ||
| 167 | + cumulativeQuantity, intentionQuantity int | ||
| 168 | + ) | ||
| 169 | + //累计实发订单 | ||
| 170 | + cumulativeQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 171 | + EndTime: time.Now().Unix() * 1000, | ||
| 172 | + OrderType: domain.OrderReal, | ||
| 173 | + PartnerId: header.UserId, | ||
| 174 | + }) | ||
| 175 | + //累计意向订单 | ||
| 176 | + intentionQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{ | ||
| 177 | + EndTime: time.Now().Unix() * 1000, | ||
| 178 | + OrderType: domain.OrderIntention, | ||
| 179 | + PartnerId: header.UserId, | ||
| 180 | + }) | ||
| 181 | + //订单数量 | ||
| 182 | + rsp.Statistics["orderQuantity"] = cumulativeQuantity + intentionQuantity | ||
| 183 | + rsp.Statistics["cumulativeQuantity"] = cumulativeQuantity | ||
| 184 | + rsp.Statistics["intentionQuantity"] = intentionQuantity | ||
| 185 | + | ||
| 186 | + } | ||
| 187 | + | ||
| 188 | + if len(orders) == 0 { | ||
| 69 | return | 189 | return |
| 190 | + } | ||
| 191 | + for i := range orders { | ||
| 192 | + rsp.List = append(rsp.List, DomainOrderToOrderListItem(orders[i])) | ||
| 193 | + } | ||
| 194 | + return | ||
| 195 | +} | ||
| 196 | +func DomainOrderToOrderListItem(order *domain.Order) *protocol.OrderListItem { | ||
| 197 | + return &protocol.OrderListItem{ | ||
| 198 | + Id: order.Id, | ||
| 199 | + OrderType: order.OrderType, | ||
| 200 | + OrderNo: order.OrderCode, | ||
| 201 | + OrderName: order.OrderName, | ||
| 202 | + OrderAmount: order.OrderAmount, | ||
| 203 | + OrderActualCount: order.OrderActualCount, | ||
| 204 | + OrderStatus: order.OrderStatus, | ||
| 205 | + UpdateTime: order.UpdateAt.Unix() * 1000, | ||
| 206 | + MyDividend: order.OrderTotalBonus(), | ||
| 207 | + IsRead: order.IsRead(), | ||
| 208 | + } | ||
| 70 | } | 209 | } |
| @@ -116,10 +116,28 @@ func (m *Order) OrderBonusOutstanding() float64 { | @@ -116,10 +116,28 @@ func (m *Order) OrderBonusOutstanding() float64 { | ||
| 116 | return utils.Decimal((m.OrderAmount - m.OrderActualAmount) * (m.PartnerBonusPercent / 100.0)) | 116 | return utils.Decimal((m.OrderAmount - m.OrderActualAmount) * (m.PartnerBonusPercent / 100.0)) |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | +//订单被取消金额 | ||
| 120 | +func (m *Order) OrderAmountCancel() float64 { | ||
| 121 | + if m.OrderAmount <= m.OrderActualAmount { | ||
| 122 | + return 0 | ||
| 123 | + } | ||
| 124 | + return utils.Decimal((m.OrderAmount - m.OrderActualAmount)) | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +func (m *Order) IsRead() int { | ||
| 128 | + if m.UpdateAt.After(m.LastViewTime) { | ||
| 129 | + return 0 | ||
| 130 | + } | ||
| 131 | + return 1 | ||
| 132 | +} | ||
| 133 | + | ||
| 119 | type OrderQueryOption struct { | 134 | type OrderQueryOption struct { |
| 120 | PartnerId int64 `json:"partnerId,omitempty"` | 135 | PartnerId int64 `json:"partnerId,omitempty"` |
| 136 | + OrderType int `json:"orderType,omitempty"` | ||
| 121 | BeginTime time.Time `json:"beginTime,omitempty"` | 137 | BeginTime time.Time `json:"beginTime,omitempty"` |
| 122 | EndTime time.Time `json:"endTime,omitempty"` | 138 | EndTime time.Time `json:"endTime,omitempty"` |
| 123 | SortByCreateTime string `json:"sortByCreateTime,omitempty"` | 139 | SortByCreateTime string `json:"sortByCreateTime,omitempty"` |
| 124 | SortByUpdateTime string `json:"sortByUpdateTime,omitempty"` | 140 | SortByUpdateTime string `json:"sortByUpdateTime,omitempty"` |
| 141 | + Offset int `json:"offset,omitempty"` | ||
| 142 | + Limit int `json:"limit,omitempty"` | ||
| 125 | } | 143 | } |
| 1 | package domain | 1 | package domain |
| 2 | 2 | ||
| 3 | +//type OrderTodayStatic 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 | +//} | ||
| 11 | +////实发订单统计 | ||
| 12 | +//type OrderRealStatic struct { | ||
| 13 | +// CumulativeQuantity int `json:"cumulativeQuantity"` //累计实发订单 | ||
| 14 | +// CumulativeMoney int `json:"cumulativeMoney"` //累计实发订单金额 | ||
| 15 | +//} | ||
| 16 | +////意向订单统计 | ||
| 17 | +//type OrderIntentionStatic struct { | ||
| 18 | +// CumulativeQuantity int `json:"cumulativeQuantity"` //累计意向订单 | ||
| 19 | +// CumulativeMoney int `json:"cumulativeMoney"` //累计意向订单金额 | ||
| 20 | +//} | ||
| 21 | + | ||
| 3 | type OrderStatic struct { | 22 | 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"` //累计实发订单金额 | 23 | + CumulativeQuantity int `json:"cumulativeQuantity"` //累计数量 |
| 24 | + CumulativeMoney int `json:"cumulativeMoney"` //累计金额 | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +type OrderStaticQuery struct { | ||
| 28 | + PartnerId int64 `json:"partnerId,omitempty"` | ||
| 29 | + BeginTime int64 `json:"beginTime,omitempty"` | ||
| 30 | + EndTime int64 `json:"endTime,omitempty"` | ||
| 31 | + OrderStatus int `json:"orderStatus,omitempty"` | ||
| 32 | + OrderType int `json:"orderType,omitempty"` | ||
| 10 | } | 33 | } |
| @@ -2,22 +2,42 @@ package dao | @@ -2,22 +2,42 @@ package dao | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" | ||
| 6 | + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models" | ||
| 5 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" | 7 | "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" |
| 8 | + "time" | ||
| 6 | ) | 9 | ) |
| 7 | 10 | ||
| 8 | type OrderDao struct { | 11 | type OrderDao struct { |
| 9 | transactionContext *transaction.TransactionContext | 12 | transactionContext *transaction.TransactionContext |
| 10 | } | 13 | } |
| 11 | 14 | ||
| 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() | 15 | +func (dao *OrderDao) OrderStatics(option *domain.OrderStaticQuery) (count int, amount float64, err error) { |
| 16 | + tx := dao.transactionContext.PgTx | ||
| 17 | + order := new(models.Order) | ||
| 18 | + q := tx.Model(order) | ||
| 19 | + q.ColumnExpr("count(*) count") | ||
| 20 | + q.ColumnExpr("sum(order_amount) total_order_amount") | ||
| 21 | + if option.PartnerId > 0 { | ||
| 22 | + q.Where(`"order".partner_id =?`, option.PartnerId) | ||
| 23 | + } | ||
| 24 | + if option.OrderType > 0 { | ||
| 25 | + q.Where(`"order".order_type =?`, option.OrderType) | ||
| 26 | + } | ||
| 27 | + if option.OrderStatus > 0 { | ||
| 28 | + q.Where(`"order".order_status =?`, option.OrderStatus) | ||
| 29 | + } | ||
| 30 | + if option.BeginTime > 0 { | ||
| 31 | + q.Where(`"order".create_at >=?`, time.Unix(option.BeginTime/1000, 0)) | ||
| 32 | + } | ||
| 33 | + if option.EndTime > 0 { | ||
| 34 | + q.Where(`"order".create_at <?`, time.Unix(option.EndTime/1000, 0)) | ||
| 35 | + } | ||
| 36 | + err = q.Select(&count, &amount) | ||
| 17 | return | 37 | return |
| 18 | } | 38 | } |
| 19 | 39 | ||
| 20 | -func NewEmployeeDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) { | 40 | +func NewOrderDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) { |
| 21 | if transactionContext == nil { | 41 | if transactionContext == nil { |
| 22 | return nil, fmt.Errorf("transactionContext参数不能为nil") | 42 | return nil, fmt.Errorf("transactionContext参数不能为nil") |
| 23 | } else { | 43 | } else { |
| @@ -68,6 +68,8 @@ func (repository *OrderRepository) Find(queryOptions map[string]interface{}) (in | @@ -68,6 +68,8 @@ func (repository *OrderRepository) Find(queryOptions map[string]interface{}) (in | ||
| 68 | query := NewQuery(tx.Model(&OrderModels), queryOptions) | 68 | query := NewQuery(tx.Model(&OrderModels), queryOptions) |
| 69 | query. | 69 | query. |
| 70 | SetWhere(`"order".partner_id= ?`, "partnerId"). | 70 | SetWhere(`"order".partner_id= ?`, "partnerId"). |
| 71 | + SetWhere(`"order".order_type= ?`, "orderType"). | ||
| 72 | + SetWhere(`"order".order_type= ?`, "orderType"). | ||
| 71 | SetWhere(`"order".create_at >= ?`, "beginTime"). | 73 | SetWhere(`"order".create_at >= ?`, "beginTime"). |
| 72 | SetWhere(`"order".create_at < ?`, "endTime"). | 74 | SetWhere(`"order".create_at < ?`, "endTime"). |
| 73 | SetLimit(). | 75 | SetLimit(). |
| @@ -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 | + "strconv" | ||
| 9 | "time" | 10 | "time" |
| 10 | ) | 11 | ) |
| 11 | 12 | ||
| @@ -41,17 +42,17 @@ func (query *Query) SetWhere(condition, key string) *Query { | @@ -41,17 +42,17 @@ func (query *Query) SetWhere(condition, key string) *Query { | ||
| 41 | 42 | ||
| 42 | func (query *Query) SetLimit() *Query { | 43 | func (query *Query) SetLimit() *Query { |
| 43 | if offset, ok := query.queryOptions["offset"]; ok { | 44 | if offset, ok := query.queryOptions["offset"]; ok { |
| 44 | - offset := offset.(int) | 45 | + offset, _ := strconv.ParseInt(fmt.Sprintf("%v", offset), 10, 64) |
| 45 | if offset > -1 { | 46 | if offset > -1 { |
| 46 | - query.Offset(offset) | 47 | + query.Offset(int(offset)) |
| 47 | } | 48 | } |
| 48 | } else { | 49 | } else { |
| 49 | query.Offset(0) | 50 | query.Offset(0) |
| 50 | } | 51 | } |
| 51 | if limit, ok := query.queryOptions["limit"]; ok { | 52 | if limit, ok := query.queryOptions["limit"]; ok { |
| 52 | - limit := limit.(int) | 53 | + limit, _ := strconv.ParseInt(fmt.Sprintf("%v", limit), 10, 64) |
| 53 | if limit > -1 { | 54 | if limit > -1 { |
| 54 | - query.Limit(limit) | 55 | + query.Limit(int(limit)) |
| 55 | } else { | 56 | } else { |
| 56 | query.Limit(20) | 57 | query.Limit(20) |
| 57 | } | 58 | } |
| 1 | package utils | 1 | package utils |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | - "fmt" | 4 | + "github.com/shopspring/decimal" |
| 5 | "math" | 5 | "math" |
| 6 | - "strconv" | ||
| 7 | ) | 6 | ) |
| 8 | 7 | ||
| 9 | -func decimal(value float64) float64 { | ||
| 10 | - return math.Trunc(value*1e1+0.5) * 1e-2 | 8 | +func decimal1(value float64) float64 { |
| 9 | + return math.Trunc(value*1e1+0.5) * 1e-1 | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +func Round(value float64, places int32) float64 { | ||
| 13 | + quantity := decimal.NewFromFloat(value) | ||
| 14 | + d := quantity.Round(places) | ||
| 15 | + rsp, _ := d.Float64() | ||
| 16 | + return rsp | ||
| 11 | } | 17 | } |
| 12 | 18 | ||
| 13 | func Decimal(value float64) float64 { | 19 | func Decimal(value float64) float64 { |
| 14 | - value = decimal(value) | ||
| 15 | - value, _ = strconv.ParseFloat(fmt.Sprintf("%.1f", value), 64) | ||
| 16 | - return value | 20 | + return Round(value, 2) |
| 17 | } | 21 | } |
| 18 | 22 | ||
| 19 | func DecimalToNumber(value float64) float64 { | 23 | func DecimalToNumber(value float64) float64 { |
| 20 | - value = decimal(value) | ||
| 21 | - value, _ = strconv.ParseFloat(fmt.Sprintf("%.f", value), 64) | ||
| 22 | - return value | 24 | + return Round(value, 2) |
| 23 | } | 25 | } |
pkg/infrastructure/utils/time.go
0 → 100644
| 1 | +package utils | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +func GetDayBegin() time.Time { | ||
| 6 | + t := time.Now() | ||
| 7 | + today, _ := time.Parse("2006-01-02", t.Format("2006-01-02")) | ||
| 8 | + return today | ||
| 9 | +} | ||
| 10 | + | ||
| 11 | +func GetDayEnd() time.Time { | ||
| 12 | + t := GetDayBegin() | ||
| 13 | + nextDay := t.AddDate(0, 0, 1) | ||
| 14 | + return nextDay | ||
| 15 | +} |
| @@ -10,8 +10,8 @@ type OrderController struct { | @@ -10,8 +10,8 @@ type OrderController struct { | ||
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | //OrderStatistics 订单统计 | 12 | //OrderStatistics 订单统计 |
| 13 | -// @router /orderStatistics [post] | ||
| 14 | -func (this *OrderController) OrderStatistics() { | 13 | +// @router /statistics [post] |
| 14 | +func (this *OrderController) Statistics() { | ||
| 15 | var msg *protocol.ResponseMessage | 15 | var msg *protocol.ResponseMessage |
| 16 | defer func() { | 16 | defer func() { |
| 17 | this.Resp(msg) | 17 | this.Resp(msg) |
| @@ -22,7 +22,9 @@ func init() { | @@ -22,7 +22,9 @@ func init() { | ||
| 22 | nsV1.Router("user/resetPassword", &controllers.UserController{}, "Post:ResetPassword") | 22 | nsV1.Router("user/resetPassword", &controllers.UserController{}, "Post:ResetPassword") |
| 23 | nsV1.Router("user/changePassword", &controllers.UserController{}, "Post:ChangePassword") | 23 | nsV1.Router("user/changePassword", &controllers.UserController{}, "Post:ChangePassword") |
| 24 | 24 | ||
| 25 | + nsV1.Router("order/statistics", &controllers.OrderController{}, "Post:Statistics") | ||
| 25 | nsV1.Router("order/details", &controllers.OrderController{}, "Post:OrderDetail") | 26 | nsV1.Router("order/details", &controllers.OrderController{}, "Post:OrderDetail") |
| 27 | + nsV1.Router("order/list", &controllers.OrderController{}, "Post:OrderList") | ||
| 26 | 28 | ||
| 27 | nsV1.Router("dividend/statistics", &controllers.DividendController{}, "Post:DividendStatistics") | 29 | nsV1.Router("dividend/statistics", &controllers.DividendController{}, "Post:DividendStatistics") |
| 28 | beego.AddNamespace(nsV1) | 30 | beego.AddNamespace(nsV1) |
| @@ -100,7 +100,7 @@ func NewReturnResponse(data interface{}, eRR error) *ResponseMessage { | @@ -100,7 +100,7 @@ func NewReturnResponse(data interface{}, eRR error) *ResponseMessage { | ||
| 100 | msg.Data = data | 100 | msg.Data = data |
| 101 | return msg | 101 | return msg |
| 102 | } | 102 | } |
| 103 | - // fmt.Println("日志:" + eRR.Error()) | 103 | + fmt.Println("日志:" + eRR.Error()) |
| 104 | if x, ok := eRR.(CustomErrParse); ok { | 104 | if x, ok := eRR.(CustomErrParse); ok { |
| 105 | msg = x.ParseToMessage() | 105 | msg = x.ParseToMessage() |
| 106 | msg.Data = data | 106 | msg.Data = data |
| @@ -6,19 +6,73 @@ type OrderDetailRequest struct { | @@ -6,19 +6,73 @@ type OrderDetailRequest struct { | ||
| 6 | } | 6 | } |
| 7 | type OrderDetailResponse struct { | 7 | type OrderDetailResponse struct { |
| 8 | Order interface{} `json:"order"` | 8 | Order interface{} `json:"order"` |
| 9 | - Partner interface{} `json:"partner"` | 9 | +} |
| 10 | +type OrderDetail struct { | ||
| 11 | + Id int64 `json:"id"` | ||
| 12 | + OrderNo string `json:"orderNo"` | ||
| 13 | + OrderName string `json:"orderName"` | ||
| 14 | + OrderStatus int `json:"orderStatus"` | ||
| 15 | + CreateTime int64 `json:"createTime"` | ||
| 16 | + UpdateTime int64 `json:"updateTime"` | ||
| 17 | + OrderQuantity int `json:"orderQuantity"` | ||
| 18 | + OrderAmount float64 `json:"orderAmount"` | ||
| 19 | + OrderAmountCancel float64 `json:"orderAmountCancel"` | ||
| 20 | + OrderDistrict interface{} `json:"orderDistrict"` | ||
| 21 | + Customer Customer `json:"customer"` | ||
| 22 | + MyDividend float64 `json:"myDividend"` | ||
| 23 | + MyDividendPercent float64 `json:"myDividendPercent"` | ||
| 24 | +} | ||
| 25 | +type Customer struct { | ||
| 26 | + Uname string `json:"uname"` | ||
| 27 | + Phone string `json:"phone"` | ||
| 10 | } | 28 | } |
| 11 | 29 | ||
| 12 | /*OrderStatistics */ | 30 | /*OrderStatistics */ |
| 13 | type OrderStatisticsRequest struct { | 31 | type OrderStatisticsRequest struct { |
| 14 | - Xxx string `json:"xxx" valid:"Required"` | ||
| 15 | } | 32 | } |
| 16 | type OrderStatisticsResponse struct { | 33 | type OrderStatisticsResponse struct { |
| 34 | + Statistics OrderStatics `json:"statistics"` | ||
| 35 | +} | ||
| 36 | +type OrderStatics struct { | ||
| 37 | + TodayIntentionQuantity int `json:"todayIntentionQuantity"` //今日新增意向订单 | ||
| 38 | + TodayIntentionMoney float64 `json:"todayIntentionMoney"` //今日新增意向订单金额 | ||
| 39 | + TodayRealQuantity int `json:"todayRealQuantity"` //今日新增实发订单 | ||
| 40 | + TodayRealMoney float64 `json:"todayRealMoney"` //今日新增实发订单金额 | ||
| 41 | + CumulativeQuantity int `json:"cumulativeQuantity"` //累计实发订单 | ||
| 42 | + CumulativeMoney float64 `json:"cumulativeMoney"` //累计实发订单金额 | ||
| 17 | } | 43 | } |
| 18 | 44 | ||
| 19 | /*OrderList */ | 45 | /*OrderList */ |
| 20 | type OrderListRequest struct { | 46 | type OrderListRequest struct { |
| 21 | - Xxx string `json:"xxx" valid:"Required"` | 47 | + StartTime int64 `json:"startTime" valid:"Required"` |
| 48 | + EndTime int64 `json:"endTime" valid:"Required"` | ||
| 49 | + OrderAction int `json:"orderAction" valid:"Required"` | ||
| 50 | + PageIndex int `json:"pageIndex"` | ||
| 51 | + PageSize int `json:"pageSize" valid:"Required"` | ||
| 22 | } | 52 | } |
| 23 | type OrderListResponse struct { | 53 | type OrderListResponse struct { |
| 54 | + List []*OrderListItem `json:"list"` | ||
| 55 | + Statistics map[string]interface{} `json:"statistics"` | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +type OrderListItem struct { | ||
| 59 | + //id | ||
| 60 | + Id int64 `json:"id,omitempty"` | ||
| 61 | + //订单类型 | ||
| 62 | + OrderType int `json:"orderType"` | ||
| 63 | + //订单编号 | ||
| 64 | + OrderNo string `json:"orderNo"` | ||
| 65 | + //订单名称 | ||
| 66 | + OrderName string `json:"orderName"` | ||
| 67 | + //订单状态 | ||
| 68 | + OrderStatus int `json:"orderStatus"` | ||
| 69 | + //实际订单数量 | ||
| 70 | + OrderActualCount int `json:"orderActualCount"` | ||
| 71 | + //订单金额 | ||
| 72 | + OrderAmount float64 `json:"orderAmount"` | ||
| 73 | + UpdateTime int64 `json:"updateTime"` | ||
| 74 | + //我的分红 | ||
| 75 | + MyDividend float64 `json:"myDividend"` | ||
| 76 | + //是否已读(0未读,1已读) | ||
| 77 | + IsRead int `json:"isRead"` | ||
| 24 | } | 78 | } |
-
请 注册 或 登录 后发表评论