作者 唐旭辉

分红列表更新

... ... @@ -10,9 +10,11 @@ type ListOrderBaseQuery struct {
Offset int `json:"offset" `
// 查询限制
Limit int `json:"limit"`
//订单类型
OrderType int `json:"orderType"`
//发货单号
DeliveryCode string `json:"deliveryCode"`
CompanyId int64 `json:"companyId"`
//订单类型
OrderType int `json:"orderType"`
PartnerOrCode string `json:"partner_or_code"`
}
... ...
package query
type ListOrderBonusQuery struct {
// 查询偏离量
Offset int `json:"offset" `
// 查询限制
Limit int `json:"limit"`
CompanyId int64 `json:"companyId"`
//订单类型
OrderType int `json:"orderType"`
PartnerOrCode string `json:"partner_or_code"`
}
... ...
... ... @@ -11,6 +11,7 @@ import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/query"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
... ... @@ -711,8 +712,85 @@ func (service OrderInfoService) UpdateGoodBouns(cmd command.UpdateGoodBouns) err
}
//PageListOrderBouns 获取订单的分红列表
func (service OrderInfoService) PageListOrderBonus(listOrderQuery query.ListOrderBonusQuery) ([]domain.OrderBase, int, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
if err = transactionContext.StartTransaction(); err != nil {
return nil, 0, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
var (
ordersM []models.OrderBase
orders []domain.OrderBase
cnt int
orderBaseDao *dao.OrderBaseDao
)
if orderBaseDao, err = factory.CreateOrderBaseDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, cnt, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
ordersM, cnt, err = orderBaseDao.OrderListByCondition(
listOrderQuery.CompanyId,
listOrderQuery.OrderType,
listOrderQuery.PartnerOrCode,
listOrderQuery.Limit,
listOrderQuery.Offset,
)
for _, orderModel := range ordersM {
order := domain.OrderBase{
Id: orderModel.Id, OrderType: orderModel.OrderType, OrderCode: orderModel.OrderCode,
DeliveryCode: orderModel.DeliveryCode, Buyer: orderModel.Buyer, RegionInfo: orderModel.RegionInfo,
PartnerId: orderModel.PartnerId, SalesmanBonusPercent: orderModel.SalesmanBonusPercent,
CreateTime: orderModel.CreateTime, DeliveryTime: orderModel.DeliveryTime, UpdateTime: orderModel.UpdateTime,
IsDisable: orderModel.IsDisable,
OrderCompute: domain.OrderCompute{
PlanPartnerBonus: orderModel.PlanPartnerBonus, UsePartnerBonus: orderModel.UsePartnerBonus,
PartnerBonusHas: orderModel.PartnerBonusHas, PartnerBonusNot: orderModel.PartnerBonusNot,
PartnerBonusExpense: orderModel.PartnerBonusExpense, SalesmanBonus: orderModel.SalesmanBonus,
PlanOrderCount: orderModel.PlanOrderCount, PlanOrderAmount: orderModel.PlanOrderAmount,
UseOrderCount: orderModel.UseOrderCount, UseOrderAmount: orderModel.UseOrderAmount,
},
PartnerInfo: domain.Partner{
Id: orderModel.PartnerId,
},
BonusStatus: orderModel.BonusStatus,
CompanyId: orderModel.CompanyId,
}
orders = append(orders, order)
}
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 {
partnerData := &domain.PartnerInfo{}
partnerData, err = PartnerInfoRepository.FindOne(domain.PartnerFindOneQuery{
UserId: orders[i].PartnerId,
})
if err != nil {
logs.Error("获取合伙(id=%d)失败%s", orders[i].PartnerId, err)
} else {
orders[i].PartnerInfo = partnerData.Partner
}
}
err = transactionContext.CommitTransaction()
if err != nil {
return orders, cnt, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return orders, cnt, nil
}
//UpdateBounsWithGoodNumber 分红时,因修改订单中商品的数量发生分红变动
func (service OrderInfoService) UpdateBounsByGoodNumber() error {
func (service OrderInfoService) UpdateBonusByGoodNumber() error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
... ... @@ -732,7 +810,7 @@ func (service OrderInfoService) UpdateBounsByGoodNumber() error {
}
//UpdateBounsByPartnerBonusPercent 分红时,因修改订单中商品的合伙人分行比例发生分红变动
func (service OrderInfoService) UpdateBounsByPartnerBonusPercent() error {
func (service OrderInfoService) UpdateBonusByPartnerBonusPercent() error {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
err error
... ...
... ... @@ -9,8 +9,22 @@ import (
const (
OrderReal = iota + 1 //实发订单
OrderIntention //意向订单
OrderHaiXian //来自小程序海鲜干货的订单
)
func GetOrderBaseTypeName(orderType int) string {
var name string
switch orderType {
case OrderReal:
name = "自建订单"
case OrderHaiXian:
name = "小程序订单"
case OrderIntention:
name = "意向订单"
}
return name
}
const (
OrderDisableNot = iota //订单未关闭
OrderDisableYes //订单已关闭
... ...
... ... @@ -3,6 +3,8 @@ package dao
import (
"fmt"
"github.com/go-pg/pg/v10/orm"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
... ... @@ -22,7 +24,7 @@ func NewOrderBaseDao(transactionContext *transaction.TransactionContext) (*Order
}
func (dao OrderBaseDao) OrderCodeExist(code string, notId ...int64) (bool, error) {
tx := dao.transactionContext.PgDd
tx := dao.transactionContext.GetDB()
m := &models.OrderBase{}
query := tx.Model(m).Where("order_code=?", code)
if len(notId) > 0 {
... ... @@ -33,7 +35,7 @@ func (dao OrderBaseDao) OrderCodeExist(code string, notId ...int64) (bool, error
}
func (dao OrderBaseDao) DeliveryCodeExist(code string, companyId int64, notId ...int64) (bool, error) {
tx := dao.transactionContext.PgDd
tx := dao.transactionContext.GetDB()
m := &models.OrderBase{}
query := tx.Model(m).Where("delivery_code=?", code).Where("company_id=?", companyId)
if len(notId) > 0 {
... ... @@ -42,3 +44,27 @@ func (dao OrderBaseDao) DeliveryCodeExist(code string, companyId int64, notId ..
ok, err := query.Exists()
return ok, err
}
//OrderListByCondition 根据条件获取订单列表
//orderType 订单类型
//partnerOrCode 合伙人姓名或订单号或发货单号
func (dao OrderBaseDao) OrderListByCondition(companyId int64, orderType int, partnerOrCode string, limit, offset int) ([]models.OrderBase, int, error) {
tx := dao.transactionContext.GetDB()
var orders []models.OrderBase
query := tx.Model(&orders).Where("order_base.company_id=?", companyId)
if orderType > 0 {
query = query.Where("order_base.order_type=?", orderType)
}
if len(partnerOrCode) > 0 {
query = query.Join("LEFT JOIN partner_info as p ON order_base.partner_id=p.id").
WhereGroup(func(q *orm.Query) (*orm.Query, error) {
q = q.WhereOr("order_base.order_code like ? ", "%"+partnerOrCode+"%").
WhereOr("order_base.delivery_code like ? ", "%"+partnerOrCode+"%").
WhereOr("p.partner_name like ? ", "%"+partnerOrCode+"%")
return q, nil
})
}
query = query.Offset(offset).Limit(limit)
cnt, err := query.SelectAndCount()
return orders, cnt, err
}
... ...
... ... @@ -5,6 +5,7 @@ import (
categoryService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerCategory/service"
partnerQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
partnerInfoService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
type CommonController struct {
... ... @@ -64,3 +65,18 @@ func (c *CommonController) GetPartnerCategory() {
}
c.ResponseData(resp)
}
// GetOrderType 下拉选项数据通用接口,获取订单类型列表
func (c *CommonController) GetOrderType() {
resp := []map[string]interface{}{
map[string]interface{}{
"id": domain.OrderReal,
"name": domain.GetOrderBaseTypeName(domain.OrderReal),
},
map[string]interface{}{
"id": domain.OrderHaiXian,
"name": domain.GetOrderBaseTypeName(domain.OrderHaiXian),
},
}
c.ResponseData(resp)
}
... ...
... ... @@ -32,7 +32,7 @@ func (c *OrderDividendController) Prepare() {
func (c *OrderDividendController) PageListOrderDividend() {
type Parameter struct {
SearchText string `json:"searchText"`
Partner int64 `json:"partner"`
OrderType int `json:"orderType"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
}
... ... @@ -45,6 +45,12 @@ func (c *OrderDividendController) PageListOrderDividend() {
c.ResponseError(errors.New("json数据解析失败"))
return
}
if !(param.OrderType == 0 ||
param.OrderType == domain.OrderReal ||
param.OrderType == domain.OrderHaiXian) {
c.ResponseError(errors.New("参数异常"))
return
}
if param.PageNumber == 0 {
param.PageNumber = 1
}
... ... @@ -53,18 +59,18 @@ func (c *OrderDividendController) PageListOrderDividend() {
}
companyId := c.GetUserCompany()
orderSrv := orderService.NewOrderInfoService(nil)
orderinfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{
PartnerId: param.Partner,
DeliveryCode: param.SearchText,
OrderType: domain.OrderReal,
Limit: param.PageSize,
Offset: (param.PageNumber - 1) * param.PageSize,
CompanyId: companyId,
orderinfos, cnt, err := orderSrv.PageListOrderBonus(orderQuery.ListOrderBonusQuery{
OrderType: param.OrderType,
PartnerOrCode: param.SearchText,
Limit: param.PageSize,
Offset: (param.PageNumber - 1) * param.PageSize,
CompanyId: companyId,
})
if err != nil {
c.ResponseError(err)
return
}
//适配数据输出
rsp := []map[string]interface{}{}
for i := range orderinfos {
orderinfo := orderinfos[i]
... ... @@ -78,6 +84,9 @@ func (c *OrderDividendController) PageListOrderDividend() {
"receiveDividends": orderinfo.OrderCompute.PartnerBonusHas,
"uncollectedDividends": orderinfo.OrderCompute.PartnerBonusNot,
"stateOfPayment": orderinfo.BonusStatus,
"orderType": orderinfo.OrderType,
"orderTypeName": domain.GetOrderBaseTypeName(orderinfo.OrderType),
"orderNumber": orderinfo.OrderCode,
}
if orderinfo.OrderCompute.UsePartnerBonus >= 0 {
m["dividendsReceivable"] = orderinfo.OrderCompute.UsePartnerBonus
... ...
... ... @@ -50,6 +50,7 @@ func init() {
beego.NSNamespace("/common",
beego.NSRouter("/partner", &controllers.CommonController{}, "POST:GetPartnerList"),
beego.NSRouter("/partnerType", &controllers.CommonController{}, "POST:GetPartnerCategory"),
beego.NSRouter("/orderType", &controllers.CommonController{}, "POST:GetOrderType"),
),
beego.NSNamespace("/enterprises",
... ...