|
|
package controllers
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
"strconv"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
|
|
|
|
|
"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.PERMISSION_ORDER); !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"`
|
|
|
//订单状态
|
|
|
OrderStatue int `json:"orderStatue"`
|
|
|
//理由
|
|
|
Reason string `json:"reason"`
|
|
|
}
|
|
|
|
|
|
//UpdateOrderPurpose 更新意向订单
|
|
|
func (c *OrderController) UpdateOrderPurpose() {
|
|
|
//用与适配前端定义的数据结构
|
|
|
var (
|
|
|
param orderDetail
|
|
|
err error
|
|
|
)
|
|
|
if err = c.BindJsonData(¶m); 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,
|
|
|
OrderActualCount: param.OrderNum,
|
|
|
//订单金额
|
|
|
OrderAmount: param.OrderPrice,
|
|
|
OrderActualAmount: param.OrderPrice,
|
|
|
//买家
|
|
|
BuyerName: param.Buyer,
|
|
|
//买家电话
|
|
|
BuyerPhone: param.BuyerPhone,
|
|
|
//地址
|
|
|
BuyerAddress: param.Address,
|
|
|
//合伙人数据
|
|
|
PartnerId: param.Partner,
|
|
|
//合伙人分红百分比
|
|
|
PartnerBonusPercent: param.PartnerRatio,
|
|
|
//业务员分红百分比
|
|
|
SalesmanBonusPercent: param.SalesmanRatio,
|
|
|
//订单类型
|
|
|
OrderType: domain.OrderIntention,
|
|
|
OrderStatus: domain.OrderStatusReserve,
|
|
|
}
|
|
|
err := orderSrv.CreateOrder(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,
|
|
|
|
|
|
OrderStatus: domain.OrderStatusReserve,
|
|
|
|
|
|
OrderType: domain.OrderIntention,
|
|
|
}
|
|
|
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(¶m); 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:"partner"`
|
|
|
PageSize int `json:"pageSize"`
|
|
|
PageNumber int `json:"pageNumber"`
|
|
|
}
|
|
|
var (
|
|
|
param Parameter
|
|
|
err error
|
|
|
)
|
|
|
if err = c.BindJsonData(¶m); 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(¶m); 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:"partner"`
|
|
|
PageSize int `json:"pageSize"`
|
|
|
PageNumber int `json:"pageNumber"`
|
|
|
}
|
|
|
var (
|
|
|
param Parameter
|
|
|
err error
|
|
|
)
|
|
|
if err = c.BindJsonData(¶m); 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,
|
|
|
"orderActualNum": orderinfo.OrderActualCount,
|
|
|
"orderActualPrice": orderinfo.OrderActualAmount,
|
|
|
"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(¶m); err != nil {
|
|
|
logs.Error(err)
|
|
|
c.ResponseError(errors.New("json数据解析失败"))
|
|
|
return
|
|
|
}
|
|
|
orderSrv := orderService.NewOrderService(nil)
|
|
|
if param.Id > 0 {
|
|
|
err = orderSrv.UpdateOrderPurpose(orderCmd.UpdateOrderCommand{
|
|
|
Id: param.Id,
|
|
|
OrderCode: param.OrderId,
|
|
|
OrderName: param.OrderName,
|
|
|
OrderCount: param.OrderNum,
|
|
|
OrderAmount: param.OrderPrice,
|
|
|
BuyerPhone: param.BuyerPhone,
|
|
|
BuyerAddress: param.Address,
|
|
|
OrderRegion: param.OrderDist,
|
|
|
PartnerBonusPercent: param.PartnerRatio,
|
|
|
SalesmanBonusPercent: param.SalesmanRatio,
|
|
|
OrderStatus: param.OrderStatue,
|
|
|
OrderType: domain.OrderReal,
|
|
|
})
|
|
|
} else {
|
|
|
err = c.addOrderReal(param)
|
|
|
}
|
|
|
if err != nil {
|
|
|
c.ResponseError(err)
|
|
|
return
|
|
|
}
|
|
|
c.ResponseData(nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//GetOrderReal 获取实发单详情
|
|
|
func (c *OrderController) GetOrderReal() {
|
|
|
type Parameter struct {
|
|
|
Id string `json:"id"`
|
|
|
}
|
|
|
var (
|
|
|
param Parameter
|
|
|
err error
|
|
|
)
|
|
|
if err = c.BindJsonData(¶m); 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.OrderActualCount,
|
|
|
"orderPrice": orderinfo.OrderActualAmount,
|
|
|
"orderDist": orderinfo.OrderRegionInfo.RegionName,
|
|
|
"orderStatue": orderinfo.OrderStatus,
|
|
|
"reason": orderinfo.Reason,
|
|
|
}
|
|
|
c.ResponseData(rsp)
|
|
|
}
|
|
|
|
|
|
//UpdateOrderReal 更新实发订单数据
|
|
|
func (c *OrderController) UpdateOrderReal() {
|
|
|
//用与适配前端定义的数据结构
|
|
|
var (
|
|
|
param orderDetail
|
|
|
err error
|
|
|
)
|
|
|
if err = c.BindJsonData(¶m); err != nil {
|
|
|
logs.Error(err)
|
|
|
c.ResponseError(errors.New("json数据解析失败"))
|
|
|
return
|
|
|
}
|
|
|
if param.Id == 0 {
|
|
|
err = c.addOrderReal(param)
|
|
|
} else {
|
|
|
err = c.editOrderReal(param)
|
|
|
}
|
|
|
if err != nil {
|
|
|
c.ResponseError(err)
|
|
|
}
|
|
|
c.ResponseData(nil)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//addOrderReal 添加实发订单
|
|
|
func (c *OrderController) addOrderReal(param orderDetail) error {
|
|
|
orderSrv := orderService.NewOrderService(nil)
|
|
|
if !(param.OrderStatue == domain.OrderStatusDeliverAll ||
|
|
|
param.OrderStatue == domain.OrderStatusDeliverSome) {
|
|
|
return lib.ThrowError(lib.ARG_ERROR, "订单状态错误")
|
|
|
}
|
|
|
Createcmd := orderCmd.CreateOrderCommand{
|
|
|
//订单区域
|
|
|
OrderRegion: param.OrderDist,
|
|
|
//订单编号
|
|
|
OrderCode: param.OrderId,
|
|
|
//订单名称
|
|
|
OrderName: param.OrderName,
|
|
|
//数量
|
|
|
OrderCount: param.OrderNum,
|
|
|
OrderActualCount: param.OrderNum,
|
|
|
//订单金额
|
|
|
OrderAmount: param.OrderPrice,
|
|
|
OrderActualAmount: param.OrderPrice,
|
|
|
//买家
|
|
|
BuyerName: param.Buyer,
|
|
|
//买家电话
|
|
|
BuyerPhone: param.BuyerPhone,
|
|
|
//地址
|
|
|
BuyerAddress: param.Address,
|
|
|
//合伙人数据
|
|
|
PartnerId: param.Partner,
|
|
|
//合伙人分红百分比
|
|
|
PartnerBonusPercent: param.PartnerRatio,
|
|
|
//业务员分红百分比
|
|
|
SalesmanBonusPercent: param.SalesmanRatio,
|
|
|
//订单类型
|
|
|
OrderType: domain.OrderReal,
|
|
|
//状态
|
|
|
OrderStatus: param.OrderStatue,
|
|
|
}
|
|
|
err := orderSrv.CreateOrder(Createcmd)
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
//editOrderReal 更新实发订单
|
|
|
func (c *OrderController) editOrderReal(param orderDetail) error {
|
|
|
updateCmd := orderCmd.UpdateOrderRealCommand{
|
|
|
Id: param.Id,
|
|
|
//订单区域
|
|
|
OrderRegion: param.OrderDist,
|
|
|
//订单编号
|
|
|
OrderCode: param.OrderId,
|
|
|
//订单名称
|
|
|
OrderName: param.OrderName,
|
|
|
//数量
|
|
|
OrderActualCount: param.OrderNum,
|
|
|
//订单金额
|
|
|
OrderActualAmount: param.OrderPrice,
|
|
|
//买家电话
|
|
|
BuyerPhone: param.BuyerPhone,
|
|
|
//地址
|
|
|
BuyerAddress: param.Address,
|
|
|
//合伙人分红百分比
|
|
|
PartnerBonusPercent: param.PartnerRatio,
|
|
|
//业务员分红百分比
|
|
|
SalesmanBonusPercent: param.SalesmanRatio,
|
|
|
//状态
|
|
|
OrderStatus: param.OrderStatue,
|
|
|
//理由
|
|
|
Reason: param.Reason,
|
|
|
}
|
|
|
orderSrv := orderService.NewOrderService(nil)
|
|
|
err := orderSrv.UpdateOrderReal(updateCmd)
|
|
|
return err
|
|
|
} |