作者 tangxuhui
package dto
type UserInfoDto struct {
}
... ...
... ... @@ -441,6 +441,32 @@ func (svr AuthService) ResetPassword(resetPasswordCommand *command.ResetPassword
func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
operator)
// 个人用户登录
if operator.UserId == 0 && len(operator.Phone) != 0 {
resultUser, err := creationUserGateway.AuthUserBaseInfo(allied_creation_user.ReqAuthUserBase{
Account: operator.Phone,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var user = map[string]interface{}{
"userId": 0,
//"userOpenId": fmt.Sprintf("%v",resultUser.UserBaseID),
"userInfo": map[string]interface{}{
"userName": resultUser.UserInfo.UserName,
"userPhone": resultUser.UserInfo.Phone,
"userAvatar": resultUser.UserInfo.Avatar,
"email": resultUser.UserInfo.Email,
},
"department": struct{}{},
"company": map[string]interface{}{},
"im": resultUser.Im,
"org": struct{}{},
}
return user, nil
}
// 企业用户登录
resultUser, err := creationUserGateway.UserGet(allied_creation_user.ReqGetUser{
UserId: int(operator.UserId),
})
... ... @@ -455,12 +481,13 @@ func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error
}
var user = map[string]interface{}{
"userId": resultUser.UserId,
//"userOpenId": fmt.Sprintf("%v",resultUser.UserBaseId),
"userInfo": map[string]interface{}{
"userName": resultUser.UserInfo.UserName,
"userPhone": resultUser.UserInfo.Phone,
"userAvatar": resultUser.UserInfo.Avatar,
//"userCode": resultUser.UserInfo.UserCode,
"email": resultUser.UserInfo.Email,
"userCode": resultUser.UserInfo.UserCode,
"email": resultUser.UserInfo.Email,
},
"department": resultUser.Department,
"company": map[string]interface{}{
... ... @@ -486,8 +513,9 @@ func (svr AuthService) getUserInfo(operator domain.Operator) (interface{}, error
func (svr AuthService) getToken(loginToken domain.LoginToken) (map[string]interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
userSearchResult, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
Phone: loginToken.Account,
UserType: domain.UserTypeEmployee,
Phone: loginToken.Account,
UserType: domain.UserTypeEmployee,
EnableStatus: domain.UserStatusEnable,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "用户信息获取失败,"+err.Error())
... ... @@ -516,17 +544,30 @@ loopUser1:
}
}
}
if !currentOrgIsOK {
if !currentOrgIsOK && loginToken.Platform == domain.LoginPlatformWeb {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "登录的公司组织不可用")
}
loginToken.UserId = int64(currentUser.UserId)
loginToken.UserBaseId = int64(currentUser.UserBaseId)
loginToken.CompanyId = int64(currentUser.Company.CompanyId)
var orgIds []int64
for i := range currentUser.UserOrg {
orgIds = append(orgIds, int64(currentUser.UserOrg[i].OrgID))
if currentOrgIsOK {
loginToken.UserId = int64(currentUser.UserId)
loginToken.UserBaseId = int64(currentUser.UserBaseId)
loginToken.CompanyId = int64(currentUser.Company.CompanyId)
var orgIds []int64
for i := range currentUser.UserOrg {
orgIds = append(orgIds, int64(currentUser.UserOrg[i].OrgID))
}
loginToken.OrgIds = orgIds
}
// 个人登录
if len(userSearchResult.Users) == 0 {
userBase, err := creationUserGateway.AuthUserBaseInfo(allied_creation_user.ReqAuthUserBase{
Account: loginToken.Account,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "账号不存在")
}
loginToken.UserBaseId = int64(userBase.UserBaseID)
}
loginToken.OrgIds = orgIds
// 2. 更新currentAccess信息
transactionContext, err := factory.CreateTransactionContext(nil)
... ...
... ... @@ -11,7 +11,7 @@ type CooperationDividendsStatisticsCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 查询偏离量
PageNumber int `json:"pageIndex" valid:"Required"`
PageNumber int `json:"pageNumber" valid:"Required"`
// 查询限制
PageSize int `json:"pageSize" valid:"Required"`
//审核状态 1:正序 2:倒序
... ...
... ... @@ -40,6 +40,8 @@ type CreditAccountItem struct {
DividendsType int `json:"dividendsType"`
DividendsAmount float64 `json:"dividendsAmount"`
} `json:"accountDetail"` //结算明细
//备注
Remarks string `json:"remark"`
}
func ToCreditAccountItem(param *allied_creation_cooperation.CreditAccount) *CreditAccountItem {
... ... @@ -62,6 +64,7 @@ func ToCreditAccountItem(param *allied_creation_cooperation.CreditAccount) *Cred
CreatedAt: param.CreatedAt.Unix() * 1000, // 创建时间
UpdatedAt: param.UpdatedAt.Unix() * 1000, // 更新时间
AccountDetail: param.AccountDetail,
Remarks: param.Remarks,
}
data.Participator.UserInfo.UserName = param.Participator.UserInfo.UsersName
data.Participator.UserInfo.UserPhone = param.Participator.UserInfo.Phone
... ...
... ... @@ -160,6 +160,7 @@ func (srv CooperationApplicationsService) PersonSearchCooperationApplications(ap
PageSize: applicationQuery.PageSize,
CompanyId: int(applicationQuery.Operator.CompanyId),
CooperationApplicationStatus: applicationQuery.Status,
UserBaseId: applicationQuery.Operator.UserBaseId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ...
package service
import (
"fmt"
"math/rand"
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
... ... @@ -112,25 +108,8 @@ func (srv CompanyStatisticsService) IndexStatistics(cmd *command.IndexStatistics
}, nil
}
// GoodsStatistics TODO:产品统计排行榜 年月榜
// GoodsStatistics 产品统计排行榜 年月榜
func (srv CompanyStatisticsService) GoodsStatistics(cmd *command.GoodsStatisticsCommand) (int64, interface{}, error) {
//type rankItem struct {
// GoodAmount float64 `json:"goodAmount"`
// GoodName string `json:"goodName"`
// GoodRatio float64 `json:"goodRatio"`
// Rank int `json:"rank"`
//}
//var items []rankItem
//for i := 0; i < 5; i++ {
// item := rankItem{
// GoodAmount: 2000,
// GoodName: fmt.Sprintf("商品%v", rand.Intn(100)),
// GoodRatio: 20,
// Rank: i + 1,
// }
// items = append(items, item)
//}
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
cooperationGoodsStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.CooperationGoodsStatistics, map[string]interface{}{
... ... @@ -147,40 +126,20 @@ func (srv CompanyStatisticsService) GoodsStatistics(cmd *command.GoodsStatistics
return 0, cooperationGoodsStatistics, nil
}
// CooperationDividendsStatistics TODO:公司共创人员列表
func (srv CompanyStatisticsService) CooperationDividendsStatistics(userMenusCommand *command.CooperationDividendsStatisticsCommand) (int64, interface{}, error) {
type cooperationDividendItem struct {
CooperationTime int64 `json:"cooperationTime"`
DividendsOrderAmount float64 `json:"dividendsOrderAmount"`
ActuallyPaidAmount float64 `json:"actuallyPaidAmount"`
UnPaidAmount float64 `json:"unPaidAmount"`
Participator struct {
UserType int `json:"userType"`
UserInfo struct {
// 用户姓名
UserName string `json:"userName,omitempty"`
// 手机号码
UserPhone string `json:"userPhone,omitempty"`
// 头像
//Avatar string `json:"avatar,omitempty"`
// 邮箱
//Email string `json:"email,omitempty"`
} `json:"userInfo"`
} `json:"participator"` // 参与人
}
var results []cooperationDividendItem
for i := 0; i < 5; i++ {
item := cooperationDividendItem{
CooperationTime: time.Now().Unix() * 1000,
DividendsOrderAmount: 6000,
ActuallyPaidAmount: 5000,
UnPaidAmount: 1000,
}
item.Participator.UserInfo.UserName = fmt.Sprintf("用户%v", rand.Intn(100))
results = append(results, item)
// CooperationDividendsStatistics 公司共创人员列表
func (srv CompanyStatisticsService) CooperationDividendsStatistics(cmd *command.CooperationDividendsStatisticsCommand) (int64, interface{}, error) {
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
cooperationUsersStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.CompanyCooperationUsersStatistics, map[string]interface{}{
"orgId": cmd.Operator.OrgId,
"offset": cmd.PageNumber * cmd.PageSize,
"limit": cmd.PageSize,
"sortByActuallyPaidAmount": cmd.SortByActuallyPaidAmount,
})
if err != nil {
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return 5, results, nil
return 0, cooperationUsersStatistics, nil
}
// CooperationPersonStatistics TODO:共创人员统计(共创人员明细)
... ...
... ... @@ -19,23 +19,21 @@ func (srv PersonStatisticsService) IndexStatistics(cmd *command.IndexStatisticsC
cmd.Operator)
// 1.项目概览统计
contracts, err := gateway.CooperationContractSearch(allied_creation_cooperation.ReqCooperationContractSearch{
PageNumber: 1,
PageSize: 1,
UserBaseId: cmd.Operator.UserBaseId,
contractStatisticsResult, err := gateway.CooperationStatistics(allied_creation_cooperation.PersonCooperationContractStatistics, map[string]interface{}{
"userBaseId": cmd.Operator.UserBaseId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
stoppedContracts, err := gateway.CooperationContractSearch(allied_creation_cooperation.ReqCooperationContractSearch{
PageNumber: 1,
PageSize: 1,
Status: 2,
UserBaseId: cmd.Operator.UserBaseId,
})
if err != nil {
type contractStatistics struct {
ContractSum int `json:"contractSum"`
ContractStoppedSum int `json:"contractStoppedSum"`
}
var cs = &contractStatistics{}
if err := json.UnmarshalFromString(json.MarshalToString(contractStatisticsResult), cs); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
gatewayUser := allied_creation_user.NewHttplibAlliedCreationUser(
cmd.Operator)
users, err := gatewayUser.UserSearch(allied_creation_user.ReqUserSearch{
... ... @@ -48,9 +46,9 @@ func (srv PersonStatisticsService) IndexStatistics(cmd *command.IndexStatisticsC
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var overview = map[string]interface{}{
"contractSum": contracts.Grid.Total, //总合约数
"contractStoppedSum": stoppedContracts.Grid.Total, //停止的合约数
"companySum": users.Count, //共创企业数
"contractSum": cs.ContractSum, //总合约数
"contractStoppedSum": cs.ContractStoppedSum, //停止的合约数
"companySum": users.Count, //共创企业数
}
// 2.本月分红统计 - 个人
... ...
... ... @@ -90,6 +90,7 @@ func (dividendsOrderService *DividendsOrderService) SearchDividendsOrder(searchD
PageSize: searchDividendsOrderQuery.PageSize,
CustomerName: searchDividendsOrderQuery.CustomerName,
DividendsOrderNumber: searchDividendsOrderQuery.DividendsOrderNumber,
OrgIds: searchDividendsOrderQuery.Operator.OrgIds,
})
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -24,9 +24,13 @@ const (
CompanyDividendsStatistics = "CompanyDividendsStatistics"
// 企业、个人 - 分红预算列表
SearchDividendsEstimates = "SearchDividendsEstimates"
// 公司 - 共创用户统计
CompanyCooperationUsersStatistics = "CompanyCooperationUsersStatistics"
// 个人 - 共创企业统计
CooperationCompanyStatistics = "CooperationCompanyStatistics"
// 个人 - 用户合约统计
PersonCooperationContractStatistics = "PersonCooperationContractStatistics"
)
// CooperationStatistics 共创统计
... ...
... ... @@ -46,6 +46,8 @@ type CreditAccount struct {
DividendsType int `json:"dividendsType"`
DividendsAmount float64 `json:"dividendsAmount"`
} `json:"accountDetail"` //结算明细
//备注
Remarks string `json:"remarks"`
}
//支付账期结算
... ...
... ... @@ -124,13 +124,13 @@ type (
//查询分红订单
type (
ReqDividendsOrderSearch struct {
CompanyId int `json:"companyId"`
CustomerName string `json:"customerName"`
DividendsOrderNumber string `json:"dividendsOrderNumber"`
OrgIds []int `json:"orgIds"`
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
UserId int `json:"userId"`
CompanyId int `json:"companyId"`
CustomerName string `json:"customerName"`
DividendsOrderNumber string `json:"dividendsOrderNumber"`
OrgIds []int64 `json:"orgIds"`
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
UserId int `json:"userId"`
}
DataDividendsOrderSearch struct {
... ...
... ... @@ -224,3 +224,34 @@ func (gateway HttplibAlliedCreationUser) AuthRefreshIM(param ReqAuthRefreshIM) (
err = gateway.GetResponseData(result, &data)
return &data, err
}
//RefreshIM 用户基础数据
func (gateway HttplibAlliedCreationUser) AuthUserBaseInfo(param ReqAuthUserBase) (*DataAuthUserBase, error) {
url := gateway.baseUrL + "/auth/user-base-info"
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 DataAuthUserBase
err = gateway.GetResponseData(result, &data)
return &data, err
}
... ...
... ... @@ -233,6 +233,38 @@ func (gateway HttplibAlliedCreationUser) UserBatchResetPassword(param ReqBatchRe
return &data, err
}
// UserBatchAdd 批量添加用户
func (gateway HttplibAlliedCreationUser) UserBatchAdd(param ReqBatchAddUser) (*DataBatchAddUser, error) {
url := fmt.Sprintf("%s%s", gateway.baseUrL, "/user/batch-add")
method := "post"
req := gateway.CreateRequest(url, method)
//TODO traceID
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 DataBatchAddUser
err = gateway.GetResponseData(result, &data)
return &data, err
}
//CooperatorUserCreate 创建共创用户
func (gateway HttplibAlliedCreationUser) CooperatorUserCreate(param ReqCreateCooperatorUser) (*DataCreateCooperatorUser, error) {
url := fmt.Sprintf("%s%s", gateway.baseUrL, "/user/cooperator")
... ...
... ... @@ -89,3 +89,27 @@ type (
CsAccountId string `json:"csAccountId"`
}
)
//重置手机号
type (
ReqAuthUserBase struct {
// 手机号码
Account string `cname:"账号" json:"account" valid:"Required"`
}
DataAuthUserBase struct {
UserBaseID int `json:"userBaseId"`
UserInfo struct {
UserName string `json:"userName"`
Phone string `json:"phone"`
// 头像
Avatar string `json:"avatar,omitempty"`
// 邮箱
Email string `json:"email,omitempty"`
} `json:"userInfo"`
Im struct {
Accid string `json:"accid"`
ImToken string `json:"imToken"`
CsAccountID string `json:"csAccountId"`
} `json:"im"`
}
)
... ...
... ... @@ -335,3 +335,32 @@ type (
} `json:"menus"`
}
)
//批量修改用户启用状态
type (
ReqBatchAddUser struct {
Users []BatchAddUserItem `json:"users"`
Password int `json:"password"`
}
DataBatchAddUser struct {
}
BatchAddUserItem struct {
CompanyID int `json:"companyId"`
UserType int `json:"userType"`
UserCode string `json:"userCode"`
OrganizationID int `json:"organizationId"`
DepartmentID int `json:"departmentId"`
UserInfo struct {
Phone string `json:"phone"`
UserName string `json:"userName"`
Email string `json:"email"`
Avatar string `json:"avatar"`
} `json:"userInfo"`
CooperationInfo struct {
CooperationCompany string `json:"cooperationCompany"`
CooperationDeadline time.Time `json:"cooperationDeadline"`
} `json:"cooperationInfo"`
}
)
... ...