作者 yangfu

1.接口调整

... ... @@ -41,3 +41,8 @@ func CreatePartnerInfoRepositoryIn(transactionContext *transaction.TransactionCo
func CreatePartnerSubAccountRepository(transactionContext *transaction.TransactionContext) (domain.PartnerSubAccountRepository, error) {
return repository.NewPartnerSubAccountRepository(transactionContext)
}
//公司信息
func CreateCompanyRepository(transactionContext *transaction.TransactionContext) (domain.CompanyRepository, error) {
return repository.NewCompanyRepository(transactionContext)
}
... ...
... ... @@ -14,21 +14,36 @@ import (
//用户信息
func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) {
var (
PartnerInfoService = service.NewPartnerInfoService(nil)
partnerInfo *domain.PartnerInfo
PartnerInfoService = service.NewPartnerInfoService(nil)
partnerInfo *domain.PartnerInfo
transactionContext, _ = factory.CreateTransactionContext(nil)
CompanyResponsitory, _ = factory.CreateCompanyRepository(transactionContext)
company *domain.Company
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
if err != nil {
transactionContext.RollbackTransaction()
}
}()
rsp = &protocol.UserInfoResponse{}
if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil {
err = protocol.NewErrWithMessage(502, err) //账号不存在
return
}
if company, err = CompanyResponsitory.FindOne(map[string]interface{}{"id": 1}); err != nil {
return
}
rsp.User = protocol.User{
Id: partnerInfo.Id,
PartnerName: partnerInfo.PartnerName,
Phone: partnerInfo.Account,
CooperateCompany: protocol.Company{
Id: 1,
Name: "福州素天下有限公司",
Id: company.Id,
Name: company.Name,
Phone: company.Phone,
},
JoinWay: partnerInfo.PartnerCategoryInfo(),
District: map[string]interface{}{"id": partnerInfo.RegionInfo.RegionId, "name": partnerInfo.RegionInfo.RegionName},
... ... @@ -40,6 +55,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
} else {
rsp.User.Salesman = map[string]interface{}{}
}
err = transactionContext.CommitTransaction()
return
}
... ...
... ... @@ -5,3 +5,10 @@ type Company struct {
Name string `json:"name"`
Phone string `json:"phone"`
}
type CompanyRepository interface {
Save(dm *Company) (*Company, error)
Remove(dm *Company) (*Company, error)
FindOne(queryOptions map[string]interface{}) (*Company, error)
Find(queryOptions map[string]interface{}) (int64, []*Company, error)
}
... ...
package dao
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
)
type CompanyDao struct {
transactionContext *transaction.TransactionContext
}
func NewCompanyDao(transactionContext *transaction.TransactionContext) (*CompanyDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &CompanyDao{
transactionContext: transactionContext,
}, nil
}
}
... ...
... ... @@ -29,6 +29,7 @@ func init() {
(*models.Order)(nil),
(*models.OrderPayment)(nil),
(*models.PartnerSubAccount)(nil),
(*models.Company)(nil),
} {
err := DB.CreateTable(model, &orm.CreateTableOptions{
Temp: false,
... ...
package repository
import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
. "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
)
type CompanyRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository *CompanyRepository) Save(dm *domain.Company) (*domain.Company, error) {
var (
err error
m = &models.Company{}
tx = repository.transactionContext.PgTx
)
if err = GobModelTransform(m, dm); err != nil {
return nil, err
}
if dm.Id == 0 {
if err = tx.Insert(m); err != nil {
return nil, err
}
return dm, nil
}
if err = tx.Update(m); err != nil {
return nil, err
}
return dm, nil
}
func (repository *CompanyRepository) Remove(Company *domain.Company) (*domain.Company, error) {
var (
tx = repository.transactionContext.PgTx
CompanyModel = &models.Company{Id: Company.Id}
)
if _, err := tx.Model(CompanyModel).Where("id = ?", Company.Id).Delete(); err != nil {
return Company, err
}
return Company, nil
}
func (repository *CompanyRepository) FindOne(queryOptions map[string]interface{}) (*domain.Company, error) {
tx := repository.transactionContext.PgTx
CompanyModel := new(models.Company)
query := NewQuery(tx.Model(CompanyModel), queryOptions)
query.SetWhere(`"company".id = ?`, "id")
if err := query.First(); err != nil {
return nil, query.HandleError(err, "没有此订单")
}
if CompanyModel.Id == 0 {
return nil, nil
}
return repository.transformPgModelToDomainModel(CompanyModel)
}
func (repository *CompanyRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Company, error) {
tx := repository.transactionContext.PgTx
var CompanyModels []*models.Company
Companys := make([]*domain.Company, 0)
query := NewQuery(tx.Model(&CompanyModels), queryOptions)
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, Companys, err
}
for _, CompanyModel := range CompanyModels {
if Company, err := repository.transformPgModelToDomainModel(CompanyModel); err != nil {
return 0, Companys, err
} else {
Companys = append(Companys, Company)
}
}
return int64(query.AffectRow), Companys, nil
}
func (repository *CompanyRepository) transformPgModelToDomainModel(CompanyModel *models.Company) (*domain.Company, error) {
m := &domain.Company{}
err := GobModelTransform(m, CompanyModel)
return m, err
}
func NewCompanyRepository(transactionContext *transaction.TransactionContext) (*CompanyRepository, error) {
if transactionContext == nil {
return nil, ERR_EMPTY_TC
}
return &CompanyRepository{transactionContext: transactionContext}, nil
}
... ...
... ... @@ -2,7 +2,9 @@ package controllers
import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/order"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
"time"
)
type OrderController struct {
... ... @@ -64,6 +66,28 @@ func (this *OrderController) OrderList() {
msg = m
return
}
request.OrderAction = domain.OrderReal
header := this.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(order.OrderList(header, request))
}
//OrderList
func (this *OrderController) Intentions() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.OrderListRequest
if err := this.JsonUnmarshal(&request); err != nil {
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
request.EndTime = time.Now().Unix() * 1000
request.OrderAction = domain.OrderIntention
header := this.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(order.OrderList(header, request))
}
... ...
... ... @@ -26,6 +26,7 @@ func init() {
nsV1.Router("/order/statistics", &controllers.OrderController{}, "Post:Statistics")
nsV1.Router("/order/details", &controllers.OrderController{}, "Post:OrderDetail")
nsV1.Router("/order/list", &controllers.OrderController{}, "Post:OrderList")
nsV1.Router("/order/intentions", &controllers.OrderController{}, "Post:Intentions")
nsV1.Router("/dividend/statistics", &controllers.DividendController{}, "Post:DividendStatistics")
nsV1.Router("/dividend/orders", &controllers.DividendController{}, "Post:DividendOrders")
... ...
... ... @@ -46,7 +46,7 @@ type OrderStatics struct {
type OrderListRequest struct {
StartTime int64 `json:"startTime" valid:"Required"`
EndTime int64 `json:"endTime" valid:"Required"`
OrderAction int `json:"orderAction" valid:"Required"`
OrderAction int `json:"orderAction"`
PageIndex int `json:"pageIndex"`
PageSize int `json:"pageSize" valid:"Required"`
}
... ...
... ... @@ -31,8 +31,9 @@ type User struct {
}
type Company struct {
Id int `json:"id"`
Name string `json:"name"`
Id int64 `json:"id"`
Name string `json:"name"`
Phone string `json:"phone"`
}
/*修改手机号-验证旧手机验证码 */
... ...