作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/partnermg into dev

1 package command 1 package command
2 2
3 import ( 3 import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
4 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" 5 "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
5 ) 6 )
6 7
@@ -33,7 +34,8 @@ type CreateOrderCommand struct { @@ -33,7 +34,8 @@ type CreateOrderCommand struct {
33 PartnerBonusPercent float64 `json:"partnerBonusPercent"` 34 PartnerBonusPercent float64 `json:"partnerBonusPercent"`
34 //业务员分红百分比 35 //业务员分红百分比
35 SalesmanBonusPercent float64 `json:"salesmanBonusPercent"` 36 SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
36 - OrderType int `json:"orderType"` 37 + //订单类型
  38 + OrderType int `json:"orderType"`
37 } 39 }
38 40
39 func (command CreateOrderCommand) ValidateCommand() error { 41 func (command CreateOrderCommand) ValidateCommand() error {
@@ -49,5 +51,8 @@ func (command CreateOrderCommand) ValidateCommand() error { @@ -49,5 +51,8 @@ func (command CreateOrderCommand) ValidateCommand() error {
49 if len(command.OrderRegion) == 0 { 51 if len(command.OrderRegion) == 0 {
50 return lib.ThrowError(lib.ARG_ERROR, "订单区域必填") 52 return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
51 } 53 }
  54 + if !(command.OrderType == domain.OrderReal || command.OrderType == domain.OrderIntention) {
  55 + return lib.ThrowError(lib.ARG_ERROR, "订单类型错误")
  56 + }
52 return nil 57 return nil
53 } 58 }
1 package command 1 package command
2 2
3 -import "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib" 3 +import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
  6 +)
4 7
5 type UpdateOrderRealCommand struct { 8 type UpdateOrderRealCommand struct {
6 //id 9 //id
@@ -43,5 +46,8 @@ func (command UpdateOrderRealCommand) ValidateCommand() error { @@ -43,5 +46,8 @@ func (command UpdateOrderRealCommand) ValidateCommand() error {
43 if len(command.OrderRegion) == 0 { 46 if len(command.OrderRegion) == 0 {
44 return lib.ThrowError(lib.ARG_ERROR, "订单区域必填") 47 return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
45 } 48 }
  49 + if !(command.OrderStatus == domain.OrderStatusDeliverSome || command.OrderStatus == domain.OrderStatusDeliverAll) {
  50 + return lib.ThrowError(lib.ARG_ERROR, "订单状态设置错误")
  51 + }
46 return nil 52 return nil
47 } 53 }
@@ -39,6 +39,7 @@ func (service OrderService) PageListOrder(listOrderQuery query.ListOrderQuery) ( @@ -39,6 +39,7 @@ func (service OrderService) PageListOrder(listOrderQuery query.ListOrderQuery) (
39 OrderCode: listOrderQuery.OrderCode, 39 OrderCode: listOrderQuery.OrderCode,
40 Offset: listOrderQuery.Offset, 40 Offset: listOrderQuery.Offset,
41 Limit: listOrderQuery.Limit, 41 Limit: listOrderQuery.Limit,
  42 + OrderType: listOrderQuery.OrderType,
42 } 43 }
43 orders, err = orderRepository.Find(query) 44 orders, err = orderRepository.Find(query)
44 if err != nil { 45 if err != nil {
@@ -115,8 +116,8 @@ func (service OrderService) GetOrder(getOrderQuery query.GetOrderQuery) (*domain @@ -115,8 +116,8 @@ func (service OrderService) GetOrder(getOrderQuery query.GetOrderQuery) (*domain
115 return order, nil 116 return order, nil
116 } 117 }
117 118
118 -//CreateOrderPurpose 创建意向单  
119 -func (service OrderService) CreateOrderPurpose(command command.CreateOrderCommand) error { 119 +//CreateOrder 创建意向单
  120 +func (service OrderService) CreateOrder(command command.CreateOrderCommand) error {
120 var ( 121 var (
121 transactionContext, _ = factory.CreateTransactionContext(nil) 122 transactionContext, _ = factory.CreateTransactionContext(nil)
122 err error 123 err error
@@ -150,21 +151,21 @@ func (service OrderService) CreateOrderPurpose(command command.CreateOrderComman @@ -150,21 +151,21 @@ func (service OrderService) CreateOrderPurpose(command command.CreateOrderComman
150 } 151 }
151 newOrder := &domain.Order{ 152 newOrder := &domain.Order{
152 //订单类型 153 //订单类型
153 - OrderType: domain.OrderIntention, 154 + OrderType: command.OrderType,
154 //订单编号 155 //订单编号
155 OrderCode: command.OrderCode, 156 OrderCode: command.OrderCode,
156 //订单名称 157 //订单名称
157 OrderName: command.OrderName, 158 OrderName: command.OrderName,
158 //订单状态 159 //订单状态
159 - OrderStatus: domain.OrderStatusReserve, 160 + OrderStatus: command.OrderStatus,
160 //数量 161 //数量
161 OrderCount: command.OrderCount, 162 OrderCount: command.OrderCount,
162 //实际数量 163 //实际数量
163 - OrderActualCount: 0, 164 + OrderActualCount: command.OrderActualCount,
164 //订单金额 165 //订单金额
165 OrderAmount: command.OrderAmount, 166 OrderAmount: command.OrderAmount,
166 //实际订单金额 167 //实际订单金额
167 - OrderActualAmount: 0, 168 + OrderActualAmount: command.OrderActualAmount,
168 //订单已支付分红金额(货款) 169 //订单已支付分红金额(货款)
169 OrderPaymentAmount: 0, 170 OrderPaymentAmount: 0,
170 //订单区域信息 171 //订单区域信息
@@ -224,6 +225,9 @@ func (service OrderService) UpdateOrderPurpose(command command.UpdateOrderComman @@ -224,6 +225,9 @@ func (service OrderService) UpdateOrderPurpose(command command.UpdateOrderComman
224 if err != nil { 225 if err != nil {
225 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 226 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
226 } 227 }
  228 + if orderData.OrderType != domain.OrderIntention {
  229 + return lib.ThrowError(lib.BUSINESS_ERROR, "订单不是意向单")
  230 + }
227 err = orderData.Update(map[string]interface{}{ 231 err = orderData.Update(map[string]interface{}{
228 //订单编号 232 //订单编号
229 "orderCode": command.OrderCode, 233 "orderCode": command.OrderCode,
@@ -262,6 +266,12 @@ func (service OrderService) RemoveOrder(id int64) error { @@ -262,6 +266,12 @@ func (service OrderService) RemoveOrder(id int64) error {
262 if err != nil { 266 if err != nil {
263 return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error()) 267 return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
264 } 268 }
  269 + if err = transactionContext.StartTransaction(); err != nil {
  270 + return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
  271 + }
  272 + defer func() {
  273 + transactionContext.RollbackTransaction()
  274 + }()
265 var ( 275 var (
266 orderRepository domain.OrderRepository 276 orderRepository domain.OrderRepository
267 order *domain.Order 277 order *domain.Order
@@ -279,14 +289,21 @@ func (service OrderService) RemoveOrder(id int64) error { @@ -279,14 +289,21 @@ func (service OrderService) RemoveOrder(id int64) error {
279 if err != nil { 289 if err != nil {
280 return lib.ThrowError(lib.RES_NO_FIND_ERROR, err.Error()) 290 return lib.ThrowError(lib.RES_NO_FIND_ERROR, err.Error())
281 } 291 }
  292 + if order.OrderType != domain.OrderIntention {
  293 + return lib.ThrowError(lib.BUSINESS_ERROR, "订单不是意向单")
  294 + }
282 err = orderRepository.Remove(order.Id) 295 err = orderRepository.Remove(order.Id)
283 if err != nil { 296 if err != nil {
284 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error()) 297 return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
285 } 298 }
  299 + err = transactionContext.CommitTransaction()
  300 + if err != nil {
  301 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  302 + }
286 return nil 303 return nil
287 } 304 }
288 305
289 -//UpdateOrderReal 更新实发单 306 +//UpdateOrderReal 更新实发单
290 func (service OrderService) UpdateOrderReal(command command.UpdateOrderRealCommand) error { 307 func (service OrderService) UpdateOrderReal(command command.UpdateOrderRealCommand) error {
291 var ( 308 var (
292 transactionContext, _ = factory.CreateTransactionContext(nil) 309 transactionContext, _ = factory.CreateTransactionContext(nil)
@@ -333,6 +350,7 @@ func (service OrderService) UpdateOrderReal(command command.UpdateOrderRealComma @@ -333,6 +350,7 @@ func (service OrderService) UpdateOrderReal(command command.UpdateOrderRealComma
333 "partnerBonusPercent": command.PartnerBonusPercent, 350 "partnerBonusPercent": command.PartnerBonusPercent,
334 "salesmanBonusPercent": command.SalesmanBonusPercent, 351 "salesmanBonusPercent": command.SalesmanBonusPercent,
335 "orderStatus": command.OrderStatus, 352 "orderStatus": command.OrderStatus,
  353 + "orderType": domain.OrderReal,
336 }) 354 })
337 if err != nil { 355 if err != nil {
338 return lib.ThrowError(lib.BUSINESS_ERROR, err.Error()) 356 return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
@@ -9,6 +9,7 @@ const ( @@ -9,6 +9,7 @@ const (
9 ) 9 )
10 10
11 // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业) 11 // 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
  12 +//合伙类别 (1.事业合伙人 2.业务合伙人 3.研发合伙人)
12 const ( 13 const (
13 PARTNER_CATEGORY_1 int = 1 14 PARTNER_CATEGORY_1 int = 1
14 PARTNER_CATEGORY_2 int = 2 15 PARTNER_CATEGORY_2 int = 2
@@ -88,13 +88,13 @@ func (repository OrderRepository) Find(queryOption domain.OrderFindQuery) ([]dom @@ -88,13 +88,13 @@ func (repository OrderRepository) Find(queryOption domain.OrderFindQuery) ([]dom
88 orderModels := []models.Order{} 88 orderModels := []models.Order{}
89 query := db.Model(&orderModels) 89 query := db.Model(&orderModels)
90 if queryOption.PartnerId > 0 { 90 if queryOption.PartnerId > 0 {
91 - query = query.Where("order.partner_id=?", queryOption.PartnerId) 91 + query = query.Where("partner_id=?", queryOption.PartnerId)
92 } 92 }
93 if len(queryOption.OrderCode) > 0 { 93 if len(queryOption.OrderCode) > 0 {
94 - query = query.Where("order.order_code like ?", "%"+queryOption.OrderCode+"%") 94 + query = query.Where("order_code like ?", "%"+queryOption.OrderCode+"%")
95 } 95 }
96 if queryOption.OrderType > 0 { 96 if queryOption.OrderType > 0 {
97 - query = query.Where("order.order_type=?", queryOption.OrderType) 97 + query = query.Where("order_type=?", queryOption.OrderType)
98 } 98 }
99 if queryOption.Offset > -1 { 99 if queryOption.Offset > -1 {
100 query = query.Offset(queryOption.Offset) 100 query = query.Offset(queryOption.Offset)
@@ -108,7 +108,7 @@ func (repository OrderRepository) Find(queryOption domain.OrderFindQuery) ([]dom @@ -108,7 +108,7 @@ func (repository OrderRepository) Find(queryOption domain.OrderFindQuery) ([]dom
108 err error 108 err error
109 ordersReturn = make([]domain.Order, 0) 109 ordersReturn = make([]domain.Order, 0)
110 ) 110 )
111 - query = query.Order("order.id DESC ") 111 + query = query.Order("order.id DESC")
112 err = query.Select() 112 err = query.Select()
113 if err != nil { 113 if err != nil {
114 return ordersReturn, err 114 return ordersReturn, err
@@ -128,10 +128,13 @@ func (repository OrderRepository) CountAll(queryOption domain.OrderFindQuery) (i @@ -128,10 +128,13 @@ func (repository OrderRepository) CountAll(queryOption domain.OrderFindQuery) (i
128 orderModels := []models.Order{} 128 orderModels := []models.Order{}
129 query := db.Model(&orderModels) 129 query := db.Model(&orderModels)
130 if queryOption.PartnerId > 0 { 130 if queryOption.PartnerId > 0 {
131 - query = query.Where("order.partner_id=?", queryOption.PartnerId) 131 + query = query.Where("partner_id=?", queryOption.PartnerId)
132 } 132 }
133 if len(queryOption.OrderCode) > 0 { 133 if len(queryOption.OrderCode) > 0 {
134 - query = query.Where("order.order_code like ?", "%"+queryOption.OrderCode+"%") 134 + query = query.Where("order_code like ?", "%"+queryOption.OrderCode+"%")
  135 + }
  136 + if queryOption.OrderType > 0 {
  137 + query = query.Where("order_type=?", queryOption.OrderType)
135 } 138 }
136 var ( 139 var (
137 err error 140 err error
@@ -140,13 +143,13 @@ func (repository OrderRepository) CountAll(queryOption domain.OrderFindQuery) (i @@ -140,13 +143,13 @@ func (repository OrderRepository) CountAll(queryOption domain.OrderFindQuery) (i
140 if err != nil { 143 if err != nil {
141 return cnt, err 144 return cnt, err
142 } 145 }
143 - return 0, nil 146 + return cnt, nil
144 } 147 }
145 148
146 func (repository OrderRepository) FindOne(qureyOptions domain.OrderFindOneQuery) (*domain.Order, error) { 149 func (repository OrderRepository) FindOne(qureyOptions domain.OrderFindOneQuery) (*domain.Order, error) {
147 var ( 150 var (
148 err error 151 err error
149 - tx = repository.transactionContext.PgTx 152 + tx = repository.transactionContext.PgDd
150 ) 153 )
151 m := new(models.Order) 154 m := new(models.Order)
152 err = tx.Model(m). 155 err = tx.Model(m).
@@ -161,6 +161,10 @@ func (c *AdminUserController) ListAdminUser() { @@ -161,6 +161,10 @@ func (c *AdminUserController) ListAdminUser() {
161 "id": adminusers[i].Id, 161 "id": adminusers[i].Id,
162 "account": adminusers[i].Account, 162 "account": adminusers[i].Account,
163 "permission": permissionTypes, 163 "permission": permissionTypes,
  164 + "statue": 0,
  165 + }
  166 + if adminusers[i].IsUsable {
  167 + m["statue"] = 1
164 } 168 }
165 listData = append(listData, m) 169 listData = append(listData, m)
166 } 170 }
@@ -171,7 +175,8 @@ func (c *AdminUserController) ListAdminUser() { @@ -171,7 +175,8 @@ func (c *AdminUserController) ListAdminUser() {
171 func (c *AdminUserController) ForbiddenAdminUser() { 175 func (c *AdminUserController) ForbiddenAdminUser() {
172 //用与适配前端定义的数据结构 176 //用与适配前端定义的数据结构
173 type Paramter struct { 177 type Paramter struct {
174 - Id int64 `json:"id"` 178 + Id int64 `json:"id"`
  179 + Statue int `json:"statue"`
175 } 180 }
176 var ( 181 var (
177 param Paramter 182 param Paramter
@@ -183,7 +188,17 @@ func (c *AdminUserController) ForbiddenAdminUser() { @@ -183,7 +188,17 @@ func (c *AdminUserController) ForbiddenAdminUser() {
183 return 188 return
184 } 189 }
185 newAdminUserService := adminuserservice.NewAdminUserService(nil) 190 newAdminUserService := adminuserservice.NewAdminUserService(nil)
186 - err = newAdminUserService.UpdateAdminIsUsable(param.Id, false) 191 + var isUsable bool
  192 + if param.Statue == 1 {
  193 + isUsable = true
  194 + } else if param.Statue == 0 {
  195 + isUsable = false
  196 + } else {
  197 + c.ResponseError(errors.New("参数错误"))
  198 + return
  199 + }
  200 +
  201 + err = newAdminUserService.UpdateAdminIsUsable(param.Id, isUsable)
187 if err != nil { 202 if err != nil {
188 c.ResponseError(err) 203 c.ResponseError(err)
189 return 204 return
  1 +package controllers
  2 +
  3 +import (
  4 + partnerQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
  5 + partnerInfoService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service"
  6 +)
  7 +
  8 +type CommonController struct {
  9 + BaseController
  10 +}
  11 +
  12 +////Prepare 重写 BaseController 的Prepare方法
  13 +func (c *CommonController) Prepare() {
  14 + c.BaseController.Prepare()
  15 + if ok := c.ValidJWTToken(); !ok {
  16 + return
  17 + }
  18 +}
  19 +
  20 +// GetPartnerList 下拉选项数据通用接口,获取合伙人列表
  21 +func (c *CommonController) GetPartnerList() {
  22 + query := partnerQuery.ListPartnerInfoQuery{
  23 + Limit: 2000,
  24 + Offset: 0,
  25 + }
  26 + newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
  27 + _, partners, err := newPartnerService.ListPartnerInfo(&query)
  28 + if err != nil {
  29 + c.ResponseError(err)
  30 + return
  31 + }
  32 + resp := []map[string]interface{}{}
  33 + for i := range partners {
  34 + m := map[string]interface{}{
  35 + "id": partners[i].Partner.Id,
  36 + "account": partners[i].Partner.Account,
  37 + "partnerName": partners[i].Partner.PartnerName,
  38 + }
  39 +
  40 + resp = append(resp, m)
  41 + }
  42 + c.ResponseData(resp)
  43 +}
@@ -51,6 +51,8 @@ type orderDetail struct { @@ -51,6 +51,8 @@ type orderDetail struct {
51 OrderDist string `json:"orderDist"` 51 OrderDist string `json:"orderDist"`
52 //id 52 //id
53 Id int64 `json:"id"` 53 Id int64 `json:"id"`
  54 + //订单状态
  55 + OrderStatue int `json:"orderStatue"`
54 } 56 }
55 57
56 //UpdateOrderPurpose 更新意向订单 58 //UpdateOrderPurpose 更新意向订单
@@ -102,8 +104,11 @@ func (c *OrderController) addOrderPurpose(param orderDetail) error { @@ -102,8 +104,11 @@ func (c *OrderController) addOrderPurpose(param orderDetail) error {
102 PartnerBonusPercent: param.PartnerRatio, 104 PartnerBonusPercent: param.PartnerRatio,
103 //业务员分红百分比 105 //业务员分红百分比
104 SalesmanBonusPercent: param.SalesmanRatio, 106 SalesmanBonusPercent: param.SalesmanRatio,
  107 + //订单类型
  108 + OrderType: domain.OrderIntention,
  109 + OrderStatus: domain.OrderStatusReserve,
105 } 110 }
106 - err := orderSrv.CreateOrderPurpose(Createcmd) 111 + err := orderSrv.CreateOrder(Createcmd)
107 return err 112 return err
108 } 113 }
109 114
@@ -162,14 +167,14 @@ func (c *OrderController) GetOrderPurpose() { @@ -162,14 +167,14 @@ func (c *OrderController) GetOrderPurpose() {
162 "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"), 167 "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),
163 "buyer": orderinfo.Buyer.BuyerName, 168 "buyer": orderinfo.Buyer.BuyerName,
164 "buyerPhone": orderinfo.Buyer.ContactInfo, 169 "buyerPhone": orderinfo.Buyer.ContactInfo,
165 - "Address": orderinfo.Buyer.ShippingAddress, 170 + "address": orderinfo.Buyer.ShippingAddress,
166 "id": orderinfo.Id, 171 "id": orderinfo.Id,
167 "partner": orderinfo.PartnerInfo.Id, 172 "partner": orderinfo.PartnerInfo.Id,
168 "partnerRatio": orderinfo.PartnerBonusPercent, 173 "partnerRatio": orderinfo.PartnerBonusPercent,
169 "salesmanRatio": orderinfo.SalesmanBonusPercent, 174 "salesmanRatio": orderinfo.SalesmanBonusPercent,
170 "orderId": orderinfo.OrderCode, 175 "orderId": orderinfo.OrderCode,
171 "orderName": orderinfo.OrderName, 176 "orderName": orderinfo.OrderName,
172 - "OrderNum": orderinfo.OrderCount, 177 + "orderNum": orderinfo.OrderCount,
173 "orderPrice": orderinfo.OrderAmount, 178 "orderPrice": orderinfo.OrderAmount,
174 "orderDist": orderinfo.OrderRegionInfo.RegionName, 179 "orderDist": orderinfo.OrderRegionInfo.RegionName,
175 "orderStatue": orderinfo.OrderStatus, 180 "orderStatue": orderinfo.OrderStatus,
@@ -181,7 +186,7 @@ func (c *OrderController) GetOrderPurpose() { @@ -181,7 +186,7 @@ func (c *OrderController) GetOrderPurpose() {
181 func (c *OrderController) PageListOrderPurpose() { 186 func (c *OrderController) PageListOrderPurpose() {
182 type Parameter struct { 187 type Parameter struct {
183 SearchText string `json:"searchText"` 188 SearchText string `json:"searchText"`
184 - Partner int64 `json:"parter"` 189 + Partner int64 `json:"partner"`
185 PageSize int `json:"pageSize"` 190 PageSize int `json:"pageSize"`
186 PageNumber int `json:"pageNumber"` 191 PageNumber int `json:"pageNumber"`
187 } 192 }
@@ -225,7 +230,7 @@ func (c *OrderController) PageListOrderPurpose() { @@ -225,7 +230,7 @@ func (c *OrderController) PageListOrderPurpose() {
225 "partner": orderinfo.PartnerInfo.PartnerName, 230 "partner": orderinfo.PartnerInfo.PartnerName,
226 "partnerRatio": orderinfo.PartnerBonusPercent, 231 "partnerRatio": orderinfo.PartnerBonusPercent,
227 "orderName": orderinfo.OrderName, 232 "orderName": orderinfo.OrderName,
228 - "OrderNum": orderinfo.OrderCount, 233 + "orderNum": orderinfo.OrderCount,
229 "orderPrice": orderinfo.OrderAmount, 234 "orderPrice": orderinfo.OrderAmount,
230 "orderDist": orderinfo.OrderRegionInfo.RegionName, 235 "orderDist": orderinfo.OrderRegionInfo.RegionName,
231 "orderStatue": orderinfo.OrderStatus, 236 "orderStatue": orderinfo.OrderStatus,
@@ -262,7 +267,7 @@ func (c *OrderController) RemoveOrderPurpose() { @@ -262,7 +267,7 @@ func (c *OrderController) RemoveOrderPurpose() {
262 func (c *OrderController) PageListOrderReal() { 267 func (c *OrderController) PageListOrderReal() {
263 type Parameter struct { 268 type Parameter struct {
264 SearchText string `json:"searchText"` 269 SearchText string `json:"searchText"`
265 - Partner int64 `json:"parter"` 270 + Partner int64 `json:"partner"`
266 PageSize int `json:"pageSize"` 271 PageSize int `json:"pageSize"`
267 PageNumber int `json:"pageNumber"` 272 PageNumber int `json:"pageNumber"`
268 } 273 }
@@ -298,18 +303,20 @@ func (c *OrderController) PageListOrderReal() { @@ -298,18 +303,20 @@ func (c *OrderController) PageListOrderReal() {
298 for i := range orderinfos { 303 for i := range orderinfos {
299 orderinfo := orderinfos[i] 304 orderinfo := orderinfos[i]
300 m := map[string]interface{}{ 305 m := map[string]interface{}{
301 - "createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),  
302 - "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),  
303 - "buyer": orderinfo.Buyer.BuyerName,  
304 - "id": orderinfo.Id,  
305 - "orderId": orderinfo.OrderCode,  
306 - "partner": orderinfo.PartnerInfo.PartnerName,  
307 - "partnerRatio": orderinfo.PartnerBonusPercent,  
308 - "orderName": orderinfo.OrderName,  
309 - "OrderNum": orderinfo.OrderCount,  
310 - "orderPrice": orderinfo.OrderAmount,  
311 - "orderDist": orderinfo.OrderRegionInfo.RegionName,  
312 - "orderStatue": orderinfo.OrderStatus, 306 + "createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),
  307 + "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),
  308 + "buyer": orderinfo.Buyer.BuyerName,
  309 + "id": orderinfo.Id,
  310 + "orderId": orderinfo.OrderCode,
  311 + "partner": orderinfo.PartnerInfo.PartnerName,
  312 + "partnerRatio": orderinfo.PartnerBonusPercent,
  313 + "orderName": orderinfo.OrderName,
  314 + "orderNum": orderinfo.OrderCount,
  315 + "orderPrice": orderinfo.OrderAmount,
  316 + "orderActualNum": orderinfo.OrderActualCount,
  317 + "orderActualPrice": orderinfo.OrderActualAmount,
  318 + "orderDist": orderinfo.OrderRegionInfo.RegionName,
  319 + "orderStatue": orderinfo.OrderStatus,
313 } 320 }
314 rsp = append(rsp, m) 321 rsp = append(rsp, m)
315 } 322 }
@@ -328,7 +335,159 @@ func (c *OrderController) OrderPurposeToReal() { @@ -328,7 +335,159 @@ func (c *OrderController) OrderPurposeToReal() {
328 c.ResponseError(errors.New("json数据解析失败")) 335 c.ResponseError(errors.New("json数据解析失败"))
329 return 336 return
330 } 337 }
  338 + cmd := orderCmd.UpdateOrderRealCommand{
  339 + Id: param.Id,
  340 + OrderCode: param.OrderId,
  341 + OrderName: param.OrderName,
  342 + OrderActualCount: param.OrderNum,
  343 + OrderActualAmount: param.OrderPrice,
  344 + BuyerPhone: param.BuyerPhone,
  345 + BuyerAddress: param.Address,
  346 + OrderRegion: param.OrderDist,
  347 + PartnerBonusPercent: param.PartnerRatio,
  348 + SalesmanBonusPercent: param.SalesmanRatio,
  349 + OrderStatus: param.OrderStatue,
  350 + }
  351 + orderSrv := orderService.NewOrderService(nil)
  352 + err = orderSrv.UpdateOrderReal(cmd)
  353 + if err != nil {
  354 + c.ResponseError(err)
  355 + return
  356 + }
  357 + c.ResponseData(nil)
  358 + return
  359 +}
  360 +
  361 +//GetOrderReal 获取实发单详情
  362 +func (c *OrderController) GetOrderReal() {
  363 + type Parameter struct {
  364 + Id string `json:"id"`
  365 + }
  366 + var (
  367 + param Parameter
  368 + err error
  369 + )
  370 + if err = c.BindJsonData(&param); err != nil {
  371 + logs.Error(err)
  372 + c.ResponseError(errors.New("json数据解析失败"))
  373 + return
  374 + }
  375 + orderid, _ := strconv.ParseInt(param.Id, 10, 64)
  376 + orderSrv := orderService.NewOrderService(nil)
  377 + orderinfo, err := orderSrv.GetOrder(orderQuery.GetOrderQuery{
  378 + OrderId: orderid,
  379 + })
  380 + if err != nil {
  381 + c.ResponseError(err)
  382 + return
  383 + }
  384 + rsp := map[string]interface{}{
  385 + "createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),
  386 + "updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),
  387 + "buyer": orderinfo.Buyer.BuyerName,
  388 + "buyerPhone": orderinfo.Buyer.ContactInfo,
  389 + "address": orderinfo.Buyer.ShippingAddress,
  390 + "id": orderinfo.Id,
  391 + "partner": orderinfo.PartnerInfo.Id,
  392 + "partnerRatio": orderinfo.PartnerBonusPercent,
  393 + "salesmanRatio": orderinfo.SalesmanBonusPercent,
  394 + "orderId": orderinfo.OrderCode,
  395 + "orderName": orderinfo.OrderName,
  396 + "orderNum": orderinfo.OrderActualCount,
  397 + "orderPrice": orderinfo.OrderActualAmount,
  398 + "orderDist": orderinfo.OrderRegionInfo.RegionName,
  399 + "orderStatue": orderinfo.OrderStatus,
  400 + }
  401 + c.ResponseData(rsp)
  402 +}
331 403
  404 +//UpdateOrderReal 更新实发订单数据
  405 +func (c *OrderController) UpdateOrderReal() {
  406 + //用与适配前端定义的数据结构
  407 + var (
  408 + param orderDetail
  409 + err error
  410 + )
  411 + if err = c.BindJsonData(&param); err != nil {
  412 + logs.Error(err)
  413 + c.ResponseError(errors.New("json数据解析失败"))
  414 + return
  415 + }
  416 + if param.Id == 0 {
  417 + err = c.addOrderReal(param)
  418 + } else {
  419 + err = c.editOrderReal(param)
  420 + }
  421 + if err != nil {
  422 + c.ResponseError(err)
  423 + }
332 c.ResponseData(nil) 424 c.ResponseData(nil)
333 return 425 return
334 } 426 }
  427 +
  428 +//addOrderReal 添加实发订单
  429 +func (c *OrderController) addOrderReal(param orderDetail) error {
  430 + orderSrv := orderService.NewOrderService(nil)
  431 + Createcmd := orderCmd.CreateOrderCommand{
  432 + //订单区域
  433 + OrderRegion: param.OrderDist,
  434 + //订单编号
  435 + OrderCode: param.OrderId,
  436 + //订单名称
  437 + OrderName: param.OrderName,
  438 + //数量
  439 + OrderCount: param.OrderNum,
  440 + OrderActualCount: param.OrderNum,
  441 + //订单金额
  442 + OrderAmount: param.OrderPrice,
  443 + OrderActualAmount: param.OrderPrice,
  444 + //买家
  445 + BuyerName: param.Buyer,
  446 + //买家电话
  447 + BuyerPhone: param.BuyerPhone,
  448 + //地址
  449 + BuyerAddress: param.Address,
  450 + //合伙人数据
  451 + PartnerId: param.Partner,
  452 + //合伙人分红百分比
  453 + PartnerBonusPercent: param.PartnerRatio,
  454 + //业务员分红百分比
  455 + SalesmanBonusPercent: param.SalesmanRatio,
  456 + //订单类型
  457 + OrderType: domain.OrderReal,
  458 + //状态
  459 + OrderStatus: param.OrderStatue,
  460 + }
  461 + err := orderSrv.CreateOrder(Createcmd)
  462 + return err
  463 +}
  464 +
  465 +//editOrderReal 更新实发订单
  466 +func (c *OrderController) editOrderReal(param orderDetail) error {
  467 + updateCmd := orderCmd.UpdateOrderRealCommand{
  468 + Id: param.Id,
  469 + //订单区域
  470 + OrderRegion: param.OrderDist,
  471 + //订单编号
  472 + OrderCode: param.OrderId,
  473 + //订单名称
  474 + OrderName: param.OrderName,
  475 + //数量
  476 + OrderActualCount: param.OrderNum,
  477 + //订单金额
  478 + OrderActualAmount: param.OrderPrice,
  479 + //买家电话
  480 + BuyerPhone: param.BuyerPhone,
  481 + //地址
  482 + BuyerAddress: param.Address,
  483 + //合伙人分红百分比
  484 + PartnerBonusPercent: param.PartnerRatio,
  485 + //业务员分红百分比
  486 + SalesmanBonusPercent: param.SalesmanRatio,
  487 + //状态
  488 + OrderStatus: param.OrderStatue,
  489 + }
  490 + orderSrv := orderService.NewOrderService(nil)
  491 + err := orderSrv.UpdateOrderReal(updateCmd)
  492 + return err
  493 +}
@@ -37,10 +37,13 @@ func init() { @@ -37,10 +37,13 @@ func init() {
37 beego.NSRouter("/purpose/update", &controllers.OrderController{}, "POST:UpdateOrderPurpose"), 37 beego.NSRouter("/purpose/update", &controllers.OrderController{}, "POST:UpdateOrderPurpose"),
38 beego.NSRouter("/purpose/detail", &controllers.OrderController{}, "POST:GetOrderPurpose"), 38 beego.NSRouter("/purpose/detail", &controllers.OrderController{}, "POST:GetOrderPurpose"),
39 beego.NSRouter("/purpose/del", &controllers.OrderController{}, "POST:RemoveOrderPurpose"), 39 beego.NSRouter("/purpose/del", &controllers.OrderController{}, "POST:RemoveOrderPurpose"),
40 - 40 + beego.NSRouter("/purpose/convert", &controllers.OrderController{}, "POST:OrderPurposeToReal"),
41 beego.NSRouter("/actual/list", &controllers.OrderController{}, "POST:PageListOrderReal"), 41 beego.NSRouter("/actual/list", &controllers.OrderController{}, "POST:PageListOrderReal"),
42 - beego.NSRouter("/actual/update", &controllers.OrderController{}, "POST:UpdateOrderPurpose"),  
43 - beego.NSRouter("/actual/detail", &controllers.OrderController{}, "POST:GetOrderPurpose"), 42 + beego.NSRouter("/actual/update", &controllers.OrderController{}, "POST:UpdateOrderReal"),
  43 + beego.NSRouter("/actual/detail", &controllers.OrderController{}, "POST:GetOrderReal"),
  44 + ),
  45 + beego.NSNamespace("/common",
  46 + beego.NSRouter("/partner", &controllers.CommonController{}, "POST:GetPartnerList"),
44 ), 47 ),
45 ) 48 )
46 beego.AddNamespace(adminRouter) 49 beego.AddNamespace(adminRouter)