作者 郑周

Merge remote-tracking branch 'origin/dev' into dev

# Conflicts:
#	cmd/discuss/api/dsl/core.json
正在显示 27 个修改的文件 包含 356 行增加446 行删除
... ... @@ -15,119 +15,6 @@
"application/json"
],
"paths": {
"v1/mini/article_tag": {
"delete": {
"summary": "后台删除文章标签",
"operationId": "DeleteTag",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/TagDeleteResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/TagDeleteRequest"
}
}
],
"requestBody": {},
"tags": [
"tags"
]
},
"post": {
"summary": "后台创建文章标签",
"operationId": "CreateTag",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/TagCreateResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/TagCreateRequest"
}
}
],
"requestBody": {},
"tags": [
"tags"
]
},
"put": {
"summary": "后台编辑文章标签",
"operationId": "EditTag",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/TagEditResponse"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/TagEditRequest"
}
}
],
"requestBody": {},
"tags": [
"tags"
]
}
},
"v1/mini/article_tag/{id}": {
"get": {
"summary": "后台获取文章标签",
"operationId": "GetTag",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/TagGetResponse"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "id",
"in": "query",
"required": true,
"type": "integer",
"format": "int64"
}
],
"requestBody": {},
"tags": [
"tags"
]
}
},
"v1/mini/comment": {
"get": {
"summary": "小程序评论",
... ... @@ -210,7 +97,7 @@
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/MessageSystemResponse"
"$ref": "#/definitions/MessageBusinessResponse"
}
}
},
... ... @@ -836,11 +723,6 @@
"content": {
"type": "string",
"description": " 内容"
},
"createdAt": {
"type": "integer",
"format": "int64",
"description": " 创建时间"
}
},
"title": "MessageSystemItem",
... ... @@ -848,8 +730,7 @@
"id",
"type",
"title",
"content",
"createdAt"
"content"
]
},
"MessageSystemRequest": {
... ... @@ -917,11 +798,17 @@
"type": "integer",
"format": "int64",
"description": " 用户ID"
},
"status": {
"type": "integer",
"format": "int32",
"description": " 审核状态 1:审核通过 2:拒绝"
}
},
"title": "MiniUserAuditRequest",
"required": [
"userId"
"userId",
"status"
]
},
"MiniUserDepartmentUsersRequest": {
... ... @@ -1051,247 +938,6 @@
"success"
]
},
"TagCreateRequest": {
"type": "object",
"properties": {
"companyId": {
"type": "integer",
"format": "int64"
},
"image": {
"type": "string"
},
"name": {
"type": "string",
"description": " 标签名称"
},
"group": {
"type": "string",
"description": " 标签分类"
},
"remark": {
"type": "string",
"description": " 备注"
}
},
"title": "TagCreateRequest",
"required": [
"companyId",
"image",
"name",
"group",
"remark"
]
},
"TagCreateResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "TagCreateResponse",
"required": [
"id"
]
},
"TagDeleteRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "TagDeleteRequest",
"required": [
"id"
]
},
"TagDeleteResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "TagDeleteResponse",
"required": [
"id"
]
},
"TagEditRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"companyId": {
"type": "integer",
"format": "int64"
},
"image": {
"type": "string"
},
"name": {
"type": "string",
"description": " 标签名称"
},
"group": {
"type": "string",
"description": " 标签分类"
},
"remark": {
"type": "string",
"description": " 备注"
}
},
"title": "TagEditRequest",
"required": [
"id",
"companyId",
"image",
"name",
"group",
"remark"
]
},
"TagEditResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "TagEditResponse",
"required": [
"id"
]
},
"TagGetRequest": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
}
},
"title": "TagGetRequest",
"required": [
"id"
]
},
"TagGetResponse": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"image": {
"type": "string"
},
"name": {
"type": "string",
"description": " 标签名称"
},
"group": {
"type": "string",
"description": " 标签分类"
},
"remark": {
"type": "string",
"description": " 备注"
}
},
"title": "TagGetResponse",
"required": [
"id",
"image",
"name",
"group",
"remark"
]
},
"TagItem": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"image": {
"type": "string"
},
"name": {
"type": "string",
"description": " 标签名称"
},
"group": {
"type": "string",
"description": " 标签分类"
},
"remark": {
"type": "string",
"description": " 备注"
},
"createdAt": {
"type": "integer",
"format": "int64"
}
},
"title": "TagItem",
"required": [
"id",
"image",
"name",
"group",
"remark",
"createdAt"
]
},
"TagListRequest": {
"type": "object",
"properties": {
"page": {
"type": "integer",
"format": "int32"
},
"size": {
"type": "integer",
"format": "int32"
}
},
"title": "TagListRequest",
"required": [
"page",
"size"
]
},
"TagListResponse": {
"type": "object",
"properties": {
"total": {
"type": "integer",
"format": "int32"
},
"list": {
"type": "array",
"items": {
"$ref": "#/definitions/TagItem"
}
}
},
"title": "TagListResponse",
"required": [
"total",
"list"
]
},
"User": {
"type": "object",
"properties": {
... ... @@ -1335,6 +981,11 @@
"UserItem": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"description": " 用户ID"
},
"companyId": {
"type": "integer",
"format": "int64",
... ... @@ -1403,6 +1054,7 @@
},
"title": "UserItem",
"required": [
"id",
"companyId",
"departmentId",
"roleId",
... ...
... ... @@ -88,6 +88,7 @@ type(
}
MiniUserAuditRequest{
UserId int64 `json:"userId"` // 用户ID
Status int `json:"status"` // 审核状态 1:审核通过 2:拒绝
}
MiniUserDepartmentUsersRequest{
... ... @@ -97,6 +98,7 @@ type(
Users []*UserItem `json:"users"`
}
UserItem {
Id int64 `json:"id,omitempty"` // 用户ID
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID
Roles []int64 `json:"roleId,omitempty"` // 角色
... ...
package company
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,6 @@ func MiniCompanySearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := company.NewMiniCompanySearchLogic(r.Context(), svcCtx)
resp, err := l.MiniCompanySearch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
package company
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,6 @@ func SystemCompanySearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := company.NewSystemCompanySearchLogic(r.Context(), svcCtx)
resp, err := l.SystemCompanySearch(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,6 @@ func MiniUserApplyJoinCompanyHandler(svcCtx *svc.ServiceContext) http.HandlerFun
l := user.NewMiniUserApplyJoinCompanyLogic(r.Context(), svcCtx)
resp, err := l.MiniUserApplyJoinCompany(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,6 @@ func MiniUserAuditHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserAuditLogic(r.Context(), svcCtx)
err := l.MiniUserAudit(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.Ok(w)
}
result.HttpResult(r, w, struct{}{}, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,6 @@ func MiniUserAuditListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserAuditListLogic(r.Context(), svcCtx)
resp, err := l.MiniUserAuditList(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,6 @@ func MiniUserDepartmentUsersHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
l := user.NewMiniUserDepartmentUsersLogic(r.Context(), svcCtx)
resp, err := l.MiniUserDepartmentUsers(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,6 @@ func MiniUserFollowHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserFollowLogic(r.Context(), svcCtx)
err := l.MiniUserFollow(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.Ok(w)
}
result.HttpResult(r, w, struct{}{}, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,6 @@ func MiniUserFollowerHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserFollowerLogic(r.Context(), svcCtx)
resp, err := l.MiniUserFollower(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,6 @@ func MiniUserFollowingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserFollowingLogic(r.Context(), svcCtx)
resp, err := l.MiniUserFollowing(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,6 @@ func MiniUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserInfoLogic(r.Context(), svcCtx)
resp, err := l.MiniUserInfo(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,6 @@ func MiniUserLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserLoginLogic(r.Context(), svcCtx)
resp, err := l.MiniUserLogin(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
result.HttpResult(r, w, resp, err)
}
}
... ...
package user
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
... ... @@ -19,10 +20,6 @@ func MiniUserUnFollowHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := user.NewMiniUserUnFollowLogic(r.Context(), svcCtx)
err := l.MiniUserUnFollow(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.Ok(w)
}
result.HttpResult(r, w, struct{}{}, err)
}
}
... ...
... ... @@ -2,6 +2,10 @@ package user
import (
"context"
"errors"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -24,7 +28,46 @@ func NewMiniUserApplyJoinCompanyLogic(ctx context.Context, svcCtx *svc.ServiceCo
}
func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.MiniUserApplyJoinCompanyRequest) (resp *types.MiniUserApplyJoinCompanyResponse, err error) {
// todo: add your logic here and delete this line
var (
conn = l.svcCtx.DefaultDBConn()
company *domain.Company
user *domain.User
)
if company, err = l.svcCtx.CompanyRepository.FindOneByCode(l.ctx, conn, req.Code); err != nil {
return nil, xerr.NewErrMsgErr("公司不存在", err)
}
if user, err = l.svcCtx.UserRepository.FindOneByCompanyIdAndPhone(l.ctx, conn, company.Id, req.Phone, []int{domain.UserAuditStatusWait, domain.UserAuditStatusPassed}); err != nil {
if errors.Is(err, domain.ErrNotFound) {
err = nil
}
}
if err != nil {
return nil, xerr.NewErrMsgErr("申请失败", err)
}
if user != nil {
if user.AuditStatus == domain.UserAuditStatusWait {
return nil, xerr.NewErrMsgErr("已申请,待审核中", err)
}
if user.AuditStatus == domain.UserAuditStatusPassed {
return nil, xerr.NewErrMsgErr("公司已申请", err)
}
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
user = &domain.User{
CompanyId: company.Id,
Phone: req.Phone,
Enable: domain.UserEnable,
Roles: make([]int64, 0),
Follower: make([]int64, 0),
Following: make([]int64, 0),
}
if user, err = l.svcCtx.UserRepository.Insert(ctx, conn, user); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("申请失败", err)
}
resp = &types.MiniUserApplyJoinCompanyResponse{}
return
}
... ...
... ... @@ -2,7 +2,6 @@ package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -24,7 +23,5 @@ func NewMiniUserAuditListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
}
func (l *MiniUserAuditListLogic) MiniUserAuditList(req *types.UserSearchRequest) (resp *types.UserSearchResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
... ... @@ -2,6 +2,9 @@ package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -23,8 +26,24 @@ func NewMiniUserAuditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Min
}
}
func (l *MiniUserAuditLogic) MiniUserAudit(req *types.MiniUserAuditRequest) error {
// todo: add your logic here and delete this line
func (l *MiniUserAuditLogic) MiniUserAudit(req *types.MiniUserAuditRequest) (err error) {
var (
conn = l.svcCtx.DefaultDBConn()
user *domain.User
)
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, req.UserId); err != nil {
return xerr.NewErrMsgErr("用户不存在", err)
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
if err = user.Audit(req.Status); err != nil {
return err
}
if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil {
return err
}
return nil
}, true); err != nil {
return xerr.NewErrMsgErr("审核失败", err)
}
return nil
}
... ...
... ... @@ -2,6 +2,9 @@ package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -24,7 +27,19 @@ func NewMiniUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mini
}
func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp *types.MiniUserInfoResponse, err error) {
// todo: add your logic here and delete this line
var (
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
user *domain.User
conn = l.svcCtx.DefaultDBConn()
)
if user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId); err != nil {
return nil, xerr.NewErrMsgErr("用户不存在", err)
}
resp = &types.MiniUserInfoResponse{
User: &types.UserItem{
Id: user.Id,
Name: user.Name,
},
}
return
}
... ...
... ... @@ -2,6 +2,13 @@ package user
import (
"context"
"fmt"
"github.com/silenceper/wechat/v2"
"github.com/silenceper/wechat/v2/cache"
miniConfig "github.com/silenceper/wechat/v2/miniprogram/config"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -24,7 +31,106 @@ func NewMiniUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Min
}
func (l *MiniUserLoginLogic) MiniUserLogin(req *types.MiniUserLoginRequest) (resp *types.MiniUserLoginResponse, err error) {
// todo: add your logic here and delete this line
var (
loginInfo *domain.LoginInfo
token string
loginCreator domain.LoginCreator = WXStuClientLogin{l: l}
)
switch req.LoginType {
case domain.LoginTypeWechatLogin:
loginInfo, err = loginCreator.WechatLogin(domain.WechatLoginRequest{Code: req.WechatAuthCode, EncryptedData: req.WechatEncryptedData, IV: req.WechatIV})
case domain.LoginTypeWechatPhoneLogin:
loginInfo, err = loginCreator.WechatPhoneLogin(domain.WechatLoginRequest{Code: req.WechatAuthCode, EncryptedData: req.WechatEncryptedData, IV: req.WechatIV})
case domain.LoginTypePhoneSmsCodeLogin:
loginInfo, err = loginCreator.PhoneSmsCodeLogin(req.Phone, req.SmsCode)
case domain.LoginTypePhonePasswordLogin:
loginInfo, err = loginCreator.PhonePasswordLogin(req.Phone, req.Password)
}
if err != nil {
return
}
var userJwtToken = tool.UserToken{}
if loginInfo.User != nil {
userJwtToken.UserId = loginInfo.User.Id
userJwtToken.CompanyId = loginInfo.User.CompanyId
userJwtToken.ClientType = "mini"
}
token, err = userJwtToken.GenerateToken(l.svcCtx.Config.MiniAuth.AccessSecret, l.svcCtx.Config.MiniAuth.AccessExpire)
if err != nil {
return nil, xerr.NewErrMsgErr("登录失败", err)
}
resp = &types.MiniUserLoginResponse{
Token: token,
Phone: loginInfo.Phone,
Success: true,
}
if loginInfo.User == nil {
resp.Success = false
}
return
}
type WXStuClientLogin struct {
l *MiniUserLoginLogic
}
func (c WXStuClientLogin) WechatPhoneLogin(r domain.WechatLoginRequest) (*domain.LoginInfo, error) {
code := r.Code
miniprogram := wechat.NewWechat().GetMiniProgram(&miniConfig.Config{
AppID: c.l.svcCtx.Config.Wechat.AppID,
AppSecret: c.l.svcCtx.Config.Wechat.AppSecret,
Cache: cache.NewMemory(),
})
authResult, err := miniprogram.GetAuth().GetPhoneNumber(code)
if err != nil || authResult.ErrCode != 0 || authResult.PhoneInfo.PhoneNumber == "" {
return nil, xerr.NewCodeErrMsg(xerr.ErrWxMiniAuthFailError, nil, fmt.Sprintf("发起授权请求失败1 err : %v , code : %s , authResult : %+v", err, code, authResult))
}
var (
users []*domain.User
phone = authResult.PhoneInfo.PhoneNumber
)
conn := c.l.svcCtx.DefaultDBConn()
_, users, err = c.l.svcCtx.UserRepository.Find(c.l.ctx, conn, domain.NewQueryOptions().
MustWithKV("phone", phone).
MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed}))
if err != nil {
return nil, err
}
response := &domain.LoginInfo{
Phone: phone,
}
if len(users) != 0 {
response.User = users[0]
}
return response, nil
}
func (c WXStuClientLogin) WechatLogin(r domain.WechatLoginRequest) (*domain.LoginInfo, error) {
return nil, nil
}
func (c WXStuClientLogin) PhonePasswordLogin(phone string, password string) (*domain.LoginInfo, error) {
panic("implement me")
}
func (c WXStuClientLogin) PhoneSmsCodeLogin(phone string, code string) (*domain.LoginInfo, error) {
var (
users []*domain.User
err error
)
conn := c.l.svcCtx.DefaultDBConn()
_, users, err = c.l.svcCtx.UserRepository.Find(c.l.ctx, conn, domain.NewQueryOptions().
MustWithKV("phone", phone).
MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed}).
WithFindOnly())
if err != nil {
return nil, err
}
response := &domain.LoginInfo{
Phone: phone,
}
if len(users) != 0 {
response.User = users[0]
}
return response, nil
}
... ...
... ... @@ -165,6 +165,7 @@ type MiniUserApplyJoinCompanyResponse struct {
type MiniUserAuditRequest struct {
UserId int64 `json:"userId"` // 用户ID
Status int `json:"status"` // 审核状态 1:审核通过 2:拒绝
}
type MiniUserDepartmentUsersRequest struct {
... ... @@ -176,6 +177,7 @@ type MiniUserDepartmentUsersResponse struct {
}
type UserItem struct {
Id int64 `json:"id,omitempty"` // 用户ID
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID
Roles []int64 `json:"roleId,omitempty"` // 角色
... ...
... ... @@ -111,6 +111,25 @@ func (repository *CompanyRepository) FindOne(ctx context.Context, conn transacti
return repository.ModelToDomainModel(m)
}
func (repository *CompanyRepository) FindOneByCode(ctx context.Context, conn transaction.Conn, code string) (*domain.Company, error) {
var (
err error
tx = conn.DB()
m = new(models.Company)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Where("code = ?", code).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return m, tx.Error
}
if _, err = repository.Query(queryFunc); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *CompanyRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.Company, error) {
var (
tx = conn.DB()
... ...
... ... @@ -111,6 +111,28 @@ func (repository *UserRepository) FindOne(ctx context.Context, conn transaction.
return repository.ModelToDomainModel(m)
}
func (repository *UserRepository) FindOneByCompanyIdAndPhone(ctx context.Context, conn transaction.Conn, companyId int64, phone string, status []int) (*domain.User, error) {
var (
err error
tx = conn.DB()
m = new(models.User)
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).
Where("company_id = ?", companyId).
Where("phone = ?", phone).
Where("audit_status in (?)", status).First(m)
if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
return nil, domain.ErrNotFound
}
return m, tx.Error
}
if _, err = repository.Query(queryFunc); err != nil {
return nil, err
}
return repository.ModelToDomainModel(m)
}
func (repository *UserRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.User, error) {
var (
tx = conn.DB()
... ... @@ -120,6 +142,12 @@ func (repository *UserRepository) Find(ctx context.Context, conn transaction.Con
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["phone"]; ok {
tx.Where("phone = ?", v)
}
if v, ok := queryOptions["auditStatus"]; ok {
tx.Where("audit_status in (?)", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -23,6 +23,7 @@ type CompanyRepository interface {
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Company) (*Company, error)
Delete(ctx context.Context, conn transaction.Conn, dm *Company) (*Company, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Company, error)
FindOneByCode(ctx context.Context, conn transaction.Conn, code string) (*Company, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Company, error)
}
... ...
... ... @@ -2,6 +2,8 @@ package domain
import (
"context"
"fmt"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
)
... ... @@ -32,6 +34,7 @@ type UserRepository interface {
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *User) (*User, error)
Delete(ctx context.Context, conn transaction.Conn, dm *User) (*User, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*User, error)
FindOneByCompanyIdAndPhone(ctx context.Context, conn transaction.Conn, companyId int64, phone string, status []int) (*User, error)
Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*User, error)
}
... ... @@ -41,3 +44,51 @@ func (m *User) Identify() interface{} {
}
return m.Id
}
const (
UserAuditStatusWait = 0 // 审核中
UserAuditStatusPassed = 1 // 审核通过
UserAuditStatusReject = 2 // 审核拒绝
)
const (
LoginTypeWechatLogin string = "wechat-login" // 微信登录
LoginTypeWechatPhoneLogin string = "wechat-phone-login" // 微信手机号登录
LoginTypePhonePasswordLogin string = "phone-password-login" // 手机密码登录
LoginTypePhoneSmsCodeLogin string = "phone-sms-code-login" // 手机验证码登录
)
const (
UserEnable = 1
UserDisable = 2
)
func (m *User) Audit(status int) error {
if !lo.Contains([]int{UserAuditStatusWait, UserAuditStatusPassed, UserAuditStatusReject}, status) {
return fmt.Errorf("unknown status:%d", status)
}
if m.AuditStatus != UserAuditStatusWait {
return fmt.Errorf("用户不是在待审核状态")
}
m.AuditStatus = status
return nil
}
type (
LoginCreator interface {
WechatLogin(r WechatLoginRequest) (*LoginInfo, error)
PhonePasswordLogin(phone string, password string) (*LoginInfo, error)
PhoneSmsCodeLogin(phone string, code string) (*LoginInfo, error)
WechatPhoneLogin(r WechatLoginRequest) (*LoginInfo, error)
}
WechatLoginRequest struct {
Code string // 授权码
EncryptedData string // 包括敏感数据在内的完整用户信息的加密数据
IV string // 加密算法的初始向量
}
LoginInfo struct {
User *User
Phone string
Message string
}
)
... ...
... ... @@ -7,6 +7,8 @@ require (
github.com/jinzhu/copier v0.4.0
github.com/jinzhu/now v1.1.5
github.com/pkg/errors v0.9.1
github.com/samber/lo v1.38.1
github.com/silenceper/wechat/v2 v2.1.4
github.com/stretchr/testify v1.8.4
github.com/tiptok/gocomm v1.0.14
github.com/zeromicro/go-zero v1.5.5
... ... @@ -21,6 +23,7 @@ require (
github.com/Shopify/sarama v1.37.2 // indirect
github.com/beego/beego/v2 v2.0.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bradfitz/gomemcache v0.0.0-20220106215444-fb4bf637b56d // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
... ... @@ -30,6 +33,7 @@ require (
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/garyburd/redigo v1.6.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
... ... @@ -80,12 +84,16 @@ require (
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.4.0 // indirect
github.com/tidwall/gjson v1.14.1 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.14.0 // indirect
... ... @@ -100,6 +108,7 @@ require (
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
... ...
... ... @@ -9,8 +9,8 @@ import (
)
var (
CtxKeyJwtUserId = "userId"
CtxKeyJwtCompanyId = "companyId"
CtxKeyJwtUserId = "UserId"
CtxKeyJwtCompanyId = "CompanyId"
)
func GetInt64FromCtx(ctx context.Context, key string) int64 {
... ... @@ -58,8 +58,8 @@ func GetUserTokenFromCtx(ctx context.Context) UserToken {
}
type UserToken struct {
UserId int64 `json:"userId"`
CompanyId int64 `json:"companyId"`
UserId int64
CompanyId int64
}
func (tk UserToken) GenerateToken(secret string, expire int64) (string, error) {
... ...
... ... @@ -21,13 +21,15 @@ func HttpResult(r *http.Request, w http.ResponseWriter, resp interface{}, err er
}
//错误返回
errCode := xerr.ServerCommonError
errMsg := "服务器开小差啦,稍后再来试一试"
internalErr := ""
causeErr := errors.Cause(err)
var (
errCode = xerr.ServerCommonError
errMsg = "服务器开小差啦,稍后再来试一试"
internalErr = ""
causeErr = errors.Cause(err)
)
codeError := &xerr.CodeError{}
if ok := errors.As(causeErr, codeError); ok { // 自定义错误类型
codeError, ok := causeErr.(*xerr.CodeError)
if ok { // 自定义错误类型
errCode = codeError.GetErrCode()
errMsg = codeError.GetErrMsg()
if codeError.InternalError != nil {
... ...