把server归到统一文件夹

This commit is contained in:
eson
2023-06-08 10:51:56 +08:00
parent dc73ff1679
commit 859c101c51
36 changed files with 179 additions and 67 deletions

View File

@@ -0,0 +1,35 @@
package logic
import (
"context"
"fusenapi/model"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"fusenapi/utils/basic"
"github.com/zeromicro/go-zero/core/logx"
)
type GetTypeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTypeLogic {
return &GetTypeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetTypeLogic) GetType(req *types.Request) (resp *types.Response) {
data, err := model.NewFsCanteenTypeModel(l.svcCtx.MysqlConn).FindGetType(l.ctx)
if err != nil {
logx.Error(err)
return
}
return resp.SetStatus(basic.CodeOK, "success", data)
}

View File

@@ -0,0 +1,39 @@
package logic
import (
"context"
"fusenapi/model"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"github.com/zeromicro/go-zero/core/logx"
)
type UserBasicInfoLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUserBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserBasicInfoLogic {
return &UserBasicInfoLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request) (resp *types.Response) {
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
if loginInfo.UserId == 0 {
return resp.SetStatus(basic.CodeOK, "parse login info err ")
}
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, loginInfo.UserId)
if err != nil {
logx.Error(err)
return resp.Set(510, err.Error())
}
return resp.SetStatus(basic.CodeOK, fsUserModel)
}

View File

@@ -0,0 +1,36 @@
package logic
import (
"context"
"fusenapi/model"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"fusenapi/utils/basic"
"github.com/zeromicro/go-zero/core/logx"
)
type UserFontsLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUserFontsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserFontsLogic {
return &UserFontsLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UserFontsLogic) UserFonts(req *types.Request) (resp *types.Response) {
data, err := model.NewFsFontModel(l.svcCtx.MysqlConn).FindAllOrderSortByDesc(l.ctx)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeOK, data)
}
return resp.SetStatus(basic.CodeOK)
}

View File

@@ -0,0 +1,72 @@
package logic
import (
"context"
"time"
"fusenapi/model"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"fusenapi/utils/basic"
"github.com/golang-jwt/jwt"
"github.com/zeromicro/go-zero/core/logx"
)
type UserLoginLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLoginLogic {
return &UserLoginLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UserLoginLogic) genJwtToken(accessSecret string, accessExpire, nowSec, userid int64) (string, error) {
claims := make(jwt.MapClaims)
claims["exp"] = nowSec + accessExpire
claims["iat"] = nowSec
claims["userid"] = userid
token := jwt.New(jwt.SigningMethodHS256)
token.Claims = claims
return token.SignedString([]byte(accessSecret))
}
func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *types.Response, jwtToken string) {
m := model.NewFsUserModel(l.svcCtx.MysqlConn)
userModel, err := m.FindOneByEmail(l.ctx, req.Name)
if err == model.ErrNotFound {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error()), jwtToken
}
if userModel.PasswordHash != req.Password {
logx.Info("密码错误")
return resp.SetStatusWithMessage(basic.CodeUnAuth, "密码错误"), jwtToken
}
// jwt 生成
nowSec := time.Now().Unix()
jwtToken, err = l.genJwtToken(l.svcCtx.Config.Auth.AccessSecret, l.svcCtx.Config.Auth.AccessExpire, nowSec, userModel.Id)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeUnAuth), jwtToken
}
err = m.UpdateVerificationToken(l.ctx, userModel.Id, jwtToken)
if err != nil {
return resp.SetStatus(basic.CodeUnAuth), jwtToken
}
data := &types.DataUserLogin{
Token: jwtToken,
}
return resp.SetStatus(basic.CodeOK, data), jwtToken
}

View File

@@ -0,0 +1,45 @@
package logic
import (
"context"
"fusenapi/utils/auth"
"fusenapi/model"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"fusenapi/utils/basic"
"github.com/zeromicro/go-zero/core/logx"
)
type UserSaveBasicInfoLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUserSaveBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserSaveBasicInfoLogic {
return &UserSaveBasicInfoLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoForm) (resp *types.Response) {
loginInfo := auth.GetUserInfoFormCtx(l.ctx)
if loginInfo.UserId == 0 {
return resp.SetStatus(basic.CodeOK, "parse login info err ")
}
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, loginInfo.UserId)
if err != nil {
if err == model.ErrNotFound {
return resp
}
logx.Error(err)
return resp
}
return resp.SetStatus(basic.CodeOK, fsUserModel)
}

View File

@@ -0,0 +1,92 @@
package logic
import (
"context"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"fusenapi/utils/basic"
"github.com/zeromicro/go-zero/core/logx"
)
type UserStatusConfigLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUserStatusConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserStatusConfigLogic {
return &UserStatusConfigLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *UserStatusConfigLogic) UserStatusConfig(req *types.RequestBasicInfoForm) (resp *types.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
return resp.SetStatus(basic.CodeOK)
}
// [
// //返回订单每个状态值
// //搜索下拉列表
// 'search_list' => [
// ['key' => -1, "name" => 'All'],
// ['key' => 1, "name" => 'Order Has Been Placed'],
// ['key' => 2, "name" => 'In Production'],
// ['key' => 3, "name" => 'Shipped'],
// ['key' => 4, "name" => 'Inventory'],
// ['key' => 8, "name" => 'Ready for Shipment'],
// ['key' => 5, "name" => 'Completed'],
// // ['key' => 6, "name" => 'Refund Under Review'],
// ['key' => 7, "name" => 'Transaction Closed'],
// ],
// //直邮单状态
// 'order_status' => [
// ['key' => 1, "name" => 'Order Has Been Placed', 'button' => ['download_invoice', 'cancel', 'again', 'toPay']],
// ['key' => 2, "name" => 'In Production', 'button' => ['download_invoice', 'again', 'toPay']],
// ['key' => 3, "name" => 'Shipped', 'button' => ['download_invoice', 'again', 'view_logistics']],
// ['key' => 5, "name" => 'Completed', 'button' => ['download_invoice', 'again', 'view_logistics', 'delete']],
// // ['key' => 6, "name" => 'Refund Under Review', 'button' => ['again', 'delete']],
// ['key' => 7, "name" => 'Transaction Closed', 'button' => ['again', 'delete']],
// ],
// //云仓单状态
// 'Inventory_status' => [
// ['key' => 1, "name" => 'Order Has Been Placed', 'button' => ['download_invoice', 'cancel', 'again', 'toPay']],
// ['key' => 2, "name" => 'In Production', 'button' => ['download_invoice', 'again', 'toPay']],
// ['key' => 4, "name" => 'Inventory', 'button' => ['download_invoice', 'again', 'go_cloud', 'toPay']],
// ['key' => 8, "name" => 'Ready for Shipment', 'button' => ['download_invoice', 'again', 'go_cloud', 'delete']],
// // ['key' => 6, "name" => 'Refund Under Review', 'button' => ['again', 'delete']],
// ['key' => 7, "name" => 'Transaction Closed', 'button' => ['again', 'delete']],
// ],
// //订单物流状态
// 'order_logistics_status' => Order::$statusFontLogisticOrder,
// //订单物流状态
// 'Inventory_logistics_status' => Order::$statusFontLogisticInventory,
// //返回订单时间筛选项
// 'time' => [
// ['key' => 0, 'name' => 'All'],
// ['key' => 1, 'name' => 'within a month'],
// ['key' => 2, 'name' => 'within a quarter'],
// ['key' => 3, 'name' => 'Within half a year'],
// ['key' => 4, 'name' => 'Within a year'],
// ],
// //退款原因说明项
// 'refund_reason' => [
// ['key' => 1, 'name' => 'I don\'t want it anymore'],
// ['key' => 2, 'name' => 'no reason'],
// ['key' => 3, 'name' => 'other'],
// ],
// //物流状态筛选项
// 'logistics_status' => [
// ['key' => -1, "name" => 'All'],
// ['key' => 1, "name" => 'Draw', 'button' => []],
// ['key' => 2, "name" => 'Shipping', 'button' => []],
// // ['key' => Deliver::STATUS_PORT, "name" => 'To the port', 'button' => []],
// ['key' => 3, "name" => 'UPS pick up', 'button' => ['check_detail']],
// ['key' => 4, "name" => 'Arrival', 'button' => []],
// ]
// ];