作者 tangxvhui

更新

package command
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
type CreateOrderCommand struct {
//订单区域
OrderRegion string
//订单编号
OrderCode string `json:"orderCode"`
//订单名称
OrderName string `json:"oderName"`
//数量
OrderCount int `json:"orderCount"`
//实际订单数量
OrderActualCount int `json:"orderActualCount"`
//订单金额
OrderAmount float64 `json:"orderAmount"`
//订单实际金额
OrderActualAmount float64 `json:"orderActualAmount"`
//订单状态
OrderStatus int `json:"orderStatus"`
//买家
BuyerName string `json:"buyerName"`
//买家电话
BuyerPhone string `json:"buyerPhone"`
//地址
BuyerAddress string `json:"address"`
//合伙人数据
PartnerId int64 `json:"partId"`
//合伙人分红百分比
PartnerBonusPercent float64 `json:"partnerBonusPercent"`
//业务员分红百分比
SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
OrderType int `json:"orderType"`
}
func (command CreateOrderCommand) ValidateCommand() error {
if len(command.BuyerName) == 0 || len(command.BuyerPhone) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "买家信息必填")
}
if len(command.BuyerAddress) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "买家地址必填")
}
if len(command.OrderCode) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单编号必填")
}
if len(command.OrderRegion) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
}
return nil
}
... ...
package command
import "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
type UpdateOrderCommand struct {
//id
Id int64 `json:"id"`
//订单编号
OrderCode string `json:"orderCode"`
//订单名称
OrderName string `json:"oderName"`
//数量
OrderCount int `json:"orderCount"`
//订单金额
OrderAmount float64 `json:"orderAmount"`
//买家
BuyerPhone string `json:"buyerPhone"`
//地址
BuyerAddress string `json:"address"`
//订单区域
OrderRegion string `json:"orderRegion"`
//合伙人分红百分比
PartnerBonusPercent float64 `json:"partnerBonusPercent"`
//业务员分红百分比
SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
}
func (command UpdateOrderCommand) ValidateCommand() error {
if command.Id == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单id错误")
}
if len(command.BuyerPhone) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "买家信息必填")
}
if len(command.BuyerAddress) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "买家地址必填")
}
if len(command.OrderCode) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单编号必填")
}
if len(command.OrderRegion) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
}
return nil
}
... ...
package command
import "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
type UpdateOrderRealCommand struct {
//id
Id int64 `json:"id"`
//订单编号
OrderCode string `json:"orderCode"`
//订单名称
OrderName string `json:"oderName"`
//数量
OrderActualCount int `json:"orderActualCount"`
//订单金额
OrderActualAmount float64 `json:"orderActualAmount"`
//买家
BuyerPhone string `json:"buyerPhone"`
//地址
BuyerAddress string `json:"address"`
//订单区域
OrderRegion string `json:"orderRegion"`
//合伙人分红百分比
PartnerBonusPercent float64 `json:"partnerBonusPercent"`
//业务员分红百分比
SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
//状态
OrderStatus int `json:"orderStatus"`
}
func (command UpdateOrderRealCommand) ValidateCommand() error {
if command.Id == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单id错误")
}
if len(command.BuyerPhone) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "买家信息必填")
}
if len(command.BuyerAddress) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "买家地址必填")
}
if len(command.OrderCode) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单编号必填")
}
if len(command.OrderRegion) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
}
return nil
}
... ...
... ... @@ -9,5 +9,6 @@ type ListOrderQuery struct {
// 查询偏离量
Offset int `json:"offset" `
// 查询限制
Limit int `json:"limit"`
Limit int `json:"limit"`
OrderType int `json:"orderType"`
}
... ...
... ... @@ -2,6 +2,7 @@ package service
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/command"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/query"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
... ... @@ -43,10 +44,25 @@ func (service OrderService) PageListOrder(listOrderQuery query.ListOrderQuery) (
if err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
cnt, err = orderRepository.CountAll(query)
if err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range orders {
var partnerData *domain.PartnerInfo
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: orders[i].PartnerInfo.Id})
if err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
orders[i].PartnerInfo = partnerData.Partner
}
return orders, cnt, nil
}
... ... @@ -74,9 +90,251 @@ func (service OrderService) GetOrder(getOrderQuery query.GetOrderQuery) (*domain
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var partnerData *domain.PartnerInfo
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: order.PartnerInfo.Id})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
order.PartnerInfo = partnerData.Partner
return order, nil
}
func (service OrderService) CreateOrde() error {
//CreateOrderPurpose 创建意向单
func (service OrderService) CreateOrderPurpose(command command.CreateOrderCommand) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = command.ValidateCommand(); err != nil {
return lib.ThrowError(lib.ARG_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var PartnerInfoRepository domain.PartnerInfoRepository
if PartnerInfoRepository, err = factory.CreatePartnerInfoRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var partnerData *domain.PartnerInfo
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{UserId: command.PartnerId})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
var orderRepository domain.OrderRepository
if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
newOrder := &domain.Order{
//订单类型
OrderType: domain.OrderIntention,
//订单编号
OrderCode: command.OrderCode,
//订单名称
OrderName: command.OrderName,
//订单状态
OrderStatus: domain.OrderStatusReserve,
//数量
OrderCount: command.OrderCount,
//实际数量
OrderActualCount: 0,
//订单金额
OrderAmount: command.OrderAmount,
//实际订单金额
OrderActualAmount: 0,
//订单已支付分红金额(货款)
OrderPaymentAmount: 0,
//订单区域信息
OrderRegionInfo: domain.RegionInfo{
RegionName: command.OrderRegion,
},
//买家
Buyer: domain.Buyer{
BuyerName: command.BuyerName,
ShippingAddress: command.BuyerAddress,
ContactInfo: command.BuyerPhone,
},
PartnerInfo: partnerData.Partner,
//合伙人分红百分比
PartnerBonusPercent: command.PartnerBonusPercent,
//业务员分红百分比
SalesmanBonusPercent: command.SalesmanBonusPercent,
}
err = orderRepository.Save(newOrder)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
//UpdateOrderPurpose 更新意向单
func (service OrderService) UpdateOrderPurpose(command command.UpdateOrderCommand) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = command.ValidateCommand(); err != nil {
return lib.ThrowError(lib.ARG_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
orderRepository domain.OrderRepository
orderData *domain.Order
)
if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
orderData, err = orderRepository.FindOne(domain.OrderFindOneQuery{
OrderId: command.Id,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = orderData.Update(map[string]interface{}{
//订单编号
"orderCode": command.OrderCode,
"oderName": command.OrderName,
"orderCount": command.OrderCount,
"orderAmount": command.OrderAmount,
"buyer": domain.Buyer{
BuyerName: orderData.Buyer.BuyerName,
ContactInfo: command.BuyerPhone,
ShippingAddress: command.BuyerAddress,
},
"orderRegion": domain.RegionInfo{
RegionName: command.OrderRegion,
},
"partnerBonusPercent": command.PartnerBonusPercent,
"salesmanBonusPercent": command.SalesmanBonusPercent,
})
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
err = orderRepository.Save(orderData)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
//RemoveOrder 删除意向单
func (service OrderService) RemoveOrder(id int64) error {
//实际业务
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
var (
orderRepository domain.OrderRepository
order *domain.Order
)
if value, err := factory.CreateOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderRepository = value
}
order, err = orderRepository.FindOne(domain.OrderFindOneQuery{
OrderId: id,
})
if err != nil {
return lib.ThrowError(lib.RES_NO_FIND_ERROR, err.Error())
}
err = orderRepository.Remove(order.Id)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
//UpdateOrderReal 更新实发单
func (service OrderService) UpdateOrderReal(command command.UpdateOrderRealCommand) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
)
if err = command.ValidateCommand(); err != nil {
return lib.ThrowError(lib.ARG_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
orderRepository domain.OrderRepository
orderData *domain.Order
)
if orderRepository, err = factory.CreateOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
orderData, err = orderRepository.FindOne(domain.OrderFindOneQuery{
OrderId: command.Id,
})
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = orderData.Update(map[string]interface{}{
//订单编号
"orderCode": command.OrderCode,
"oderName": command.OrderName,
"orderActualCount": command.OrderActualCount,
"orderActualAmount": command.OrderActualAmount,
"buyer": domain.Buyer{
BuyerName: orderData.Buyer.BuyerName,
ContactInfo: command.BuyerPhone,
ShippingAddress: command.BuyerAddress,
},
"orderRegion": domain.RegionInfo{
RegionName: command.OrderRegion,
},
"partnerBonusPercent": command.PartnerBonusPercent,
"salesmanBonusPercent": command.SalesmanBonusPercent,
"orderStatus": command.OrderStatus,
})
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
}
err = orderRepository.Save(orderData)
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
err = transactionContext.CommitTransaction()
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
... ...
package domain
import "time"
import (
"time"
)
const (
OrderStatusReserve = iota + 1 //预定中
... ... @@ -44,11 +46,11 @@ type Order struct {
//订单已支付分红金额(货款)
OrderPaymentAmount float64 `json:"orderPaymentAmount"`
//订单区域信息
OrderRegionInfo *RegionInfo `json:"orderRegionInfo"`
OrderRegionInfo RegionInfo `json:"orderRegionInfo"`
//买家
Buyer *Buyer `json:"buyer"`
Buyer Buyer `json:"buyer"`
//合伙人数据
PartnerInfo *Partner `json:"partnerInfo"`
PartnerInfo Partner `json:"partnerInfo"`
//合伙人分红百分比
PartnerBonusPercent float64 `json:"partnerBonusPercent"`
//业务员分红百分比
... ... @@ -61,7 +63,49 @@ type Order struct {
}
//TODO
func (order Order) Update(data map[string]interface{}) error {
func (order *Order) Update(data map[string]interface{}) error {
if v, ok := data["orderType"]; ok {
order.OrderType = v.(int)
}
if v, ok := data["orderCode"]; ok {
order.OrderCode = v.(string)
}
if v, ok := data["oderName"]; ok {
order.OrderName = v.(string)
}
if v, ok := data["orderStatus"]; ok {
order.OrderStatus = v.(int)
}
if v, ok := data["orderCount"]; ok {
order.OrderCount = v.(int)
}
if v, ok := data["orderActualCount"]; ok {
order.OrderActualCount = v.(int)
}
if v, ok := data["orderAmount"]; ok {
order.OrderAmount = v.(float64)
}
if v, ok := data["orderActualAmount"]; ok {
order.OrderActualAmount = v.(float64)
}
if v, ok := data["orderPaymentAmount"]; ok {
order.OrderPaymentAmount = v.(float64)
}
if v, ok := data["orderRegion"]; ok {
order.OrderRegionInfo = v.(RegionInfo)
}
if v, ok := data["buyer"]; ok {
order.Buyer = v.(Buyer)
}
if v, ok := data["partnerInfo"]; ok {
order.PartnerInfo = v.(Partner)
}
if v, ok := data["partnerBonusPercent"]; ok {
order.PartnerBonusPercent = v.(float64)
}
if v, ok := data["salesmanBonusPercent"]; ok {
order.SalesmanBonusPercent = v.(float64)
}
return nil
}
... ... @@ -74,6 +118,7 @@ type OrderFindQuery struct {
OrderCode string
Offset int
Limit int
OrderType int
}
type OrderRepository interface {
... ... @@ -81,4 +126,5 @@ type OrderRepository interface {
FindOne(qureyOptions OrderFindOneQuery) (*Order, error)
Find(queryOptions OrderFindQuery) ([]Order, error)
CountAll(queryOption OrderFindQuery) (int, error)
Remove(id int64) error
}
... ...
... ... @@ -2,6 +2,7 @@ package dao
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
... ... @@ -27,6 +28,15 @@ func (dao *OrderDao) Update(options map[string]interface{}) (err error) {
return
}
func (dao *OrderDao) OrderCodeIsExist(code string, orderType int) (bool, error) {
tx := dao.transactionContext.PgDd
ok, err := tx.Model(new(models.Order)).
Where("order_code=?", code).
Where("order_type=?", orderType).
Exists()
return ok, err
}
func (dao *OrderDao) GetOrderBaseInfo(id int64) (data map[string]interface{}, err error) {
tx := dao.transactionContext.PgTx
order := new(models.Order)
... ...
... ... @@ -33,9 +33,9 @@ type Order struct {
//最后分红状态
BonusStatus int
//订单区域信息
OrderRegionInfo *domain.RegionInfo
OrderRegionInfo domain.RegionInfo
Buyer *domain.Buyer
Buyer domain.Buyer
//合伙人编号
PartnerId int64
PartnerInfo PartnerInfo `pg:"fk:partner_id"`
... ...
... ... @@ -37,7 +37,7 @@ func (reponsitory OrderRepository) transformPgModelToDomainModel(orderModel *mod
OrderPaymentAmount: orderModel.OrderPaymentAmount,
OrderRegionInfo: orderModel.OrderRegionInfo,
Buyer: orderModel.Buyer,
PartnerInfo: &domain.Partner{
PartnerInfo: domain.Partner{
Id: orderModel.PartnerId,
},
PartnerBonusPercent: orderModel.PartnerBonusPercent,
... ... @@ -87,13 +87,15 @@ func (repository OrderRepository) Find(queryOption domain.OrderFindQuery) ([]dom
db := repository.transactionContext.PgDd
orderModels := []models.Order{}
query := db.Model(&orderModels)
if queryOption.PartnerId > 0 {
query = query.Where("order.partner_id=?", queryOption.PartnerId)
}
if len(queryOption.OrderCode) > 0 {
query = query.Where("order.order_code like ?", "%"+queryOption.OrderCode+"%")
}
if queryOption.OrderType > 0 {
query = query.Where("order.order_type=?", queryOption.OrderType)
}
if queryOption.Offset > -1 {
query = query.Offset(queryOption.Offset)
}
... ... @@ -156,3 +158,15 @@ func (repository OrderRepository) FindOne(qureyOptions domain.OrderFindOneQuery)
result, err := repository.transformPgModelToDomainModel(m)
return &result, err
}
func (repository OrderRepository) Remove(id int64) error {
var (
err error
tx = repository.transactionContext.PgTx
)
m := &models.Order{
Id: id,
}
_, err = tx.Model(m).WherePK().Delete()
return err
}
... ...
package controllers
import (
"errors"
"strconv"
"github.com/astaxie/beego/logs"
orderCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/command"
orderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/query"
orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/order/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
type OrderController struct {
BaseController
}
////Prepare 重写 BaseController 的Prepare方法
func (c *OrderController) Prepare() {
c.BaseController.Prepare()
if ok := c.ValidJWTToken(); !ok {
return
}
if ok := c.ValidAdminPermission(domain.PERMINSSION_ADMIN_USER); !ok {
return
}
}
type orderDetail struct {
//买家姓名
Buyer string `json:"buyer"`
//买家联系方式
BuyerPhone string `json:"buyerPhone"`
//收货地址
Address string `json:"address"`
//对应合伙人 id
Partner int64 `json:"partner"`
//合伙人抽成比例
PartnerRatio float64 `json:"partnerRatio"`
//业务员抽成比例
SalesmanRatio float64 `json:"salesmanRatio"`
//订单号
OrderId string `json:"orderId"`
//订单名称
OrderName string `json:"orderName"`
//订单数量
OrderNum int `json:"orderNum"`
//订单金额
OrderPrice float64 `json:"orderPrice"`
//订单区域
OrderDist string `json:"orderDist"`
//id
Id int64 `json:"id"`
}
//UpdateOrderPurpose 更新意向订单
func (c *OrderController) UpdateOrderPurpose() {
//用与适配前端定义的数据结构
var (
param orderDetail
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
if param.Id == 0 {
err = c.addOrderPurpose(param)
} else {
err = c.editOrderPurpose(param)
}
if err != nil {
c.ResponseError(err)
}
c.ResponseData(nil)
return
}
func (c *OrderController) addOrderPurpose(param orderDetail) error {
orderSrv := orderService.NewOrderService(nil)
Createcmd := orderCmd.CreateOrderCommand{
//订单区域
OrderRegion: param.OrderDist,
//订单编号
OrderCode: param.OrderId,
//订单名称
OrderName: param.OrderName,
//数量
OrderCount: param.OrderNum,
//订单金额
OrderAmount: param.OrderPrice,
//买家
BuyerName: param.Buyer,
//买家电话
BuyerPhone: param.BuyerPhone,
//地址
BuyerAddress: param.Address,
//合伙人数据
PartnerId: param.Partner,
//合伙人分红百分比
PartnerBonusPercent: param.PartnerRatio,
//业务员分红百分比
SalesmanBonusPercent: param.SalesmanRatio,
}
err := orderSrv.CreateOrderPurpose(Createcmd)
return err
}
func (c *OrderController) editOrderPurpose(param orderDetail) error {
updateCmd := orderCmd.UpdateOrderCommand{
Id: param.Id,
//订单区域
OrderRegion: param.OrderDist,
//订单编号
OrderCode: param.OrderId,
//订单名称
OrderName: param.OrderName,
//数量
OrderCount: param.OrderNum,
//订单金额
OrderAmount: param.OrderPrice,
//买家电话
BuyerPhone: param.BuyerPhone,
//地址
BuyerAddress: param.Address,
//合伙人分红百分比
PartnerBonusPercent: param.PartnerRatio,
//业务员分红百分比
SalesmanBonusPercent: param.SalesmanRatio,
}
orderSrv := orderService.NewOrderService(nil)
err := orderSrv.UpdateOrderPurpose(updateCmd)
return err
}
//GetOrderPurpose 获取意向订单
func (c *OrderController) GetOrderPurpose() {
type Parameter struct {
Id string `json:"id"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
orderid, _ := strconv.ParseInt(param.Id, 10, 64)
orderSrv := orderService.NewOrderService(nil)
orderinfo, err := orderSrv.GetOrder(orderQuery.GetOrderQuery{
OrderId: orderid,
})
if err != nil {
c.ResponseError(err)
return
}
rsp := map[string]interface{}{
"createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),
"updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),
"buyer": orderinfo.Buyer.BuyerName,
"buyerPhone": orderinfo.Buyer.ContactInfo,
"Address": orderinfo.Buyer.ShippingAddress,
"id": orderinfo.Id,
"partner": orderinfo.PartnerInfo.Id,
"partnerRatio": orderinfo.PartnerBonusPercent,
"salesmanRatio": orderinfo.SalesmanBonusPercent,
"orderId": orderinfo.OrderCode,
"orderName": orderinfo.OrderName,
"OrderNum": orderinfo.OrderCount,
"orderPrice": orderinfo.OrderAmount,
"orderDist": orderinfo.OrderRegionInfo.RegionName,
"orderStatue": orderinfo.OrderStatus,
}
c.ResponseData(rsp)
}
//PageListOrderPurpose 分页获取意向订单列表
func (c *OrderController) PageListOrderPurpose() {
type Parameter struct {
SearchText string `json:"searchText"`
Partner int64 `json:"parter"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
if param.PageNumber == 0 {
param.PageNumber = 1
}
if param.PageSize == 0 {
param.PageSize = 20
}
orderSrv := orderService.NewOrderService(nil)
orderinfos, cnt, err := orderSrv.PageListOrder(orderQuery.ListOrderQuery{
PartnerId: param.Partner,
OrderCode: param.SearchText,
OrderType: domain.OrderIntention,
Limit: param.PageSize,
Offset: (param.PageNumber - 1) * param.PageSize,
})
if err != nil {
c.ResponseError(err)
return
}
rsp := []map[string]interface{}{}
for i := range orderinfos {
orderinfo := orderinfos[i]
m := map[string]interface{}{
"createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),
"updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),
"buyer": orderinfo.Buyer.BuyerName,
"id": orderinfo.Id,
"orderId": orderinfo.OrderCode,
"partner": orderinfo.PartnerInfo.PartnerName,
"partnerRatio": orderinfo.PartnerBonusPercent,
"orderName": orderinfo.OrderName,
"OrderNum": orderinfo.OrderCount,
"orderPrice": orderinfo.OrderAmount,
"orderDist": orderinfo.OrderRegionInfo.RegionName,
"orderStatue": orderinfo.OrderStatus,
}
rsp = append(rsp, m)
}
c.ResponsePageList(rsp, cnt, param.PageNumber)
}
//RemoveOrderPurpose 删除意向订单
func (c *OrderController) RemoveOrderPurpose() {
type Parameter struct {
Id int64 `json:"id"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
orderSrv := orderService.NewOrderService(nil)
err = orderSrv.RemoveOrder(param.Id)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
}
//PageListOrderReal 分页获取实发订单列表
func (c *OrderController) PageListOrderReal() {
type Parameter struct {
SearchText string `json:"searchText"`
Partner int64 `json:"parter"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
if param.PageNumber == 0 {
param.PageNumber = 1
}
if param.PageSize == 0 {
param.PageSize = 20
}
orderSrv := orderService.NewOrderService(nil)
orderinfos, cnt, err := orderSrv.PageListOrder(orderQuery.ListOrderQuery{
PartnerId: param.Partner,
OrderCode: param.SearchText,
OrderType: domain.OrderReal,
Limit: param.PageSize,
Offset: (param.PageNumber - 1) * param.PageSize,
})
if err != nil {
c.ResponseError(err)
return
}
rsp := []map[string]interface{}{}
for i := range orderinfos {
orderinfo := orderinfos[i]
m := map[string]interface{}{
"createTime": orderinfo.CreateAt.Local().Format("2006-01-02 15:04:05"),
"updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),
"buyer": orderinfo.Buyer.BuyerName,
"id": orderinfo.Id,
"orderId": orderinfo.OrderCode,
"partner": orderinfo.PartnerInfo.PartnerName,
"partnerRatio": orderinfo.PartnerBonusPercent,
"orderName": orderinfo.OrderName,
"OrderNum": orderinfo.OrderCount,
"orderPrice": orderinfo.OrderAmount,
"orderDist": orderinfo.OrderRegionInfo.RegionName,
"orderStatue": orderinfo.OrderStatus,
}
rsp = append(rsp, m)
}
c.ResponsePageList(rsp, cnt, param.PageNumber)
}
//UpdateOrderPurpose 意向订单转实发单
func (c *OrderController) OrderPurposeToReal() {
//用与适配前端定义的数据结构
var (
param orderDetail
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
c.ResponseData(nil)
return
}
... ...
... ... @@ -32,6 +32,16 @@ func init() {
beego.NSRouter("/detail", &controllers.DividendsController{}, "POST:Detail"),
beego.NSRouter("/list", &controllers.DividendsController{}, "POST:List"),
),
beego.NSNamespace("/order",
beego.NSRouter("/purpose/list", &controllers.OrderController{}, "POST:PageListOrderPurpose"),
beego.NSRouter("/purpose/update", &controllers.OrderController{}, "POST:UpdateOrderPurpose"),
beego.NSRouter("/purpose/detail", &controllers.OrderController{}, "POST:GetOrderPurpose"),
beego.NSRouter("/purpose/del", &controllers.OrderController{}, "POST:RemoveOrderPurpose"),
beego.NSRouter("/actual/list", &controllers.OrderController{}, "POST:PageListOrderReal"),
beego.NSRouter("/actual/update", &controllers.OrderController{}, "POST:UpdateOrderPurpose"),
beego.NSRouter("/actual/detail", &controllers.OrderController{}, "POST:GetOrderPurpose"),
),
)
beego.AddNamespace(adminRouter)
}
... ...