作者 唐旭辉

更新

... ... @@ -328,7 +328,7 @@ func (service UsersService) GetUserData(userId int64, companyId int64) (map[stri
Id: userId, CompanyId: companyId,
})
if err != nil {
e := fmt.Sprintf("获取用户(id=%d)数据失败;%s", userId, err)
e := fmt.Sprintf("获取用户(id=%d;company_id=%d)数据失败;%s", userId, companyId, err)
return nil, lib.ThrowError(lib.INTERNAL_SERVER_ERROR, e)
}
var partnerIds []int64
... ...
package domain
import "time"
// 业务分红信息 是否关闭【0;否】【1:是】
const (
BUSINESS_BONUS_ENABLE int8 = 0
BUSINESS_BONUS_DISABLE int8 = 1
)
// 分红状态 1:待支付分红 2:已支付分红
const (
//待支付
BUSINESS_BONUS_WAIT_PAY int = 1
//已支付
BUSINESS_BONUS_HAS_PAY int = 2
)
// 业务分红信息
type BusinessBonus struct {
// 唯一标识
Id int64 `json:"id"`
// 公司编号
CompanyId int64 `json:"companyId"`
// 合伙人信息Id
PartnerInfoId int64 `json:"partnerInfoId"`
// 应收分红
Bonus float64 `json:"bonus"`
// 未收分红
BonusNot float64 `json:"bonusNot"`
// 分红支出
BonusExpense float64 `json:"bonusExpense"`
// 是否关闭【0;否】【1:是】
IsDisable int8 `json:"isDisable"`
// 分红状态 1:待支付分红 2:已支付分红
BonusStatus int8 `json:"bonusStatus"`
// 创建时间
CreateAt time.Time `json:"createAt"`
// 更新时间
UpdateAt time.Time `json:"updateAt"`
// 删除时间
DeleteAt time.Time `json:"deleteAt"`
}
type BusinessBonusFindOneQuery struct {
Id int64
PartnerId int64
}
type BusinessBonusFindQuery struct {
Offset int
Limit int
}
type BusinessBonusRepository interface {
Add(dm *BusinessBonus) error
Edit(dm *BusinessBonus) error
FindOne(BusinessBonusFindOneQuery) (*BusinessBonus, error)
Find(BusinessBonusFindQuery) (int, []BusinessBonus, error)
}
... ...
package service
type BusinessBonusService interface {
EnableOrDisable(userid int64) error
}
... ...
... ... @@ -15,7 +15,7 @@ type BusinessBonus struct {
// 公司编号
CompanyId int64
// 合伙人信息Id
PartnerInfoId string
PartnerInfoId int64
// 应收分红
Bonus float64
// 未收分红
... ...
package repository
import (
"errors"
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type BusinessBonusRepository struct {
transactionContext *transaction.TransactionContext
}
func (repository *BusinessBonusRepository) transformPgModelToDomainModel(BusinessBonusModel *models.BusinessBonus) (domain.BusinessBonus, error) {
m := domain.BusinessBonus{}
return m, nil
}
func NewBusinessBonusRepository(transactionContext *transaction.TransactionContext) (*BusinessBonusRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &BusinessBonusRepository{transactionContext: transactionContext}, nil
}
func (repository *BusinessBonusRepository) Add(dm *domain.BusinessBonus) error {
tx := repository.transactionContext.PgTx
bonusModel := models.BusinessBonus{
Id: dm.Id,
CompanyId: dm.CompanyId,
PartnerInfoId: dm.PartnerInfoId,
Bonus: dm.Bonus,
BonusNot: dm.Bonus,
BonusExpense: dm.BonusExpense,
IsDisable: dm.IsDisable,
BonusStatus: dm.BonusStatus,
}
_, err := tx.Model(&bonusModel).
Insert()
dm.CreateAt = bonusModel.CreateAt
dm.UpdateAt = bonusModel.UpdateAt
dm.Id = bonusModel.Id
return err
}
func (repository *BusinessBonusRepository) Edit(dm *domain.BusinessBonus) error {
tx := repository.transactionContext.PgTx
bonusModel := models.BusinessBonus{
Id: dm.Id,
CompanyId: dm.CompanyId,
PartnerInfoId: dm.PartnerInfoId,
Bonus: dm.Bonus,
BonusNot: dm.Bonus,
BonusExpense: dm.BonusExpense,
IsDisable: dm.IsDisable,
BonusStatus: dm.BonusStatus,
CreateAt: dm.CreateAt,
UpdateAt: dm.UpdateAt,
}
_, err := tx.Model(&bonusModel).WherePK().Update()
return err
}
func (repository *BusinessBonusRepository) FindOne(queryOptions domain.BusinessBonusFindOneQuery) (*domain.BusinessBonus, error) {
tx := repository.transactionContext.PgTx
BusinessBonusModel := new(models.BusinessBonus)
var hasCondition bool
query := tx.Model(BusinessBonusModel).Where("delete_at ISNULL")
if queryOptions.Id > 0 {
hasCondition = true
query = query.Where("id=?", queryOptions.Id)
}
if queryOptions.PartnerId > 0 {
hasCondition = true
query = query.Where("partner_info_id=?", queryOptions.PartnerId)
}
if !hasCondition {
return nil, errors.New("没有查询条件")
}
if err := query.First(); err != nil {
return nil, err
}
data, err := repository.transformPgModelToDomainModel(BusinessBonusModel)
return &data, err
}
func (repository *BusinessBonusRepository) Find(queryOptions domain.BusinessBonusFindQuery) (int, []domain.BusinessBonus, error) {
tx := repository.transactionContext.PgTx
var (
err error
cnt int
businessBonuss []domain.BusinessBonus
businessBonusModels []models.BusinessBonus
)
query := tx.Model(&businessBonusModels)
if cnt, err = query.SelectAndCount(); err != nil {
return 0, businessBonuss, err
}
for i := range businessBonusModels {
if businessBonus, err := repository.transformPgModelToDomainModel(&businessBonusModels[i]); err != nil {
return 0, businessBonuss, err
} else {
businessBonuss = append(businessBonuss, businessBonus)
}
}
return cnt, businessBonuss, nil
}
... ...
... ... @@ -10,6 +10,7 @@ import (
"github.com/astaxie/beego/logs"
userCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/command"
userService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
type AdminLoginController struct {
... ... @@ -23,7 +24,9 @@ func (c *AdminLoginController) Prepare() {
urlIn := map[string]int{
"/v1/auth/captcha-init": 1,
"/v1/auth/login": 1,
"/v1/auth/login2": 1,
}
nowUrl := c.Ctx.Input.URL()
if _, ok := urlIn[nowUrl]; ok {
//跳过校验
... ... @@ -99,6 +102,23 @@ func (c *AdminLoginController) Login() {
return
}
//Login2 开发临时使用
func (c *AdminLoginController) Login2() {
newToken := `eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.` +
`eyJleHAiOjE1OTk3NjEwNDQsImlhdCI6MTU5OTcxNzg0NCwiaXNzI` +
`joibW1tX3BhcnRuZXJtZyIsIm5iZiI6MTU5OTcxNzg0NCwidWlkIjo` +
`zMjU0ODUxNzgyMTYzMjAwLCJjb21wYW55SWQiOjF9.H6EKUJAtv22OZ` +
`2R59K1xAAaqUzSROAkXfprpqoBpMX8`
returnData := map[string]interface{}{
"access": map[string]interface{}{
"accessToken": newToken,
"expiresIn": lib.JWtExpiresSecond,
},
}
c.ResponseData(returnData)
return
}
//CaptchaInit 极验初始化
func (c *AdminLoginController) CaptchaInit() {
const (
... ...
... ... @@ -11,6 +11,7 @@ func init() {
beego.NSRouter("/login", &controllers.AdminLoginController{}, "POST:Login"),
beego.NSRouter("/captcha-init", &controllers.AdminLoginController{}, "POST:CaptchaInit"),
beego.NSRouter("/profile", &controllers.AdminLoginController{}, "POST:AdminpPofile"),
beego.NSRouter("/login2", &controllers.AdminLoginController{}, "POST:Login2"), //开发临时使用
// beego.NSRouter("/pwd-update", &controllers.AdminLoginController{}, "POST:PwdUpdate"),
),
beego.NSNamespace("/admin",
... ...