作者 yangfu

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

package command
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
... ... @@ -33,7 +34,8 @@ type CreateOrderCommand struct {
PartnerBonusPercent float64 `json:"partnerBonusPercent"`
//业务员分红百分比
SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
OrderType int `json:"orderType"`
//订单类型
OrderType int `json:"orderType"`
}
func (command CreateOrderCommand) ValidateCommand() error {
... ... @@ -49,5 +51,8 @@ func (command CreateOrderCommand) ValidateCommand() error {
if len(command.OrderRegion) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
}
if !(command.OrderType == domain.OrderReal || command.OrderType == domain.OrderIntention) {
return lib.ThrowError(lib.ARG_ERROR, "订单类型错误")
}
return nil
}
... ...
package command
import "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
type UpdateOrderRealCommand struct {
//id
... ... @@ -43,5 +46,8 @@ func (command UpdateOrderRealCommand) ValidateCommand() error {
if len(command.OrderRegion) == 0 {
return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
}
if !(command.OrderStatus == domain.OrderStatusDeliverSome || command.OrderStatus == domain.OrderStatusDeliverAll) {
return lib.ThrowError(lib.ARG_ERROR, "订单状态设置错误")
}
return nil
}
... ...
... ... @@ -39,6 +39,7 @@ func (service OrderService) PageListOrder(listOrderQuery query.ListOrderQuery) (
OrderCode: listOrderQuery.OrderCode,
Offset: listOrderQuery.Offset,
Limit: listOrderQuery.Limit,
OrderType: listOrderQuery.OrderType,
}
orders, err = orderRepository.Find(query)
if err != nil {
... ... @@ -115,8 +116,8 @@ func (service OrderService) GetOrder(getOrderQuery query.GetOrderQuery) (*domain
return order, nil
}
//CreateOrderPurpose 创建意向单
func (service OrderService) CreateOrderPurpose(command command.CreateOrderCommand) error {
//CreateOrder 创建意向单
func (service OrderService) CreateOrder(command command.CreateOrderCommand) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
... ... @@ -150,21 +151,21 @@ func (service OrderService) CreateOrderPurpose(command command.CreateOrderComman
}
newOrder := &domain.Order{
//订单类型
OrderType: domain.OrderIntention,
OrderType: command.OrderType,
//订单编号
OrderCode: command.OrderCode,
//订单名称
OrderName: command.OrderName,
//订单状态
OrderStatus: domain.OrderStatusReserve,
OrderStatus: command.OrderStatus,
//数量
OrderCount: command.OrderCount,
//实际数量
OrderActualCount: 0,
OrderActualCount: command.OrderActualCount,
//订单金额
OrderAmount: command.OrderAmount,
//实际订单金额
OrderActualAmount: 0,
OrderActualAmount: command.OrderActualAmount,
//订单已支付分红金额(货款)
OrderPaymentAmount: 0,
//订单区域信息
... ... @@ -224,6 +225,9 @@ func (service OrderService) UpdateOrderPurpose(command command.UpdateOrderComman
if err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
if orderData.OrderType != domain.OrderIntention {
return lib.ThrowError(lib.BUSINESS_ERROR, "订单不是意向单")
}
err = orderData.Update(map[string]interface{}{
//订单编号
"orderCode": command.OrderCode,
... ... @@ -262,6 +266,12 @@ func (service OrderService) RemoveOrder(id int64) error {
if err != nil {
return lib.ThrowError(lib.TRANSACTION_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
order *domain.Order
... ... @@ -279,14 +289,21 @@ func (service OrderService) RemoveOrder(id int64) error {
if err != nil {
return lib.ThrowError(lib.RES_NO_FIND_ERROR, err.Error())
}
if order.OrderType != domain.OrderIntention {
return lib.ThrowError(lib.BUSINESS_ERROR, "订单不是意向单")
}
err = orderRepository.Remove(order.Id)
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
}
//UpdateOrderReal 更新实发单
//UpdateOrderReal 更新实发单
func (service OrderService) UpdateOrderReal(command command.UpdateOrderRealCommand) error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
... ... @@ -333,6 +350,7 @@ func (service OrderService) UpdateOrderReal(command command.UpdateOrderRealComma
"partnerBonusPercent": command.PartnerBonusPercent,
"salesmanBonusPercent": command.SalesmanBonusPercent,
"orderStatus": command.OrderStatus,
"orderType": domain.OrderReal,
})
if err != nil {
return lib.ThrowError(lib.BUSINESS_ERROR, err.Error())
... ...
... ... @@ -9,6 +9,7 @@ const (
)
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
//合伙类别 (1.事业合伙人 2.业务合伙人 3.研发合伙人)
const (
PARTNER_CATEGORY_1 int = 1
PARTNER_CATEGORY_2 int = 2
... ...
... ... @@ -88,13 +88,13 @@ func (repository OrderRepository) Find(queryOption domain.OrderFindQuery) ([]dom
orderModels := []models.Order{}
query := db.Model(&orderModels)
if queryOption.PartnerId > 0 {
query = query.Where("order.partner_id=?", queryOption.PartnerId)
query = query.Where("partner_id=?", queryOption.PartnerId)
}
if len(queryOption.OrderCode) > 0 {
query = query.Where("order.order_code like ?", "%"+queryOption.OrderCode+"%")
query = query.Where("order_code like ?", "%"+queryOption.OrderCode+"%")
}
if queryOption.OrderType > 0 {
query = query.Where("order.order_type=?", queryOption.OrderType)
query = query.Where("order_type=?", queryOption.OrderType)
}
if queryOption.Offset > -1 {
query = query.Offset(queryOption.Offset)
... ... @@ -108,7 +108,7 @@ func (repository OrderRepository) Find(queryOption domain.OrderFindQuery) ([]dom
err error
ordersReturn = make([]domain.Order, 0)
)
query = query.Order("order.id DESC ")
query = query.Order("order.id DESC")
err = query.Select()
if err != nil {
return ordersReturn, err
... ... @@ -128,10 +128,13 @@ func (repository OrderRepository) CountAll(queryOption domain.OrderFindQuery) (i
orderModels := []models.Order{}
query := db.Model(&orderModels)
if queryOption.PartnerId > 0 {
query = query.Where("order.partner_id=?", queryOption.PartnerId)
query = query.Where("partner_id=?", queryOption.PartnerId)
}
if len(queryOption.OrderCode) > 0 {
query = query.Where("order.order_code like ?", "%"+queryOption.OrderCode+"%")
query = query.Where("order_code like ?", "%"+queryOption.OrderCode+"%")
}
if queryOption.OrderType > 0 {
query = query.Where("order_type=?", queryOption.OrderType)
}
var (
err error
... ... @@ -140,13 +143,13 @@ func (repository OrderRepository) CountAll(queryOption domain.OrderFindQuery) (i
if err != nil {
return cnt, err
}
return 0, nil
return cnt, nil
}
func (repository OrderRepository) FindOne(qureyOptions domain.OrderFindOneQuery) (*domain.Order, error) {
var (
err error
tx = repository.transactionContext.PgTx
tx = repository.transactionContext.PgDd
)
m := new(models.Order)
err = tx.Model(m).
... ...
... ... @@ -161,6 +161,10 @@ func (c *AdminUserController) ListAdminUser() {
"id": adminusers[i].Id,
"account": adminusers[i].Account,
"permission": permissionTypes,
"statue": 0,
}
if adminusers[i].IsUsable {
m["statue"] = 1
}
listData = append(listData, m)
}
... ... @@ -171,7 +175,8 @@ func (c *AdminUserController) ListAdminUser() {
func (c *AdminUserController) ForbiddenAdminUser() {
//用与适配前端定义的数据结构
type Paramter struct {
Id int64 `json:"id"`
Id int64 `json:"id"`
Statue int `json:"statue"`
}
var (
param Paramter
... ... @@ -183,7 +188,17 @@ func (c *AdminUserController) ForbiddenAdminUser() {
return
}
newAdminUserService := adminuserservice.NewAdminUserService(nil)
err = newAdminUserService.UpdateAdminIsUsable(param.Id, false)
var isUsable bool
if param.Statue == 1 {
isUsable = true
} else if param.Statue == 0 {
isUsable = false
} else {
c.ResponseError(errors.New("参数错误"))
return
}
err = newAdminUserService.UpdateAdminIsUsable(param.Id, isUsable)
if err != nil {
c.ResponseError(err)
return
... ...
package controllers
import (
partnerQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
partnerInfoService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service"
)
type CommonController struct {
BaseController
}
////Prepare 重写 BaseController 的Prepare方法
func (c *CommonController) Prepare() {
c.BaseController.Prepare()
if ok := c.ValidJWTToken(); !ok {
return
}
}
// GetPartnerList 下拉选项数据通用接口,获取合伙人列表
func (c *CommonController) GetPartnerList() {
query := partnerQuery.ListPartnerInfoQuery{
Limit: 2000,
Offset: 0,
}
newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
_, partners, err := newPartnerService.ListPartnerInfo(&query)
if err != nil {
c.ResponseError(err)
return
}
resp := []map[string]interface{}{}
for i := range partners {
m := map[string]interface{}{
"id": partners[i].Partner.Id,
"account": partners[i].Partner.Account,
"partnerName": partners[i].Partner.PartnerName,
}
resp = append(resp, m)
}
c.ResponseData(resp)
}
... ...
... ... @@ -51,6 +51,8 @@ type orderDetail struct {
OrderDist string `json:"orderDist"`
//id
Id int64 `json:"id"`
//订单状态
OrderStatue int `json:"orderStatue"`
}
//UpdateOrderPurpose 更新意向订单
... ... @@ -102,8 +104,11 @@ func (c *OrderController) addOrderPurpose(param orderDetail) error {
PartnerBonusPercent: param.PartnerRatio,
//业务员分红百分比
SalesmanBonusPercent: param.SalesmanRatio,
//订单类型
OrderType: domain.OrderIntention,
OrderStatus: domain.OrderStatusReserve,
}
err := orderSrv.CreateOrderPurpose(Createcmd)
err := orderSrv.CreateOrder(Createcmd)
return err
}
... ... @@ -162,14 +167,14 @@ func (c *OrderController) GetOrderPurpose() {
"updateTime": orderinfo.UpdateAt.Local().Format("2006-01-02 15:04:05"),
"buyer": orderinfo.Buyer.BuyerName,
"buyerPhone": orderinfo.Buyer.ContactInfo,
"Address": orderinfo.Buyer.ShippingAddress,
"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,
"orderNum": orderinfo.OrderCount,
"orderPrice": orderinfo.OrderAmount,
"orderDist": orderinfo.OrderRegionInfo.RegionName,
"orderStatue": orderinfo.OrderStatus,
... ... @@ -181,7 +186,7 @@ func (c *OrderController) GetOrderPurpose() {
func (c *OrderController) PageListOrderPurpose() {
type Parameter struct {
SearchText string `json:"searchText"`
Partner int64 `json:"parter"`
Partner int64 `json:"partner"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
}
... ... @@ -225,7 +230,7 @@ func (c *OrderController) PageListOrderPurpose() {
"partner": orderinfo.PartnerInfo.PartnerName,
"partnerRatio": orderinfo.PartnerBonusPercent,
"orderName": orderinfo.OrderName,
"OrderNum": orderinfo.OrderCount,
"orderNum": orderinfo.OrderCount,
"orderPrice": orderinfo.OrderAmount,
"orderDist": orderinfo.OrderRegionInfo.RegionName,
"orderStatue": orderinfo.OrderStatus,
... ... @@ -262,7 +267,7 @@ func (c *OrderController) RemoveOrderPurpose() {
func (c *OrderController) PageListOrderReal() {
type Parameter struct {
SearchText string `json:"searchText"`
Partner int64 `json:"parter"`
Partner int64 `json:"partner"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
}
... ... @@ -298,18 +303,20 @@ func (c *OrderController) PageListOrderReal() {
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,
"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)
}
... ... @@ -328,7 +335,159 @@ func (c *OrderController) OrderPurposeToReal() {
c.ResponseError(errors.New("json数据解析失败"))
return
}
cmd := orderCmd.UpdateOrderRealCommand{
Id: param.Id,
OrderCode: param.OrderId,
OrderName: param.OrderName,
OrderActualCount: param.OrderNum,
OrderActualAmount: param.OrderPrice,
BuyerPhone: param.BuyerPhone,
BuyerAddress: param.Address,
OrderRegion: param.OrderDist,
PartnerBonusPercent: param.PartnerRatio,
SalesmanBonusPercent: param.SalesmanRatio,
OrderStatus: param.OrderStatue,
}
orderSrv := orderService.NewOrderService(nil)
err = orderSrv.UpdateOrderReal(cmd)
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(&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.OrderActualCount,
"orderPrice": orderinfo.OrderActualAmount,
"orderDist": orderinfo.OrderRegionInfo.RegionName,
"orderStatue": orderinfo.OrderStatus,
}
c.ResponseData(rsp)
}
//UpdateOrderReal 更新实发订单数据
func (c *OrderController) UpdateOrderReal() {
//用与适配前端定义的数据结构
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.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)
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,
}
orderSrv := orderService.NewOrderService(nil)
err := orderSrv.UpdateOrderReal(updateCmd)
return err
}
... ...
... ... @@ -37,10 +37,13 @@ func init() {
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("/purpose/convert", &controllers.OrderController{}, "POST:OrderPurposeToReal"),
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.NSRouter("/actual/update", &controllers.OrderController{}, "POST:UpdateOrderReal"),
beego.NSRouter("/actual/detail", &controllers.OrderController{}, "POST:GetOrderReal"),
),
beego.NSNamespace("/common",
beego.NSRouter("/partner", &controllers.CommonController{}, "POST:GetPartnerList"),
),
)
beego.AddNamespace(adminRouter)
... ...