contact us
This commit is contained in:
parent
fff760253a
commit
9bb5f1b2dd
|
@ -4,15 +4,16 @@ import (
|
|||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// casbin_rule
|
||||
// casbin_rule 后台--权限规则表
|
||||
type CasbinRule struct {
|
||||
PType *string `gorm:"default:'';" json:"p_type"` //
|
||||
V0 *string `gorm:"default:'';" json:"v0"` //
|
||||
V1 *string `gorm:"default:'';" json:"v1"` //
|
||||
V2 *string `gorm:"default:'';" json:"v2"` //
|
||||
V3 *string `gorm:"default:'';" json:"v3"` //
|
||||
V4 *string `gorm:"default:'';" json:"v4"` //
|
||||
V5 *string `gorm:"default:'';" json:"v5"` //
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 序号
|
||||
PType *string `gorm:"default:'';" json:"p_type"` //
|
||||
V0 *string `gorm:"default:'';" json:"v0"` //
|
||||
V1 *string `gorm:"default:'';" json:"v1"` //
|
||||
V2 *string `gorm:"default:'';" json:"v2"` //
|
||||
V3 *string `gorm:"default:'';" json:"v3"` //
|
||||
V4 *string `gorm:"default:'';" json:"v4"` //
|
||||
V5 *string `gorm:"default:'';" json:"v5"` //
|
||||
}
|
||||
type CasbinRuleModel struct {
|
||||
db *gorm.DB
|
||||
|
|
|
@ -20,6 +20,7 @@ type FsAdminApi struct {
|
|||
UpdateUid *int64 `gorm:"default:0;" json:"update_uid"` // 更新人
|
||||
DeleteUid *int64 `gorm:"default:0;" json:"delete_uid"` // 删除人
|
||||
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除:1=是 0=否
|
||||
Method *int64 `gorm:"default:0;" json:"method"` // 接口方法
|
||||
}
|
||||
type FsAdminApiModel struct {
|
||||
db *gorm.DB
|
||||
|
|
23
model/gmodel/fs_admin_role_api_gen.go
Normal file
23
model/gmodel/fs_admin_role_api_gen.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package gmodel
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// fs_admin_role_api 后台--角色接口表
|
||||
type FsAdminRoleApi struct {
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 序号
|
||||
RoleId *int64 `gorm:"index;default:0;" json:"role_id"` // 角色ID
|
||||
MenuId *int64 `gorm:"index;default:0;" json:"menu_id"` // 菜单ID
|
||||
ApiId *int64 `gorm:"index;default:0;" json:"api_id"` // 接口ID
|
||||
ApiPath *string `gorm:"default:'';" json:"api_path"` //
|
||||
ApiMethod *int64 `gorm:"default:0;" json:"api_method"` // 接口方法
|
||||
}
|
||||
type FsAdminRoleApiModel struct {
|
||||
db *gorm.DB
|
||||
name string
|
||||
}
|
||||
|
||||
func NewFsAdminRoleApiModel(db *gorm.DB) *FsAdminRoleApiModel {
|
||||
return &FsAdminRoleApiModel{db: db, name: "fs_admin_role_api"}
|
||||
}
|
2
model/gmodel/fs_admin_role_api_logic.go
Normal file
2
model/gmodel/fs_admin_role_api_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package gmodel
|
||||
// TODO: 使用model的属性做你想做的
|
|
@ -2,18 +2,20 @@ package gmodel
|
|||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// fs_contact 该表暂未使用
|
||||
type FsContact struct {
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
||||
Name *string `gorm:"default:'';" json:"name"` // 名字
|
||||
Email *string `gorm:"index;default:'';" json:"email"` // 邮箱
|
||||
Subject *int64 `gorm:"default:0;" json:"subject"` // 主题
|
||||
Message *string `gorm:"default:'';" json:"message"` // 消息
|
||||
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间
|
||||
Status *int64 `gorm:"default:0;" json:"status"` // 状态位 是否已处理
|
||||
Mark *string `gorm:"default:'';" json:"mark"` // 后台订单备注
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` //
|
||||
Name *string `gorm:"default:'';" json:"name"` //
|
||||
Email *string `gorm:"index;default:'';" json:"email"` // 邮箱
|
||||
Subject *string `gorm:"default:'0';" json:"subject"` // 主题
|
||||
Message *string `gorm:"default:'';" json:"message"` // 消息
|
||||
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
|
||||
Status *int64 `gorm:"default:0;" json:"status"` // 状态位 是否已处理
|
||||
Mark *string `gorm:"default:'';" json:"mark"` // 后台订单备注
|
||||
Phone *string `gorm:"default:'';" json:"phone"` //
|
||||
}
|
||||
type FsContactModel struct {
|
||||
db *gorm.DB
|
||||
|
|
|
@ -1,3 +1,9 @@
|
|||
package gmodel
|
||||
|
||||
import "context"
|
||||
|
||||
// TODO: 使用model的属性做你想做的
|
||||
|
||||
func (contact *FsContactModel) Save(ctx context.Context, obj *FsContact) (err error) {
|
||||
return contact.db.WithContext(ctx).Model(&FsContact{}).Create(obj).Error
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@ type FsProduct struct {
|
|||
Type *int64 `gorm:"default:0;" json:"type"` // 分类ID
|
||||
Title *string `gorm:"default:'';" json:"title"` // 名称
|
||||
TitleCn *string `gorm:"default:'';" json:"title_cn"` // 中文名称
|
||||
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序
|
||||
Cover *string `gorm:"default:'';" json:"cover"` // 封面图
|
||||
Imgs *string `gorm:"default:'';" json:"imgs"` // 一个或多个介绍图或视频
|
||||
Keywords *string `gorm:"default:'';" json:"keywords"` // 关键字
|
||||
Intro *string `gorm:"default:'';" json:"intro"` // 简要描述
|
||||
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序
|
||||
SelledNum *int64 `gorm:"default:0;" json:"selled_num"` // 已卖数量
|
||||
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间
|
||||
View *int64 `gorm:"default:0;" json:"view"` // 浏览量
|
||||
|
|
|
@ -18,7 +18,7 @@ type FsShoppingCart struct {
|
|||
PurchaseQuantity *int64 `gorm:"default:0;" json:"purchase_quantity"` // 购买数量
|
||||
Snapshot *string `gorm:"default:'';" json:"snapshot"` //
|
||||
IsSelected *int64 `gorm:"default:0;" json:"is_selected"` // 是否被选中 0非 1是
|
||||
IsHighlyCustomized *int64 `gorm:"default:0;" json:"is_highly_customized"` // 是否高度定制 0非 1是(针对客人高度定制只能后台增加如购物车)
|
||||
IsHighlyCustomized *int64 `gorm:"default:0;" json:"is_highly_customized"` // 是否高度定制 0非 1是(针对客人高度定制,该类行无法跳详情页)
|
||||
Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` //
|
||||
Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` //
|
||||
}
|
||||
|
|
|
@ -4,12 +4,13 @@ import "gorm.io/gorm"
|
|||
|
||||
// AllModelsGen 所有Model集合,修改单行,只要不改字段名,不会根据新的内容修改,需要修改的话手动删除
|
||||
type AllModelsGen struct {
|
||||
CasbinRule *CasbinRuleModel // casbin_rule
|
||||
CasbinRule *CasbinRuleModel // casbin_rule 后台--权限规则表
|
||||
FsAddress *FsAddressModel // fs_address 用户地址表
|
||||
FsAdminApi *FsAdminApiModel // fs_admin_api 后台--接口表
|
||||
FsAdminDepartment *FsAdminDepartmentModel // fs_admin_department 后台--部门表
|
||||
FsAdminMenu *FsAdminMenuModel // fs_admin_menu 后台--菜单表
|
||||
FsAdminRole *FsAdminRoleModel // fs_admin_role 后台--角色表
|
||||
FsAdminRoleApi *FsAdminRoleApiModel // fs_admin_role_api 后台--角色接口表
|
||||
FsAdminUser *FsAdminUserModel // fs_admin_user 后台--管理员表
|
||||
FsAuthAssignment *FsAuthAssignmentModel // fs_auth_assignment 用户角色和权限信息
|
||||
FsAuthItem *FsAuthItemModel // fs_auth_item 用户角色和权限信息
|
||||
|
@ -122,6 +123,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
|
|||
FsAdminDepartment: NewFsAdminDepartmentModel(gdb),
|
||||
FsAdminMenu: NewFsAdminMenuModel(gdb),
|
||||
FsAdminRole: NewFsAdminRoleModel(gdb),
|
||||
FsAdminRoleApi: NewFsAdminRoleApiModel(gdb),
|
||||
FsAdminUser: NewFsAdminUserModel(gdb),
|
||||
FsAuthAssignment: NewFsAuthAssignmentModel(gdb),
|
||||
FsAuthItem: NewFsAuthItemModel(gdb),
|
||||
|
|
35
server/info/internal/handler/contactushandler.go
Normal file
35
server/info/internal/handler/contactushandler.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/info/internal/logic"
|
||||
"fusenapi/server/info/internal/svc"
|
||||
"fusenapi/server/info/internal/types"
|
||||
)
|
||||
|
||||
func ContactUsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.ContactUsRequest
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewContactUsLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.ContactUs(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -62,6 +62,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/api/info/restaurant/list",
|
||||
Handler: RestaurantListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/info/contact/us",
|
||||
Handler: ContactUsHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
66
server/info/internal/logic/contactuslogic.go
Normal file
66
server/info/internal/logic/contactuslogic.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/info/internal/svc"
|
||||
"fusenapi/server/info/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ContactUsLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewContactUsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ContactUsLogic {
|
||||
return &ContactUsLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// 处理进入前逻辑w,r
|
||||
// func (l *ContactUsLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *ContactUsLogic) ContactUs(req *types.ContactUsRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
|
||||
if !auth.ValidateEmail(req.Email) {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "email format error")
|
||||
}
|
||||
|
||||
if req.Message == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "remarks must exist")
|
||||
}
|
||||
|
||||
now := time.Now().UTC()
|
||||
err := l.svcCtx.AllModels.FsContact.Save(l.ctx, &gmodel.FsContact{
|
||||
Name: &req.Name,
|
||||
Email: &req.Email,
|
||||
Phone: &req.Phone,
|
||||
Message: &req.Message,
|
||||
Status: gmodel.FsInt64(0),
|
||||
Ctime: &now,
|
||||
})
|
||||
if err != nil {
|
||||
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, err.Error())
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
}
|
||||
|
||||
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
|
||||
// func (l *ContactUsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
|
||||
// // httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
// }
|
|
@ -5,6 +5,13 @@ import (
|
|||
"fusenapi/utils/basic"
|
||||
)
|
||||
|
||||
type ContactUsRequest struct {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Phone string `json:"phone"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type UserInfoRequest struct {
|
||||
Module []string `json:"module"`
|
||||
}
|
||||
|
|
|
@ -39,9 +39,19 @@ service info {
|
|||
|
||||
@handler RestaurantListHandler
|
||||
get /api/info/restaurant/list(request) returns (response);
|
||||
|
||||
@handler ContactUsHandler
|
||||
post /api/info/contact/us(ContactUsRequest) returns (response);
|
||||
}
|
||||
|
||||
type (
|
||||
ContactUsRequest {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Phone string `json:"phone"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
UserInfoRequest {
|
||||
Module []string `json:"module"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user