作者 yangfu

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

... ... @@ -33,7 +33,7 @@ func CreateAdminPermissionRepository(options map[string]interface{}) (domain.Adm
return repository.NewAdminPermissionRepository(transactionContext)
}
//CreatePartnerInfoRepository 合伙人信息
//CreateOrderPaymentRepository 分红单信息
func CreateOrderPaymentRepository(options map[string]interface{}) (domain.OrderPaymentRepository, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
... ... @@ -41,3 +41,12 @@ func CreateOrderPaymentRepository(options map[string]interface{}) (domain.OrderP
}
return repository.NewOrderPaymentRepository(transactionContext)
}
//CreateOrderRepository 订单信息
func CreateOrderRepository(options map[string]interface{}) (domain.OrderRepository, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*transaction.TransactionContext)
}
return repository.NewOrderRepository(transactionContext)
}
... ...
package query
//ListOrderQuery 获取用户列表
type GetOrderQuery struct {
OrderId int64 `json:"orderId"`
}
... ...
package query
//ListOrderQuery 获取用户列表
type ListOrderQuery struct {
//合伙人id
PartnerId int64 `json:"partnerId" `
//订单编号
OrderCode string `json:"order_code"`
// 查询偏离量
Offset int `json:"offset" `
// 查询限制
Limit int `json:"limit"`
}
... ...
package service
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
"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"
)
//OrderService 管理员相关服务
type OrderService struct {
}
func NewOrderService(option map[string]interface{}) *OrderService {
newAdminUserService := new(OrderService)
return newAdminUserService
}
func (service OrderService) PageListOrder(listOrderQuery query.ListOrderQuery) ([]domain.Order, int, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, 0, lib.ThrowError(lib.TRANSACTION_ERROR, err.Error())
}
var (
orderRepository domain.OrderRepository
orders []domain.Order
cnt int
)
if value, err := factory.CreateOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, 0, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderRepository = value
}
query := domain.OrderFindQuery{
PartnerId: listOrderQuery.PartnerId,
OrderCode: listOrderQuery.OrderCode,
Offset: listOrderQuery.Offset,
Limit: listOrderQuery.Limit,
}
orders, err = orderRepository.Find(query)
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())
}
return orders, cnt, nil
}
func (service OrderService) GetOrder(getOrderQuery query.GetOrderQuery) (*domain.Order, error) {
//实际业务
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, 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 nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
} else {
orderRepository = value
}
order, err = orderRepository.FindOne(domain.OrderFindOneQuery{
OrderId: getOrderQuery.OrderId,
})
if err != nil {
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
return order, nil
}
func (service OrderService) CreateOrde() error {
return nil
}
... ...
... ... @@ -135,6 +135,7 @@ func (PartnerInfoService *PartnerInfoService) UpdatePartnerInfo(updatePartnerInf
partnerInfo.Salesman = updatePartnerInfoCommand.Salesman
partnerInfo.Status = updatePartnerInfoCommand.Status
partnerInfo.RegionInfo = updatePartnerInfoCommand.RegionInfo
partnerInfo.CooperateTime = updatePartnerInfoCommand.CooperateTime
if _, err = partnerInfoRepository.Save(partnerInfo); err != nil {
return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -22,6 +22,21 @@ type AdminUser struct {
Permission []AdminPermissionBase `json:"permission"`
}
//TODO
func (adminUser *AdminUser) Update(data map[string]string) error {
return nil
}
//TODO
func (adminUser *AdminUser) ChangePassword(data string) error {
return nil
}
//TODO
func (admin *AdminUser) ChangeIsUsable(yesOrNo bool) error {
return nil
}
type AdminUserFindQuery struct {
AccountLike string
Offset int
... ...
... ... @@ -38,35 +38,47 @@ type Order struct {
//实际数量
OrderActualCount int `json:"orderActualCount"`
//订单金额
OrderAmount int `json:"orderAmount"`
OrderAmount float64 `json:"orderAmount"`
//实际订单金额
OrderActualAmount int `json:"orderActualAmount"`
OrderActualAmount float64 `json:"orderActualAmount"`
//订单已支付分红金额(货款)
OrderPaymentAmount int `json:"orderPaymentAmount"`
OrderPaymentAmount float64 `json:"orderPaymentAmount"`
//订单区域信息
OrderRegionInfo *RegionInfo `json:"orderRegionInfo"`
//买家
Buyer *Buyer `json:"buyer"`
//合伙人id
PartnerId int64 `json:"PartnerId"`
//合伙人数据
PartnerInfo *PartnerInfo `json:"partnerInfo"`
PartnerInfo *Partner `json:"partnerInfo"`
//合伙人分红百分比
PartnerBonusPercent float64 `json:"partnerBonusPercent"`
//业务员分红百分比
SalesmanBonusPercent float64 `json:"salesmanBonusPercent"`
//最后查看得时间
LastViewTime time.Time `json:"lastViewTime"`
//更新时间
UpdateAt time.Time `json:"updateAt"`
CreateAt time.Time `json:"createAt"`
}
// type PartnerFindOneQuery struct {
// UserId int64
// AccountEqual string
// }
//TODO
func (order Order) Update(data map[string]interface{}) error {
return nil
}
type OrderFindOneQuery struct {
OrderId int64
}
type OrderFindQuery struct {
PartnerId int64
OrderCode string
Offset int
Limit int
}
type OrderRepository interface {
Save(*Order) error
//FindOne(qureyOptions AdminUserFindOneQuery) (*AdminUser, error)
// Find(queryOptions AdminUserFindQuery) ([]AdminUser, error)
// CountAll(queryOption AdminUserFindQuery) (int, error)
Save(order *Order) error
FindOne(qureyOptions OrderFindOneQuery) (*Order, error)
Find(queryOptions OrderFindQuery) ([]Order, error)
CountAll(queryOption OrderFindQuery) (int, error)
}
... ...
... ... @@ -16,20 +16,13 @@ const (
)
type PartnerInfo struct {
Partner Partner
// // 合伙人ID
// Id int64 `json:"id"`
// // 合伙人姓名
// PartnerName string `json:"partnerName"`
// // 登录账号
// Account string `json:"account"`
Partner Partner `json:"partner"`
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
PartnerCategory int `json:"partnerCategory"`
// 登录密码
Password string `json:"password"`
// 状态(1:启用或者0:禁用)
Status int `json:"status"`
//创建时间
CreateAt time.Time `json:"createAt"`
//更新时间
... ... @@ -42,10 +35,26 @@ type PartnerInfo struct {
Salesman []Salesman `json:"salesman"`
}
//TODO
func (partner *PartnerInfo) Update(data map[string]string) error {
return nil
}
//TODO
func (partner *PartnerInfo) ChangeStatus(yesOrNo bool) error {
return nil
}
//TODO
func (partner *PartnerInfo) ChangePassword(pwd string) error {
return nil
}
type PartnerFindOneQuery struct {
UserId int64
AccountEqual string
}
type PartnerFindQuery struct {
Offset int
Limit int
... ...
package models
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"context"
"time"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
type Order struct {
... ... @@ -49,3 +52,18 @@ type Order struct {
//上一次查看时间 已读情况
LastViewTime time.Time
}
var _ pg.BeforeUpdateHook = (*Order)(nil)
func (or *Order) BeforeUpdate(ctx context.Context) (context.Context, error) {
or.UpdateAt = time.Now()
return ctx, nil
}
var _ pg.BeforeInsertHook = (*Order)(nil)
func (or *Order) BeforeInsert(ctx context.Context) (context.Context, error) {
or.CreateAt = time.Now()
or.UpdateAt = time.Now()
return ctx, nil
}
... ...
... ... @@ -122,7 +122,7 @@ func (reponsitory AdminUserRepository) Find(queryOption domain.AdminUserFindQuer
err error
adminuserReturn = make([]domain.AdminUser, 0)
)
query = query.Order("admin_user.id DESC ")
query = query.Order("admin_user.id DESC")
err = query.Select()
if err != nil {
return adminuserReturn, err
... ...
... ... @@ -22,19 +22,137 @@ func NewOrderRepository(transactionContext *transaction.TransactionContext) (*Or
}
return &OrderRepository{transactionContext: transactionContext}, nil
}
func (reponsitory OrderRepository) transformPgModelToDomainModel(adminuserModel *models.Order) (domain.Order, error) {
result := domain.Order{}
func (reponsitory OrderRepository) transformPgModelToDomainModel(orderModel *models.Order) (domain.Order, error) {
result := domain.Order{
Id: orderModel.Id,
OrderType: orderModel.OrderType,
OrderCode: orderModel.OrderCode,
OrderName: orderModel.OrderName,
OrderStatus: orderModel.OrderStatus,
OrderCount: orderModel.OrderCount,
OrderActualCount: orderModel.OrderActualCount,
OrderAmount: orderModel.OrderAmount,
OrderActualAmount: orderModel.OrderActualAmount,
OrderPaymentAmount: orderModel.OrderPaymentAmount,
OrderRegionInfo: orderModel.OrderRegionInfo,
Buyer: orderModel.Buyer,
PartnerInfo: &domain.Partner{
Id: orderModel.PartnerId,
},
PartnerBonusPercent: orderModel.PartnerBonusPercent,
SalesmanBonusPercent: orderModel.SalesmanBonusPercent,
LastViewTime: orderModel.LastViewTime,
UpdateAt: orderModel.UpdateAt,
CreateAt: orderModel.CreateAt,
}
return result, nil
}
func (repository OrderRepository) Save(orderInfo *domain.Order) error {
return nil
var (
err error
tx = repository.transactionContext.PgTx
)
m := &models.Order{
Id: orderInfo.Id,
OrderType: orderInfo.OrderType,
OrderCode: orderInfo.OrderCode,
OrderName: orderInfo.OrderName,
OrderStatus: orderInfo.OrderStatus,
OrderCount: orderInfo.OrderCount,
OrderActualCount: orderInfo.OrderActualCount,
OrderAmount: orderInfo.OrderAmount,
OrderActualAmount: orderInfo.OrderActualAmount,
OrderPaymentAmount: orderInfo.OrderPaymentAmount,
OrderRegionInfo: orderInfo.OrderRegionInfo,
Buyer: orderInfo.Buyer,
PartnerId: orderInfo.PartnerInfo.Id,
PartnerBonusPercent: orderInfo.PartnerBonusPercent,
SalesmanBonusPercent: orderInfo.SalesmanBonusPercent,
CreateAt: orderInfo.CreateAt,
UpdateAt: orderInfo.UpdateAt,
LastViewTime: orderInfo.LastViewTime,
}
if m.Id == 0 {
err = tx.Insert(m)
orderInfo.Id = m.Id
} else {
err = tx.Update(m)
}
return err
}
func (repository OrderRepository) Find() (*domain.Order, error) {
return nil, nil
func (repository OrderRepository) Find(queryOption domain.OrderFindQuery) ([]domain.Order, error) {
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.Offset > -1 {
query = query.Offset(queryOption.Offset)
}
if queryOption.Limit > 0 {
query = query.Limit(queryOption.Limit)
} else {
query = query.Limit(20)
}
var (
err error
ordersReturn = make([]domain.Order, 0)
)
query = query.Order("order.id DESC ")
err = query.Select()
if err != nil {
return ordersReturn, err
}
for i := range orderModels {
domainOrder, err := repository.transformPgModelToDomainModel(&orderModels[i])
if err != nil {
return ordersReturn, err
}
ordersReturn = append(ordersReturn, domainOrder)
}
return ordersReturn, nil
}
func (repository OrderRepository) CountAll(queryOption domain.OrderFindQuery) (int, error) {
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+"%")
}
var (
err error
)
cnt, err := query.Count()
if err != nil {
return cnt, err
}
return 0, nil
}
func (repository OrderRepository) FindOne() ([]domain.Order, error) {
return nil, nil
func (repository OrderRepository) FindOne(qureyOptions domain.OrderFindOneQuery) (*domain.Order, error) {
var (
err error
tx = repository.transactionContext.PgTx
)
m := new(models.Order)
err = tx.Model(m).
Where("id=?", qureyOptions.OrderId).
First()
if err != nil {
return nil, err
}
result, err := repository.transformPgModelToDomainModel(m)
return &result, err
}
... ...
... ... @@ -114,7 +114,7 @@ func (repository *PartnerInfoRepository) Find(queryOption domain.PartnerFindQuer
err error
partnerReturn = make([]domain.PartnerInfo, 0)
)
query = query.Order("partner_info.id DESC")
query = query.Order("id DESC")
err = query.Select()
if err != nil {
return partnerReturn, err
... ...