作者 yangfu
正在显示 26 个修改的文件 包含 663 行增加280 行删除
... ... @@ -4,6 +4,7 @@ go 1.16
require (
github.com/beego/beego/v2 v2.0.1
github.com/boombuler/barcode v1.0.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/go-pg/pg/v10 v10.10.1
github.com/go-redis/redis v6.14.2+incompatible
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
)
type LoginCommand struct {
Phone string `json:"phone" valid:"Required"`
GrantType string `json:"grantType" valid:"Required"` //登录方式(signInPassword 密码登录、signInCaptcha 验证码登录)
Password string `json:"password"`
Captcha string `json:"captcha"`
}
func (orgAddCommand *LoginCommand) Valid(validation *validation.Validation) {
}
func (orgAddCommand *LoginCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(orgAddCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package dto
type CompanyItem struct {
CompanyId int `json:"companyId,string"`
CompanyName string `json:"companyName"`
}
type OrgItem struct {
OrganizationId int `json:"organizationId,string"`
OrganizationName string `json:"organizationName"`
CompanyId int `json:"companyId"`
}
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type GetCompanyOrgsByUserQuery struct {
//操作人
Operator domain.Operator `json:"-"`
Phone string `json:"phone" valid:"Required"` //手机号
}
func (orgAddCommand *GetCompanyOrgsByUserQuery) Valid(validation *validation.Validation) {
}
func (orgAddCommand *GetCompanyOrgsByUserQuery) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(orgAddCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
package query
type QrcodeLoginStatusQuery struct {
Token string `json:"token"`
}
... ...
package service
import (
"errors"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/auth/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/auth/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/auth/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/cache"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/sms_serve"
)
type AuthService struct{}
//AuthLogin 用户登录
func (srv AuthService) AuthLogin(loginCommand *command.LoginCommand) (interface{}, error) {
var (
result interface{}
err error
)
switch loginCommand.GrantType {
case "signInPassword":
//账号密码登录
result, err = srv.SignInPassword(loginCommand.Phone, loginCommand.Password)
case "signInCaptcha":
//手机验证码登录
result, err = srv.SignInCaptcha(loginCommand.Phone, loginCommand.Captcha)
default:
err = errors.New("登录方式无法解析")
}
return result, err
}
//SignInPassword 使用账号密码校验
func (srv AuthService) SignInPassword(account string, password string) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
_, err := creationUserGateway.AuthCheckPassword(allied_creation_user.ReqAuthCheckPassword{
Password: password,
Phone: account,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
ltoken := domain.LoginToken{
UserId: 0,
Account: account,
Platform: domain.LoginPlatformApp,
CompanyId: 0,
}
authcode, err := ltoken.GenerateAuthCode()
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
result := map[string]string{
"authCode": authcode,
}
return result, nil
}
//SignInCaptcha 使用手机验证码登录
func (srv AuthService) SignInCaptcha(phone string, captcha string) (interface{}, error) {
smsServeGateway := sms_serve.NewHttplibHttplibSmsServe()
err := smsServeGateway.CheckSmsCode(phone, captcha)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
ltoken := domain.LoginToken{
UserId: 0,
Account: phone,
Platform: domain.LoginPlatformApp,
CompanyId: 0,
}
authcode, err := ltoken.GenerateAuthCode()
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
result := map[string]string{
"authCode": authcode,
}
return result, nil
}
//GetCompanyOrgsByUser 获取登录用户的公司组织列表
func (srv AuthService) GetCompanyOrgsByUser(queryParam query.GetCompanyOrgsByUserQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(queryParam.Operator)
result, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
Phone: queryParam.Phone,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var (
companys []dto.CompanyItem
orgs []dto.OrgItem
)
for _, v := range result.Users {
companys = append(companys, dto.CompanyItem{
CompanyId: v.Company.CompanyId,
CompanyName: v.Company.CompanyName,
})
for _, vv := range v.UserOrg {
orgs = append(orgs, dto.OrgItem{
OrganizationId: vv.OrgID,
OrganizationName: vv.OrgName,
CompanyId: v.Company.CompanyId,
})
}
}
data := map[string]interface{}{
"companys": companys,
"organizations": orgs,
}
return data, nil
}
//GetQrcode 获取扫码登录需要的二维码
func (srv AuthService) GetQrcode() (interface{}, error) {
qrmsg := domain.QrcodeMessage{}
imgBase64, err := qrmsg.GenerateImageBase64()
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
qrCache := cache.LoginQrcodeCache{}
err = qrCache.Save(qrmsg)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
data := map[string]interface{}{
"image": imgBase64,
"token": qrmsg.Token,
}
return data, nil
}
//QrcodeLoginStatus 扫码登录状态
func (srv AuthService) QrcodeLoginStatus(queryParam query.QrcodeLoginStatusQuery) (interface{}, error) {
qrmsg := domain.QrcodeMessage{}
err := qrmsg.ParseToken(queryParam.Token)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
qrCache := cache.LoginQrcodeCache{}
qrmsgCache, err := qrCache.Get(qrmsg.Id)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
data := map[string]interface{}{
"isLogin": qrmsgCache.IsLogin,
}
return data, nil
}
... ...
... ... @@ -4,84 +4,14 @@ import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
)
type CreateCooperationContractCommand struct {
CooperationContract struct {
CooperationContractId int `json:"cooperationContractId,string"`
// 共创合约描述
Description string `json:"Description"`
// 共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 共创项目编号,
CooperationProjectNumber string `json:"cooperationProjectNumber"`
// 共创合约发起部门编码
DepartmentId string `json:"departmentId"`
// 共创合约承接对象,1员工,2共创用户,3公开
CooperationContractUndertakerType []int `json:"cooperationContractUndertakerType"`
// 共创合约名称
CooperationContractName string `json:"cooperationContractName"`
// 共创模式编码,手动输入,唯一确定
CooperationModeNumber string `json:"cooperationModeNumber"`
// 共创合约发起人uid
SponsorUserId string `json:"sponsorUserId"`
} `json:"cooperationContract"`
// 业绩分红激励规则列表
DividendsIncentivesRules []struct {
// 关联的项目合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 推荐人抽成比例
ReferrerPercentage float64 `json:"referrerPercentage"`
// 业务员抽成比例
SalesmanPercentage float64 `json:"salesmanPercentage"`
// 分红规则激励百分点
DividendsIncentivesPercentage float64 `json:"dividendsIncentivesPercentage"`
// 分红规则激励阶段,
DividendsIncentivesStage int64 `json:"dividendsIncentivesStage,string,"`
// 分红规则激励阶段结束
DividendsIncentivesStageEnd int `json:"dividendsIncentivesStageEnd"`
// 分红规则激励阶段开始
DividendsIncentivesStageStart int `json:"dividendsIncentivesStageStart"`
} `json:"dividendsIncentivesRules"`
// 金额激励规则列表
MoneyIncentivesRules []struct {
// 金额激励规则ID
MoneyIncentivesRuleId int64 `json:"moneyIncentivesRuleId,string,"`
// 关联的共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 激励金额
MoneyIncentivesAmount float64 `json:"moneyIncentivesAmount"`
// 金额激励阶段,
MoneyIncentivesStage int64 `json:"moneyIncentivesStage,string,"`
// 金额激励规则时间
MoneyIncentivesTime int `json:"moneyIncentivesTime"`
// 推荐人抽成比例
ReferrerPercentage float64 `json:"referrerPercentage"`
// 业务员抽成比例
SalesmanPercentage float64 `json:"salesmanPercentage"`
} `json:"moneyIncentivesRules"`
// 关联用户id
RelationUser []int `json:"relationUser"`
//承接人列表
ContractUndertaker []struct {
HasReferrer bool `json:"hasReferrer"`
HasSalesman bool `json:"hasSalesman"`
UsersId int `json:"usersId,string,"`
ReferrerUser struct {
UserId int `json:"userId,string,"`
} `json:"referrerUser"`
SalesmanUser struct {
UserId int `json:"userId"`
} `json:"salesmanUser"`
Attachment []struct {
Name string `json:"name"`
Type string `json:"type"`
Url string `json:"url"`
FileSize int `json:"fileSize"`
} `json:"attachment"`
} `json:"contractUndertaker"`
//操作人
Operator domain.Operator `json:"-"`
allied_creation_cooperation.ReqCooperationContractAdd
}
func (createCooperationContractCommand *CreateCooperationContractCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -4,9 +4,12 @@ import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type EnableCooperationContractCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 共创合约ID
CooperationContractId []string `json:"cooperationContractId" valid:"Required"`
// 暂停和恢复的状态
... ...
... ... @@ -2,87 +2,16 @@ package command
import (
"fmt"
"time"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
)
type UpdateCooperationContractCommand struct {
CooperationContract struct {
CooperationContractId int `json:"cooperationContractId,string"`
// 共创合约描述
Description string `json:"Description"`
// 共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 共创项目编号,
CooperationProjectNumber string `json:"cooperationProjectNumber"`
// 共创合约发起部门编码
DepartmentId string `json:"departmentId"`
// 共创合约承接对象,1员工,2共创用户,3公开
CooperationContractUndertakerType []int `json:"cooperationContractUndertakerType"`
// 共创合约名称
CooperationContractName string `json:"cooperationContractName"`
// 共创模式编码,手动输入,唯一确定
CooperationModeNumber string `json:"cooperationModeNumber"`
// 共创合约发起人uid
SponsorUserId string `json:"sponsorUserId"`
} `json:"cooperationContract"`
// 业绩分红激励规则列表
DividendsIncentivesRules []struct {
// 关联的项目合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 推荐人抽成比例
ReferrerPercentage float64 `json:"referrerPercentage"`
// 业务员抽成比例
SalesmanPercentage float64 `json:"salesmanPercentage"`
// 分红规则激励百分点
DividendsIncentivesPercentage float64 `json:"dividendsIncentivesPercentage"`
// 分红规则激励阶段,
DividendsIncentivesStage int64 `json:"dividendsIncentivesStage,string,"`
// 分红规则激励阶段结束
DividendsIncentivesStageEnd time.Time `json:"dividendsIncentivesStageEnd"`
// 分红规则激励阶段开始
DividendsIncentivesStageStart time.Time `json:"dividendsIncentivesStageStart"`
} `json:"dividendsIncentivesRules"`
// 金额激励规则列表
MoneyIncentivesRules []struct {
// 金额激励规则ID
MoneyIncentivesRuleId int64 `json:"moneyIncentivesRuleId,string,"`
// 关联的共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 激励金额
MoneyIncentivesAmount float64 `json:"moneyIncentivesAmount"`
// 金额激励阶段,
MoneyIncentivesStage int64 `json:"moneyIncentivesStage,string,"`
// 金额激励规则时间
MoneyIncentivesTime time.Time `json:"moneyIncentivesTime"`
// 推荐人抽成比例
ReferrerPercentage float64 `json:"referrerPercentage"`
// 业务员抽成比例
SalesmanPercentage float64 `json:"salesmanPercentage"`
} `json:"moneyIncentivesRules"`
// 关联用户id
RelationUser []int `json:"relationUser"`
//承接人列表
ContractUndertaker []struct {
HasReferrer bool `json:"hasReferrer"`
HasSalesman bool `json:"hasSalesman"`
UsersId int `json:"usersId,string,"`
ReferrerUser struct {
UserId int `json:"userId,string,"`
} `json:"referrerUser"`
SalesmanUser struct {
UserId int `json:"userId"`
} `json:"salesmanUser"`
Attachment []struct {
Name string `json:"name"`
Type string `json:"type"`
Url string `json:"url"`
FileSize int `json:"fileSize"`
} `json:"attachment"`
} `json:"contractUndertaker"`
//操作人
Operator domain.Operator `json:"-"`
allied_creation_cooperation.ReqCooperationContractUpdate
}
func (updateCooperationContractCommand *UpdateCooperationContractCommand) Valid(validation *validation.Validation) {
... ...
package dto
import "time"
type CooperationContractItem struct {
CooperationContractId int `json:"cooperationContractId,string,"`
CooperationContractNumber string `json:"cooperationContractNumber"` //合约编号
CooperationProjectNumber string `json:"cooperationProjectNumber"`
CooperationContractName string `json:"CooperationContractName"` //合约名称
Department string `json:"department"`
IncentivesType string `json:"incentivesType"` //Incentives激励方式
CooperationContractSponsor struct {
UserId int `json:"userId,string,"`
UserName string `json:"userName"`
} `json:"cooperationContractSponsor"` //共创发起人
CooperationMode struct {
CooperationModeId int `json:"cooperationModeId,string,"` // 共创模式ID
CooperationModeNumber string `json:"cooperationModeNumber"` // 共创模式编码,
CooperationModeName string `json:"cooperationModeName"` // 模式名称,
} `json:"cooperationMode"` //共创模式
Status int `json:"status"` //合约状态
CreateTtime time.Time `json:"createTtime"`
Org struct {
OrgId int `json:"orgId"` //发部门, id
OrgName string `json:"orgName"` //发起企业
} `json:"org"` //组织结构
}
type CooperationContractInfo struct {
}
... ...
... ... @@ -4,11 +4,14 @@ import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type GetCooperationContractQuery struct {
//操作人
Operator domain.Operator `json:"-"`
// 共创合约ID
CooperationContractId int `json:"cooperationContractId" valid:"Required"`
CooperationContractId int `json:"cooperationContractId,string" valid:"Required"`
}
func (getCooperationContractQuery *GetCooperationContractQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -4,9 +4,12 @@ import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type ListCooperationContractQuery struct {
//操作人
Operator domain.Operator `json:"-"`
// 查询偏离量
PageNumber int `json:"pageNumber"`
// 查询限制
... ...
... ... @@ -4,6 +4,7 @@ import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/cooperationContract/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/cooperationContract/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
)
// 共创合约管理
... ... @@ -15,7 +16,12 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
if err := createCooperationContractCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
return nil, nil
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(createCooperationContractCommand.Operator)
_, err := creationCooperationGateway.CooperationContractAdd(createCooperationContractCommand.ReqCooperationContractAdd)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return createCooperationContractCommand, err
}
// 暂停恢复共创合约
... ... @@ -32,7 +38,14 @@ func (cooperationContractService *CooperationContractService) GetCooperationCont
if err := getCooperationContractQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
return nil, nil
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(getCooperationContractQuery.Operator)
result, err := creationCooperationGateway.CooperationContractGet(allied_creation_cooperation.ReqCooperationContractGet{
CooperationContractId: getCooperationContractQuery.CooperationContractId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
// 返回共创合约管理列表
... ... @@ -40,6 +53,12 @@ func (cooperationContractService *CooperationContractService) ListCooperationCon
if err := listCooperationContractQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(listCooperationContractQuery.Operator)
result, err := creationCooperationGateway.CooperationContractSearch(allied_creation_cooperation.ReqCooperationContractSearch{})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
_ = result
return nil, nil
}
... ...
... ... @@ -2,11 +2,10 @@ package command
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
)
type RemoveDividendsReturnedOrderCommand struct {
//操作人
Operator domain.Operator `json:"-"`
allied_creation_cooperation.ReqDividendsReturnedOrderRemove
Operator domain.Operator `json:"-"`
DividendsReturnedOrderID []string `json:"dividendsReturnedOrderId"` //分红退货单记录id
}
... ...
package service
import (
"strconv"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/dividendsReturnedOrder/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/dividendsReturnedOrder/query"
... ... @@ -37,7 +39,14 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) GetDividends
// 移除分红退货单服务
func (dividendsReturnedOrderService *DividendsReturnedOrderService) RemoveDividendsReturnedOrder(removeDividendsReturnedOrderCommand *command.RemoveDividendsReturnedOrderCommand) (interface{}, error) {
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(removeDividendsReturnedOrderCommand.Operator)
_, err := creationCooperationGateway.DividendsReturnedOrderRemove(removeDividendsReturnedOrderCommand.ReqDividendsReturnedOrderRemove)
ids := []int{}
for _, v := range removeDividendsReturnedOrderCommand.DividendsReturnedOrderID {
id, _ := strconv.Atoi(v)
ids = append(ids, id)
}
_, err := creationCooperationGateway.DividendsReturnedOrderBatchRemove(allied_creation_cooperation.ReqDividendsReturnedOrderBatchRemove{
DividendsReturnedOrderIDs: ids,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
... ...
package domain
import (
"bytes"
"encoding/base64"
"fmt"
"image/png"
"time"
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/qr"
jwt "github.com/dgrijalva/jwt-go"
)
const (
qrcodeTokenSecret string = "bbe35ad433dd8e67"
qrcodeCodeExpire int64 = 60 * 30 //15分钟过期
)
type QrcodeMessage struct {
jwt.StandardClaims
Id string `json:"id"`
Token string `json:"token"`
IsLogin bool `json:"isLogin"`
//用户id
UserId int64 `json:"userId"`
UserBaseId int64 `json:"userBaseId"`
// 账号
Account string `json:"account"`
// 公司id
CompanyId int64 `json:"companyId"`
// 组织id
OrgId int64 `json:"orgId"`
}
func (qrmsg *QrcodeMessage) GenerateImageBase64() ([]byte, error) {
nowTime := time.Now().Unix()
qrmsg.StandardClaims = jwt.StandardClaims{
NotBefore: nowTime,
IssuedAt: nowTime,
ExpiresAt: nowTime + qrcodeCodeExpire,
Issuer: "allied_creation_gateway",
}
qrmsg.Id = fmt.Sprintf("%d", time.Now().UnixNano())
token := jwt.NewWithClaims(jwt.SigningMethodHS256, *qrmsg)
str, err := token.SignedString([]byte(qrcodeTokenSecret))
if err != nil {
return nil, err
}
//初始化数据
qrmsg.Token = str
qrmsg.IsLogin = false
qrCode, err := qr.Encode(str, qr.M, qr.Auto)
if err != nil {
return nil, err
}
qrCode, err = barcode.Scale(qrCode, 200, 200)
if err != nil {
return nil, err
}
var buf bytes.Buffer
err = png.Encode(&buf, qrCode)
if err != nil {
return nil, err
}
var result []byte
base64.StdEncoding.Encode(result, buf.Bytes())
return result, err
}
func (qrmsg *QrcodeMessage) ParseToken(str string) error {
tokenClaims, err := jwt.ParseWithClaims(
str,
qrmsg,
func(token *jwt.Token) (interface{}, error) {
return []byte(loginTokenSecret), nil
})
if err != nil {
return err
}
if claim, ok := tokenClaims.Claims.(*QrcodeMessage); ok && tokenClaims.Valid {
*qrmsg = *claim
}
return nil
}
... ...
package cache
import (
"encoding/json"
"time"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
//二维码信息缓存
type LoginQrcodeCache struct {
}
func (lq LoginQrcodeCache) keyString(str string) string {
str1 := KEY_PREFIX + "login:qrcode:" + str
return str1
}
func (lq LoginQrcodeCache) Save(qrcode domain.QrcodeMessage) error {
nowTime := time.Now().Unix()
exp := qrcode.ExpiresAt - nowTime
if exp <= 0 {
exp = 60 * 60 * 2
}
key := lq.keyString(qrcode.Id)
bt, _ := json.Marshal(qrcode)
result := clientRedis.Set(key, string(bt), time.Duration(exp))
return result.Err()
}
func (lq LoginQrcodeCache) Remove(id string) error {
keyStr := lq.keyString(id)
result := clientRedis.Del(keyStr)
return result.Err()
}
func (lq LoginQrcodeCache) Get(id string) (*domain.QrcodeMessage, error) {
keyStr := lq.keyString(id)
result := clientRedis.Get(keyStr)
re, _ := result.Result()
var data domain.QrcodeMessage
err := json.Unmarshal([]byte(re), &data)
if err != nil {
return nil, err
}
return &data, err
}
... ...
... ... @@ -40,37 +40,6 @@ func (gateway HttplibAlliedCreationCooperation) DividendsEstimateIncentive(param
return &data, err
}
// DividendsEstimateAdd 创建分红预算
func (gateway HttplibAlliedCreationCooperation) DividendsEstimateAdd(param ReqDividendsEstimateAdd) (*DataDividendsEstimateAdd, error) {
url := gateway.baseUrL + "/dividends-estimates"
method := "POST"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向业务模块请求数据:创建分红预算。", map[string]interface{}{
"api": method + ":" + url,
"param": param,
})
req, err := req.JSONBody(param)
if err != nil {
return nil, fmt.Errorf("请求创建分红预算失败:%w", err)
}
byteResult, err := req.Bytes()
if err != nil {
return nil, fmt.Errorf("获取创建分红预算失败:%w", err)
}
log.Logger.Debug("获取业务模块请求数据:创建分红预算。", map[string]interface{}{
"result": string(byteResult),
})
var result service_gateway.GatewayResponse
err = json.Unmarshal(byteResult, &result)
if err != nil {
return nil, fmt.Errorf("解析创建分红预算:%w", err)
}
var data DataDividendsEstimateAdd
err = gateway.GetResponseData(result, &data)
return &data, err
}
// DividendsEstimateUpdate 更新分红预算
func (gateway HttplibAlliedCreationCooperation) DividendsEstimateUpdate(param ReqDividendsEstimateUpdate) (*DataDividendsEstimateUpdate, error) {
url := gateway.baseUrL + "/dividends-estimates/{dividendsEstimateId}"
... ...
... ... @@ -198,8 +198,8 @@ func (gateway HttplibAlliedCreationCooperation) DividendsReturnedOrderGet(param
}
// DividendsReturnedOrderBatchRemove 批量移除分红退货单
func (gateway HttplibAlliedCreationCooperation) DividendsReturnedOrderBatchRemove(param ReqDividendsReturnedOrderRemove) (
*DataDividendsReturnedOrderRemove, error) {
func (gateway HttplibAlliedCreationCooperation) DividendsReturnedOrderBatchRemove(param ReqDividendsReturnedOrderBatchRemove) (
*DataDividendsReturnedOrderBatchRemove, error) {
url := gateway.baseUrL + "/dividends-returned-orders/batch-remove"
method := "POST"
req := gateway.CreateRequest(url, method)
... ... @@ -224,7 +224,7 @@ func (gateway HttplibAlliedCreationCooperation) DividendsReturnedOrderBatchRemov
if err != nil {
return nil, fmt.Errorf("解析移除分红退货单:%w", err)
}
var data DataDividendsReturnedOrderRemove
var data DataDividendsReturnedOrderBatchRemove
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
package allied_creation_cooperation
import "time"
import (
"time"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
//创建共创合约
type (
//分红激励规则
DividendsIncentivesRule struct {
// 关联的项目合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 推荐人抽成比例
ReferrerPercentage float64 `json:"referrerPercentage"`
// 业务员抽成比例
SalesmanPercentage float64 `json:"salesmanPercentage"`
// 分红规则激励百分点
DividendsIncentivesPercentage float64 `json:"dividendsIncentivesPercentage"`
// 分红规则激励阶段,
DividendsIncentivesStage int64 `json:"dividendsIncentivesStage,string"`
// 分红规则激励阶段结束
DividendsIncentivesStageEnd time.Time `json:"dividendsIncentivesStageEnd"`
// 分红规则激励阶段开始
DividendsIncentivesStageStart time.Time `json:"dividendsIncentivesStageStart"`
}
//金额激励规则
MoneyIncentivesRule struct {
// 金额激励规则ID
MoneyIncentivesRuleId int64 `json:"moneyIncentivesRuleId,string"`
// 关联的共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 激励金额
MoneyIncentivesAmount float64 `json:"moneyIncentivesAmount"`
// 金额激励阶段
MoneyIncentivesStage int `json:"moneyIncentivesStage"`
// 金额激励规则时间
MoneyIncentivesTime time.Time `json:"moneyIncentivesTime"`
// 推荐人抽成比例
ReferrerPercentage float64 `json:"referrerPercentage"`
// 业务员抽成比例
SalesmanPercentage float64 `json:"salesmanPercentage"`
}
//合约承接方
Undertaker struct {
UndertakerId string `json:"undertakerId"` //承接人用户id
RerferrerId string `json:"rerferrerId"` //推荐人用户id
SalesmanId string `json:"salesmanId"` //关联业务员id
Attachment domain.Attachment `json:"attachment"`
}
ReqCooperationContractAdd struct {
// 共创合约描述
CooperationContractDescription string ` json:"cooperationContractDescription"`
CooperationContractDescription string `json:"cooperationContractDescription"`
// 共创合约编号
CooperationContractNumber string ` json:"cooperationContractNumber"`
CooperationContractNumber string `json:"cooperationContractNumber"`
// 共创项目编号,
CooperationProjectNumber string `json:"cooperationProjectNumber" `
// 共创合约发起部门编码
DepartmentNumber string `json:"departmentNumber"`
CooperationProjectNumber string `json:"cooperationProjectNumber"`
// 共创合约发起部门id
DepartmentId string `json:"departmentId"`
// 共创合约承接对象,1员工,2共创用户,3公开
CooperationContractUndertakerType []int ` json:"cooperationContractUndertakerType"`
CooperationContractUndertakerType []int `json:"cooperationContractUndertakerType"`
// 共创合约名称
CooperationContractName string `json:"cooperationContractName"`
// 共创模式编码,手动输入,唯一确定
CooperationModeNumber string ` json:"cooperationModeNumber"`
// 共创模式编码,
CooperationModeNumber string `json:"cooperationModeNumber"`
// 共创合约发起人uid
SponsorUid string `json:"sponsorUid,omitempty"`
SponsorUid string `json:"sponsorUid"`
// 业绩分红激励规则列表
DividendsIncentivesRules []struct {
// 关联的项目合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 推荐人抽成比例
ReferrerPercentage float64 `json:"referrerPercentage"`
// 业务员抽成比例
SalesmanPercentage float64 `json:"salesmanPercentage"`
// 分红规则激励百分点
DividendsIncentivesPercentage float64 `json:"dividendsIncentivesPercentage"`
// 分红规则激励阶段,阶段返回时需要转换为中文数字
DividendsIncentivesStage int64 `json:"dividendsIncentivesStage,string"`
// 分红规则激励阶段结束
DividendsIncentivesStageEnd time.Time `json:"dividendsIncentivesStageEnd"`
// 分红规则激励阶段开始
DividendsIncentivesStageStart time.Time `json:"dividendsIncentivesStageStart"`
} `json:"dividendsIncentivesRules"`
DividendsIncentivesRules []DividendsIncentivesRule `json:"dividendsIncentivesRules"`
// 金额激励规则列表
MoneyIncentivesRules []struct {
// 金额激励规则ID
MoneyIncentivesRuleId int64 `json:"moneyIncentivesRuleId,string"`
// 关联的共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 激励金额
MoneyIncentivesAmount float64 `json:"moneyIncentivesAmount"`
// 金额激励阶段,阶段返回时需要转换为中文数字
MoneyIncentivesStage int64 `json:"moneyIncentivesStage,string"`
// 金额激励阶段有效期结束
MoneyIncentivesStageEnd time.Time `json:"moneyIncentivesStageEnd"`
// 金额激励阶段有效期开始
MoneyIncentivesStageStart time.Time `json:"moneyIncentivesStageStart"`
// 金额激励规则时间
MoneyIncentivesTime time.Time `json:"moneyIncentivesTime"`
// 推荐人抽成比例
ReferrerPercentage float64 `json:"referrerPercentage"`
// 业务员抽成比例
SalesmanPercentage float64 `json:"salesmanPercentage"`
} `json:"moneyIncentivesRules"`
MoneyIncentivesRules []MoneyIncentivesRule `json:"moneyIncentivesRules"`
// 承接方列表
Undertakers []struct {
UserId int64 `json:"userId,string"`
// 用户基本id
UserBaseId int64 `json:"userBaseId,string"`
// 用户所属组织机构
Org struct {
// 组织机构ID
OrgId int64 `json:"orgId,string"`
// 组织名称
OrgName string `json:"orgName"`
}
} `json:"undertakers"`
Undertakers []Undertaker `json:"undertakers"`
//关联业务员
RelevantIds []string `json:"relevantIds"`
}
DataCooperationContractAdd struct {
... ... @@ -81,7 +85,31 @@ type (
//更新共创合约
type (
ReqCooperationContractUpdate struct {
CooperationContractId int
CooperationContractId int `json:"cooperationContractId"`
// 共创合约描述
CooperationContractDescription string `json:"cooperationContractDescription"`
// 共创合约编号
CooperationContractNumber string `json:"cooperationContractNumber"`
// 共创项目编号,
CooperationProjectNumber string `json:"cooperationProjectNumber"`
// 共创合约发起部门id
DepartmentId string `json:"departmentId"`
// 共创合约承接对象,1员工,2共创用户,3公开
CooperationContractUndertakerType []int `json:"cooperationContractUndertakerType"`
// 共创合约名称
CooperationContractName string `json:"cooperationContractName"`
// 共创模式编码,
CooperationModeNumber string `json:"cooperationModeNumber"`
// 共创合约发起人uid
SponsorUid string `json:"sponsorUid,omitempty,"`
// 业绩分红激励规则列表
DividendsIncentivesRules []DividendsIncentivesRule `json:"dividendsIncentivesRules"`
// 金额激励规则列表
MoneyIncentivesRules []MoneyIncentivesRule `json:"moneyIncentivesRules"`
// 承接方列表
Undertakers []Undertaker `json:"undertakers"`
//关联业务员
RelevantIds []string `json:"relevantIds"`
}
DataCooperationContractUpdate struct {
... ... @@ -91,6 +119,10 @@ type (
//查询共创合约
type (
ReqCooperationContractSearch struct {
// 查询偏离量
PageNumber int `json:"pageNumber"`
// 查询限制
PageSize int `json:"pageSize" valid:"Required"`
}
DataCooperationContractSearch struct {
... ... @@ -100,6 +132,11 @@ type (
//根据承接人查询并返回共创项目合约
type (
ReqCooperationContractSearchByUndertaker struct {
CooperationContractName string //合约名称
SponsorName string //项目发起人姓名
UserId int //合约发起人
PageNumber int
PageIndex int
}
DataCooperationContractSearchByUndertaker struct {
... ... @@ -128,7 +165,7 @@ type (
//返回共创合约详情
type (
ReqCooperationContractGet struct {
CooperationContractId int
CooperationContractId int `json:"cooperationContractId"`
}
DataCooperationContractGet struct {
... ...
package allied_creation_cooperation
import "time"
//确定预算分红激励
type (
ReqDividendsEstimateIncentive struct {
// companyId
// orgId
// userId
CooperationContractNumber string //合约编号
OrderOrReturnedOrderNum string //分红订单号/退货单号
}
DataDividendsEstimateIncentive struct {
}
)
//创建分红预算
type (
ReqDividendsEstimateAdd struct {
}
DataDividendsEstimateAdd struct {
}
)
//更新分红预算
type (
ReqDividendsEstimateUpdate struct {
... ... @@ -39,9 +37,41 @@ type (
//查询分红预算单
type (
ReqDividendsEstimateSearch struct {
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
}
DataDividendsEstimateSearch struct {
Grid struct {
Total int
List []struct {
DividendsEstimateId int64 `json:"dividendsEstimateId,string"` // 承接人分红预算记录ID
DividendsAccountStatus int32 `json:"dividendsAccountStatus"` // 分红结算状态
DividendsAmount float64 `json:"dividendsAmount"` // 分红金额
DividendsEstimateOrderNumber string `json:"dividendsEstimateOrderNumber"` // 承接人分红预算单号
DividendsEstimateTime time.Time `json:"dividendsEstimateTime"` // 分红预算时间
DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与分红类型,1承接人,2推荐人,3关联业务员
DividendsType int32 `json:"dividendsType"` // 分红类型,1订单分红,2退货冲销,3金额激励
OrderOrReturnedOrderNum string `json:"orderOrReturnedOrderNum"` // 分红订单号或退货单号
CooperationProjectNumber string `json:"cooperationProjectNumber"` // 共创项目编号,
DividendsUser struct {
UserId int64 `json:"userId,string"` // 用户ID,
UserBaseId int64 `json:"userBaseId,string"` // 用户基本id
UserType int32 `json:"userType"` // 用户类型
} `json:"dividendsUser"` // 分红用户
Org struct {
OrgId int64 `json:"orgId,string"` // 组织机构ID
OrgName string `json:"orgName"` // 组织名称
} `json:"org"` // 数据所属组织机构
Company struct {
CompanyId int64 `json:"companyId,string"` // 公司ID,
CompanyLogo string `json:"companyLogo"` // 公司logo
CompanyName string `json:"companyName"` // 公司名称
} `json:"company"` // 公司
CreatedAt time.Time `json:"createdAt"` // 创建时间
UpdatedAt time.Time `json:"updatedAt"` // 更新时间
}
}
}
)
... ... @@ -108,6 +138,31 @@ type (
}
DataDividendsEstimateGet struct {
DividendsEstimateId int64 `json:"dividendsEstimateId,string"` // 承接人分红预算记录ID
DividendsAccountStatus int32 `json:"dividendsAccountStatus"` // 分红结算状态
DividendsAmount float64 `json:"dividendsAmount"` // 分红金额
DividendsEstimateOrderNumber string `json:"dividendsEstimateOrderNumber"` // 承接人分红预算单号
DividendsEstimateTime time.Time `json:"dividendsEstimateTime"` // 分红预算时间
DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与分红类型,1承接人,2推荐人,3关联业务员
DividendsType int32 `json:"dividendsType"` // 分红类型,1订单分红,2退货冲销,3金额激励
OrderOrReturnedOrderNum string `json:"orderOrReturnedOrderNum"` // 分红订单号或退货单号
CooperationProjectNumber string `json:"cooperationProjectNumber"` // 共创项目编号,
DividendsUser struct {
UserId int64 `json:"userId,string"` // 用户ID,
UserBaseId int64 `json:"userBaseId,string"` // 用户基本id
UserType int32 `json:"userType"` // 用户类型
} `json:"dividendsUser"` // 分红用户
Org struct {
OrgId int64 `json:"orgId,string"` // 组织机构ID
OrgName string `json:"orgName"` // 组织名称
} `json:"org"` // 数据所属组织机构
Company struct {
CompanyId int64 `json:"companyId,string"` // 公司ID,
CompanyLogo string `json:"companyLogo"` // 公司logo
CompanyName string `json:"companyName"` // 公司名称
} `json:"company"` // 公司
CreatedAt time.Time `json:"createdAt"` // 创建时间
UpdatedAt time.Time `json:"updatedAt"` // 更新时间
}
)
... ...
... ... @@ -110,6 +110,16 @@ type (
}
)
//批量移除分红退货单
type (
ReqDividendsReturnedOrderBatchRemove struct {
DividendsReturnedOrderIDs []int `json:"dividendsReturnedOrderIds"` //分红退货单记录id
}
DataDividendsReturnedOrderBatchRemove struct {
}
)
//返回分红退货单列表
type (
ReqDividendsReturnedOrderList struct {
... ...
... ... @@ -19,23 +19,15 @@ func (controller *baseController) returnPageListData(count int64, data interface
controller.Response(dataMap, err)
}
func (controller *baseController) GetUserId() int64 {
return 1
}
func (controller *baseController) GetCompanyId() int64 {
return 1
}
func (controller *baseController) GetUserBaseId() int64 {
return 1
}
func (controller *baseController) GetOrgId() int64 {
return 1
}
func (controller *baseController) GetOperator() domain.Operator {
// tk, _ := middleware.FormCtxLoginToken(controller.Ctx)
// operator := domain.Operator{
// UserId: tk.UserId,
// CompanyId: tk.CompanyId,
// OrgId: tk.OrgId,
// UserBaseId: tk.UserBaseId,
// }
return domain.Operator{
UserId: 9,
CompanyId: 23,
... ...
... ... @@ -24,7 +24,7 @@ func (controller *CooperationContractController) UpdateCooperationContract() {
updateCooperationContractCommand := &command.UpdateCooperationContractCommand{}
controller.Unmarshal(updateCooperationContractCommand)
contractId, _ := controller.GetInt(":contractId")
updateCooperationContractCommand.CooperationContract.CooperationContractId = contractId
updateCooperationContractCommand.CooperationContractId = contractId
data, err := cooperationContractService.UpdateCooperationContract(updateCooperationContractCommand)
controller.Response(data, err)
}
... ...
... ... @@ -44,8 +44,6 @@ func (controller *DividendsReturnedOrderController) RemoveDividendsReturnedOrder
if err != nil {
log.Logger.Debug("json err:" + err.Error())
}
projectId, _ := controller.GetInt(":projectId")
removeDividendsReturnedOrderCommand.DividendsReturnedOrderID = projectId
removeDividendsReturnedOrderCommand.Operator = controller.GetOperator()
data, err := dividendsReturnedOrderService.RemoveDividendsReturnedOrder(removeDividendsReturnedOrderCommand)
controller.Response(data, err)
... ...
package middleware
import (
"github.com/beego/beego/v2/server/web/context"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
type CtxKeyLoginToken struct{}
func JWTAuth(ctx *context.Context) {
tokenStr := ctx.Input.Header("xxxx")
tk := domain.LoginToken{}
err := tk.ParseToken(tokenStr)
if err != nil {
//
return
}
ctx.Input.SetData(CtxKeyLoginToken{}, domain.LoginToken{})
}
func NewCtxLoginToken(ctx *context.Context, tk domain.LoginToken) {
ctx.Input.SetData(CtxKeyLoginToken{}, domain.LoginToken{})
}
func FormCtxLoginToken(ctx *context.Context) (domain.LoginToken, bool) {
val := ctx.Input.GetData(CtxKeyLoginToken{})
if v, ok := val.(domain.LoginToken); ok {
return v, true
}
return domain.LoginToken{}, false
}
... ...