mirror of
https://gitlab.52pay.top/go/easygoadmin.git
synced 2025-09-26 22:58:01 +08:00
feat: 初始化项目
初始化项目
This commit is contained in:
31
.gitignore
vendored
Normal file
31
.gitignore
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
.DS_Store
|
||||
.buildpath
|
||||
.hgignore.swp
|
||||
.project
|
||||
.orig
|
||||
.swp
|
||||
.idea/
|
||||
.settings/
|
||||
.vscode/
|
||||
vender/
|
||||
log/
|
||||
composer.lock
|
||||
gitpush.sh
|
||||
pkg/
|
||||
bin/
|
||||
cbuild
|
||||
*/.DS_Store
|
||||
config/config.toml
|
||||
main
|
||||
.vscode
|
||||
go.sum
|
||||
|
||||
node_modules/
|
||||
src/
|
||||
dist/
|
||||
package.json
|
||||
package-lock.json
|
||||
webpack.config.js
|
||||
.svn
|
||||
|
||||
go_build_main_go.exe
|
165
LICENSE
Normal file
165
LICENSE
Normal file
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
96
README.md
96
README.md
@@ -1,92 +1,74 @@
|
||||
# easygoadmin
|
||||
# gin layui 后台管理框架
|
||||
|
||||
# 文档地址: http://docs.gin.layui.easygoadmin.vip/#/
|
||||
|
||||
|
||||
|
||||
## Getting started
|
||||
## 1.数据表创建
|
||||
|
||||
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
|
||||
参考文档:
|
||||
|
||||
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
|
||||
|
||||
## Add your files
|
||||

|
||||
|
||||
如type或status这两个字段注释一定要用上面的格式写, 这样才能自动生成响应的功能, 其他需要类似功能的字段也是.
|
||||
|
||||
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
|
||||
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
|
||||
|
||||
```
|
||||
cd existing_repo
|
||||
git remote add origin https://gitlab.52pay.top/go/easygoadmin.git
|
||||
git branch -M main
|
||||
git push -uf origin main
|
||||
`create_time` DATETIME NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '最新更新时间',
|
||||
```
|
||||
|
||||
## Integrate with your tools
|
||||
create_time和update_time建议用上面两个
|
||||
|
||||
- [ ] [Set up project integrations](https://gitlab.52pay.top/go/easygoadmin/-/settings/integrations)
|
||||
|
||||
## Collaborate with your team
|
||||
## 2.生成控制器和模型
|
||||
|
||||
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
|
||||
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
|
||||
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
|
||||
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
|
||||
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
|
||||

|
||||
|
||||
## Test and Deploy
|
||||
建议使用代码生成器
|
||||
|
||||
Use the built-in continuous integration in GitLab.
|
||||
手动在这个目录下创建模型
|
||||
|
||||
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
|
||||
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
|
||||
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
|
||||
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
|
||||
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
|
||||

|
||||
|
||||
***
|
||||
## 3.路由
|
||||
|
||||
# Editing this README
|
||||
系统根据表名创建一个路由文件, 但是这个文件的路由不会被注册到程序, 所有需要把里面的路由复制到router.go文件, 或者采用下面的方式:
|
||||
|
||||
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
|
||||

|
||||
|
||||
## Suggestions for a good README
|
||||
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
|
||||

|
||||
|
||||
## Name
|
||||
Choose a self-explaining name for your project.
|
||||
需要放到需要使用的中间件下面
|
||||
|
||||
## Description
|
||||
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
|
||||
|
||||
## Badges
|
||||
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
|
||||
|
||||
## Visuals
|
||||
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
|
||||
## 4.开发中需要注意的问题
|
||||
|
||||
## Installation
|
||||
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
|
||||
[介绍 · Go语言中文文档-xorm (topgoer.com)](http://xorm.topgoer.com/)
|
||||
|
||||
## Usage
|
||||
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
|
||||
### 4.1 修改数据
|
||||
|
||||
## Support
|
||||
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
|
||||

|
||||
|
||||
## Roadmap
|
||||
If you have ideas for releases in the future, it is a good idea to list them in the README.
|
||||
使用结构体修改数据的时候一定要加上 Cols 指定要修改的字段, 要修改几个加几个, 不然有概率会出现不可预知的问题, 或者使用Map[string]interface{}类型修改数据
|
||||
|
||||
## Contributing
|
||||
State if you are open to contributions and what your requirements are for accepting them.
|
||||
### 4.2 配置文件
|
||||
|
||||
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
|
||||
```
|
||||
config/config.toml
|
||||
```
|
||||
|
||||
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
|
||||
这个是配置文件, 一般git忽略掉这样测试环境和线上不会被覆盖, 发上线的的时候最好手动创建
|
||||
|
||||
## Authors and acknowledgment
|
||||
Show your appreciation to those who have contributed to the project.
|
||||
系统后台 sql 文件
|
||||
|
||||
## License
|
||||
For open source projects, say how it is licensed.
|
||||
也可以参考这里的技术文档生成模型
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
xorm reverse mysql 数据库账号t:数据库密码@/数据库名?charset=utf8mb4 templates/goxorm app/model
|
||||
|
||||
## Project status
|
||||
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
|
||||
|
215
app/controller/ad.go
Normal file
215
app/controller/ad.go
Normal file
@@ -0,0 +1,215 @@
|
||||
/**
|
||||
* 广告管理-控制器
|
||||
* @author
|
||||
* @since 2021/11/15
|
||||
* @File : ad
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var Ad = new(adCtl)
|
||||
|
||||
type adCtl struct{}
|
||||
|
||||
func (c *adCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "ad_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *adCtl) List(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.AdPageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用分页查询方法
|
||||
list, count, err := service.Ad.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *adCtl) Edit(ctx *gin.Context) {
|
||||
// 查询记录
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
info := &model.Ad{Id: id}
|
||||
has, err := info.Get()
|
||||
if !has || err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 广告图片
|
||||
if info.Cover != "" {
|
||||
info.Cover = utils.GetImageUrl(info.Cover)
|
||||
}
|
||||
|
||||
// 富文本图片替换处理
|
||||
if info.Content != "" {
|
||||
info.Content = strings.ReplaceAll(info.Content, "[IMG_URL]", utils.ImageUrl())
|
||||
}
|
||||
|
||||
// 广告位列表
|
||||
list := make([]model.AdSort, 0)
|
||||
utils.XormDb.Where("mark=1").Find(&list)
|
||||
adSortList := make(map[int]string, 0)
|
||||
for _, v := range list {
|
||||
adSortList[v.Id] = v.Description
|
||||
}
|
||||
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "ad_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
"typeList": common.AD_TYPE_LIST,
|
||||
"adSortList": adSortList,
|
||||
})
|
||||
} else {
|
||||
// 添加
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "ad_edit.html").WriteTpl()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *adCtl) Add(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.AdAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.Ad.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *adCtl) Update(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.AdUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.Ad.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *adCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.Ad.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *adCtl) Status(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.AdStatusReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用设置状态方法
|
||||
rows, err := service.Ad.Status(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "设置成功",
|
||||
})
|
||||
}
|
181
app/controller/ad_sort.go
Normal file
181
app/controller/ad_sort.go
Normal file
@@ -0,0 +1,181 @@
|
||||
/**
|
||||
* 广告位-控制器
|
||||
* @author
|
||||
* @since 2021/11/15
|
||||
* @File : adsort
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var AdSort = new(adSortCtl)
|
||||
|
||||
type adSortCtl struct{}
|
||||
|
||||
func (c *adSortCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "adsort_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *adSortCtl) List(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.AdSortPageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用查询分页方法
|
||||
list, count, err := service.AdSort.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *adSortCtl) Edit(ctx *gin.Context) {
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
// 编辑
|
||||
info := &model.AdSort{Id: id}
|
||||
has, err := info.Get()
|
||||
if !has || err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "adsort_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
"platformList": common.ADSORT_PLATFORM_LIST,
|
||||
})
|
||||
} else {
|
||||
// 添加
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "adsort_edit.html").WriteTpl(gin.H{
|
||||
"platformList": common.ADSORT_PLATFORM_LIST,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *adSortCtl) Add(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.AdSortAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.AdSort.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *adSortCtl) Update(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.AdSortUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.AdSort.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *adSortCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.AdSort.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *adSortCtl) GetAdSortList(ctx *gin.Context) {
|
||||
// 调用查询列表方法
|
||||
list := service.AdSort.GetAdSortList()
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
})
|
||||
}
|
21
app/controller/analysis.go
Normal file
21
app/controller/analysis.go
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* 统计分析
|
||||
* @author
|
||||
* @since 2021/11/30
|
||||
* @File : analysis
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var Analysis = new(analysisCtl)
|
||||
|
||||
type analysisCtl struct{}
|
||||
|
||||
func (c *analysisCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "analysis_index.html").WriteTpl()
|
||||
}
|
190
app/controller/city.go
Normal file
190
app/controller/city.go
Normal file
@@ -0,0 +1,190 @@
|
||||
/**
|
||||
* 城市管理-控制器
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : city
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var City = new(cityCtl)
|
||||
|
||||
type cityCtl struct{}
|
||||
|
||||
func (c *cityCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "city_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *cityCtl) List(ctx *gin.Context) {
|
||||
//// 参数
|
||||
//var req *dto.CityQueryReq
|
||||
//if err := ctx.ShouldBind(&req); err != nil {
|
||||
// ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
// Code: -1,
|
||||
// Msg: err.Error(),
|
||||
// })
|
||||
// return
|
||||
//}
|
||||
|
||||
// 调用获取列表方法
|
||||
list := service.City.GetList(nil)
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *cityCtl) Edit(ctx *gin.Context) {
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
// 编辑
|
||||
info := &model.City{Id: id}
|
||||
has, err := info.Get()
|
||||
if !has || err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "city_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
"levelList": common.CITY_LEVEL,
|
||||
})
|
||||
} else {
|
||||
// 添加
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "city_edit.html").WriteTpl()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *cityCtl) Add(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.CityAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.City.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *cityCtl) Update(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.CityUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.City.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *cityCtl) Delete(ctx *gin.Context) {
|
||||
// 参数
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.City.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *cityCtl) GetChilds(ctx *gin.Context) {
|
||||
// 参数验证
|
||||
var req *dto.CityChildReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用获取子级城市
|
||||
list, err := service.City.GetChilds(req.CityCode)
|
||||
if err != nil {
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
})
|
||||
}
|
123
app/controller/config.go
Normal file
123
app/controller/config.go
Normal file
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* 配置管理-控制器
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : config
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var Config = new(configCtl)
|
||||
|
||||
type configCtl struct{}
|
||||
|
||||
func (c *configCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "config_index.html").WriteTpl(gin.H{
|
||||
"configTypeList": common.CONFIG_DATA_TYPE_LIST,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *configCtl) List(ctx *gin.Context) {
|
||||
// 调用查询列表方法
|
||||
list := service.Config.GetList()
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *configCtl) Add(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.ConfigAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.Config.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *configCtl) Update(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.ConfigUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.Config.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *configCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.Config.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
162
app/controller/config_data.go
Normal file
162
app/controller/config_data.go
Normal file
@@ -0,0 +1,162 @@
|
||||
/**
|
||||
* 配置数据-控制器
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : config_data
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var ConfigData = new(configDataCtl)
|
||||
|
||||
type configDataCtl struct{}
|
||||
|
||||
func (c *configDataCtl) List(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.ConfigDataPageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用查询方法
|
||||
list, count, err := service.ConfigData.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *configDataCtl) Add(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.ConfigDataAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.ConfigData.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *configDataCtl) Update(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.ConfigDataUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.ConfigData.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *configDataCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.ConfigData.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *configDataCtl) Status(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.ConfigDataStatusReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用设置方法
|
||||
rows, err := service.ConfigData.Status(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "设置成功",
|
||||
})
|
||||
}
|
198
app/controller/config_web.go
Normal file
198
app/controller/config_web.go
Normal file
@@ -0,0 +1,198 @@
|
||||
/**
|
||||
* 系统配置-控制器
|
||||
* @author
|
||||
* @since 2021/11/15
|
||||
* @File : config_web
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/gstr"
|
||||
"easygoadmin/utils/response"
|
||||
"encoding/json"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 控制器管理对象
|
||||
var ConfigWeb = new(configWebCtl)
|
||||
|
||||
type configWebCtl struct{}
|
||||
|
||||
func (c *configWebCtl) Index(ctx *gin.Context) {
|
||||
if ctx.Request.Method == "POST" {
|
||||
// 返回结果
|
||||
if utils.AppDebug() {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "演示环境,暂无权限操作",
|
||||
})
|
||||
return
|
||||
}
|
||||
// key:string类型,value:interface{} 类型能存任何数据类型
|
||||
var jsonObj map[string]interface{}
|
||||
data, _ := ctx.GetRawData()
|
||||
json.Unmarshal(data, &jsonObj)
|
||||
// 遍历处理数据源
|
||||
for key, val := range jsonObj {
|
||||
// 参数处理
|
||||
if key == "checkbox" {
|
||||
// 复选框
|
||||
|
||||
item := gstr.Split(key, "__")
|
||||
// KEY值
|
||||
key = item[0]
|
||||
} else if strings.Contains(key, "upimage") {
|
||||
// 单图上传
|
||||
|
||||
item := gstr.Split(key, "__")
|
||||
// KEY值
|
||||
key = item[0]
|
||||
if strings.Contains(gconv.String(val), "temp") {
|
||||
image, _ := utils.SaveImage(gconv.String(val), "config")
|
||||
// 赋值给参数
|
||||
val = image
|
||||
} else {
|
||||
// 赋值给参数
|
||||
val = gstr.Replace(gconv.String(val), utils.ImageUrl(), "")
|
||||
}
|
||||
} else if strings.Contains(key, "upimgs") {
|
||||
// 多图上传
|
||||
item := gstr.Split(key, "__")
|
||||
// KEY值
|
||||
key = item[0]
|
||||
// 图片地址处理
|
||||
urlArr := gstr.Split(gconv.String(val), ",")
|
||||
list := make([]string, 0)
|
||||
for _, v := range urlArr {
|
||||
if strings.Contains(gconv.String(v), "temp") {
|
||||
image, _ := utils.SaveImage(v, "config")
|
||||
list = append(list, image)
|
||||
} else {
|
||||
image := gstr.Replace(v, utils.ImageUrl(), "")
|
||||
list = append(list, image)
|
||||
}
|
||||
}
|
||||
// 数组转字符串,逗号分隔
|
||||
val = strings.Join(list, ",")
|
||||
} else if strings.Contains(key, "ueditor") {
|
||||
item := gstr.Split(key, "__")
|
||||
// KEY值
|
||||
key = item[0]
|
||||
|
||||
// 富文本处理(待完善)
|
||||
// TODO...
|
||||
}
|
||||
|
||||
var info model.ConfigData
|
||||
has, err := utils.XormDb.Where("code=?", key).Get(&info)
|
||||
if err != nil || !has {
|
||||
continue
|
||||
}
|
||||
|
||||
// 更新记录
|
||||
entity := &model.ConfigData{Id: info.Id}
|
||||
entity.Value = gconv.String(val)
|
||||
entity.UpdateUser = utils.Uid(ctx)
|
||||
entity.UpdateTime = time.Now().Unix()
|
||||
entity.Update()
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "保存成功",
|
||||
})
|
||||
return
|
||||
}
|
||||
// 配置ID
|
||||
configId := ctx.Query("configId")
|
||||
if configId == "" {
|
||||
configId = "1"
|
||||
}
|
||||
|
||||
// 获取配置列表
|
||||
configData := make([]model.Config, 0)
|
||||
utils.XormDb.Where("mark=1").Find(&configData)
|
||||
configList := make(map[string]string)
|
||||
for _, v := range configData {
|
||||
configList[gconv.String(v.Id)] = v.Name
|
||||
}
|
||||
|
||||
// 获取配置项列表
|
||||
itemData := make([]model.ConfigData, 0)
|
||||
utils.XormDb.Where("config_id=? and status=1 and mark=1", configId).OrderBy("sort asc").Find(&itemData)
|
||||
itemList := make([]map[string]interface{}, 0)
|
||||
for _, v := range itemData {
|
||||
item := make(map[string]interface{})
|
||||
item["id"] = v.Id
|
||||
item["title"] = v.Title
|
||||
item["code"] = v.Code
|
||||
item["value"] = v.Value
|
||||
item["type"] = v.Type
|
||||
|
||||
if v.Type == "checkbox" {
|
||||
// 复选框
|
||||
re := regexp.MustCompile(`\r?\n`)
|
||||
list := gstr.Split(re.ReplaceAllString(v.Options, "|"), "|")
|
||||
optionsList := make(map[string]string)
|
||||
for _, val := range list {
|
||||
re2 := regexp.MustCompile(`:|:|\s+`)
|
||||
item := gstr.Split(re2.ReplaceAllString(val, "|"), "|")
|
||||
optionsList[item[0]] = item[1]
|
||||
}
|
||||
item["optionsList"] = optionsList
|
||||
} else if v.Type == "radio" {
|
||||
// 单选框
|
||||
re := regexp.MustCompile(`\r?\n`)
|
||||
list := gstr.Split(re.ReplaceAllString(v.Options, "|"), "|")
|
||||
optionsList := make(map[string]string)
|
||||
for _, v := range list {
|
||||
re2 := regexp.MustCompile(`:|:|\s+`)
|
||||
item := gstr.Split(re2.ReplaceAllString(v, "|"), "|")
|
||||
optionsList[item[0]] = item[1]
|
||||
}
|
||||
item["optionsList"] = optionsList
|
||||
|
||||
} else if v.Type == "select" {
|
||||
// 下拉选择框
|
||||
re := regexp.MustCompile(`\r?\n`)
|
||||
list := gstr.Split(re.ReplaceAllString(v.Options, "|"), "|")
|
||||
optionsList := make(map[string]string)
|
||||
for _, v := range list {
|
||||
re2 := regexp.MustCompile(`:|:|\s+`)
|
||||
item := gstr.Split(re2.ReplaceAllString(v, "|"), "|")
|
||||
optionsList[item[0]] = item[1]
|
||||
}
|
||||
item["optionsList"] = optionsList
|
||||
} else if v.Type == "image" {
|
||||
// 单图片
|
||||
item["value"] = utils.GetImageUrl(v.Value)
|
||||
} else if v.Type == "images" {
|
||||
// 多图片
|
||||
list := gstr.Split(v.Value, ",")
|
||||
itemList := make([]string, 0)
|
||||
for _, v := range list {
|
||||
// 图片地址
|
||||
item := utils.GetImageUrl(v)
|
||||
itemList = append(itemList, item)
|
||||
}
|
||||
item["value"] = itemList
|
||||
}
|
||||
itemList = append(itemList, item)
|
||||
}
|
||||
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "configweb_index.html").WriteTpl(gin.H{
|
||||
"configId": configId,
|
||||
"configList": configList,
|
||||
"itemList": itemList,
|
||||
})
|
||||
}
|
103
app/controller/customer.go
Normal file
103
app/controller/customer.go
Normal file
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* 用户管理-控制器
|
||||
* @author
|
||||
* @since 2021/11/11
|
||||
* @File : user
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var Coutomer = new(customerCtl)
|
||||
|
||||
type customerCtl struct{}
|
||||
|
||||
// 搜索 根据手机号或订单号
|
||||
func (c *customerCtl) Search(ctx *gin.Context) {
|
||||
// 绑定参数
|
||||
var req *dto.CustomerSearchReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用查询列表方法
|
||||
data := service.Customer.Search(req)
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
// 购买话费券订单退款
|
||||
func (c *customerCtl) CouponRefund(ctx *gin.Context) {
|
||||
// 绑定参数
|
||||
var req *dto.CustomerCouponRefundReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用查询列表方法
|
||||
msg, ok := service.Customer.CouponRefund(req, utils.Uid(ctx))
|
||||
|
||||
if !ok {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: msg,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "退款成功",
|
||||
})
|
||||
}
|
||||
|
||||
// 购买话费券订单退款
|
||||
func (c *customerCtl) RechargeRefund(ctx *gin.Context) {
|
||||
// 绑定参数
|
||||
var req *dto.CustomerCouponRefundReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用方法
|
||||
msg, ok := service.Customer.RechargeRefund(req, utils.Uid(ctx))
|
||||
|
||||
if !ok {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: msg,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "退款成功",
|
||||
})
|
||||
}
|
169
app/controller/dept.go
Normal file
169
app/controller/dept.go
Normal file
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
* 部门管理-控制器
|
||||
* @author
|
||||
* @since 2021/9/13
|
||||
* @File : dept
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var Dept = new(deptCtl)
|
||||
|
||||
type deptCtl struct{}
|
||||
|
||||
func (c *deptCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "dept_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *deptCtl) List(ctx *gin.Context) {
|
||||
//// 参数绑定
|
||||
//var req *dto.DeptPageReq
|
||||
//if err := ctx.ShouldBind(&req); err != nil {
|
||||
// ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
// Code: -1,
|
||||
// Msg: err.Error(),
|
||||
// })
|
||||
// return
|
||||
//}
|
||||
|
||||
// 调用查询列表方法
|
||||
list, err := service.Dept.GetList(nil)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "操作成功",
|
||||
Data: list,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *deptCtl) Edit(ctx *gin.Context) {
|
||||
// 查询记录
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
info := &model.Dept{Id: id}
|
||||
isOk, err := info.Get()
|
||||
if !isOk || err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
}
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "dept_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
"typeList": common.DEPT_TYPE_LIST,
|
||||
})
|
||||
} else {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "dept_edit.html").WriteTpl(gin.H{
|
||||
"typeList": common.DEPT_TYPE_LIST,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *deptCtl) Add(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.DeptAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.Dept.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *deptCtl) Update(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.DeptUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.Dept.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *deptCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
// 调用删除方法
|
||||
rows, err := service.Dept.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *deptCtl) GetDeptList(ctx *gin.Context) {
|
||||
// 查询部门列表
|
||||
list := make([]model.Dept, 0)
|
||||
utils.XormDb.Where("mark=1").Asc("sort").Find(&list)
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
})
|
||||
}
|
122
app/controller/dict.go
Normal file
122
app/controller/dict.go
Normal file
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* 字典管理-控制器
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : dict
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var Dict = new(dictCtl)
|
||||
|
||||
type dictCtl struct{}
|
||||
|
||||
func (c *dictCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "dict_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *dictCtl) List(ctx *gin.Context) {
|
||||
|
||||
// 调用查询列表方法
|
||||
list := service.Dict.GetList()
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *dictCtl) Add(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.DictAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.Dict.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *dictCtl) Update(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.DictUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.Dict.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *dictCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.Dict.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
134
app/controller/dict_data.go
Normal file
134
app/controller/dict_data.go
Normal file
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* 字典数据-控制器
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : dict_data
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var DictData = new(dictDataCtl)
|
||||
|
||||
type dictDataCtl struct{}
|
||||
|
||||
func (c *dictDataCtl) List(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.DictDataPageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用查询分页方法
|
||||
list, count, err := service.DictData.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *dictDataCtl) Add(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.DictDataAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.DictData.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *dictDataCtl) Update(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.DictDataUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.DictData.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *dictDataCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.DictData.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
230
app/controller/example.go
Normal file
230
app/controller/example.go
Normal file
@@ -0,0 +1,230 @@
|
||||
/**
|
||||
* 演示一管理-控制器
|
||||
* @author
|
||||
* @since 2022-04-19
|
||||
* @File : example
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var Example = new(exampleCtl)
|
||||
|
||||
type exampleCtl struct{}
|
||||
|
||||
func (c *exampleCtl) Index(ctx *gin.Context) {
|
||||
// 模板渲染
|
||||
response.BuildTpl(ctx, "example_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *exampleCtl) T(ctx *gin.Context) {
|
||||
// 模板渲染
|
||||
ctx.String(http.StatusOK, "TTTT")
|
||||
}
|
||||
|
||||
func (c *exampleCtl) List(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.ExamplePageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用获取列表方法
|
||||
list, count, err := service.Example.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Data: list,
|
||||
Msg: "操作成功",
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *exampleCtl) Edit(ctx *gin.Context) {
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
// 编辑
|
||||
info := &model.Example{Id: id}
|
||||
has, err := info.Get()
|
||||
if !has || err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 头像
|
||||
if info.Avatar != "" {
|
||||
info.Avatar = utils.GetImageUrl(info.Avatar)
|
||||
}
|
||||
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "example_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
})
|
||||
} else {
|
||||
// 添加
|
||||
response.BuildTpl(ctx, "example_edit.html").WriteTpl()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *exampleCtl) Add(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.ExampleAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.Example.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *exampleCtl) Update(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.ExampleUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.Example.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *exampleCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.Example.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *exampleCtl) Status(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.ExampleStatusReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用设置状态方法
|
||||
rows, err := service.Example.Status(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "设置成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *exampleCtl) IsVip(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.ExampleIsVipReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用设置状态方法
|
||||
rows, err := service.Example.IsVip(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "设置成功",
|
||||
})
|
||||
}
|
193
app/controller/example2.go
Normal file
193
app/controller/example2.go
Normal file
@@ -0,0 +1,193 @@
|
||||
/**
|
||||
* 演示二管理-控制器
|
||||
* @author
|
||||
* @since 2022-04-19
|
||||
* @File : example2
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var Example2 = new(example2Ctl)
|
||||
|
||||
type example2Ctl struct{}
|
||||
|
||||
func (c *example2Ctl) Index(ctx *gin.Context) {
|
||||
// 模板渲染
|
||||
response.BuildTpl(ctx, "example2_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *example2Ctl) List(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.Example2PageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用获取列表方法
|
||||
list, count, err := service.Example2.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Data: list,
|
||||
Msg: "操作成功",
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *example2Ctl) Edit(ctx *gin.Context) {
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
// 编辑
|
||||
info := &model.Example2{Id: id}
|
||||
has, err := info.Get()
|
||||
if !has || err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "example2_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
})
|
||||
} else {
|
||||
// 添加
|
||||
response.BuildTpl(ctx, "example2_edit.html").WriteTpl()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *example2Ctl) Add(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.Example2AddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.Example2.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *example2Ctl) Update(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.Example2UpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.Example2.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *example2Ctl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.Example2.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *example2Ctl) Status(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.Example2StatusReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用设置状态方法
|
||||
rows, err := service.Example2.Status(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "设置成功",
|
||||
})
|
||||
}
|
119
app/controller/generate.go
Normal file
119
app/controller/generate.go
Normal file
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* 代码生成器-控制器
|
||||
* @author
|
||||
* @since 2021/11/15
|
||||
* @File : generate
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 控制器管理对象
|
||||
var Generate = new(generateCtl)
|
||||
|
||||
type generateCtl struct{}
|
||||
|
||||
func (c *generateCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "generate_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *generateCtl) List(ctx *gin.Context) {
|
||||
// 参数验证
|
||||
var req *dto.GeneratePageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用查询列表方法
|
||||
list, err := service.Generate.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
Count: gconv.Int64(len(list)),
|
||||
})
|
||||
}
|
||||
|
||||
func (c *generateCtl) Generate(ctx *gin.Context) {
|
||||
// 参数验证
|
||||
var req dto.GenerateFileReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 调用生成方法
|
||||
err := service.Generate.Generate(req, ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "模块生成成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *generateCtl) BatchGenerate(ctx *gin.Context) {
|
||||
// 生成对象
|
||||
var req *dto.BatchGenerateFileReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 参数分析
|
||||
tableList := strings.Split(req.Tables, ",")
|
||||
count := 0
|
||||
for _, item := range tableList {
|
||||
itemList := strings.Split(item, "|")
|
||||
// 组装参数对象
|
||||
var param dto.GenerateFileReq
|
||||
param.Name = itemList[0]
|
||||
param.Comment = itemList[1]
|
||||
// 调用生成方法
|
||||
err := service.Generate.Generate(param, ctx)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
}
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "本次共生成【" + strconv.Itoa(count) + "】个模块文件",
|
||||
})
|
||||
}
|
221
app/controller/index.go
Normal file
221
app/controller/index.go
Normal file
@@ -0,0 +1,221 @@
|
||||
/**
|
||||
* 系统主页-控制器
|
||||
* @author
|
||||
* @since 2021/9/7
|
||||
* @File : index
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/app/vo"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 用户API管理对象
|
||||
var Index = new(indexCtl)
|
||||
|
||||
type indexCtl struct{}
|
||||
|
||||
func (c *indexCtl) None(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
id := ctx.Param("id")
|
||||
if id == "" {
|
||||
ctx.String(http.StatusOK, "")
|
||||
return
|
||||
}
|
||||
res := service.PbShortLink.GetInfoById(ctx, gconv.Int64(id))
|
||||
if res.Id == 0 || res.Url == "" {
|
||||
ctx.String(http.StatusOK, "")
|
||||
return
|
||||
}
|
||||
ctx.Redirect(http.StatusTemporaryRedirect, res.Url)
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (c *indexCtl) Index(ctx *gin.Context) {
|
||||
// 已登录
|
||||
// 获取用户信息
|
||||
userInfo := service.Login.GetProfile(ctx)
|
||||
// 获取菜单列表
|
||||
menuList := service.Menu.GetPermissionMenuList(userInfo.Id)
|
||||
// 渲染模板并绑定数据
|
||||
response.BuildTpl(ctx, "index.html").WriteTpl(gin.H{
|
||||
"userInfo": userInfo,
|
||||
"menuList": menuList,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *indexCtl) Main(ctx *gin.Context) {
|
||||
response.BuildTpl(ctx, "welcome.html").WriteTpl()
|
||||
}
|
||||
|
||||
// 个人中心
|
||||
func (c *indexCtl) UserInfo(ctx *gin.Context) {
|
||||
if ctx.Request.Method == "POST" {
|
||||
// 参数验证
|
||||
var req *dto.UserInfoReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 更新信息
|
||||
_, err := service.User.UpdateUserInfo(req, utils.Uid(ctx))
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
return
|
||||
}
|
||||
// 获取用户信息
|
||||
userInfo := service.Login.GetProfile(ctx)
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "user_info.html").WriteTpl(gin.H{
|
||||
"userInfo": userInfo,
|
||||
})
|
||||
}
|
||||
|
||||
// 获取系统菜单
|
||||
func (c *indexCtl) Menu(ctx *gin.Context) {
|
||||
// 获取菜单列表
|
||||
menuList := service.Menu.GetPermissionList(utils.Uid(ctx))
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "操作成功",
|
||||
Data: menuList,
|
||||
})
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
func (c *indexCtl) User(ctx *gin.Context) {
|
||||
// 获取用户信息
|
||||
user := model.User{}
|
||||
has, err := utils.XormDb.Id(utils.Uid(ctx)).Get(&user)
|
||||
if err != nil && !has {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 用户信息
|
||||
var profile vo.ProfileInfoVo
|
||||
profile.Realname = user.Realname
|
||||
profile.Nickname = user.Nickname
|
||||
profile.Avatar = utils.GetImageUrl(user.Avatar)
|
||||
profile.Gender = user.Gender
|
||||
profile.Mobile = user.Mobile
|
||||
profile.Email = user.Email
|
||||
profile.Intro = user.Intro
|
||||
profile.Address = user.Address
|
||||
// 角色
|
||||
profile.Roles = make([]interface{}, 0)
|
||||
// 权限
|
||||
profile.Authorities = make([]interface{}, 0)
|
||||
// 获取权限节点
|
||||
permissionList := service.Menu.GetPermissionsList(utils.Uid(ctx))
|
||||
profile.PermissionList = permissionList
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: profile,
|
||||
})
|
||||
}
|
||||
|
||||
//// 个人中心
|
||||
//func (c *indexCtl) UpdateUserInfo(ctx *gin.Context) {
|
||||
// // 参数验证
|
||||
// var req *dto.UserInfoReq
|
||||
// if err := ctx.ShouldBind(&req); err != nil {
|
||||
// ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
// Code: -1,
|
||||
// Msg: err.Error(),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// // 更新信息
|
||||
// _, err := service.User.UpdateUserInfo(req, utils.Uid(ctx))
|
||||
// if err != nil {
|
||||
// ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
// Code: -1,
|
||||
// Msg: err.Error(),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// // 返回结果
|
||||
// ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
// Code: 0,
|
||||
// Msg: "更新成功",
|
||||
// })
|
||||
//}
|
||||
|
||||
// 更新密码
|
||||
func (c *indexCtl) UpdatePwd(ctx *gin.Context) {
|
||||
// 参数验证
|
||||
var req *dto.UpdatePwd
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新密码方法
|
||||
rows, err := service.User.UpdatePwd(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新密码成功",
|
||||
})
|
||||
}
|
||||
|
||||
// 注销系统
|
||||
func (c *indexCtl) Logout(ctx *gin.Context) {
|
||||
// 初始化session对象
|
||||
session := sessions.Default(ctx)
|
||||
//session.Set("userId", "")
|
||||
//session.Save()
|
||||
// 删除session数据
|
||||
//session.Delete("userId")
|
||||
// 清空session
|
||||
session.Clear()
|
||||
// 保存session数据
|
||||
session.Save()
|
||||
// 跳转登录页,方式:301(永久移动),308(永久重定向),307(临时重定向)
|
||||
ctx.Redirect(http.StatusTemporaryRedirect, "/login")
|
||||
}
|
214
app/controller/item.go
Normal file
214
app/controller/item.go
Normal file
@@ -0,0 +1,214 @@
|
||||
/**
|
||||
* 站点管理-控制器
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : item
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var Item = new(itemCtl)
|
||||
|
||||
type itemCtl struct{}
|
||||
|
||||
func (c *itemCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "item_index.html").WriteTpl(gin.H{
|
||||
"typeList": common.ITEM_TYPE_LIST,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *itemCtl) List(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.ItemPageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用分页查询方法
|
||||
list, count, err := service.Item.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *itemCtl) Edit(ctx *gin.Context) {
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
// 编辑
|
||||
info := &model.Item{Id: id}
|
||||
has, err := info.Get()
|
||||
if !has || err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 站点图片
|
||||
info.Image = utils.GetImageUrl(info.Image)
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "item_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
"typeList": common.ITEM_TYPE_LIST,
|
||||
})
|
||||
|
||||
} else {
|
||||
// 添加
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "item_edit.html").WriteTpl(gin.H{
|
||||
"typeList": common.ITEM_TYPE_LIST,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *itemCtl) Add(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.ItemAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.Item.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *itemCtl) Update(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.ItemUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.Item.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *itemCtl) Delete(ctx *gin.Context) {
|
||||
// 参数
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.Item.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *itemCtl) Status(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.ItemStatusReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用设置方法
|
||||
rows, err := service.Item.Status(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "设置成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *itemCtl) GetItemList(ctx *gin.Context) {
|
||||
// 查询站点列表
|
||||
list := make([]model.Item, 0)
|
||||
utils.XormDb.Where("status=1 and mark=1").OrderBy("sort asc").Find(&list)
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
})
|
||||
}
|
206
app/controller/item_cate.go
Normal file
206
app/controller/item_cate.go
Normal file
@@ -0,0 +1,206 @@
|
||||
/**
|
||||
* 栏目管理-控制器
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : item_cate
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var ItemCate = new(itemCateCtl)
|
||||
|
||||
type itemCateCtl struct{}
|
||||
|
||||
func (c *itemCateCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "itemcate_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *itemCateCtl) List(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.ItemCateQueryReq
|
||||
//if err := ctx.ShouldBind(&req); err != nil {
|
||||
// ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
// Code: -1,
|
||||
// Msg: err.Error(),
|
||||
// })
|
||||
// return
|
||||
//}
|
||||
|
||||
// 调用
|
||||
list := service.ItemCate.GetList(req)
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *itemCateCtl) Edit(ctx *gin.Context) {
|
||||
// 站点列表
|
||||
result := make([]model.Item, 0)
|
||||
utils.XormDb.Where("mark=1").Find(&result)
|
||||
var itemList = map[int]string{}
|
||||
for _, v := range result {
|
||||
itemList[v.Id] = v.Name
|
||||
}
|
||||
|
||||
// 记录ID
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
// 编辑
|
||||
info := &model.ItemCate{Id: id}
|
||||
has, err := info.Get()
|
||||
if !has || err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 封面
|
||||
if info.IsCover == 1 && info.Cover != "" {
|
||||
info.Cover = utils.GetImageUrl(info.Cover)
|
||||
}
|
||||
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "itemcate_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
"itemList": itemList,
|
||||
})
|
||||
} else {
|
||||
// 添加
|
||||
response.BuildTpl(ctx, "itemcate_edit.html").WriteTpl(gin.H{
|
||||
"itemList": itemList,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *itemCateCtl) Add(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.ItemCateAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.ItemCate.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *itemCateCtl) Update(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.ItemCateUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.ItemCate.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *itemCateCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.ItemCate.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *itemCateCtl) GetCateList(ctx *gin.Context) {
|
||||
list := make([]model.ItemCate, 0)
|
||||
utils.XormDb.Where("status=1 and mark=1").OrderBy("sort asc").Find(&list)
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *itemCateCtl) GetCateTreeList(ctx *gin.Context) {
|
||||
itemId := gconv.Int(ctx.Query("itemId"))
|
||||
list, err := service.ItemCate.GetCateTreeList(itemId, 0)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 数据源转换
|
||||
result := service.ItemCate.MakeList(list)
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "操作成功",
|
||||
Data: result,
|
||||
})
|
||||
}
|
185
app/controller/level.go
Normal file
185
app/controller/level.go
Normal file
@@ -0,0 +1,185 @@
|
||||
/**
|
||||
* 职级管理-控制器
|
||||
* @author
|
||||
* @since 2021/8/20
|
||||
* @File : level
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var Level = new(levelCtl)
|
||||
|
||||
type levelCtl struct{}
|
||||
|
||||
func (c *levelCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "level_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *levelCtl) List(ctx *gin.Context) {
|
||||
// 请求参数
|
||||
var req *dto.LevelPageReq
|
||||
// 请求验证
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 调用获取列表函数
|
||||
list, count, err := service.Level.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果集
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Data: list,
|
||||
Msg: "操作成功",
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *levelCtl) Edit(ctx *gin.Context) {
|
||||
// 查询记录
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
info := &model.Level{Id: id}
|
||||
has, err := info.Get()
|
||||
if !has || err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "level_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
})
|
||||
} else {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "level_edit.html").WriteTpl()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *levelCtl) Add(ctx *gin.Context) {
|
||||
var req *dto.LevelAddReq
|
||||
// 请求验证
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
id, err := service.Level.Add(req, utils.Uid(ctx))
|
||||
if err != nil || id <= 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 保存成功
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "保存成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *levelCtl) Update(ctx *gin.Context) {
|
||||
// 参数验证
|
||||
var req *dto.LevelUpdateReq
|
||||
// 请求验证
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 调用更新方法
|
||||
rows, err := service.Level.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 更新成功
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *levelCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
// 调用删除方法
|
||||
rows, err := service.Level.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 删除成功
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *levelCtl) Status(ctx *gin.Context) {
|
||||
var req *dto.LevelStatusReq
|
||||
// 请求验证
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
rows, err := service.Level.Status(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 设置成功
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "设置成功",
|
||||
})
|
||||
}
|
209
app/controller/link.go
Normal file
209
app/controller/link.go
Normal file
@@ -0,0 +1,209 @@
|
||||
/**
|
||||
* 友链管理-控制器
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : link
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var Link = new(linkCtl)
|
||||
|
||||
type linkCtl struct{}
|
||||
|
||||
func (c *linkCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "link_index.html").WriteTpl(gin.H{
|
||||
"typeList": common.LINK_TYPE_LIST,
|
||||
"platformList": common.LINK_PLATFORM_LIST,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *linkCtl) List(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.LinkPageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用分页查询方法
|
||||
list, count, err := service.Link.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *linkCtl) Edit(ctx *gin.Context) {
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
// 修改
|
||||
info := &model.Link{Id: id}
|
||||
has, err := info.Get()
|
||||
if err != nil || !has {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 友链图片
|
||||
if info.Image != "" {
|
||||
info.Image = utils.GetImageUrl(info.Image)
|
||||
}
|
||||
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "link_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
"typeList": common.LINK_TYPE_LIST,
|
||||
"formList": common.LINK_FORM_LIST,
|
||||
"platformList": common.LINK_PLATFORM_LIST,
|
||||
})
|
||||
} else {
|
||||
// 添加
|
||||
response.BuildTpl(ctx, "link_edit.html").WriteTpl(gin.H{
|
||||
"typeList": common.LINK_TYPE_LIST,
|
||||
"formList": common.LINK_FORM_LIST,
|
||||
"platformList": common.LINK_PLATFORM_LIST,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *linkCtl) Add(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.LinkAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.Link.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结构
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *linkCtl) Update(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.LinkUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.Link.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *linkCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.Link.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *linkCtl) Status(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.LinkStatusReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用设置方法
|
||||
rows, err := service.Link.Status(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "设置成功",
|
||||
})
|
||||
}
|
151
app/controller/login.go
Normal file
151
app/controller/login.go
Normal file
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
* 登录-控制器
|
||||
* @author
|
||||
* @since 2021/9/7
|
||||
* @File : login
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mojocn/base64Captcha"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 用户控制器管理对象
|
||||
var Login = new(loginCtl)
|
||||
|
||||
type loginCtl struct{}
|
||||
|
||||
// 系统登录
|
||||
func (c *loginCtl) Login(ctx *gin.Context) {
|
||||
if ctx.Request.Method == "POST" {
|
||||
var req *dto.LoginReq
|
||||
// 获取参数并验证
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
// 返回错误信息
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "登录错误",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 校验验证码
|
||||
verifyRes := base64Captcha.VerifyCaptcha(req.IdKey, req.Captcha)
|
||||
if !verifyRes {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "验证码不正确",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 系统登录
|
||||
if err := service.Login.UserLogin(req.UserName, req.Password, ctx); err != nil {
|
||||
// 登录错误
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 登录成功
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "登录成功",
|
||||
})
|
||||
return
|
||||
}
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "login.html").WriteTpl()
|
||||
return
|
||||
}
|
||||
|
||||
// 客服登录
|
||||
func (c *loginCtl) LoginKf(ctx *gin.Context) {
|
||||
if ctx.Request.Method == "POST" {
|
||||
var req *dto.LoginReq
|
||||
// 获取参数并验证
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
// 返回错误信息
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "登录错误",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 校验验证码
|
||||
verifyRes := base64Captcha.VerifyCaptcha(req.IdKey, req.Captcha)
|
||||
if !verifyRes {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "验证码不正确",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 系统登录
|
||||
if err := service.Login.UserLogin(req.UserName, req.Password, ctx); err != nil {
|
||||
// 登录错误
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 登录成功
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "登录成功",
|
||||
})
|
||||
return
|
||||
}
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "login_kf.html").WriteTpl()
|
||||
return
|
||||
}
|
||||
|
||||
// 客服
|
||||
func (c *loginCtl) Customer(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
ctx.HTML(http.StatusOK, "customer.html", gin.H{})
|
||||
//response.BuildTpl(ctx, "customer.html").WriteTpl()
|
||||
return
|
||||
}
|
||||
|
||||
// 验证码
|
||||
func (c *loginCtl) Captcha(ctx *gin.Context) {
|
||||
// 验证码参数配置:字符,公式,验证码配置
|
||||
var configC = base64Captcha.ConfigCharacter{
|
||||
Height: 60,
|
||||
Width: 240,
|
||||
//const CaptchaModeNumber:数字,CaptchaModeAlphabet:字母,CaptchaModeArithmetic:算术,CaptchaModeNumberAlphabet:数字字母混合.
|
||||
Mode: base64Captcha.CaptchaModeAlphabet,
|
||||
ComplexOfNoiseText: base64Captcha.CaptchaComplexLower,
|
||||
ComplexOfNoiseDot: base64Captcha.CaptchaComplexLower,
|
||||
IsShowHollowLine: false,
|
||||
IsShowNoiseDot: false,
|
||||
IsShowNoiseText: false,
|
||||
IsShowSlimeLine: false,
|
||||
IsShowSineLine: false,
|
||||
CaptchaLen: 4,
|
||||
}
|
||||
///create a characters captcha.
|
||||
idKeyC, capC := base64Captcha.GenerateCaptcha("", configC)
|
||||
//以base64编码
|
||||
base64stringC := base64Captcha.CaptchaWriteToBase64Encoding(capC)
|
||||
|
||||
// 返回结果集
|
||||
ctx.JSON(http.StatusOK, common.CaptchaRes{
|
||||
Code: 0,
|
||||
IdKey: idKeyC,
|
||||
Data: base64stringC,
|
||||
Msg: "操作成功",
|
||||
})
|
||||
}
|
83
app/controller/login_log.go
Normal file
83
app/controller/login_log.go
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* 登录日志-控制器
|
||||
* @author
|
||||
* @since 2021/11/12
|
||||
* @File : login_log
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var LoginLog = new(loginLogCtl)
|
||||
|
||||
type loginLogCtl struct{}
|
||||
|
||||
func (c *loginLogCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "loginlog_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *loginLogCtl) List(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.LoginLogPageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用分页查询方法
|
||||
list, count, err := service.LoginLog.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *loginLogCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.LoginLog.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
214
app/controller/member.go
Normal file
214
app/controller/member.go
Normal file
@@ -0,0 +1,214 @@
|
||||
/**
|
||||
* 会员管理-控制器
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : member
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var Member = new(memberCtl)
|
||||
|
||||
type memberCtl struct{}
|
||||
|
||||
func (c *memberCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "member_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *memberCtl) List(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.MemberPageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用分页查询方法
|
||||
list, count, err := service.Member.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *memberCtl) Edit(ctx *gin.Context) {
|
||||
|
||||
// 会员等级
|
||||
list := make([]model.MemberLevel, 0)
|
||||
utils.XormDb.Where("mark=1").Find(&list)
|
||||
memberLevelList := make(map[int]string, 0)
|
||||
for _, v := range list {
|
||||
memberLevelList[v.Id] = v.Name
|
||||
}
|
||||
|
||||
// 记录ID
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
// 编辑
|
||||
info := &model.Member{Id: id}
|
||||
has, err := info.Get()
|
||||
if !has || err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 头像
|
||||
if info.Avatar != "" {
|
||||
info.Avatar = utils.GetImageUrl(info.Avatar)
|
||||
}
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "member_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
"memberLevelList": memberLevelList,
|
||||
"deviceList": common.MEMBER_DEVICE_LIST,
|
||||
"sourceList": common.MEMBER_SOURCE_LIST,
|
||||
})
|
||||
} else {
|
||||
// 添加
|
||||
response.BuildTpl(ctx, "member_edit.html").WriteTpl(gin.H{
|
||||
"memberLevelList": memberLevelList,
|
||||
"deviceList": common.MEMBER_DEVICE_LIST,
|
||||
"sourceList": common.MEMBER_SOURCE_LIST,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *memberCtl) Add(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.MemberAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.Member.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *memberCtl) Update(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.MemberUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.Member.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *memberCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.Member.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *memberCtl) Status(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.MemberStatusReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用设置方法
|
||||
rows, err := service.Member.Status(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "设置成功",
|
||||
})
|
||||
}
|
177
app/controller/member_level.go
Normal file
177
app/controller/member_level.go
Normal file
@@ -0,0 +1,177 @@
|
||||
/**
|
||||
* 会员等级-控制器
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : member_level
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var MemberLevel = new(memberLevelCtl)
|
||||
|
||||
type memberLevelCtl struct{}
|
||||
|
||||
func (c *memberLevelCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "memberlevel_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *memberLevelCtl) List(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.MemberLevelPageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用分页查询方法
|
||||
list, count, err := service.MemberLevel.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *memberLevelCtl) Edit(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
// 编辑
|
||||
info := &model.MemberLevel{Id: id}
|
||||
has, err := info.Get()
|
||||
if !has || err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "memberlevel_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
})
|
||||
} else {
|
||||
// 添加
|
||||
response.BuildTpl(ctx, "memberlevel_edit.html").WriteTpl()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *memberLevelCtl) Add(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.MemberLevelAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.MemberLevel.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *memberLevelCtl) Update(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.MemberLevelUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.MemberLevel.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *memberLevelCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.MemberLevel.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *memberLevelCtl) GetMemberLevelList(ctx *gin.Context) {
|
||||
list := make([]model.MemberLevel, 0)
|
||||
utils.XormDb.Where("mark=1").OrderBy("sort asc").Find(&list)
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
})
|
||||
}
|
234
app/controller/menu.go
Normal file
234
app/controller/menu.go
Normal file
@@ -0,0 +1,234 @@
|
||||
/**
|
||||
* 菜单管理-控制器
|
||||
* @author
|
||||
* @since 2021/9/13
|
||||
* @File : menu
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var Menu = new(menuCtl)
|
||||
|
||||
type menuCtl struct{}
|
||||
|
||||
func (c *menuCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "menu_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *menuCtl) List(ctx *gin.Context) {
|
||||
//// 参数绑定
|
||||
//var req *dto.MenuQueryReq
|
||||
//if err := ctx.Bind(&req); err != nil {
|
||||
// ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
// Code: -1,
|
||||
// Msg: err.Error(),
|
||||
// })
|
||||
// return
|
||||
//}
|
||||
|
||||
// 调用查询列表方法
|
||||
list, err := service.Menu.GetList(nil)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *menuCtl) Edit(ctx *gin.Context) {
|
||||
// 获取菜单列表
|
||||
menuTreeList, _ := service.Menu.GetTreeList()
|
||||
// 数据源转换
|
||||
menuList := service.Menu.MakeList(menuTreeList)
|
||||
|
||||
// 记录ID
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
// 编辑
|
||||
info := &model.Menu{Id: id}
|
||||
has, err := info.Get()
|
||||
if err != nil || !has {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 获取节点
|
||||
funcList := make([]model.Menu, 0)
|
||||
utils.XormDb.Where("pid=? and type=1 and mark=1", id).Find(&funcList)
|
||||
sortList := make([]interface{}, 0)
|
||||
for _, v := range funcList {
|
||||
sortList = append(sortList, v.Sort)
|
||||
}
|
||||
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "menu_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
"typeList": common.MENU_TYPE_LIST,
|
||||
"funcList": sortList,
|
||||
"menuList": menuList,
|
||||
})
|
||||
} else {
|
||||
// 添加
|
||||
|
||||
pid := ctx.GetInt("pid")
|
||||
var info model.Menu
|
||||
info.Pid = pid
|
||||
info.Status = 1
|
||||
info.Target = 1
|
||||
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "menu_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
"typeList": common.MENU_TYPE_LIST,
|
||||
"funcList": make([]interface{}, 0),
|
||||
"menuList": menuList,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *menuCtl) Detail(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
id := ctx.Query("id")
|
||||
if id == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
info := model.Menu{Id: gconv.Int(id)}
|
||||
has, err := info.Get()
|
||||
if err != nil || !has {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 菜单信息
|
||||
menu := dto.MenuInfoVo{}
|
||||
menu.Menu = info
|
||||
// 获取权限节点
|
||||
if info.Type == 0 {
|
||||
// 获取角色菜单权限列表
|
||||
var menuList []model.Menu
|
||||
utils.XormDb.Where("pid=?", info.Id).Where("type=1").Where("mark=1").Find(&menuList)
|
||||
checkedList := make([]int, 0)
|
||||
for _, v := range menuList {
|
||||
checkedList = append(checkedList, v.Sort)
|
||||
}
|
||||
if len(checkedList) > 0 {
|
||||
menu.CheckedList = checkedList
|
||||
} else {
|
||||
menu.CheckedList = make([]int, 0)
|
||||
}
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: menu,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *menuCtl) Add(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.MenuAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.Menu.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *menuCtl) Update(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.MenuUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.Menu.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *menuCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
// 调用删除方法
|
||||
rows, err := service.Menu.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
205
app/controller/notice.go
Normal file
205
app/controller/notice.go
Normal file
@@ -0,0 +1,205 @@
|
||||
/**
|
||||
* 通知公告-控制器
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : notice
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var Notice = new(noticeCtl)
|
||||
|
||||
type noticeCtl struct{}
|
||||
|
||||
func (c *noticeCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "notice_index.html").WriteTpl(gin.H{
|
||||
"sourceList": common.NOTICE_SOURCE_LIST,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *noticeCtl) List(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.NoticePageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用分页查询方法
|
||||
list, count, err := service.Notice.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *noticeCtl) Edit(ctx *gin.Context) {
|
||||
// 查询记录
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
info := &model.Notice{Id: id}
|
||||
has, err := info.Get()
|
||||
if !has || err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 富文本图片替换处理
|
||||
if info.Content != "" {
|
||||
info.Content = strings.ReplaceAll(info.Content, "[IMG_URL]", utils.ImageUrl())
|
||||
}
|
||||
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "notice_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
"sourceList": common.NOTICE_SOURCE_LIST,
|
||||
})
|
||||
} else {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "notice_edit.html").WriteTpl(gin.H{
|
||||
"sourceList": common.NOTICE_SOURCE_LIST,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *noticeCtl) Add(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.NoticeAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.Notice.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *noticeCtl) Update(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.NoticeUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.Notice.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *noticeCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.Notice.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *noticeCtl) Status(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.NoticeStatusReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用设置状态方法
|
||||
rows, err := service.Notice.Status(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "设置成功",
|
||||
})
|
||||
}
|
49
app/controller/oper_log.go
Normal file
49
app/controller/oper_log.go
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* 操作日志-控制器
|
||||
* @author
|
||||
* @since 2021/11/12
|
||||
* @File : OperLog
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var OperLog = new(operLogCtl)
|
||||
|
||||
type operLogCtl struct{}
|
||||
|
||||
func (c *operLogCtl) List(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.OperLogPageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用分页查询方法
|
||||
list, count, err := service.OperLog.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
Count: count,
|
||||
})
|
||||
}
|
204
app/controller/position.go
Normal file
204
app/controller/position.go
Normal file
@@ -0,0 +1,204 @@
|
||||
/**
|
||||
* 岗位管理-控制器
|
||||
* @author
|
||||
* @since 2021/9/10
|
||||
* @File : position
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var Position = new(positionCtl)
|
||||
|
||||
type positionCtl struct{}
|
||||
|
||||
func (c *positionCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "position_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *positionCtl) List(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.PositionPageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用查询列表方法
|
||||
list, count, err := service.Position.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "操作成功",
|
||||
Data: list,
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *positionCtl) Edit(ctx *gin.Context) {
|
||||
// 查询记录
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
info := &model.Position{Id: id}
|
||||
isOk, err := info.Get()
|
||||
if !isOk || err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
}
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "position_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
})
|
||||
} else {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "position_edit.html").WriteTpl()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (c *positionCtl) Add(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.PositionAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.Position.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *positionCtl) Update(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.PositionUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.Position.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *positionCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
// 调用删除方法
|
||||
rows, err := service.Position.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 删除成功
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *positionCtl) Status(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.PositionStatusReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用设置状态方法
|
||||
rows, err := service.Position.Status(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "设置成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *positionCtl) GetPositionList(ctx *gin.Context) {
|
||||
// 查询岗位列表
|
||||
list := make([]model.Position, 0)
|
||||
utils.XormDb.Where("status=1 and mark=1").Asc("sort").Find(&list)
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
})
|
||||
}
|
204
app/controller/role.go
Normal file
204
app/controller/role.go
Normal file
@@ -0,0 +1,204 @@
|
||||
/**
|
||||
* 角色管理-控制器
|
||||
* @author
|
||||
* @since 2021/9/13
|
||||
* @File : role
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var Role = new(roleCtl)
|
||||
|
||||
type roleCtl struct{}
|
||||
|
||||
func (c *roleCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "role_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *roleCtl) List(ctx *gin.Context) {
|
||||
// 绑定参数
|
||||
var req *dto.RolePageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用查询列表方法
|
||||
list, count, err := service.Role.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *roleCtl) Edit(ctx *gin.Context) {
|
||||
// 查询记录
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
info := &model.Role{Id: id}
|
||||
isOk, err := info.Get()
|
||||
if !isOk || err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
}
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "role_edit.html").WriteTpl(gin.H{
|
||||
"info": info,
|
||||
})
|
||||
} else {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "role_edit.html").WriteTpl()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *roleCtl) Add(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.RoleAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.Role.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *roleCtl) Update(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.RoleUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.Role.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新方法",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *roleCtl) Delete(ctx *gin.Context) {
|
||||
// 记录ID
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.Role.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *roleCtl) Status(ctx *gin.Context) {
|
||||
// 参数绑定
|
||||
var req *dto.RoleStatusReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用设置状态方法
|
||||
rows, err := service.Role.Status(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "设置成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *roleCtl) GetRoleList(ctx *gin.Context) {
|
||||
// 获取角色列表
|
||||
list := make([]model.Role, 0)
|
||||
utils.XormDb.Where("status=1 and mark=1").Asc("sort").Find(&list)
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: list,
|
||||
})
|
||||
}
|
76
app/controller/role_menu.go
Normal file
76
app/controller/role_menu.go
Normal file
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* 角色菜单-控制器
|
||||
* @author
|
||||
* @since 2021/9/14
|
||||
* @File : role_menu
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var RoleMenu = new(roleMenuCtl)
|
||||
|
||||
type roleMenuCtl struct{}
|
||||
|
||||
func (c *roleMenuCtl) Index(ctx *gin.Context) {
|
||||
// 角色ID
|
||||
roleId := ctx.Param("roleId")
|
||||
if roleId == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "角色ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 获取角色菜单权限列表
|
||||
list, err := service.RoleMenu.GetRoleMenuList(gconv.Int(roleId))
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Data: list,
|
||||
Msg: "操作成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *roleMenuCtl) Save(ctx *gin.Context) {
|
||||
var req *dto.RoleMenuSaveReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用保存方法
|
||||
err := service.RoleMenu.Save(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "保存成功",
|
||||
})
|
||||
}
|
91
app/controller/test.go
Normal file
91
app/controller/test.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 用户API管理对象
|
||||
var Test = new(testCtl)
|
||||
|
||||
type testCtl struct{}
|
||||
|
||||
func (c *testCtl) Test(ctx *gin.Context) {
|
||||
//cache := utils.GetRedisHelper()
|
||||
//cache.Set(ctx, "cacheTest", "1112", 10*time.Minute)
|
||||
//utils.SendSms("18583618609", "【B卡特权】优惠券购买成功!请下载B卡特权APP进行使用。下载或需要帮助请点击: https://d.shareyi.top/2 ,退订回T", "Cloud")
|
||||
// goodsId 类型:2移动 3电信 4联通
|
||||
//strLQ, okLQ := utils.OrderDirectAdd("19828267470", "recharge202210231337", "work.shareyi.top:9097", 1, 100)
|
||||
//strLQ, okLQ := utils.OrderDirectAdd("19888888888", "recharge202210231338", "work.shareyi.top:9097", 1, 100)
|
||||
//{"code":1019,"message":"您的IP不在IP白名单内,联系平台添加","result":null,"sign":null}
|
||||
//if !okLQ {
|
||||
// logs.Error("调快充接口失败")
|
||||
//}
|
||||
//logs.Debug("strLQ, okLQ----------------------", strLQ, okLQ)
|
||||
//a, b := utils.Refund(36, "recharge2022102617412013698", "4200001627202210267407543317", "", 95)
|
||||
//logs.Debug(a, b)
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Data: nil,
|
||||
Msg: "查询成功2",
|
||||
Count: 0,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *testCtl) Test2(ctx *gin.Context) {
|
||||
//panic("this is panic")
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Data: nil,
|
||||
Msg: "查询成功2",
|
||||
Count: 0,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *testCtl) TestJwt(ctx *gin.Context) {
|
||||
str, err := utils.GenerateToken(1, "18583638609", "asd")
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
}
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Data: nil,
|
||||
Msg: "查询成功: " + str,
|
||||
Count: 0,
|
||||
})
|
||||
}
|
||||
|
||||
type TestReq struct {
|
||||
Jwt string `form:"jwt"` // 用户名
|
||||
}
|
||||
|
||||
func (c *testCtl) TestCheckJwt(ctx *gin.Context) {
|
||||
jwt := ctx.Query("jwt")
|
||||
fmt.Println("req", jwt)
|
||||
str, err := utils.ParseToken(jwt)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
}
|
||||
jsonStr, _ := json.Marshal(str)
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Data: nil,
|
||||
Msg: "查询成功: " + string(jsonStr),
|
||||
Count: 0,
|
||||
})
|
||||
}
|
42
app/controller/upload.go
Normal file
42
app/controller/upload.go
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 文件上传-控制器
|
||||
* @author
|
||||
* @since 2021/11/18
|
||||
* @File : upload
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// 控制器管理对象
|
||||
var Upload = new(uploadCtl)
|
||||
|
||||
type uploadCtl struct{}
|
||||
|
||||
func (c *uploadCtl) UploadImage(ctx *gin.Context) {
|
||||
// 调用上传方法
|
||||
result, err := service.Upload.UploadImage(ctx)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 拼接图片地址
|
||||
result.FileUrl = utils.GetImageUrl(result.FileUrl)
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "上传成功",
|
||||
Data: result,
|
||||
})
|
||||
}
|
302
app/controller/user.go
Normal file
302
app/controller/user.go
Normal file
@@ -0,0 +1,302 @@
|
||||
/**
|
||||
* 用户管理-控制器
|
||||
* @author
|
||||
* @since 2021/11/11
|
||||
* @File : user
|
||||
*/
|
||||
package controller
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/service"
|
||||
"easygoadmin/app/vo"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"easygoadmin/utils/response"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var User = new(userCtl)
|
||||
|
||||
type userCtl struct{}
|
||||
|
||||
func (c *userCtl) Index(ctx *gin.Context) {
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "user_index.html").WriteTpl()
|
||||
}
|
||||
|
||||
func (c *userCtl) List(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.UserPageReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用获取列表方法
|
||||
list, count, err := service.User.GetList(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Data: list,
|
||||
Msg: "查询成功",
|
||||
Count: count,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *userCtl) Edit(ctx *gin.Context) {
|
||||
// 获取职级
|
||||
levelAll := make([]model.Level, 0)
|
||||
utils.XormDb.Where("status=1 and mark=1").Find(&levelAll)
|
||||
levelList := make(map[int]string, 0)
|
||||
for _, v := range levelAll {
|
||||
levelList[v.Id] = v.Name
|
||||
}
|
||||
// 获取岗位
|
||||
positionAll := make([]model.Position, 0)
|
||||
utils.XormDb.Where("status=1 and mark=1").Find(&positionAll)
|
||||
positionList := make(map[int]string, 0)
|
||||
for _, v := range positionAll {
|
||||
positionList[v.Id] = v.Name
|
||||
}
|
||||
// 获取部门列表
|
||||
deptData, _ := service.Dept.GetDeptTreeList()
|
||||
deptList := service.Dept.MakeList(deptData)
|
||||
// 获取角色
|
||||
roleData := make([]model.Role, 0)
|
||||
utils.XormDb.Where("status=1 and mark=1").Find(&roleData)
|
||||
roleList := make(map[int]string)
|
||||
for _, v := range roleData {
|
||||
roleList[v.Id] = v.Name
|
||||
}
|
||||
|
||||
// 记录ID
|
||||
id := gconv.Int(ctx.Query("id"))
|
||||
if id > 0 {
|
||||
// 编辑
|
||||
info := &model.User{Id: id}
|
||||
has, err := info.Get()
|
||||
if err != nil || !has {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var userInfo = vo.UserInfoVo{}
|
||||
userInfo.User = *info
|
||||
// 头像
|
||||
userInfo.Avatar = utils.GetImageUrl(info.Avatar)
|
||||
|
||||
// 角色ID
|
||||
var userRoleList []model.UserRole
|
||||
utils.XormDb.Where("user_id=?", info.Id).Find(&userRoleList)
|
||||
roleIds := make([]interface{}, 0)
|
||||
for _, v := range userRoleList {
|
||||
roleIds = append(roleIds, v.RoleId)
|
||||
}
|
||||
userInfo.RoleIds = roleIds
|
||||
|
||||
// 渲染模板
|
||||
response.BuildTpl(ctx, "user_edit.html").WriteTpl(gin.H{
|
||||
"info": userInfo,
|
||||
"genderList": utils.GENDER_LIST,
|
||||
"levelList": levelList,
|
||||
"positionList": positionList,
|
||||
"deptList": deptList,
|
||||
"roleList": roleList,
|
||||
})
|
||||
} else {
|
||||
// 添加
|
||||
response.BuildTpl(ctx, "user_edit.html").WriteTpl(gin.H{
|
||||
"genderList": utils.GENDER_LIST,
|
||||
"levelList": levelList,
|
||||
"positionList": positionList,
|
||||
"deptList": deptList,
|
||||
"roleList": roleList,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *userCtl) Add(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.UserAddReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用添加方法
|
||||
rows, err := service.User.Add(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "添加成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *userCtl) Update(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.UserUpdateReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用更新方法
|
||||
rows, err := service.User.Update(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "更新成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *userCtl) Delete(ctx *gin.Context) {
|
||||
// 参数
|
||||
ids := ctx.Param("ids")
|
||||
if ids == "" {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "记录ID不能为空",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用删除方法
|
||||
rows, err := service.User.Delete(ids)
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "删除成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *userCtl) Status(ctx *gin.Context) {
|
||||
// 参数
|
||||
var req *dto.UserStatusReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用设置方法
|
||||
rows, err := service.User.Status(req, utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "设置成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *userCtl) ResetPwd(ctx *gin.Context) {
|
||||
// 参数验证
|
||||
var req *dto.UserResetPwdReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 调用重置密码方法
|
||||
rows, err := service.User.ResetPwd(gconv.Int(req.Id), utils.Uid(ctx))
|
||||
if err != nil || rows == 0 {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "重置密码成功",
|
||||
})
|
||||
}
|
||||
|
||||
func (c *userCtl) CheckUser(ctx *gin.Context) {
|
||||
// 参数验证
|
||||
var req *dto.CheckUserReq
|
||||
if err := ctx.ShouldBind(&req); err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
// 调用检查用户方法
|
||||
user, err := service.User.CheckUser(req)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
ctx.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: 0,
|
||||
Msg: "查询成功",
|
||||
Data: user,
|
||||
})
|
||||
}
|
57
app/dto/ad.go
Normal file
57
app/dto/ad.go
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* 广告Dto
|
||||
* @author
|
||||
* @since 2021/11/15
|
||||
* @File : ad
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 列表查询
|
||||
type AdPageReq struct {
|
||||
Title string `form:"title"` // 广告标题
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加广告
|
||||
type AdAddReq struct {
|
||||
Title string `form:"title" binding:"required"` // 广告标题
|
||||
AdSortId string `form:"adSortId" binding:"required"` // 广告位ID
|
||||
Cover string `form:"cover"` // 广告图片
|
||||
Type string `form:"type" binding:"required"` // 广告格式:1图片 2文字 3视频 4推荐
|
||||
Description string `form:"description" binding:"required"` // 广告描述
|
||||
Content string `form:"content"` // 广告内容
|
||||
Url string `form:"url" binding:"required"` // 广告链接
|
||||
Width string `form:"width"` // 广告宽度
|
||||
Height string `form:"height"` // 广告高度
|
||||
StartTime string `form:"startTime" binding:"required"` // 开始时间
|
||||
EndTime string `form:"endTime" binding:"required"` // 结束时间
|
||||
Status string `form:"status" binding:"required"` // 状态:1在用 2停用
|
||||
Sort string `form:"sort"` // 排序
|
||||
Note string `form:"note"` // 备注
|
||||
}
|
||||
|
||||
// 更新广告
|
||||
type AdUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Title string `form:"title" binding:"required"` // 广告标题
|
||||
AdSortId string `form:"adSortId" binding:"required"` // 广告位ID
|
||||
Cover string `form:"cover"` // 广告图片
|
||||
Type string `form:"type" binding:"required"` // 广告格式:1图片 2文字 3视频 4推荐
|
||||
Description string `form:"description" binding:"required"` // 广告描述
|
||||
Content string `form:"content"` // 广告内容
|
||||
Url string `form:"url" binding:"required"` // 广告链接
|
||||
Width string `form:"width"` // 广告宽度
|
||||
Height string `form:"height"` // 广告高度
|
||||
StartTime string `form:"startTime" binding:"required"` // 开始时间
|
||||
EndTime string `form:"endTime" binding:"required"` // 结束时间
|
||||
Status string `form:"status" binding:"required"` // 状态:1在用 2停用
|
||||
Sort string `form:"sort"` // 排序
|
||||
Note string `form:"note"` // 备注
|
||||
}
|
||||
|
||||
// 设置状态
|
||||
type AdStatusReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
}
|
35
app/dto/ad_sort.go
Normal file
35
app/dto/ad_sort.go
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 广告位Dto
|
||||
* @author
|
||||
* @since 2021/11/15
|
||||
* @File : ad_sort
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 列表查询条件
|
||||
type AdSortPageReq struct {
|
||||
Description string `form:"name"` // 广告位描述
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加广告位
|
||||
type AdSortAddReq struct {
|
||||
Description string `form:"description" binding:"required"` // 广告位描述
|
||||
ItemId string `form:"itemId" binding:"required"` // 站点ID
|
||||
CateId string `form:"cateId" binding:"required"` // 栏目ID
|
||||
LocId string `form:"locId" binding:"required"` // 广告页面位置
|
||||
Platform string `form:"platform" binding:"required"` // 站点类型:1PC网站 2WAP手机站 3微信小程序 4APP移动端
|
||||
Sort string `form:"sort"` // 广告位排序
|
||||
}
|
||||
|
||||
// 更新广告位
|
||||
type AdSortUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Description string `form:"description" binding:"required"` // 广告位描述
|
||||
ItemId string `form:"itemId" binding:"required"` // 站点ID
|
||||
CateId string `form:"cateId" binding:"required"` // 栏目ID
|
||||
LocId string `form:"locId" binding:"required"` // 广告页面位置
|
||||
Platform string `form:"platform" binding:"required"` // 站点类型:1PC网站 2WAP手机站 3微信小程序 4APP移动端
|
||||
Sort string `form:"sort"` // 广告位排序
|
||||
}
|
45
app/dto/city.go
Normal file
45
app/dto/city.go
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 城市Dto
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : city
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 列表查询条件
|
||||
type CityQueryReq struct {
|
||||
Name string `form:"name"` // 城市名称
|
||||
Pid int `form:"pid"` // 上级ID
|
||||
}
|
||||
|
||||
// 添加城市
|
||||
type CityAddReq struct {
|
||||
Pid string `form:"pid"` // 父级编号
|
||||
Level string `form:"level" binding:"required"` // 城市级别:1省 2市 3区
|
||||
Name string `form:"name" binding:"required"` // 城市名称
|
||||
Citycode string `form:"citycode"` // 城市编号(区号)
|
||||
PAdcode string `form:"pAdcode"` // 父级地理编号
|
||||
Adcode string `form:"adcode"` // 地理编号
|
||||
Lng string `form:"lng"` // 城市坐标中心点经度(* 1e6):如果是中国,此值是 1e7
|
||||
Lat string `form:"lat"` // 城市坐标中心点纬度(* 1e6)
|
||||
Sort string `form:"sort"` // 排序号
|
||||
}
|
||||
|
||||
// 编辑城市
|
||||
type CityUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"` // 主键ID
|
||||
Pid string `form:"pid"` // 父级编号
|
||||
Level string `form:"level" binding:"required"` // 城市级别:1省 2市 3区
|
||||
Name string `form:"name" binding:"required"` // 城市名称
|
||||
Citycode string `form:"citycode"` // 城市编号(区号)
|
||||
PAdcode string `form:"pAdcode"` // 父级地理编号
|
||||
Adcode string `form:"adcode"` // 地理编号
|
||||
Lng string `form:"lng"` // 城市坐标中心点经度(* 1e6):如果是中国,此值是 1e7
|
||||
Lat string `form:"lat"` // 城市坐标中心点纬度(* 1e6)
|
||||
Sort string `form:"sort"` // 排序号
|
||||
}
|
||||
|
||||
// 获取子级城市
|
||||
type CityChildReq struct {
|
||||
CityCode string `form:"citycode" binding:"required"`
|
||||
}
|
20
app/dto/config.go
Normal file
20
app/dto/config.go
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* 配置Dto
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : config
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 添加配置
|
||||
type ConfigAddReq struct {
|
||||
Name string `form:"name" binding:"required"` // 配置名称
|
||||
Sort int `form:"sort"` // 显示顺序
|
||||
}
|
||||
|
||||
// 修改配置
|
||||
type ConfigUpdateReq struct {
|
||||
Id int `form:"id" binding:"required"` // 主键ID
|
||||
Name string `form:"name" binding:"required"` // 配置名称
|
||||
Sort int `form:"sort"` // 显示顺序
|
||||
}
|
46
app/dto/config_data.go
Normal file
46
app/dto/config_data.go
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* 配置数据Dto
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : config_data
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 字典项列表查询条件
|
||||
type ConfigDataPageReq struct {
|
||||
ConfigId int `form:"configId"` // 字典ID
|
||||
Title string `form:"name"` // 配置标题
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加字典项
|
||||
type ConfigDataAddReq struct {
|
||||
Title string `form:"title" binding:"required"` // 配置标题
|
||||
Code string `form:"code" binding:"required"` // 配置编码
|
||||
Value string `form:"value"` // 配置值
|
||||
Options string `form:"options"` // 配置项
|
||||
ConfigId string `form:"configId" binding:"required"` // 配置ID
|
||||
Type string `form:"type" binding:"required"` // 配置类型
|
||||
Sort string `form:"sort"` // 排序
|
||||
Note string `form:"note"` // 配置说明
|
||||
}
|
||||
|
||||
// 更新字典项
|
||||
type ConfigDataUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Title string `form:"title" binding:"required"` // 配置标题
|
||||
Code string `form:"code" binding:"required"` // 配置编码
|
||||
Value string `form:"value"` // 配置值
|
||||
Options string `form:"options"` // 配置项
|
||||
ConfigId string `form:"configId" binding:"required"` // 配置ID
|
||||
Type string `form:"type" binding:"required"` // 配置类型
|
||||
Sort string `form:"sort"` // 排序
|
||||
Note string `form:"note"` // 配置说明
|
||||
}
|
||||
|
||||
// 设置状态
|
||||
type ConfigDataStatusReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
}
|
18
app/dto/customer.go
Normal file
18
app/dto/customer.go
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Dto
|
||||
* @author
|
||||
* @since 2021/11/11
|
||||
* @File : user
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 用户分页查询条件
|
||||
type CustomerSearchReq struct {
|
||||
Mobile string `form:"mobile"` // 手机号
|
||||
OutTradeNo string `form:"out_trade_no"` // 订单号
|
||||
}
|
||||
|
||||
// 用户分页查询条件
|
||||
type CustomerCouponRefundReq struct {
|
||||
Ids string `form:"ids"` // 退款订单id
|
||||
}
|
45
app/dto/dept.go
Normal file
45
app/dto/dept.go
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 部门Dto
|
||||
* @author
|
||||
* @since 2021/9/13
|
||||
* @File : dept
|
||||
*/
|
||||
package dto
|
||||
|
||||
import "easygoadmin/app/model"
|
||||
|
||||
// 分页查询条件
|
||||
type DeptPageReq struct {
|
||||
Name string `form:"name"` // 部门名称
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加部门
|
||||
type DeptAddReq struct {
|
||||
Name string `form:"name" binding:"required"`
|
||||
Code string `form:"code" binding:"required"`
|
||||
Fullname string `form:"fullname" binding:"required"`
|
||||
Type string `form:"type" binding:"required"`
|
||||
Pid string `form:"pid"`
|
||||
Sort string `form:"sort"`
|
||||
Note string
|
||||
}
|
||||
|
||||
// 部门编辑
|
||||
type DeptUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Name string `form:"name" binding:"required"`
|
||||
Code string `form:"code" binding:"required"`
|
||||
Fullname string `form:"fullname" binding:"required"`
|
||||
Type string `form:"type" binding:"required"`
|
||||
Pid string `form:"pid"`
|
||||
Sort string `form:"sort"`
|
||||
Note string
|
||||
}
|
||||
|
||||
// 部门树结构
|
||||
type DeptTreeNode struct {
|
||||
model.Dept
|
||||
Children []*DeptTreeNode `json:"children"` // 子栏目
|
||||
}
|
24
app/dto/dict.go
Normal file
24
app/dto/dict.go
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* 字典Dto
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : dict
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 添加字典
|
||||
type DictAddReq struct {
|
||||
Name string `form:"name" binding:"required"` // 字典名称
|
||||
Code string `form:"code" binding:"required"` // 字典值
|
||||
Sort int `form:"sort"` // 显示顺序
|
||||
Note string `form:"note"` // 字典备注
|
||||
}
|
||||
|
||||
// 修改字典
|
||||
type DictUpdateReq struct {
|
||||
Id int `form:"id" binding:"required"` // 主键ID
|
||||
Name string `form:"name" binding:"required"` // 字典名称
|
||||
Code string `form:"code" binding:"required"` // 字典值
|
||||
Sort int `form:"sort"` // 显示顺序
|
||||
Note string `form:"note"` // 字典备注
|
||||
}
|
34
app/dto/dict_data.go
Normal file
34
app/dto/dict_data.go
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* 字典数据Dto
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : dict_data
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 字典项列表查询条件
|
||||
type DictDataPageReq struct {
|
||||
DictId int `form:"dictId"` // 字典ID
|
||||
Name string `form:"name"` // 字典项名称
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加字典项
|
||||
type DictDataAddReq struct {
|
||||
Name string `form:"name,unique" binding:"required"` // 字典项名称
|
||||
Code string `form:"code" binding:"required"` // 字典项值
|
||||
DictId string `form:"dictId" binding:"required"` // 字典类型ID
|
||||
Note string `form:"note"` // 备注
|
||||
Sort string `form:"sort"` // 显示顺序
|
||||
}
|
||||
|
||||
// 更新字典项
|
||||
type DictDataUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Name string `form:"name,unique" binding:"required"` // 字典项名称
|
||||
Code string `form:"code" binding:"required"` // 字典项值
|
||||
DictId string `form:"dictId" binding:"required"` // 字典类型ID
|
||||
Note string `form:"note"` // 备注
|
||||
Sort string `form:"sort"` // 显示顺序
|
||||
}
|
65
app/dto/example.go
Normal file
65
app/dto/example.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package dto
|
||||
|
||||
// 分页查询
|
||||
type ExamplePageReq struct {
|
||||
Name string `form:"name"` // 测试名称
|
||||
|
||||
Status int `form:"status"` // 状态:1正常 2停用
|
||||
|
||||
Type int `form:"type"` // 类型:1京东 2淘宝 3拼多多 4唯品会
|
||||
|
||||
IsVip int `form:"isVip"` // 是否VIP:1是 2否
|
||||
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加演示一
|
||||
type ExampleAddReq struct {
|
||||
Name string `form:"name" binding:"required"` // 测试名称
|
||||
|
||||
Avatar string `form:"avatar" binding:"required"` // 头像
|
||||
|
||||
Content string `form:"content" binding:"required"` // 内容
|
||||
|
||||
Status string `form:"status" binding:"required"` // 状态:1正常 2停用
|
||||
|
||||
Type string `form:"type" binding:"required"` // 类型:1京东 2淘宝 3拼多多 4唯品会
|
||||
|
||||
IsVip string `form:"isVip" binding:"required"` // 是否VIP:1是 2否
|
||||
|
||||
Sort string `form:"sort" binding:"required"` // 排序号
|
||||
|
||||
}
|
||||
|
||||
// 编辑演示一
|
||||
type ExampleUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
|
||||
Name string `form:"name" binding:"required"` // 测试名称
|
||||
|
||||
Avatar string `form:"avatar" binding:"required"` // 头像
|
||||
|
||||
Content string `form:"content" binding:"required"` // 内容
|
||||
|
||||
Status string `form:"status" binding:"required"` // 状态:1正常 2停用
|
||||
|
||||
Type string `form:"type" binding:"required"` // 类型:1京东 2淘宝 3拼多多 4唯品会
|
||||
|
||||
IsVip string `form:"isVip" binding:"required"` // 是否VIP:1是 2否
|
||||
|
||||
Sort string `form:"sort" binding:"required"` // 排序号
|
||||
|
||||
}
|
||||
|
||||
// 设置状态
|
||||
type ExampleStatusReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
}
|
||||
|
||||
// 设置是否VIP
|
||||
type ExampleIsVipReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
IsVip string `form:"isVip" binding:"required"`
|
||||
}
|
39
app/dto/example2.go
Normal file
39
app/dto/example2.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package dto
|
||||
|
||||
// 分页查询
|
||||
type Example2PageReq struct {
|
||||
Name string `form:"name"` // 演示名称
|
||||
|
||||
Status int `form:"status"` // 状态:1正常 2停用
|
||||
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加演示二
|
||||
type Example2AddReq struct {
|
||||
Name string `form:"name" binding:"required"` // 演示名称
|
||||
|
||||
Status string `form:"status" binding:"required"` // 状态:1正常 2停用
|
||||
|
||||
Sort string `form:"sort" binding:"required"` // 排序号
|
||||
|
||||
}
|
||||
|
||||
// 编辑演示二
|
||||
type Example2UpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
|
||||
Name string `form:"name" binding:"required"` // 演示名称
|
||||
|
||||
Status string `form:"status" binding:"required"` // 状态:1正常 2停用
|
||||
|
||||
Sort string `form:"sort" binding:"required"` // 排序号
|
||||
|
||||
}
|
||||
|
||||
// 设置状态
|
||||
type Example2StatusReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
}
|
26
app/dto/generate.go
Normal file
26
app/dto/generate.go
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* 代码生成器Dto
|
||||
* @author
|
||||
* @since 2021/11/15
|
||||
* @File : generate
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 分页查询条件
|
||||
type GeneratePageReq struct {
|
||||
Name string `form:"name"` // 表名称
|
||||
Comment string `form:"comment"` // 表描述
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 生成文件
|
||||
type GenerateFileReq struct {
|
||||
Name string `form:"name"` // 表名称
|
||||
Comment string `form:"comment"` // 表描述
|
||||
}
|
||||
|
||||
// 批量生成文件
|
||||
type BatchGenerateFileReq struct {
|
||||
Tables string `form:"tables"` // 表名称
|
||||
}
|
44
app/dto/item.go
Normal file
44
app/dto/item.go
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 站点Dto
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : item
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 分页查询条件
|
||||
type ItemPageReq struct {
|
||||
Name string `form:"name"` // 站点名称
|
||||
Type int `form:"type"` // 站点类型
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加站点
|
||||
type ItemAddReq struct {
|
||||
Name string `form:"name" binding:"required"` // 站点名称
|
||||
Type string `form:"type" binding:"required"` // 站点类型:1普通站点 2其他
|
||||
Url string `form:"url" binding:"required"` // 站点地址
|
||||
Image string `form:"image"` // 站点图片
|
||||
Status string `form:"status" binding:"required"` // 状态:1在用 2停用
|
||||
Note string `form:"note"` // 站点备注
|
||||
Sort string `form:"sort"` // 显示顺序
|
||||
}
|
||||
|
||||
// 更新站点
|
||||
type ItemUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Name string `form:"name" binding:"required"` // 站点名称
|
||||
Type string `form:"type" binding:"required"` // 站点类型:1普通站点 2其他
|
||||
Url string `form:"url" binding:"required"` // 站点地址
|
||||
Image string `form:"image"` // 站点图片
|
||||
Status string `form:"status" binding:"required"` // 状态:1在用 2停用
|
||||
Note string `form:"note"` // 站点备注
|
||||
Sort string `form:"sort"` // 显示顺序
|
||||
}
|
||||
|
||||
// 设置状态
|
||||
type ItemStatusReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
}
|
41
app/dto/item_cate.go
Normal file
41
app/dto/item_cate.go
Normal file
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 栏目Dto
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : item_cate
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 栏目查询条件
|
||||
type ItemCateQueryReq struct {
|
||||
Name string `form:"name"` // 栏目名称
|
||||
}
|
||||
|
||||
// 添加站点
|
||||
type ItemCateAddReq struct {
|
||||
Name string `form:"name" binding:"required"` // 栏目名称
|
||||
Pid string `form:"pid"` // 父级ID
|
||||
ItemId string `form:"itemId" binding:"required"` // 站点ID
|
||||
Pinyin string `form:"pinyin" binding:"required"` // 拼音(全)
|
||||
Code string `form:"code" binding:"required"` // 拼音(简)
|
||||
IsCover string `form:"isCover" binding:"required"` // 是否有封面:1是 2否
|
||||
Cover string `form:"cover"` // 封面
|
||||
Status string `form:"status" binding:"required"` // 状态:1启用 2停用
|
||||
Note string `form:"note"` // 备注
|
||||
Sort string `form:"sort"` // 排序
|
||||
}
|
||||
|
||||
// 修改
|
||||
type ItemCateUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Name string `form:"name" binding:"required"` // 栏目名称
|
||||
Pid string `form:"pid"` // 父级ID
|
||||
ItemId string `form:"itemId" binding:"required"` // 站点ID
|
||||
Pinyin string `form:"pinyin" binding:"required"` // 拼音(全)
|
||||
Code string `form:"code" binding:"required"` // 拼音(简)
|
||||
IsCover string `form:"isCover" binding:"required"` // 是否有封面:1是 2否
|
||||
Cover string `form:"cover"` // 封面
|
||||
Status string `form:"status" binding:"required"` // 状态:1启用 2停用
|
||||
Note string `form:"note"` // 备注
|
||||
Sort string `form:"sort"` // 排序
|
||||
}
|
35
app/dto/level.go
Normal file
35
app/dto/level.go
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 职级Dto
|
||||
* @author
|
||||
* @since 2021/9/6
|
||||
* @File : level
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 分页查询
|
||||
type LevelPageReq struct {
|
||||
Name string `form:"name"` // 职级名称
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加职级
|
||||
type LevelAddReq struct {
|
||||
Name string `form:"name" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
Sort string `form:"sort"`
|
||||
}
|
||||
|
||||
// 编辑职级
|
||||
type LevelUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Name string `form:"name" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
Sort string `form:"sort"`
|
||||
}
|
||||
|
||||
// 设置状态
|
||||
type LevelStatusReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
}
|
53
app/dto/link.go
Normal file
53
app/dto/link.go
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* 友链Dto
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : link
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 分页查询条件
|
||||
type LinkPageReq struct {
|
||||
Name string `form:"name"` // 友链名称
|
||||
Type int `form:"type"` // 友链类型
|
||||
Platform int `form:"platform"` // 投放平台
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加友链
|
||||
type LinkAddReq struct {
|
||||
Name string `form:"name" binding:"required"` // 友链名称
|
||||
Type string `form:"type" binding:"required"` // 类型:1友情链接 2合作伙伴
|
||||
Url string `form:"url"` // 友链地址
|
||||
ItemId string `form:"itemId"` // 站点ID
|
||||
CateId string `form:"cateId"` // 栏目ID
|
||||
Platform string `form:"platform" binding:"required"` // 平台:1PC站 2WAP站 3微信小程序 4APP应用
|
||||
Form string `form:"form" binding:"required"` // 友链形式:1文字链接 2图片链接
|
||||
Image string `form:"image"` // 友链图片
|
||||
Status string `form:"status" binding:"required"` // 状态:1在用 2停用
|
||||
Sort string `form:"sort"` // 显示顺序
|
||||
Note string `form:"note"` // 备注
|
||||
}
|
||||
|
||||
// 修改友链
|
||||
type LinkUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Name string `form:"name" binding:"required"` // 友链名称
|
||||
Type string `form:"type" binding:"required"` // 类型:1友情链接 2合作伙伴
|
||||
Url string `form:"url"` // 友链地址
|
||||
ItemId string `form:"itemId"` // 站点ID
|
||||
CateId string `form:"cateId"` // 栏目ID
|
||||
Platform string `form:"platform" binding:"required"` // 平台:1PC站 2WAP站 3微信小程序 4APP应用
|
||||
Form string `form:"form" binding:"required"` // 友链形式:1文字链接 2图片链接
|
||||
Image string `form:"image"` // 友链图片
|
||||
Status string `form:"status" binding:"required"` // 状态:1在用 2停用
|
||||
Sort string `form:"sort"` // 显示顺序
|
||||
Note string `form:"note"` // 备注
|
||||
}
|
||||
|
||||
// 设置状态
|
||||
type LinkStatusReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
}
|
15
app/dto/login.go
Normal file
15
app/dto/login.go
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 登录Dto
|
||||
* @author
|
||||
* @since 2021/9/9
|
||||
* @File : login
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 系统登录
|
||||
type LoginReq struct {
|
||||
UserName string `form:"username" binding:"required,min=4,max=30"`
|
||||
Password string `form:"password" binding:"required,min=6,max=12"`
|
||||
Captcha string `form:"captcha" binding:"required,min=4,max=6"`
|
||||
IdKey string `form:"idKey" binding:"required"`
|
||||
}
|
14
app/dto/login_log.go
Normal file
14
app/dto/login_log.go
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* 登录日志Dto
|
||||
* @author
|
||||
* @since 2021/11/12
|
||||
* @File : login_log
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 分页信息查询条件
|
||||
type LoginLogPageReq struct {
|
||||
Username string `form:"username"` // 用户账号
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
64
app/dto/member.go
Normal file
64
app/dto/member.go
Normal file
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* 会员Dto
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : member
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 分页查询条件
|
||||
type MemberPageReq struct {
|
||||
Username string `form:"username"` // 用户名
|
||||
Gender int `form:"gender"` // 性别(1男 2女 3未知)
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加会员
|
||||
type MemberAddReq struct {
|
||||
Username string `form:"username,unique" binding:"required"` // 用户名
|
||||
Password string `form:"password" binding:"required"` // 登录密码
|
||||
MemberLevel string `form:"memberLevel" binding:"required"` // 会员等级
|
||||
Realname string `form:"realname" binding:"required"` // 真实姓名
|
||||
Nickname string `form:"nickname" binding:"required"` // 用户昵称
|
||||
Gender string `form:"gender" binding:"required"` // 性别(1男 2女 3未知)
|
||||
Avatar string `form:"avatar" binding:"required"` // 用户头像
|
||||
Birthday string `form:"birthday" binding:"required"` // 出生日期
|
||||
ProvinceCode string `form:"provinceCode" binding:"required"` // 省份编号
|
||||
CityCode string `form:"cityCode" binding:"required"` // 市区编号
|
||||
DistrictCode string `form:"districtCode" binding:"required"` // 区县编号
|
||||
Address string `form:"address" binding:"required"` // 详细地址
|
||||
Intro string `form:"intro"` // 个人简介
|
||||
Signature string `form:"signature"` // 个性签名
|
||||
Device string `form:"device" binding:"required"` // 设备类型:1苹果 2安卓 3WAP站 4PC站 5后台添加
|
||||
Source string `form:"source" binding:"required"` // 来源:1、APP注册;2、后台添加;
|
||||
Status string `form:"status" binding:"required"` // 是否启用 1、启用 2、停用
|
||||
}
|
||||
|
||||
// 更新会员
|
||||
type MemberUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Username string `form:"username,unique" binding:"required"` // 用户名
|
||||
Password string `form:"password" binding:"required"` // 登录密码
|
||||
MemberLevel string `form:"memberLevel" binding:"required"` // 会员等级
|
||||
Realname string `form:"realname" binding:"required"` // 真实姓名
|
||||
Nickname string `form:"nickname" binding:"required"` // 用户昵称
|
||||
Gender string `form:"gender" binding:"required"` // 性别(1男 2女 3未知)
|
||||
Avatar string `form:"avatar" binding:"required"` // 用户头像
|
||||
Birthday string `form:"birthday" binding:"required"` // 出生日期
|
||||
ProvinceCode string `form:"provinceCode" binding:"required"` // 省份编号
|
||||
CityCode string `form:"cityCode" binding:"required"` // 市区编号
|
||||
DistrictCode string `form:"districtCode" binding:"required"` // 区县编号
|
||||
Address string `form:"address" binding:"required"` // 详细地址
|
||||
Intro string `form:"intro"` // 个人简介
|
||||
Signature string `form:"signature"` // 个性签名
|
||||
Device string `form:"device" binding:"required"` // 设备类型:1苹果 2安卓 3WAP站 4PC站 5后台添加
|
||||
Source string `form:"source" binding:"required"` // 来源:1、APP注册;2、后台添加;
|
||||
Status string `form:"status" binding:"required"` // 是否启用 1、启用 2、停用
|
||||
}
|
||||
|
||||
// 设置状态
|
||||
type MemberStatusReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
}
|
27
app/dto/member_level.go
Normal file
27
app/dto/member_level.go
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* 会员等级Dto
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : member_level
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 查询会员等级
|
||||
type MemberLevelPageReq struct {
|
||||
Name string `form:"name"` // 等级名称
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加会员等级
|
||||
type MemberLevelAddReq struct {
|
||||
Name string `form:"name" binding:"required"` // 级别名称
|
||||
Sort string `form:"sort"` // 排序号
|
||||
}
|
||||
|
||||
// 更新会员等级
|
||||
type MemberLevelUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Name string `form:"name" binding:"required"` // 级别名称
|
||||
Sort string `form:"sort"` // 排序号
|
||||
}
|
51
app/dto/menu.go
Normal file
51
app/dto/menu.go
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* 菜单Dto
|
||||
* @author
|
||||
* @since 2021/9/13
|
||||
* @File : menu
|
||||
*/
|
||||
package dto
|
||||
|
||||
import "easygoadmin/app/model"
|
||||
|
||||
// 列表查询条件
|
||||
type MenuQueryReq struct {
|
||||
Title string `form:"name"` // 菜单标题
|
||||
}
|
||||
|
||||
// 添加菜单
|
||||
type MenuAddReq struct {
|
||||
Name string `form:"name" binding:"required"` // 菜单标题
|
||||
Icon string `form:"icon" binding:"required"` // 图标
|
||||
Url string `form:"url" binding:"required"` // URL地址
|
||||
Pid string `form:"pid"` // 上级ID
|
||||
Type string `form:"type"` // 类型:1模块 2导航 3菜单 4节点
|
||||
Permission string `form:"permission"` // 权限标识
|
||||
Status string `form:"status" binding:"required"` // 状态:1正常 2禁用
|
||||
Target string `form:"target"` // 打开方式:1内部打开 2外部打开
|
||||
Note string `form:"note"` // 菜单备注
|
||||
Sort string `form:"sort"` // 显示顺序
|
||||
Func string `form:"func"` // 权限节点
|
||||
}
|
||||
|
||||
// 更新菜单
|
||||
type MenuUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Name string `form:"name" binding:"required"` // 菜单标题
|
||||
Icon string `form:"icon" binding:"required"` // 图标
|
||||
Url string `form:"url" binding:"required"` // URL地址
|
||||
Pid string `form:"pid"` // 上级ID
|
||||
Type string `form:"type"` // 类型:1模块 2导航 3菜单 4节点
|
||||
Permission string `form:"permission"` // 权限标识
|
||||
Status string `form:"status" binding:"required"` // 状态:1正常 2禁用
|
||||
Target string `form:"target"` // 打开方式:1内部打开 2外部打开
|
||||
Note string `form:"note"` // 菜单备注
|
||||
Sort string `form:"sort"` // 显示顺序
|
||||
Func string `form:"func"` // 权限节点
|
||||
}
|
||||
|
||||
// 菜单信息
|
||||
type MenuInfoVo struct {
|
||||
model.Menu
|
||||
CheckedList []int `form:"checkedList"` // 权限节点列表
|
||||
}
|
40
app/dto/notice.go
Normal file
40
app/dto/notice.go
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 通知公告Dto
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : notice
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 分页查询
|
||||
type NoticePageReq struct {
|
||||
Title string `form:"title"` // 通知标题
|
||||
Source int `form:"source"` // 通知来源
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加通知公告
|
||||
type NoticeAddReq struct {
|
||||
Title string `form:"title" binding:"required"` // 通知标题
|
||||
Content string `form:"content" binding:"required"` // 通知内容
|
||||
Source string `form:"source" binding:"required"` // 来源:1内部通知 2外部新闻
|
||||
IsTop string `form:"isTop" binding:"required"` // 是否置顶:1是 2否
|
||||
Status string `form:"status" binding:"required"` // 状态:1已发布 2待发布
|
||||
}
|
||||
|
||||
// 更新通知公告
|
||||
type NoticeUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Title string `form:"title" binding:"required"` // 通知标题
|
||||
Content string `form:"content" binding:"required"` // 通知内容
|
||||
Source string `form:"source" binding:"required"` // 来源:1内部通知 2外部新闻
|
||||
IsTop string `form:"isTop" binding:"required"` // 是否置顶:1是 2否
|
||||
Status string `form:"status" binding:"required"` // 状态:1已发布 2待发布
|
||||
}
|
||||
|
||||
// 设置状态
|
||||
type NoticeStatusReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
}
|
15
app/dto/oper_log.go
Normal file
15
app/dto/oper_log.go
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 操作日志Dto
|
||||
* @author
|
||||
* @since 2021/11/12
|
||||
* @File : oper_log
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 分页查询条件
|
||||
type OperLogPageReq struct {
|
||||
Username string `form:"username"` // 操作账号
|
||||
Model string `form:"model"` // 操作模块
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
35
app/dto/position.go
Normal file
35
app/dto/position.go
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 岗位Dto
|
||||
* @author
|
||||
* @since 2021/9/10
|
||||
* @File : position
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 分页查询条件
|
||||
type PositionPageReq struct {
|
||||
Name string `form:"name"` // 岗位名称
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加岗位
|
||||
type PositionAddReq struct {
|
||||
Name string `form:"name" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
Sort string `form:"sort"`
|
||||
}
|
||||
|
||||
// 更新岗位
|
||||
type PositionUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Name string `form:"name" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
Sort string `form:"sort"`
|
||||
}
|
||||
|
||||
// 设置状态
|
||||
type PositionStatusReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
}
|
39
app/dto/role.go
Normal file
39
app/dto/role.go
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* 角色Dto
|
||||
* @author
|
||||
* @since 2021/9/13
|
||||
* @File : role
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 分页查询条件
|
||||
type RolePageReq struct {
|
||||
Name string `form:"name"` // 角色名称
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加角色
|
||||
type RoleAddReq struct {
|
||||
Name string `form:"name" binding:"required"`
|
||||
Code string `form:"code" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
Sort string `form:"sort"`
|
||||
Note string `form:"note"`
|
||||
}
|
||||
|
||||
// 更新角色
|
||||
type RoleUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Name string `form:"name" binding:"required"`
|
||||
Code string `form:"code" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
Sort string `form:"sort"`
|
||||
Note string `form:"note"`
|
||||
}
|
||||
|
||||
// 设置状态
|
||||
type RoleStatusReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
}
|
13
app/dto/role_menu.go
Normal file
13
app/dto/role_menu.go
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* 角色菜单Dto
|
||||
* @author
|
||||
* @since 2021/9/14
|
||||
* @File : role_menu
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 角色菜单数据
|
||||
type RoleMenuSaveReq struct {
|
||||
RoleId int `form:"roleId" binding:"required"`
|
||||
MenuIds string `form:"menuIds" binding:"required"`
|
||||
}
|
101
app/dto/user.go
Normal file
101
app/dto/user.go
Normal file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* 用户Dto
|
||||
* @author
|
||||
* @since 2021/11/11
|
||||
* @File : user
|
||||
*/
|
||||
package dto
|
||||
|
||||
// 用户分页查询条件
|
||||
type UserPageReq struct {
|
||||
Realname string `form:"realname"` // 用户名
|
||||
Gender int `form:"gender"` // 性别
|
||||
Page int `form:"page"` // 页码
|
||||
Limit int `form:"limit"` // 每页数
|
||||
}
|
||||
|
||||
// 添加用户
|
||||
type UserAddReq struct {
|
||||
Realname string `form:"realname" binding:"required"`
|
||||
Nickname string `form:"nickname" binding:"required"`
|
||||
Gender string `form:"gender" binding:""`
|
||||
Avatar string `form:"avatar" binding:""`
|
||||
Mobile string `form:"mobile" binding:"required"`
|
||||
Email string `form:"email" binding:""`
|
||||
Birthday string `form:"birthday" binding:""`
|
||||
DeptId string `form:"deptId" binding:""`
|
||||
LevelId string `form:"levelId" binding:""`
|
||||
PositionId string `form:"positionId" binding:""`
|
||||
ProvinceCode string `form:"provinceCode" binding:""` // 省份编号
|
||||
CityCode string `form:"cityCode" binding:""` // 市区编号
|
||||
DistrictCode string `form:"districtCode" binding:""` // 区县编号
|
||||
Address string `form:"address"`
|
||||
Username string `form:"username" binding:"required"`
|
||||
Password string `form:"password"`
|
||||
Intro string `form:"intro"`
|
||||
Status string `form:"status"`
|
||||
Note string `form:"note"`
|
||||
Sort string `form:"sort"`
|
||||
RoleIds string `form:"roleIds"` // 用户角色
|
||||
}
|
||||
|
||||
// 更新用户
|
||||
type UserUpdateReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Realname string `form:"realname" binding:"required"`
|
||||
Nickname string `form:"nickname" binding:"required"`
|
||||
Gender string `form:"gender" binding:""`
|
||||
Avatar string `form:"avatar" binding:""`
|
||||
Mobile string `form:"mobile" binding:"required"`
|
||||
Email string `form:"email" binding:""`
|
||||
Birthday string `form:"birthday" binding:""`
|
||||
DeptId string `form:"deptId" binding:""`
|
||||
LevelId string `form:"levelId" binding:""`
|
||||
PositionId string `form:"positionId" binding:""`
|
||||
ProvinceCode string `form:"provinceCode" binding:""` // 省份编号
|
||||
CityCode string `form:"cityCode" binding:""` // 市区编号
|
||||
DistrictCode string `form:"districtCode" binding:""` // 区县编号
|
||||
Address string `form:"address"`
|
||||
Username string `form:"username" binding:"required"`
|
||||
Password string `form:"password"`
|
||||
Intro string `form:"intro"`
|
||||
Status string `form:"status"`
|
||||
Note string `form:"note"`
|
||||
Sort string `form:"sort"`
|
||||
RoleIds string `form:"roleIds"` // 用户角色
|
||||
}
|
||||
|
||||
// 设置状态
|
||||
type UserStatusReq struct {
|
||||
Id string `form:"id" binding:"required"`
|
||||
Status string `form:"status" binding:"required"`
|
||||
}
|
||||
|
||||
// 重置密码
|
||||
type UserResetPwdReq struct {
|
||||
Id int `form:"id" binding:"required"`
|
||||
}
|
||||
|
||||
// 检查用户
|
||||
type CheckUserReq struct {
|
||||
Username string `form:"username" binding:"required"` // 用户名
|
||||
}
|
||||
|
||||
// 更新密码
|
||||
type UpdatePwd struct {
|
||||
OldPassword string `form:"oldPassword" binding:"required"` // 旧密码
|
||||
NewPassword string `form:"newPassword" binding:"required"` // 新密码
|
||||
RePassword string `form:"rePassword" binding:"required"` // 确认密码
|
||||
}
|
||||
|
||||
// 用户中心
|
||||
type UserInfoReq struct {
|
||||
Avatar string `form:"avatar"` // 头像
|
||||
Realname string `form:"realname" binding:"required"` // 真实姓名
|
||||
Nickname string `form:"nickname" binding:"required"` // 昵称
|
||||
Gender string `form:"gender" binding:"required"` // 性别:1男 2女 3保密
|
||||
Mobile string `form:"mobile" binding:"required"` // 手机号码
|
||||
Email string `form:"email" binding:"required"` // 邮箱地址
|
||||
Address string `form:"address"` // 详细地址
|
||||
Intro string `form:"intro"` // 个人简介
|
||||
}
|
195
app/middleware/checklogin.go
Normal file
195
app/middleware/checklogin.go
Normal file
@@ -0,0 +1,195 @@
|
||||
/**
|
||||
* 登录验证中间件
|
||||
* @author
|
||||
* @since 2021/8/20
|
||||
* @File : checkauth
|
||||
*/
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gin-contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func CheckLogin() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
//fmt.Println("登录验证中间件")
|
||||
// 放行设置
|
||||
path := c.Request.URL.Path
|
||||
|
||||
urlItem := []string{"/captcha", "/login", "/loginKf", "/"}
|
||||
urlCusItem := []string{"/customer", "/loginKf"}
|
||||
if !utils.InStringArray(path, urlItem) && !strings.Contains(path, "resource") {
|
||||
if !strings.Contains(path, "api") {
|
||||
if !utils.IsLogin(c) {
|
||||
// 跳转登录页,方式:301(永久移动),308(永久重定向),307(临时重定向)
|
||||
if utils.InStringArray(path, urlCusItem) {
|
||||
c.Redirect(http.StatusTemporaryRedirect, "/loginKf")
|
||||
return
|
||||
}
|
||||
c.Redirect(http.StatusTemporaryRedirect, "/login")
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
// 前置中间件
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// 验证权限
|
||||
func CheckAuth() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
//fmt.Println("登录验证中间件")
|
||||
// 放行设置
|
||||
urlItem := []string{"/captcha", "/login", "/loginKf", "/"}
|
||||
path := c.Request.URL.Path
|
||||
match, _ := regexp.Match("/[1-9]\\d*", []byte(path))
|
||||
if !utils.InStringArray(c.Request.URL.Path, urlItem) && !strings.Contains(c.Request.URL.Path, "resource") {
|
||||
if !strings.Contains(c.Request.URL.Path, "api") && !match {
|
||||
// 初始化session对象
|
||||
session := sessions.Default(c)
|
||||
userId := session.Get("userId")
|
||||
if userId != 1 && !strings.Contains(path, "edit") {
|
||||
menuIdArr := getRoleApiIds(c, gconv.Int64(userId))
|
||||
if len(menuIdArr) == 0 {
|
||||
c.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "无权限",
|
||||
})
|
||||
c.Abort()
|
||||
}
|
||||
menuId := getMenuId(c, path)
|
||||
if menuId != "" {
|
||||
if !utils.InStringArray(menuId, menuIdArr) {
|
||||
c.JSON(http.StatusOK, common.JsonResult{
|
||||
Code: -1,
|
||||
Msg: "无权限!",
|
||||
})
|
||||
c.Abort()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 前置中间件
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// 跨域
|
||||
func DoCors() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
method := c.Request.Method
|
||||
|
||||
origin := c.Request.Header.Get("Origin")
|
||||
var headerKeys []string
|
||||
for k, _ := range c.Request.Header {
|
||||
headerKeys = append(headerKeys, k)
|
||||
}
|
||||
headerStr := strings.Join(headerKeys, ", ")
|
||||
if headerStr != "" {
|
||||
headerStr = fmt.Sprintf("access-control-allow-origin, access-control-allow-headers,AppToken, %s", headerStr)
|
||||
} else {
|
||||
headerStr = "access-control-allow-origin, access-control-allow-headers,AppToken"
|
||||
}
|
||||
if origin != "" {
|
||||
//-_-~
|
||||
// c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
|
||||
c.Header("Access-Control-Allow-Origin", origin)
|
||||
|
||||
//c.Header("Access-Control-Allow-Headers", headerStr)
|
||||
c.Header("Access-Control-Allow-Headers", "Authorization, Content-Length, X-CSRF-Token, Token,session,X_Requested_With,Accept, Origin, Host, Connection, Accept-Encoding, Accept-Language,DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Pragma")
|
||||
|
||||
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
||||
// c.Header("Access-Control-Allow-Headers", "Authorization, Content-Length, X-CSRF-Token, Accept, Origin, Host, Connection, Accept-Encoding, Accept-Language,DNT, X-CustomHeader, Keep-Alive, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Pragma")
|
||||
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
|
||||
c.Header("Access-Control-Max-Age", "172800")
|
||||
c.Header("Access-Control-Allow-Credentials", "true")
|
||||
c.Set("content-type", "application/json")
|
||||
}
|
||||
|
||||
//放行所有OPTIONS方法
|
||||
if method == "OPTIONS" {
|
||||
c.JSON(http.StatusOK, "Options Request!")
|
||||
//c.AbortWithStatus(http.StatusNoContent)
|
||||
}
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
// 根据userId 获取有权限的menuId
|
||||
func getRoleApiIds(c *gin.Context, userId int64) []string {
|
||||
apiIdsArr := make([]string, 0)
|
||||
cache := utils.GetRedisHelper()
|
||||
cacheKey := fmt.Sprintf("Middleware:GetRoleApiIds:V1:%d", userId)
|
||||
val := cache.Get(c, cacheKey).Val()
|
||||
if val != "" {
|
||||
json.Unmarshal([]byte(val), &apiIdsArr)
|
||||
return apiIdsArr
|
||||
}
|
||||
|
||||
userRole := make([]model.UserRole, 0)
|
||||
// 创建查询实例
|
||||
query := utils.XormDb.Where("user_id = ?", gconv.String(userId)).Table("sys_user_role")
|
||||
err := query.Find(&userRole)
|
||||
if err != nil {
|
||||
return apiIdsArr
|
||||
}
|
||||
roleArr := make([]string, 0)
|
||||
for _, item := range userRole {
|
||||
roleArr = append(roleArr, gconv.String(item.RoleId))
|
||||
}
|
||||
if len(roleArr) > 0 {
|
||||
//roleMenuArr := make([]int, 0)
|
||||
roleStr := strings.Join(roleArr, ",")
|
||||
whereId := fmt.Sprintf("role_id IN (%s)", roleStr)
|
||||
roleMenu := make([]model.RoleMenu, 0)
|
||||
errR := utils.XormDb.Where(whereId).Find(&roleMenu)
|
||||
if errR == nil {
|
||||
for _, item := range roleMenu {
|
||||
apiIdsArr = append(apiIdsArr, gconv.String(item.MenuId))
|
||||
}
|
||||
}
|
||||
}
|
||||
jsonStr, _ := json.Marshal(apiIdsArr)
|
||||
cache.Set(c, cacheKey, jsonStr, 2*time.Minute)
|
||||
|
||||
return apiIdsArr
|
||||
}
|
||||
|
||||
// 根据userId 获取有权限的menuId
|
||||
func getMenuId(c *gin.Context, path string) string {
|
||||
menuId := ""
|
||||
cache := utils.GetRedisHelper()
|
||||
cacheKey := fmt.Sprintf("Middleware:GetMenuId:V3:%s", path)
|
||||
val := cache.Get(c, cacheKey).Val()
|
||||
if val != "" {
|
||||
return val
|
||||
}
|
||||
|
||||
var menu model.Menu
|
||||
// 创建查询实例
|
||||
query := utils.XormDb.Where("url = ?", path).Select("id").
|
||||
Table("sys_menu")
|
||||
_, err := query.Get(&menu)
|
||||
if err != nil || menu.Id == 0 {
|
||||
return menuId
|
||||
}
|
||||
menuId = gconv.String(menu.Id)
|
||||
cache.Set(c, cacheKey, menuId, 2*time.Minute)
|
||||
|
||||
return menuId
|
||||
}
|
54
app/model/ad.go
Normal file
54
app/model/ad.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type Ad struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(10)"`
|
||||
Title string `json:"title" xorm:"not null comment('广告标题') index VARCHAR(100)"`
|
||||
AdSortId int `json:"adSortId" xorm:"not null default 0 comment('广告位ID') index INT(11)"`
|
||||
Cover string `json:"cover" xorm:"default 'NULL' comment('广告图片') VARCHAR(255)"`
|
||||
Type int `json:"type" xorm:"not null default 0 comment('广告格式:1图片 2文字 3视频 4推荐') TINYINT(1)"`
|
||||
Description string `json:"description" xorm:"default 'NULL' comment('广告描述') VARCHAR(150)"`
|
||||
Content string `json:"content" xorm:"default 'NULL' comment('广告内容') TEXT"`
|
||||
Url string `json:"url" xorm:"default 'NULL' comment('广告链接') TEXT"`
|
||||
Width int `json:"width" xorm:"not null default 0 comment('广告宽度') INT(10)"`
|
||||
Height int `json:"height" xorm:"not null default 0 comment('广告高度') INT(10)"`
|
||||
StartTime int64 `json:"startTime" xorm:"default 'NULL' comment('开始时间') DATETIME"`
|
||||
EndTime int64 `json:"endTime" xorm:"default 'NULL' comment('结束时间') DATETIME"`
|
||||
ViewNum int `json:"viewNum" xorm:"not null default 0 comment('点击率') INT(10)"`
|
||||
Status int `json:"status" xorm:"not null default 1 comment('状态:1在用 2停用') TINYINT(1)"`
|
||||
Sort int `json:"sort" xorm:"not null default 125 comment('排序') SMALLINT(5)"`
|
||||
Note string `json:"note" xorm:"default 'NULL' comment('备注') VARCHAR(255)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(10)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"not null comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"default 0 comment('更新人') INT(10)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识(1正常 0删除)') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *Ad) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *Ad) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *Ad) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *Ad) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&Ad{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *Ad) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&Ad{})
|
||||
}
|
45
app/model/ad_sort.go
Normal file
45
app/model/ad_sort.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type AdSort struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(10)"`
|
||||
Description string `json:"description" xorm:"not null comment('广告位描述') VARCHAR(255)"`
|
||||
ItemId int `json:"itemId" xorm:"not null default 0 comment('站点ID') INT(10)"`
|
||||
CateId int `json:"cateId" xorm:"not null default 0 comment('栏目ID') SMALLINT(5)"`
|
||||
LocId int `json:"locId" xorm:"not null default 0 comment('广告页面位置') SMALLINT(5)"`
|
||||
Platform int `json:"platform" xorm:"not null default 1 comment('站点类型:1PC网站 2WAP手机站 3微信小程序 4APP移动端') TINYINT(1)"`
|
||||
Sort int `json:"sort" xorm:"not null default 125 comment('广告位排序') SMALLINT(5)"`
|
||||
CreateUser int `json:"create_user" xorm:"default 0 comment('添加人') INT(10)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"default 0 comment('更新人') INT(10)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识(1正常 0删除)') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *AdSort) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *AdSort) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *AdSort) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *AdSort) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&AdSort{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *AdSort) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&AdSort{})
|
||||
}
|
48
app/model/city.go
Normal file
48
app/model/city.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type City struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('编号') INT(11)"`
|
||||
Pid int `json:"pid" xorm:"not null default 0 comment('父级编号') INT(11)"`
|
||||
Level int `json:"level" xorm:"not null default 0 comment('城市级别:1省 2市 3区') TINYINT(1)"`
|
||||
Name string `json:"name" xorm:"not null comment('城市名称') index VARCHAR(50)"`
|
||||
Citycode string `json:"citycode" xorm:"not null comment('城市编号(区号)') VARCHAR(10)"`
|
||||
PAdcode string `json:"PAdcode" xorm:"default 'NULL' comment('父级地理编号') VARCHAR(10)"`
|
||||
Adcode string `json:"adcode" xorm:"default 'NULL' comment('地理编号') VARCHAR(10)"`
|
||||
Lng string `json:"lng" xorm:"default 'NULL' comment('城市坐标中心点经度(* 1e6):如果是中国,此值是 1e7') VARCHAR(10)""`
|
||||
Lat string `json:"lat" xorm:"default 'NULL' comment('城市坐标中心点纬度(* 1e6)') VARCHAR(10)""`
|
||||
Sort int `json:"sort" xorm:"not null default 125 comment('排序号') TINYINT(3)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(11)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"not null default 0 comment('更新人') INT(11)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标记') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *City) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *City) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *City) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *City) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&City{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *City) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&City{})
|
||||
}
|
41
app/model/config.go
Normal file
41
app/model/config.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(11)"`
|
||||
Name string `json:"name" xorm:"not null comment('分组名称') index VARCHAR(30)"`
|
||||
Sort int `json:"sort" xorm:"not null comment('排序') TINYINT(2)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(11)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"not null default 0 comment('更新人') INT(11)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *Config) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *Config) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *Config) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *Config) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&Config{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *Config) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&Config{})
|
||||
}
|
48
app/model/config_data.go
Normal file
48
app/model/config_data.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type ConfigData struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(11)"`
|
||||
Title string `json:"title" xorm:"not null comment('配置标题') index VARCHAR(50)"`
|
||||
Code string `json:"code" xorm:"not null comment('配置编码') index VARCHAR(100)"`
|
||||
Value string `json:"value" xorm:"default 'NULL' comment('配置值') TEXT"`
|
||||
Options string `json:"options" xorm:"default 'NULL' comment('配置项') VARCHAR(255)"`
|
||||
ConfigId int `json:"configId" xorm:"not null default 0 comment('配置ID') INT(11)"`
|
||||
Type string `json:"type" xorm:"not null comment('配置类型') VARCHAR(16)"`
|
||||
Status int `json:"status" xorm:"not null default 1 comment('状态:1正常 2停用') TINYINT(1)"`
|
||||
Sort int `json:"sort" xorm:"not null default 0 comment('排序') SMALLINT(3)"`
|
||||
Note string `json:"note" xorm:"default 'NULL' comment('配置说明') VARCHAR(500)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(11)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"not null default 0 comment('更新人') INT(11)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识:1正常 0删除') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *ConfigData) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *ConfigData) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *ConfigData) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *ConfigData) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&ConfigData{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *ConfigData) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&ConfigData{})
|
||||
}
|
46
app/model/dept.go
Normal file
46
app/model/dept.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type Dept struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(11)"`
|
||||
Name string `json:"name" xorm:"not null comment('部门名称') index VARCHAR(50)"`
|
||||
Code string `json:"code" xorm:"default 'NULL' comment('部门编码') VARCHAR(150)"`
|
||||
Fullname string `json:"fullname" xorm:"default 'NULL' comment('部门全称') VARCHAR(150)"`
|
||||
Type int `json:"type" xorm:"not null default 0 comment('类型:1公司 2子公司 3部门 4小组') TINYINT(1)"`
|
||||
Pid int `json:"pid" xorm:"not null default 0 comment('上级ID') index INT(11)"`
|
||||
Sort int `json:"sort" xorm:"not null default 125 comment('排序') SMALLINT(5)"`
|
||||
Note string `json:"note" xorm:"default 'NULL' comment('备注说明') VARCHAR(255)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(11)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('创建时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"default 0 comment('更新人') INT(11)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *Dept) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *Dept) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *Dept) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *Dept) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&Dept{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *Dept) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&Dept{})
|
||||
}
|
43
app/model/dict.go
Normal file
43
app/model/dict.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type Dict struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(11)"`
|
||||
Name string `json:"name" xorm:"not null comment('字典名称') index VARCHAR(30)"`
|
||||
Code string `json:"code" xorm:"not null comment('字典值') VARCHAR(50)"`
|
||||
Sort int `json:"sort" xorm:"not null default 125 comment('显示顺序') SMALLINT(5)"`
|
||||
Note string `json:"note" xorm:"default 'NULL' comment('字典备注') VARCHAR(255)"`
|
||||
CreateUser int `json:"create_user" xorm:"default 0 comment('添加人') INT(11)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"default 0 comment('更新人') INT(11)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *Dict) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *Dict) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *Dict) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *Dict) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&Dict{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *Dict) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&Dict{})
|
||||
}
|
45
app/model/dict_data.go
Normal file
45
app/model/dict_data.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type DictData struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(11)"`
|
||||
Name string `json:"name" xorm:"not null comment('字典项名称') unique VARCHAR(50)"`
|
||||
Code string `json:"code" xorm:"not null comment('字典项值') VARCHAR(50)"`
|
||||
DictId int `json:"dictId" xorm:"not null default 0 comment('字典类型ID') INT(11)"`
|
||||
Status int `json:"status" xorm:"not null default 1 comment('状态:1在用 2停用') TINYINT(1)"`
|
||||
Note string `json:"note" xorm:"default 'NULL' comment('备注') VARCHAR(300)"`
|
||||
Sort int `json:"sort" xorm:"not null default 125 comment('显示顺序') SMALLINT(5)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(11)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"not null default 0 comment('更新人') INT(11)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标记') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *DictData) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *DictData) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *DictData) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *DictData) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&DictData{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *DictData) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&DictData{})
|
||||
}
|
46
app/model/example.go
Normal file
46
app/model/example.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type Example struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('唯一性标识') INT(11)"`
|
||||
Name string `json:"name" xorm:"default 'NULL' comment('测试名称') index VARCHAR(30)"`
|
||||
Avatar string `json:"avatar" xorm:"default 'NULL' comment('头像') VARCHAR(255)"`
|
||||
Content string `json:"content" xorm:"default 'NULL' comment('内容') VARCHAR(255)"`
|
||||
Status int `json:"status" xorm:"default 1 comment('状态:1正常 2停用') TINYINT(1)"`
|
||||
Type int `json:"type" xorm:"default 1 comment('类型:1京东 2淘宝 3拼多多 4唯品会') INT(11)"`
|
||||
IsVip int `json:"isVip" xorm:"default 2 comment('是否VIP:1是 2否') TINYINT(1)"`
|
||||
Sort int `json:"sort" xorm:"default 0 comment('排序号') INT(11)"`
|
||||
CreateUser int `json:"create_user" xorm:"default 0 comment('添加人') INT(11)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"default 0 comment('更新人') INT(11)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"default 1 comment('有效标识') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *Example) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *Example) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *Example) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *Example) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&Example{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *Example) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&Example{})
|
||||
}
|
42
app/model/example2.go
Normal file
42
app/model/example2.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type Example2 struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('唯一性标识') INT(11)"`
|
||||
Name string `json:"name" xorm:"default 'NULL' comment('演示名称') index VARCHAR(30)"`
|
||||
Status int `json:"status" xorm:"default 1 comment('状态:1正常 2停用') TINYINT(1)"`
|
||||
Sort int `json:"sort" xorm:"default 0 comment('排序号') INT(11)"`
|
||||
CreateUser int `json:"create_user" xorm:"default 0 comment('添加人') INT(11)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"default 0 comment('更新人') INT(11)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"default 1 comment('有效标识') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *Example2) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *Example2) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *Example2) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *Example2) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&Example2{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *Example2) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&Example2{})
|
||||
}
|
46
app/model/item.go
Normal file
46
app/model/item.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type Item struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('唯一性标识') INT(10)"`
|
||||
Name string `json:"name" xorm:"not null comment('站点名称') index VARCHAR(15)"`
|
||||
Type int `json:"type" xorm:"not null default 1 comment('站点类型:1普通站点 2其他') TINYINT(3)"`
|
||||
Url string `json:"url" xorm:"not null comment('站点地址') VARCHAR(60)"`
|
||||
Image string `json:"image" xorm:"not null comment('站点图片') VARCHAR(100)"`
|
||||
Status int `json:"status" xorm:"not null default 1 comment('状态:1在用 2停用') TINYINT(1)"`
|
||||
Note string `json:"note" xorm:"not null comment('站点备注') VARCHAR(255)"`
|
||||
Sort int `json:"sort" xorm:"not null default 125 comment('显示顺序') SMALLINT(5)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(10)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"not null comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"default 0 comment('更新人') INT(10)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识(1正常 0删除)') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *Item) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *Item) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *Item) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *Item) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&Item{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *Item) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&Item{})
|
||||
}
|
49
app/model/item_cate.go
Normal file
49
app/model/item_cate.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type ItemCate struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('ID') INT(11)"`
|
||||
Name string `json:"name" xorm:"default 'NULL' comment('栏目名称') VARCHAR(30)"`
|
||||
Pid int `json:"pid" xorm:"default 0 comment('父级ID') index INT(11)"`
|
||||
ItemId int `json:"itemId" xorm:"default 0 comment('站点ID') index INT(11)"`
|
||||
Pinyin string `json:"pinyin" xorm:"default 'NULL' comment('拼音(全)') VARCHAR(50)"`
|
||||
Code string `json:"code" xorm:"default 'NULL' comment('拼音(简)') VARCHAR(10)"`
|
||||
IsCover int `json:"isCover" xorm:"not null comment('是否有封面:1是 2否') TINYINT(1)"`
|
||||
Cover string `json:"cover" xorm:"default 'NULL' comment('封面') VARCHAR(50)"`
|
||||
Status int `json:"status" xorm:"default 1 comment('状态:1启用 2停用') TINYINT(1)"`
|
||||
Note string `json:"note" xorm:"default 'NULL' comment('备注') VARCHAR(200)"`
|
||||
Sort int `json:"sort" xorm:"default 125 comment('排序') INT(11)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(10)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"not null comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"default 0 comment('更新人') INT(10)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识(1正常 0删除)') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *ItemCate) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *ItemCate) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *ItemCate) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *ItemCate) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&ItemCate{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *ItemCate) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&ItemCate{})
|
||||
}
|
44
app/model/layout.go
Normal file
44
app/model/layout.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type Layout struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(10)"`
|
||||
LayoutDescId int `json:"layout_desc_id" xorm:"not null default 0 comment('布局描述ID') INT(10)"`
|
||||
Type int `json:"type" xorm:"not null default 0 comment('类型:1资讯文章') TINYINT(1)"`
|
||||
TypeId int `json:"type_id" xorm:"not null default 0 comment('对应的类型编号') INT(10)"`
|
||||
Image string `json:"image" xorm:"not null comment('图片路径') VARCHAR(150)"`
|
||||
Sort int `json:"sort" xorm:"not null default 125 comment('显示顺序') INT(11)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(10)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"not null default 0 comment('更新人') INT(10)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识(1正常 0删除)') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *Layout) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *Layout) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *Layout) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *Layout) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&Layout{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *Layout) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&Layout{})
|
||||
}
|
43
app/model/layout_desc.go
Normal file
43
app/model/layout_desc.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type LayoutDesc struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(10)"`
|
||||
LocDesc string `json:"loc_desc" xorm:"not null comment('页面位置描述') VARCHAR(255)"`
|
||||
LocId int `json:"loc_id" xorm:"not null default 0 comment('位置编号') INT(11)"`
|
||||
ItemId int `json:"item_id" xorm:"not null default 0 comment('站点ID') INT(10)"`
|
||||
Sort int `json:"sort" xorm:"not null default 125 comment('排序号') INT(11)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(10)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"not null default 0 comment('更新人') INT(10)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识(1正常 0删除)') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *LayoutDesc) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *LayoutDesc) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *LayoutDesc) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *LayoutDesc) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&LayoutDesc{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *LayoutDesc) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&LayoutDesc{})
|
||||
}
|
40
app/model/level.go
Normal file
40
app/model/level.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package model
|
||||
|
||||
import "easygoadmin/utils"
|
||||
|
||||
type Level struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(11)"`
|
||||
Name string `json:"name" xorm:"not null comment('职级名称') index VARCHAR(30)"`
|
||||
Status int `json:"status" xorm:"not null default 1 comment('状态:1正常 2停用') TINYINT(1)"`
|
||||
Sort int `json:"sort" xorm:"not null default 125 comment('显示顺序') INT(11)"`
|
||||
CreateUser int `json:"create_user" xorm:"default 0 comment('添加人') INT(11)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 0 comment('创建时间') INT(11)"`
|
||||
UpdateUser int `json:"update_user" xorm:"default 0 comment('更新人') INT(11)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 0 comment('更新时间') INT(11)"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *Level) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *Level) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *Level) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *Level) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&Level{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *Level) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&Level{})
|
||||
}
|
50
app/model/link.go
Normal file
50
app/model/link.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type Link struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('唯一性标识') INT(10)"`
|
||||
Name string `json:"name" xorm:"default 'NULL' comment('友链名称') VARCHAR(50)"`
|
||||
Type int `json:"type" xorm:"not null default 1 comment('类型:1友情链接 2合作伙伴') TINYINT(1)"`
|
||||
Url string `json:"url" xorm:"default 'NULL' comment('友链地址') VARCHAR(150)"`
|
||||
ItemId int `json:"itemId" xorm:"not null default 0 comment('站点ID') INT(10)"`
|
||||
CateId int `json:"cateId" xorm:"not null default 0 comment('栏目ID') INT(10)"`
|
||||
Platform int `json:"platform" xorm:"not null default 1 comment('平台:1PC站 2WAP站 3微信小程序 4APP应用') TINYINT(1)"`
|
||||
Form int `json:"form" xorm:"not null default 1 comment('友链形式:1文字链接 2图片链接') TINYINT(1)"`
|
||||
Image string `json:"image" xorm:"default 'NULL' comment('友链图片') VARCHAR(50)"`
|
||||
Status int `json:"status" xorm:"not null default 1 comment('状态:1在用 2停用') TINYINT(1)"`
|
||||
Sort int `json:"sort" xorm:"not null default 125 comment('显示顺序') SMALLINT(5)"`
|
||||
Note string `json:"note" xorm:"default 'NULL' comment('备注') VARCHAR(255)"`
|
||||
CreateUser int `json:"create_user" xorm:"default 0 comment('添加人') INT(10)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"default 0 comment('更新人') INT(10)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识(1正常 0删除)') index TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *Link) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *Link) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *Link) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *Link) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&Link{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *Link) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&Link{})
|
||||
}
|
124
app/model/localtime.go
Normal file
124
app/model/localtime.go
Normal file
@@ -0,0 +1,124 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LocalTime time.Time
|
||||
|
||||
func (l LocalTime) MarshalJSON() ([]byte, error) {
|
||||
b := make([]byte, 0, len(localDateTimeFormat)+2)
|
||||
b = append(b, '"')
|
||||
b = time.Time(l).AppendFormat(b, localDateTimeFormat)
|
||||
b = append(b, '"')
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (l *LocalTime) UnmarshalJSON(b []byte) error {
|
||||
now, err := time.ParseInLocation(`"`+localDateTimeFormat+`"`, string(b), time.Local)
|
||||
*l = LocalTime(now)
|
||||
return err
|
||||
}
|
||||
|
||||
func (l LocalTime) String() string {
|
||||
return time.Time(l).Format(localDateTimeFormat)
|
||||
}
|
||||
|
||||
func (l LocalTime) Now() LocalTime {
|
||||
return LocalTime(time.Now())
|
||||
}
|
||||
|
||||
func (l LocalTime) ParseTime(t time.Time) LocalTime {
|
||||
return LocalTime(t)
|
||||
}
|
||||
|
||||
func (j LocalTime) format() string {
|
||||
return time.Time(j).Format(localDateTimeFormat)
|
||||
}
|
||||
|
||||
func (j LocalTime) MarshalText() ([]byte, error) {
|
||||
return []byte(j.format()), nil
|
||||
}
|
||||
|
||||
func (l *LocalTime) FromDB(b []byte) error {
|
||||
if nil == b || len(b) == 0 {
|
||||
l = nil
|
||||
return nil
|
||||
}
|
||||
var now time.Time
|
||||
var err error
|
||||
|
||||
now, err = time.ParseInLocation(localDateTimeFormat, string(b), time.Local)
|
||||
if nil == err {
|
||||
*l = LocalTime(now)
|
||||
return nil
|
||||
}
|
||||
now, err = time.ParseInLocation("2006-01-02T15:04:05Z", string(b), time.Local)
|
||||
if nil == err {
|
||||
*l = LocalTime(now)
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
//func (t *LocalTime) Scan(v interface{}) error {
|
||||
// // Should be more strictly to check this type.
|
||||
// vt, err := time.Parse("2006-01-02 15:04:05", string(v.([]byte)))
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// *t = LocalTime(vt)
|
||||
// return nil
|
||||
//}
|
||||
|
||||
func (l *LocalTime) ToDB() ([]byte, error) {
|
||||
if nil == l {
|
||||
return nil, nil
|
||||
}
|
||||
return []byte(time.Time(*l).Format(localDateTimeFormat)), nil
|
||||
}
|
||||
|
||||
func (l *LocalTime) Value() (driver.Value, error) {
|
||||
if nil == l {
|
||||
return nil, nil
|
||||
}
|
||||
return time.Time(*l).Format(localDateTimeFormat), nil
|
||||
}
|
||||
|
||||
// XTime 1. 创建 time.Time 类型的副本 XTime;
|
||||
type XTime struct {
|
||||
time.Time
|
||||
}
|
||||
|
||||
// MarshalJSON 2. 为 Xtime 重写 MarshaJSON 方法,在此方法中实现自定义格式的转换;
|
||||
func (t XTime) MarshalJSON() ([]byte, error) {
|
||||
output := fmt.Sprintf("\"%s\"", t.Format("2006-01-02 15:04:05"))
|
||||
return []byte(output), nil
|
||||
}
|
||||
|
||||
// Value 3. 为 Xtime 实现 Value 方法,写入数据库时会调用该方法将自定义时间类型转换并写入数据库;
|
||||
func (t XTime) Value() (driver.Value, error) {
|
||||
var zeroTime time.Time
|
||||
if t.Time.UnixNano() == zeroTime.UnixNano() {
|
||||
return nil, nil
|
||||
}
|
||||
return t.Time, nil
|
||||
}
|
||||
|
||||
// Scan 4. 为 Xtime 实现 Scan 方法,读取数据库时会调用该方法将时间数据转换成自定义时间类型;
|
||||
func (t *XTime) Scan(v interface{}) error {
|
||||
value, ok := v.(time.Time)
|
||||
if ok {
|
||||
*t = XTime{Time: value}
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("can not convert %v to timestamp", v)
|
||||
}
|
||||
|
||||
func TimeToXTime(expires string) *XTime {
|
||||
var t, _ = time.ParseInLocation(localDateTimeFormat, expires, time.Local)
|
||||
return &XTime{Time: t}
|
||||
}
|
52
app/model/login_log.go
Normal file
52
app/model/login_log.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type LoginLog struct {
|
||||
Id int64 `json:"id" xorm:"pk autoincr comment('主键ID') BIGINT(20)"`
|
||||
Username string `json:"username" xorm:"default 'NULL' comment('操作账号') VARCHAR(255)"`
|
||||
Method string `json:"method" xorm:"default 'NULL' comment('操作方法') VARCHAR(30)"`
|
||||
OperUrl string `json:"operUrl" xorm:"default 'NULL' comment('请求URL') VARCHAR(255)"`
|
||||
OperIp string `json:"operIp" xorm:"default '''' comment('主机地址') VARCHAR(50)"`
|
||||
OperLocation string `json:"operLocation" xorm:"default '''' comment('操作地点') VARCHAR(255)"`
|
||||
Os string `json:"os" xorm:"default 'NULL' comment('操作系统') VARCHAR(255)"`
|
||||
RequestParam string `json:"requestParam" xorm:"default '''' comment('请求参数') VARCHAR(2000)"`
|
||||
Browser string `json:"browser" xorm:"default 'NULL' comment('浏览器') VARCHAR(255)"`
|
||||
Result string `json:"result" xorm:"default '''' comment('返回参数') VARCHAR(2000)"`
|
||||
Status int `json:"status" xorm:"default 1 comment('操作状态:0操作成功 1操作失败') TINYINT(1)"`
|
||||
Type int `json:"type" xorm:"default 0 comment('操作类型:1登录成功 2登录失败 3注销成功 2注销失败') TINYINT(1)"`
|
||||
UserAgent string `json:"user_agent" xorm:"default 'NULL' comment('代理信息') TEXT"`
|
||||
Note string `json:"note" xorm:"default 'NULL' comment('备注') VARCHAR(2000)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(11)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('操作时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"not null default 0 comment('更新人') INT(11)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *LoginLog) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *LoginLog) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *LoginLog) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *LoginLog) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&LoginLog{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *LoginLog) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&LoginLog{})
|
||||
}
|
65
app/model/member.go
Normal file
65
app/model/member.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type Member struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"`
|
||||
Openid string `json:"openid" xorm:"default 'NULL' comment('用户唯一标识') VARCHAR(50)"`
|
||||
Username string `json:"username" xorm:"not null comment('用户名') index unique VARCHAR(30)"`
|
||||
Password string `json:"password" xorm:"default 'NULL' comment('密码') CHAR(32)"`
|
||||
MemberLevel int `json:"memberLevel" xorm:"not null default 0 comment('会员等级') SMALLINT(3)"`
|
||||
Realname string `json:"realname" xorm:"default 'NULL' comment('真实姓名') VARCHAR(50)"`
|
||||
Nickname string `json:"nickname" xorm:"default 'NULL' comment('用户昵称') VARCHAR(50)"`
|
||||
Gender int `json:"gender" xorm:"not null default 3 comment('性别(1男 2女 3未知)') TINYINT(1)"`
|
||||
Avatar string `json:"avatar" xorm:"default '''' comment('用户头像') VARCHAR(180)"`
|
||||
Birthday int64 `json:"birthday" xorm:"default 'NULL' comment('出生日期') DATE"`
|
||||
ProvinceCode string `json:"province_code" xorm:"default 'NULL' comment('户籍省份编号') VARCHAR(30)"`
|
||||
CityCode string `json:"city_code" xorm:"default 'NULL' comment('户籍城市编号') VARCHAR(30)"`
|
||||
DistrictCode string `json:"district_code" xorm:"default 'NULL' comment('户籍区/县编号') VARCHAR(30)"`
|
||||
Address string `json:"address" xorm:"default 'NULL' comment('详细地址') VARCHAR(255)"`
|
||||
Intro string `json:"intro" xorm:"default 'NULL' comment('个人简介') TEXT"`
|
||||
Signature string `json:"signature" xorm:"default 'NULL' comment('个性签名') VARCHAR(30)"`
|
||||
Device int `json:"device" xorm:"not null default 0 comment('设备类型:1苹果 2安卓 3WAP站 4PC站 5后台添加') TINYINT(1)"`
|
||||
DeviceCode string `json:"device_code" xorm:"default 'NULL' comment('推送的别名') VARCHAR(40)"`
|
||||
PushAlias string `json:"push_alias" xorm:"default '''' comment('推送的别名') VARCHAR(40)"`
|
||||
Source int `json:"source" xorm:"not null default 1 comment('来源:1、APP注册;2、后台添加;') TINYINT(1)"`
|
||||
Status int `json:"status" xorm:"not null default 1 comment('是否启用 1、启用 2、停用') TINYINT(1)"`
|
||||
AppVersion string `json:"appVersion" xorm:"default '''' comment('客户端版本号') VARCHAR(30)"`
|
||||
Code string `json:"code" xorm:"default 'NULL' comment('我的推广码') VARCHAR(10)"`
|
||||
LoginIp string `json:"loginIp" xorm:"default 'NULL' comment('最近登录IP') VARCHAR(30)"`
|
||||
LoginTime int64 `json:"loginTime" xorm:"default 'NULL' comment('登录时间') DATETIME"`
|
||||
LoginRegion string `json:"loginRegion" xorm:"default 'NULL' comment('上次登录地点') VARCHAR(20)"`
|
||||
LoginCount int `json:"loginCount" xorm:"not null default 0 comment('登录总次数') INT(10)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(11)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('创建时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"not null default 0 comment('修改人') INT(11)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识:1正常 0删除') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *Member) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *Member) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *Member) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *Member) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&Member{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *Member) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&Member{})
|
||||
}
|
41
app/model/member_level.go
Normal file
41
app/model/member_level.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type MemberLevel struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(11)"`
|
||||
Name string `json:"name" xorm:"not null comment('级别名称') index VARCHAR(30)"`
|
||||
Sort int `json:"sort" xorm:"not null default 125 comment('排序号') INT(11)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(11)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('创建时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"not null default 0 comment('更新人') INT(11)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *MemberLevel) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *MemberLevel) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *MemberLevel) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *MemberLevel) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&MemberLevel{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *MemberLevel) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&MemberLevel{})
|
||||
}
|
48
app/model/menu.go
Normal file
48
app/model/menu.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package model
|
||||
|
||||
import "easygoadmin/utils"
|
||||
|
||||
type Menu struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('唯一性标识') INT(10)"`
|
||||
Name string `json:"name" xorm:"not null comment('菜单名称') index VARCHAR(30)"`
|
||||
Icon string `json:"icon" xorm:"comment('图标') VARCHAR(50)"`
|
||||
Url string `json:"url" xorm:"comment('URL地址') VARCHAR(150)"`
|
||||
Param string `json:"param" xorm:"comment('参数') VARCHAR(150)"`
|
||||
Pid int `json:"pid" xorm:"not null default 0 comment('上级ID') index INT(10)"`
|
||||
Type int `json:"type" xorm:"not null default 0 comment('类型:1模块 2导航 3菜单 4节点') TINYINT(1)"`
|
||||
Permission string `json:"permission" xorm:"comment('权限标识') VARCHAR(150)"`
|
||||
Status int `json:"status" xorm:"not null default 1 comment('是否显示:1显示 2不显示') TINYINT(1)"`
|
||||
Target int `json:"target" xorm:"not null default 1 comment('打开方式:1内部打开 2外部打开') TINYINT(1)"`
|
||||
Note string `json:"note" xorm:"comment('菜单备注') VARCHAR(255)"`
|
||||
Sort int `json:"sort" xorm:"default 125 comment('显示顺序') SMALLINT(5)"`
|
||||
CreateUser int `json:"create_user" xorm:"default 0 comment('添加人') INT(11)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 0 comment('创建时间') INT(11)"`
|
||||
UpdateUser int `json:"update_user" xorm:"default 0 comment('更新人') INT(11)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 0 comment('更新时间') INT(11)"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *Menu) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *Menu) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *Menu) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *Menu) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&Menu{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *Menu) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&Menu{})
|
||||
}
|
45
app/model/notice.go
Normal file
45
app/model/notice.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type Notice struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('通知ID') INT(11)"`
|
||||
Title string `json:"title" xorm:"not null comment('通知标题') index VARCHAR(150)"`
|
||||
Content string `json:"content" xorm:"not null comment('通知内容') TEXT"`
|
||||
Source int `json:"source" xorm:"not null comment('来源:1内部通知 2外部通知') TINYINT(1)"`
|
||||
IsTop int `json:"isTop" xorm:"not null default 2 comment('是否置顶:1是 2否') TINYINT(1)"`
|
||||
Browse int `json:"browse" xorm:"not null default 0 comment('阅读量') INT(10)"`
|
||||
Status int `json:"status" xorm:"not null default 2 comment('状态:1已发布 2待发布') TINYINT(1)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(10)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"default 0 comment('更新人') INT(10)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *Notice) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *Notice) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *Notice) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *Notice) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&Notice{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *Notice) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&Notice{})
|
||||
}
|
52
app/model/oper_log.go
Normal file
52
app/model/oper_log.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type OperLog struct {
|
||||
Id int64 `json:"id" xorm:"pk autoincr comment('主键ID') BIGINT(20)"`
|
||||
Model string `json:"model" xorm:"not null comment('操作模块') VARCHAR(150)"`
|
||||
OperType int `json:"operType" xorm:"not null default 0 comment('操作类型:0其它 1新增 2修改 3删除 4查询 5设置状态 6导入 7导出 8设置权限 9设置密码') INT(2)"`
|
||||
OperMethod string `json:"operMethod" xorm:"default 'NULL' comment('操作方法') VARCHAR(30)"`
|
||||
Username string `json:"username" xorm:"default 'NULL' comment('操作账号') VARCHAR(255)"`
|
||||
OperName string `json:"operName" xorm:"default 'NULL' comment('操作用户') VARCHAR(50)"`
|
||||
OperUrl string `json:"operUrl" xorm:"default 'NULL' comment('请求URL') VARCHAR(255)"`
|
||||
OperIp string `json:"operIp" xorm:"default '''' comment('主机地址') VARCHAR(50)"`
|
||||
OperLocation string `json:"operLocation" xorm:"default '''' comment('操作地点') VARCHAR(255)"`
|
||||
RequestParam string `json:"requestParam" xorm:"default '''' comment('请求参数') VARCHAR(2000)"`
|
||||
Result string `json:"result" xorm:"default '''' comment('返回参数') VARCHAR(2000)"`
|
||||
Status int `json:"status" xorm:"default 0 comment('日志状态:0正常日志 1错误日志') TINYINT(1)"`
|
||||
UserAgent string `json:"user_agent" xorm:"default 'NULL' comment('代理信息') TEXT"`
|
||||
Note string `json:"note" xorm:"default 'NULL' comment('备注') VARCHAR(2000)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(11)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('操作时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"not null default 0 comment('更新人') INT(11)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *OperLog) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *OperLog) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *OperLog) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *OperLog) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&OperLog{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *OperLog) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&OperLog{})
|
||||
}
|
42
app/model/position.go
Normal file
42
app/model/position.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type Position struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(11)"`
|
||||
Name string `json:"name" xorm:"default 'NULL' comment('岗位名称') index VARCHAR(30)"`
|
||||
Status int `json:"status" xorm:"default 1 comment('状态:1正常 2停用') TINYINT(1)"`
|
||||
Sort int `json:"sort" xorm:"default 125 comment('显示顺序') INT(11)"`
|
||||
CreateUser int `json:"create_user" xorm:"default 0 comment('添加人') INT(11)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"default 0 comment('更新人') INT(11)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"default 1 comment('有效标识') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *Position) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *Position) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *Position) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *Position) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&Position{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *Position) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&Position{})
|
||||
}
|
44
app/model/role.go
Normal file
44
app/model/role.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type Role struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(10)"`
|
||||
Name string `json:"name" xorm:"not null comment('角色名称') index VARCHAR(30)"`
|
||||
Code string `json:"code" xorm:"not null comment('角色标签') VARCHAR(100)"`
|
||||
Note string `json:"note" xorm:"default 'NULL' comment('备注') VARCHAR(255)"`
|
||||
Sort int `json:"sort" xorm:"not null default 125 comment('排序') SMALLINT(5)"`
|
||||
Status int `json:"status" xorm:"not null default 1 comment('状态:1正常 2停用') TINYINT(1)"`
|
||||
CreateUser int `json:"create_user" xorm:"not null default 0 comment('添加人') INT(10)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('添加时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"default 0 comment('更新人') INT(10)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识(1正常 0删除)') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *Role) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *Role) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *Role) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *Role) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&Role{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *Role) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&Role{})
|
||||
}
|
23
app/model/role_menu.go
Normal file
23
app/model/role_menu.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package model
|
||||
|
||||
import "easygoadmin/utils"
|
||||
|
||||
type RoleMenu struct {
|
||||
RoleId int `json:"role_id" xorm:"not null default 0 comment('角色ID') SMALLINT(5)"`
|
||||
MenuId int `json:"menu_id" xorm:"not null default 0 comment('菜单ID') index SMALLINT(5)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *RoleMenu) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *RoleMenu) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *RoleMenu) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&RoleMenu{})
|
||||
}
|
64
app/model/user.go
Normal file
64
app/model/user.go
Normal file
@@ -0,0 +1,64 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"easygoadmin/utils"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
Id int `json:"id" xorm:"not null pk autoincr comment('主键ID') INT(11)"`
|
||||
Realname string `json:"realname" xorm:"default 'NULL' comment('真实姓名') index VARCHAR(150)"`
|
||||
Nickname string `json:"nickname" xorm:"default 'NULL' comment('昵称') VARCHAR(150)"`
|
||||
Gender int `json:"gender" xorm:"default 3 comment('性别:1男 2女 3保密') TINYINT(1)"`
|
||||
Avatar string `json:"avatar" xorm:"default 'NULL' comment('头像') VARCHAR(150)"`
|
||||
Mobile string `json:"mobile" xorm:"default 'NULL' comment('手机号码') CHAR(11)"`
|
||||
Email string `json:"email" xorm:"default 'NULL' comment('邮箱地址') VARCHAR(30)"`
|
||||
Birthday int64 `json:"birthday" xorm:"default 'NULL' comment('出生日期') DATE"`
|
||||
DeptId int `json:"deptId" xorm:"default 0 comment('部门ID') INT(11)"`
|
||||
LevelId int `json:"levelId" xorm:"default 0 comment('职级ID') INT(11)"`
|
||||
PositionId int `json:"positionId" xorm:"default 0 comment('岗位ID') SMALLINT(3)"`
|
||||
ProvinceCode string `json:"province_code" xorm:"default 'NULL' comment('省份编号') VARCHAR(50)"`
|
||||
CityCode string `json:"city_code" xorm:"default 'NULL' comment('市区编号') VARCHAR(50)"`
|
||||
DistrictCode string `json:"district_code" xorm:"default 'NULL' comment('区县编号') VARCHAR(50)"`
|
||||
Address string `json:"address" xorm:"default 'NULL' comment('详细地址') VARCHAR(255)"`
|
||||
CityName string `json:"city_name" xorm:"default 'NULL' comment('所属城市') VARCHAR(150)"`
|
||||
Username string `json:"username" xorm:"default 'NULL' comment('登录用户名') VARCHAR(50)"`
|
||||
Password string `json:"password" xorm:"default 'NULL' comment('登录密码') VARCHAR(150)"`
|
||||
Salt string `json:"salt" xorm:"default 'NULL' comment('盐加密') VARCHAR(30)"`
|
||||
Intro string `json:"intro" xorm:"default 'NULL' comment('个人简介') VARCHAR(500)"`
|
||||
Status int `json:"status" xorm:"default 1 comment('状态:1正常 2禁用') TINYINT(1)"`
|
||||
Note string `json:"note" xorm:"default 'NULL' comment('备注') VARCHAR(500)"`
|
||||
Sort int `json:"sort" xorm:"default 125 comment('排序号') INT(11)"`
|
||||
LoginNum int `json:"login_num" xorm:"default 0 comment('登录次数') INT(11)"`
|
||||
LoginIp string `json:"login_ip" xorm:"default 'NULL' comment('最近登录IP') VARCHAR(20)"`
|
||||
LoginTime int64 `json:"login_time" xorm:"default 'NULL' comment('最近登录时间') DATETIME"`
|
||||
CreateUser int `json:"create_user" xorm:"default 0 comment('添加人') INT(10)"`
|
||||
CreateTime int64 `json:"create_time" xorm:"default 'NULL' comment('创建时间') DATETIME"`
|
||||
UpdateUser int `json:"update_user" xorm:"default 0 comment('更新人') INT(10)"`
|
||||
UpdateTime int64 `json:"update_time" xorm:"default 'NULL' comment('更新时间') DATETIME"`
|
||||
Mark int `json:"mark" xorm:"not null default 1 comment('有效标识(1正常 0删除)') TINYINT(1)"`
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *User) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *User) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
func (r *User) Update() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Update(r)
|
||||
}
|
||||
|
||||
// 删除
|
||||
func (r *User) Delete() (int64, error) {
|
||||
return utils.XormDb.Id(r.Id).Delete(&User{})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *User) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&User{})
|
||||
}
|
27
app/model/user_role.go
Normal file
27
app/model/user_role.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import "easygoadmin/utils"
|
||||
|
||||
type UserRole struct {
|
||||
UserId int `json:"user_id" xorm:"not null default 0 comment('人员ID') index INT(10)"`
|
||||
RoleId int `json:"role_id" xorm:"not null default 0 comment('角色ID') INT(10)"`
|
||||
}
|
||||
|
||||
func (r *UserRole) TableName() string {
|
||||
return "sys_user_role"
|
||||
}
|
||||
|
||||
// 根据条件查询单条数据
|
||||
func (r *UserRole) Get() (bool, error) {
|
||||
return utils.XormDb.Get(r)
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
func (r *UserRole) Insert() (int64, error) {
|
||||
return utils.XormDb.Insert(r)
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
func (r *UserRole) BatchDelete(ids ...int64) (int64, error) {
|
||||
return utils.XormDb.In("id", ids).Delete(&UserRole{})
|
||||
}
|
222
app/service/ad.go
Normal file
222
app/service/ad.go
Normal file
@@ -0,0 +1,222 @@
|
||||
/**
|
||||
* 广告-服务类
|
||||
* @author
|
||||
* @since 2021/11/15
|
||||
* @File : ad
|
||||
*/
|
||||
package service
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/vo"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var Ad = new(adService)
|
||||
|
||||
type adService struct{}
|
||||
|
||||
func (s *adService) GetList(req *dto.AdPageReq) ([]vo.AdInfoVo, int64, error) {
|
||||
// 创建查询实例
|
||||
query := utils.XormDb.Where("mark=1")
|
||||
// 查询条件
|
||||
if req != nil {
|
||||
// 广告标题
|
||||
if req.Title != "" {
|
||||
query = query.Where("title like ?", "%"+req.Title+"%")
|
||||
}
|
||||
}
|
||||
// 排序
|
||||
query = query.OrderBy("sort asc")
|
||||
// 分页
|
||||
offset := (req.Page - 1) * req.Limit
|
||||
query = query.Limit(req.Limit, offset)
|
||||
// 对象转换
|
||||
var list []model.Ad
|
||||
count, err := query.FindAndCount(&list)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 数据处理
|
||||
result := make([]vo.AdInfoVo, 0)
|
||||
for _, v := range list {
|
||||
item := vo.AdInfoVo{}
|
||||
item.Ad = v
|
||||
// 广告封面
|
||||
if v.Cover != "" {
|
||||
item.Cover = utils.GetImageUrl(v.Cover)
|
||||
}
|
||||
// 广告类型
|
||||
if v.Type > 0 {
|
||||
item.TypeName = common.AD_TYPE_LIST[v.Type]
|
||||
}
|
||||
// 所属广告位
|
||||
if v.AdSortId > 0 {
|
||||
adSortInfo := &model.AdSort{Id: v.AdSortId}
|
||||
has, err := adSortInfo.Get()
|
||||
if err == nil && has {
|
||||
item.AdSortDesc = adSortInfo.Description + " >> " + gconv.String(adSortInfo.LocId)
|
||||
}
|
||||
}
|
||||
result = append(result, item)
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
return result, count, err
|
||||
}
|
||||
|
||||
func (s *adService) Add(req *dto.AdAddReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
|
||||
// 富文本处理
|
||||
content := utils.SaveImageContent(req.Content, req.Title, "ad")
|
||||
|
||||
// 实例化对象
|
||||
var entity model.Ad
|
||||
entity.Title = req.Title
|
||||
entity.AdSortId = gconv.Int(req.AdSortId)
|
||||
entity.Type = gconv.Int(req.Type)
|
||||
entity.Description = req.Description
|
||||
entity.Content = content
|
||||
entity.Url = req.Url
|
||||
entity.Width = gconv.Int(req.Width)
|
||||
entity.Height = gconv.Int(req.Height)
|
||||
// 开始日期转换
|
||||
startTime, _ := time.Parse("2006-01-02 15:04:05", req.StartTime)
|
||||
entity.StartTime = startTime.Unix()
|
||||
// 结束日期转换
|
||||
endTime, _ := time.Parse("2006-01-02 15:04:05", req.EndTime)
|
||||
entity.EndTime = endTime.Unix()
|
||||
entity.Status = gconv.Int(req.Status)
|
||||
entity.Sort = gconv.Int(req.Sort)
|
||||
entity.Note = req.Note
|
||||
entity.CreateUser = userId
|
||||
entity.CreateTime = time.Now().Unix()
|
||||
entity.Mark = 1
|
||||
|
||||
// 广告封面
|
||||
if entity.Type == 1 {
|
||||
// 图片
|
||||
cover, err := utils.SaveImage(req.Cover, "ad")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
entity.Cover = cover
|
||||
} else {
|
||||
entity.Cover = ""
|
||||
}
|
||||
|
||||
// 插入数据
|
||||
return entity.Insert()
|
||||
}
|
||||
|
||||
func (s *adService) Update(req *dto.AdUpdateReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 查询记录
|
||||
entity := &model.Ad{Id: gconv.Int(req.Id)}
|
||||
has, err := entity.Get()
|
||||
if err != nil || !has {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 富文本处理
|
||||
content := utils.SaveImageContent(req.Content, req.Title, "ad")
|
||||
|
||||
// 设置对象
|
||||
entity.Title = req.Title
|
||||
entity.AdSortId = gconv.Int(req.AdSortId)
|
||||
entity.Type = gconv.Int(req.Type)
|
||||
entity.Description = req.Description
|
||||
entity.Content = content
|
||||
entity.Url = req.Url
|
||||
entity.Width = gconv.Int(req.Width)
|
||||
entity.Height = gconv.Int(req.Height)
|
||||
// 开始日期转换
|
||||
startTime, _ := time.Parse("2006-01-02 15:04:05", req.StartTime)
|
||||
entity.StartTime = startTime.Unix()
|
||||
// 结束日期转换
|
||||
endTime, _ := time.Parse("2006-01-02 15:04:05", req.EndTime)
|
||||
entity.EndTime = endTime.Unix()
|
||||
entity.Status = gconv.Int(req.Status)
|
||||
entity.Sort = gconv.Int(req.Sort)
|
||||
entity.Note = req.Note
|
||||
entity.UpdateUser = userId
|
||||
entity.UpdateTime = time.Now().Unix()
|
||||
|
||||
// 广告封面
|
||||
if entity.Type == 1 {
|
||||
// 图片
|
||||
cover, err := utils.SaveImage(req.Cover, "ad")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
entity.Cover = cover
|
||||
} else {
|
||||
entity.Cover = ""
|
||||
}
|
||||
|
||||
// 更新信息
|
||||
return entity.Update()
|
||||
}
|
||||
|
||||
func (s *adService) Delete(ids string) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 记录ID
|
||||
idsArr := strings.Split(ids, ",")
|
||||
if len(idsArr) == 1 {
|
||||
// 单个删除
|
||||
entity := &model.Ad{Id: gconv.Int(ids)}
|
||||
rows, err := entity.Delete()
|
||||
if err != nil || rows == 0 {
|
||||
return 0, errors.New("删除失败")
|
||||
}
|
||||
return rows, nil
|
||||
} else {
|
||||
// 批量删除
|
||||
count := 0
|
||||
for _, v := range idsArr {
|
||||
id, _ := strconv.Atoi(v)
|
||||
entity := &model.Ad{Id: id}
|
||||
rows, err := entity.Delete()
|
||||
if rows == 0 || err != nil {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
}
|
||||
return int64(count), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *adService) Status(req *dto.AdStatusReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 查询记录是否存在
|
||||
info := &model.Ad{Id: gconv.Int(req.Id)}
|
||||
has, err := info.Get()
|
||||
if err != nil || !has {
|
||||
return 0, errors.New("记录不存在")
|
||||
}
|
||||
|
||||
// 设置状态
|
||||
entity := &model.Ad{}
|
||||
entity.Id = info.Id
|
||||
entity.Status = gconv.Int(req.Status)
|
||||
entity.UpdateUser = userId
|
||||
entity.UpdateTime = time.Now().Unix()
|
||||
return entity.Update()
|
||||
}
|
167
app/service/ad_sort.go
Normal file
167
app/service/ad_sort.go
Normal file
@@ -0,0 +1,167 @@
|
||||
/**
|
||||
* 广告位-服务类
|
||||
* @author
|
||||
* @since 2021/11/15
|
||||
* @File : ad_sort
|
||||
*/
|
||||
package service
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/vo"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var AdSort = new(adSortService)
|
||||
|
||||
type adSortService struct{}
|
||||
|
||||
func (s *adSortService) GetList(req *dto.AdSortPageReq) ([]vo.AdSortInfoVo, int64, error) {
|
||||
// 创建查询实例
|
||||
query := utils.XormDb.Where("mark=1")
|
||||
// 查询条件
|
||||
if req != nil {
|
||||
// 广告位名称
|
||||
if req.Description != "" {
|
||||
query = query.Where("description like ?", "%"+req.Description+"%")
|
||||
}
|
||||
}
|
||||
// 排序
|
||||
query = query.OrderBy("sort asc")
|
||||
// 分页
|
||||
offset := (req.Page - 1) * req.Limit
|
||||
query = query.Limit(req.Limit, offset)
|
||||
// 对象转换
|
||||
var list []model.AdSort
|
||||
count, err := query.FindAndCount(&list)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 数据处理
|
||||
var result = make([]vo.AdSortInfoVo, 0)
|
||||
for _, v := range list {
|
||||
platformName, ok := common.ADSORT_PLATFORM_LIST[v.Platform]
|
||||
item := vo.AdSortInfoVo{}
|
||||
item.AdSort = v
|
||||
if ok {
|
||||
item.PlatformName = platformName
|
||||
}
|
||||
// 站点名称
|
||||
if v.ItemId > 0 {
|
||||
info := &model.Item{Id: v.ItemId}
|
||||
has, err2 := info.Get()
|
||||
if err2 == nil && has {
|
||||
item.ItemName = info.Name
|
||||
}
|
||||
}
|
||||
|
||||
// 栏目名称
|
||||
if v.CateId > 0 {
|
||||
cateName := ItemCate.GetCateName(v.CateId, ">>")
|
||||
item.CateName = cateName
|
||||
}
|
||||
|
||||
// 加入数组
|
||||
result = append(result, item)
|
||||
}
|
||||
|
||||
return result, count, nil
|
||||
}
|
||||
|
||||
func (s *adSortService) Add(req *dto.AdSortAddReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 实例化对象
|
||||
var entity model.AdSort
|
||||
entity.Description = req.Description
|
||||
entity.ItemId = gconv.Int(req.ItemId)
|
||||
entity.CateId = gconv.Int(req.CateId)
|
||||
entity.LocId = gconv.Int(req.LocId)
|
||||
entity.Platform = gconv.Int(req.Platform)
|
||||
entity.Sort = gconv.Int(req.Sort)
|
||||
entity.CreateUser = userId
|
||||
entity.CreateTime = time.Now().Unix()
|
||||
entity.Mark = 1
|
||||
|
||||
// 插入数据
|
||||
return entity.Insert()
|
||||
}
|
||||
|
||||
func (s *adSortService) Update(req *dto.AdSortUpdateReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 查询记录
|
||||
entity := &model.AdSort{Id: gconv.Int(req.Id)}
|
||||
has, err := entity.Get()
|
||||
if err != nil || !has {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 设置对象
|
||||
entity.Description = req.Description
|
||||
entity.ItemId = gconv.Int(req.ItemId)
|
||||
entity.CateId = gconv.Int(req.CateId)
|
||||
entity.LocId = gconv.Int(req.LocId)
|
||||
entity.Platform = gconv.Int(req.Platform)
|
||||
entity.Sort = gconv.Int(req.Sort)
|
||||
entity.UpdateUser = userId
|
||||
entity.UpdateTime = time.Now().Unix()
|
||||
|
||||
// 更新记录
|
||||
return entity.Update()
|
||||
}
|
||||
|
||||
func (s *adSortService) Delete(ids string) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 记录ID
|
||||
idsArr := strings.Split(ids, ",")
|
||||
if len(idsArr) == 1 {
|
||||
// 单个删除
|
||||
entity := &model.AdSort{Id: gconv.Int(ids)}
|
||||
rows, err := entity.Delete()
|
||||
if err != nil || rows == 0 {
|
||||
return 0, errors.New("删除失败")
|
||||
}
|
||||
return rows, nil
|
||||
} else {
|
||||
// 批量删除
|
||||
count := 0
|
||||
for _, v := range idsArr {
|
||||
id, _ := strconv.Atoi(v)
|
||||
entity := &model.AdSort{Id: id}
|
||||
rows, err := entity.Delete()
|
||||
if rows == 0 || err != nil {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
}
|
||||
return int64(count), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *adSortService) GetAdSortList() []vo.AdSortInfoVo {
|
||||
// 查询广告位列表
|
||||
var list []model.AdSort
|
||||
utils.XormDb.Where("mark=1").OrderBy("sort asc").Find(&list)
|
||||
// 数据处理
|
||||
result := make([]vo.AdSortInfoVo, 0)
|
||||
for _, v := range list {
|
||||
item := vo.AdSortInfoVo{}
|
||||
item.AdSort = v
|
||||
item.Description = v.Description + " >> " + gconv.String(v.LocId)
|
||||
result = append(result, item)
|
||||
}
|
||||
return result
|
||||
}
|
189
app/service/city.go
Normal file
189
app/service/city.go
Normal file
@@ -0,0 +1,189 @@
|
||||
/**
|
||||
* 城市-服务类
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : city
|
||||
*/
|
||||
package service
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/vo"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/gconv"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var City = new(cityService)
|
||||
|
||||
type cityService struct{}
|
||||
|
||||
func (s *cityService) GetList(req *dto.CityQueryReq) []vo.CityInfoVo {
|
||||
// 创建查询对象
|
||||
query := utils.XormDb.Where("mark=1")
|
||||
// 查询条件
|
||||
if req != nil {
|
||||
// 上级ID
|
||||
query = query.Where("pid=?", req.Pid)
|
||||
// 城市名称
|
||||
if req.Name != "" {
|
||||
query = query.Where("name like ?", "%"+req.Name+"%")
|
||||
}
|
||||
}
|
||||
// 排序
|
||||
query = query.OrderBy("sort asc")
|
||||
// 对象转换
|
||||
var list []model.City
|
||||
query.FindAndCount(&list)
|
||||
|
||||
// 数据解析
|
||||
var result = make([]vo.CityInfoVo, 0)
|
||||
// 遍历数据
|
||||
for _, v := range list {
|
||||
item := vo.CityInfoVo{}
|
||||
item.City = v
|
||||
if v.Level < 3 {
|
||||
item.HaveChild = true
|
||||
} else {
|
||||
item.HaveChild = false
|
||||
}
|
||||
result = append(result, item)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (s *cityService) Add(req *dto.CityAddReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 实例化对象
|
||||
var entity model.City
|
||||
entity.Name = req.Name
|
||||
entity.Pid = gconv.Int(req.Pid)
|
||||
entity.Level = gconv.Int(req.Level)
|
||||
entity.Citycode = req.Citycode
|
||||
entity.PAdcode = req.PAdcode
|
||||
entity.Adcode = req.Adcode
|
||||
entity.Lng = req.Lng
|
||||
entity.Lat = req.Lat
|
||||
entity.Sort = gconv.Int(req.Sort)
|
||||
entity.CreateUser = userId
|
||||
entity.CreateTime = time.Now().Unix()
|
||||
entity.Mark = 1
|
||||
|
||||
// 插入记录
|
||||
return entity.Insert()
|
||||
}
|
||||
|
||||
func (s *cityService) Update(req *dto.CityUpdateReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 查询记录
|
||||
entity := &model.City{Id: gconv.Int(req.Id)}
|
||||
has, err := entity.Get()
|
||||
if err != nil || !has {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 设置对象属性
|
||||
entity.Name = req.Name
|
||||
entity.Pid = gconv.Int(req.Pid)
|
||||
entity.Level = gconv.Int(req.Level)
|
||||
entity.Citycode = req.Citycode
|
||||
entity.PAdcode = req.PAdcode
|
||||
entity.Adcode = req.Adcode
|
||||
entity.Lng = req.Lng
|
||||
entity.Lat = req.Lat
|
||||
entity.Sort = gconv.Int(req.Sort)
|
||||
entity.UpdateUser = userId
|
||||
entity.UpdateTime = time.Now().Unix()
|
||||
|
||||
// 更新记录
|
||||
return entity.Update()
|
||||
}
|
||||
|
||||
func (s *cityService) Delete(ids string) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 记录ID
|
||||
idsArr := strings.Split(ids, ",")
|
||||
if len(idsArr) == 1 {
|
||||
// 单个删除
|
||||
entity := &model.City{Id: gconv.Int(ids)}
|
||||
rows, err := entity.Delete()
|
||||
if err != nil || rows == 0 {
|
||||
return 0, errors.New("删除失败")
|
||||
}
|
||||
return rows, nil
|
||||
} else {
|
||||
// 批量删除
|
||||
count := 0
|
||||
for _, v := range idsArr {
|
||||
id, _ := strconv.Atoi(v)
|
||||
entity := &model.City{Id: id}
|
||||
rows, err := entity.Delete()
|
||||
if rows == 0 || err != nil {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
}
|
||||
return int64(count), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *cityService) GetChilds(cityCode string) ([]model.City, error) {
|
||||
var info model.City
|
||||
has, err := utils.XormDb.Where("citycode=?", cityCode).Get(&info)
|
||||
if err != nil || !has {
|
||||
return nil, errors.New("城市不能存在")
|
||||
}
|
||||
list := make([]model.City, 0)
|
||||
utils.XormDb.Where("pid=? and mark=1", info.Id).Find(&list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (s *cityService) GetCityName(cityCode string, delimiter string) string {
|
||||
//info := &model.City{Citycode: cityCode}
|
||||
var info model.City
|
||||
has, err := utils.XormDb.Where("citycode=?", cityCode).Get(&info)
|
||||
if err != nil || !has {
|
||||
return ""
|
||||
}
|
||||
// 城市ID
|
||||
cityId := info.Id
|
||||
// 声明数组
|
||||
list := make([]string, 0)
|
||||
for {
|
||||
if cityId <= 0 {
|
||||
// 退出
|
||||
break
|
||||
}
|
||||
// 业务处理
|
||||
info = model.City{}
|
||||
has2, err2 := utils.XormDb.Id(cityId).Get(&info)
|
||||
if err2 != nil || !has2 {
|
||||
break
|
||||
}
|
||||
// 上级栏目ID
|
||||
cityId = info.Pid
|
||||
// 加入数组
|
||||
list = append(list, info.Name)
|
||||
}
|
||||
// 结果数据处理
|
||||
if len(list) > 0 {
|
||||
// 数组反转
|
||||
utils.Reverse(&list)
|
||||
// 拼接字符串
|
||||
return strings.Join(list, delimiter)
|
||||
}
|
||||
return ""
|
||||
}
|
100
app/service/config.go
Normal file
100
app/service/config.go
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* 配置-服务类
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : config
|
||||
*/
|
||||
package service
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/gconv"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var Config = new(configService)
|
||||
|
||||
type configService struct{}
|
||||
|
||||
func (s *configService) GetList() []model.Config {
|
||||
// 创建查询对象
|
||||
query := utils.XormDb.
|
||||
Where("mark=1").
|
||||
OrderBy("sort asc")
|
||||
// 对象转换
|
||||
var list []model.Config
|
||||
query.FindAndCount(&list)
|
||||
return list
|
||||
}
|
||||
|
||||
func (s *configService) Add(req *dto.ConfigAddReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 实例化对象
|
||||
var entity model.Config
|
||||
entity.Name = req.Name
|
||||
entity.Sort = req.Sort
|
||||
entity.CreateUser = userId
|
||||
entity.CreateTime = time.Now().Unix()
|
||||
entity.Mark = 1
|
||||
|
||||
// 插入记录
|
||||
return entity.Insert()
|
||||
}
|
||||
|
||||
func (s *configService) Update(req *dto.ConfigUpdateReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 查询记录
|
||||
entity := &model.Config{Id: req.Id}
|
||||
has, err := entity.Get()
|
||||
if err != nil || !has {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 设置对象
|
||||
entity.Name = req.Name
|
||||
entity.Sort = req.Sort
|
||||
entity.UpdateUser = userId
|
||||
entity.UpdateTime = time.Now().Unix()
|
||||
|
||||
// 更新数据
|
||||
return entity.Update()
|
||||
}
|
||||
|
||||
func (s *configService) Delete(ids string) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 记录ID
|
||||
idsArr := strings.Split(ids, ",")
|
||||
if len(idsArr) == 1 {
|
||||
// 单个删除
|
||||
entity := &model.Config{Id: gconv.Int(ids)}
|
||||
rows, err := entity.Delete()
|
||||
if err != nil || rows == 0 {
|
||||
return 0, errors.New("删除失败")
|
||||
}
|
||||
return rows, nil
|
||||
} else {
|
||||
// 批量删除
|
||||
count := 0
|
||||
for _, v := range idsArr {
|
||||
id, _ := strconv.Atoi(v)
|
||||
entity := &model.Config{Id: id}
|
||||
rows, err := entity.Delete()
|
||||
if rows == 0 || err != nil {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
}
|
||||
return int64(count), nil
|
||||
}
|
||||
}
|
159
app/service/config_data.go
Normal file
159
app/service/config_data.go
Normal file
@@ -0,0 +1,159 @@
|
||||
/**
|
||||
* 配置数据-服务类
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : config_data
|
||||
*/
|
||||
package service
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/vo"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/common"
|
||||
"easygoadmin/utils/gconv"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ConfigData = new(configDataService)
|
||||
|
||||
type configDataService struct{}
|
||||
|
||||
func (s *configDataService) GetList(req *dto.ConfigDataPageReq) ([]vo.ConfigDataVo, int64, error) {
|
||||
// 创建查询对象
|
||||
query := utils.XormDb.Where("config_id=?", req.ConfigId).Where("mark=1")
|
||||
// 查询条件
|
||||
if req != nil {
|
||||
// 字典项名称
|
||||
if req.Title != "" {
|
||||
query = query.Where("title like ?", "%"+req.Title+"%")
|
||||
}
|
||||
}
|
||||
// 排序
|
||||
query = query.OrderBy("sort asc")
|
||||
// 分页
|
||||
offset := (req.Page - 1) * req.Limit
|
||||
query = query.Limit(req.Limit, offset)
|
||||
// 对象转换
|
||||
var list []model.ConfigData
|
||||
count, err := query.FindAndCount(&list)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 数据源处理
|
||||
var result = make([]vo.ConfigDataVo, 0)
|
||||
for _, v := range list {
|
||||
typeName, ok := common.CONFIG_DATA_TYPE_LIST[v.Type]
|
||||
item := vo.ConfigDataVo{}
|
||||
item.ConfigData = v
|
||||
if ok {
|
||||
item.TypeName = typeName
|
||||
}
|
||||
result = append(result, item)
|
||||
}
|
||||
return result, count, nil
|
||||
}
|
||||
|
||||
func (s *configDataService) Add(req *dto.ConfigDataAddReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 实例化对象
|
||||
var entity model.ConfigData
|
||||
entity.Title = req.Title
|
||||
entity.Code = req.Code
|
||||
entity.Value = req.Value
|
||||
entity.Options = req.Options
|
||||
entity.ConfigId = gconv.Int(req.ConfigId)
|
||||
entity.Type = req.Type
|
||||
entity.Sort = gconv.Int(req.Sort)
|
||||
entity.Note = req.Note
|
||||
entity.CreateUser = userId
|
||||
entity.CreateTime = time.Now().Unix()
|
||||
entity.Mark = 1
|
||||
|
||||
// 插入数据
|
||||
return entity.Insert()
|
||||
}
|
||||
|
||||
func (s *configDataService) Update(req *dto.ConfigDataUpdateReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 查询记录
|
||||
entity := &model.ConfigData{Id: gconv.Int(req.Id)}
|
||||
has, err := entity.Get()
|
||||
if err != nil || !has {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 设置对象
|
||||
entity.Title = req.Title
|
||||
entity.Code = req.Code
|
||||
entity.Value = req.Value
|
||||
entity.Options = req.Options
|
||||
entity.ConfigId = gconv.Int(req.ConfigId)
|
||||
entity.Type = req.Type
|
||||
entity.Sort = gconv.Int(req.Sort)
|
||||
entity.Note = req.Note
|
||||
entity.UpdateUser = userId
|
||||
entity.UpdateTime = time.Now().Unix()
|
||||
|
||||
// 更新记录
|
||||
return entity.Update()
|
||||
}
|
||||
|
||||
func (s *configDataService) Delete(ids string) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 记录ID
|
||||
idsArr := strings.Split(ids, ",")
|
||||
if len(idsArr) == 1 {
|
||||
// 单个删除
|
||||
entity := &model.ConfigData{Id: gconv.Int(ids)}
|
||||
rows, err := entity.Delete()
|
||||
if err != nil || rows == 0 {
|
||||
return 0, errors.New("删除失败")
|
||||
}
|
||||
return rows, nil
|
||||
} else {
|
||||
// 批量删除
|
||||
count := 0
|
||||
for _, v := range idsArr {
|
||||
id, _ := strconv.Atoi(v)
|
||||
entity := &model.ConfigData{Id: id}
|
||||
rows, err := entity.Delete()
|
||||
if rows == 0 || err != nil {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
}
|
||||
return int64(count), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *configDataService) Status(req *dto.ConfigDataStatusReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 查询记录是否存在
|
||||
info := &model.ConfigData{Id: gconv.Int(req.Id)}
|
||||
has, err := info.Get()
|
||||
if err != nil || !has {
|
||||
return 0, errors.New("记录不存在")
|
||||
}
|
||||
|
||||
// 设置状态
|
||||
entity := &model.ConfigData{}
|
||||
entity.Id = info.Id
|
||||
entity.Status = gconv.Int(req.Status)
|
||||
entity.UpdateUser = userId
|
||||
entity.UpdateTime = time.Now().Unix()
|
||||
return entity.Update()
|
||||
}
|
164
app/service/customer.go
Normal file
164
app/service/customer.go
Normal file
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* 用户-服务类
|
||||
* @author
|
||||
* @since 2021/11/11
|
||||
* @File : user
|
||||
*/
|
||||
package service
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/gconv"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var Customer = new(customerService)
|
||||
|
||||
type customerService struct{}
|
||||
|
||||
// 搜索
|
||||
func (s *customerService) Search(req *dto.CustomerSearchReq) map[string]interface{} {
|
||||
mobile := req.Mobile
|
||||
outTradeNo := req.OutTradeNo
|
||||
|
||||
reData := map[string]interface{}{}
|
||||
|
||||
userList := make([]model.PbUser, 0)
|
||||
couponList := make([]model.PbOrderCoupon, 0)
|
||||
rechargeList := make([]model.PbOrderRecharge, 0)
|
||||
reData["coupon_orders"] = couponList
|
||||
reData["recharge_orders"] = rechargeList
|
||||
if mobile == "" && outTradeNo == "" {
|
||||
return reData
|
||||
}
|
||||
|
||||
userIdStr := ""
|
||||
userIdArr := make([]string, 0)
|
||||
|
||||
if mobile != "" {
|
||||
userList = PbUser.GetListByMobile(mobile, "")
|
||||
if len(userList) > 0 {
|
||||
for _, item := range userList {
|
||||
userIdArr = append(userIdArr, gconv.String(item.Id))
|
||||
}
|
||||
userIdStr = fmt.Sprintf("user_id in (%s)", strings.Join(userIdArr, ","))
|
||||
}
|
||||
}
|
||||
queryCoupon := utils.XormDb.Where("status != 1")
|
||||
queryRecharge := utils.XormDb.Where("status != 1")
|
||||
if userIdStr != "" {
|
||||
queryCoupon = queryCoupon.Where(userIdStr)
|
||||
queryRecharge = utils.XormDb.
|
||||
Where("re_mobile like ? AND status != 1", fmt.Sprintf("%s%s%s", "%", mobile, "%")).
|
||||
Or(fmt.Sprintf("%s%s", userIdStr, " AND status != 1"))
|
||||
}
|
||||
if outTradeNo != "" {
|
||||
if strings.Contains(outTradeNo, "coupon") {
|
||||
queryCoupon = queryCoupon.Where("out_trade_no like ?", fmt.Sprintf("%s%s%s", "%", outTradeNo, "%"))
|
||||
}
|
||||
if strings.Contains(outTradeNo, "recharge") {
|
||||
queryRecharge = queryRecharge.Where("out_trade_no like ?", fmt.Sprintf("%s%s%s", "%", outTradeNo, "%"))
|
||||
}
|
||||
}
|
||||
queryCoupon.Desc("id").
|
||||
Limit(20).
|
||||
Find(&couponList)
|
||||
queryRecharge.Desc("id").
|
||||
Limit(20).
|
||||
Find(&rechargeList)
|
||||
|
||||
reData["coupon_orders"] = couponList
|
||||
reData["recharge_orders"] = rechargeList
|
||||
|
||||
return reData
|
||||
}
|
||||
|
||||
func (s *customerService) CouponRefund(req *dto.CustomerCouponRefundReq, workId int) (string, bool) {
|
||||
msg := ""
|
||||
orderInfo := &model.PbOrderCoupon{Id: gconv.Int(req.Ids)}
|
||||
has, err := orderInfo.Get()
|
||||
//状态:1=待支付,2=待使用,3=已使用,4=已退款,5=投诉中
|
||||
if err != nil || !has {
|
||||
return "记录不存在", false
|
||||
}
|
||||
if orderInfo.Status == 1 {
|
||||
return "订单未支付", false
|
||||
}
|
||||
if orderInfo.Status == 4 {
|
||||
return "订单已退款", false
|
||||
}
|
||||
dom, ok := utils.Refund(orderInfo.PayId, orderInfo.OutTradeNo, orderInfo.TransactionId, orderInfo.WxComplaintId, orderInfo.PayAmount)
|
||||
if !ok {
|
||||
return "退款失败", false
|
||||
}
|
||||
if dom.Get("code").Int() == 1 {
|
||||
update := new(model.PbOrderCoupon)
|
||||
update.Status = 4
|
||||
update.RefundTime = model.XTime{Time: time.Now()}
|
||||
update.Workid = int64(workId)
|
||||
utils.XormDb.Id(orderInfo.Id).Cols("status, refund_time, work_id").Update(update)
|
||||
|
||||
// 创建查询实例
|
||||
query := utils.XormDb.Where("user_id = ?", orderInfo.UserId)
|
||||
|
||||
// 对象转换
|
||||
couponInfo := make([]model.PbUserCoupon, 0)
|
||||
errCoupon := query.Find(&couponInfo)
|
||||
if errCoupon == nil {
|
||||
for _, item := range couponInfo {
|
||||
if item.CouponAmount == 5 {
|
||||
utils.XormDb.Exec("UPDATE pb_user_coupon SET left_num = left_num - 10, total_num = total_num - 10 where id = ? ", item.Id)
|
||||
} else if item.CouponAmount == 10 {
|
||||
utils.XormDb.Exec("UPDATE pb_user_coupon SET left_num = left_num - 5, total_num = total_num - 5 where id = ? ", item.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "退款成功", true
|
||||
}
|
||||
msg = dom.Get("msg").String()
|
||||
return msg, false
|
||||
}
|
||||
|
||||
func (s *customerService) RechargeRefund(req *dto.CustomerCouponRefundReq, workId int) (string, bool) {
|
||||
|
||||
orderInfo := &model.PbOrderRecharge{Id: gconv.Int(req.Ids)}
|
||||
has, err := orderInfo.Get()
|
||||
//状态:1待支付 2未使用 3已使用 4补单中 5充值成功 6充值失败 7退款中 8已退款
|
||||
if err != nil || !has {
|
||||
return "记录不存在", false
|
||||
}
|
||||
if orderInfo.Status == 1 {
|
||||
return "订单未支付", false
|
||||
}
|
||||
if orderInfo.Status == 4 {
|
||||
return "补单中 无法退款", false
|
||||
}
|
||||
if orderInfo.Status == 7 {
|
||||
return "订单退款中", false
|
||||
}
|
||||
if orderInfo.Status == 8 {
|
||||
return "订单已退款", false
|
||||
}
|
||||
str, ok := utils.RechargeRefund(orderInfo.RechargeType, orderInfo.RechargeNo, orderInfo.OutTradeNo)
|
||||
if !ok {
|
||||
return "退款失败", false
|
||||
}
|
||||
|
||||
update := new(model.PbOrderRecharge)
|
||||
update.WorkId = int64(workId)
|
||||
if ok {
|
||||
update.Status = 7
|
||||
update.RefundTime = model.XTime{Time: time.Now()}
|
||||
utils.XormDb.Id(orderInfo.Id).Cols("status, refund_time, work_id").Update(update)
|
||||
return str, true
|
||||
} else {
|
||||
utils.XormDb.Id(orderInfo.Id).Cols("work_id").Update(update)
|
||||
return str, false
|
||||
}
|
||||
|
||||
}
|
171
app/service/dept.go
Normal file
171
app/service/dept.go
Normal file
@@ -0,0 +1,171 @@
|
||||
/**
|
||||
* 部门-服务类
|
||||
* @author
|
||||
* @since 2021/9/13
|
||||
* @File : dept
|
||||
*/
|
||||
package service
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/app/vo"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/gconv"
|
||||
"errors"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var Dept = new(deptService)
|
||||
|
||||
type deptService struct{}
|
||||
|
||||
func (s *deptService) GetList(req *dto.DeptPageReq) ([]model.Dept, error) {
|
||||
// 创建查询实例
|
||||
query := utils.XormDb.Where("mark=1")
|
||||
// 查询条件
|
||||
if req != nil {
|
||||
// 部门名称
|
||||
if req.Name != "" {
|
||||
query = query.Where("name like ?", "%"+req.Name+"%")
|
||||
}
|
||||
}
|
||||
// 排序
|
||||
query = query.OrderBy("sort")
|
||||
// 查询数据
|
||||
var list []model.Dept
|
||||
err := query.Find(&list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (s *deptService) Add(req *dto.DeptAddReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 实例化对象
|
||||
var entity model.Dept
|
||||
entity.Name = req.Name
|
||||
entity.Code = req.Code
|
||||
entity.Fullname = req.Fullname
|
||||
entity.Type = gconv.Int(req.Type)
|
||||
entity.Pid = gconv.Int(req.Pid)
|
||||
entity.Sort = gconv.Int(req.Sort)
|
||||
entity.Note = req.Note
|
||||
entity.CreateUser = userId
|
||||
entity.CreateTime = time.Now().Unix()
|
||||
entity.Mark = 1
|
||||
// 插入记录
|
||||
rows, err := entity.Insert()
|
||||
if err != nil || rows == 0 {
|
||||
return 0, errors.New("添加失败")
|
||||
}
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
func (s *deptService) Update(req *dto.DeptUpdateReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 查询记录
|
||||
entity := &model.Dept{Id: gconv.Int(req.Id)}
|
||||
has, err := entity.Get()
|
||||
if err != nil || !has {
|
||||
return 0, err
|
||||
}
|
||||
// 设置参数
|
||||
entity.Name = req.Name
|
||||
entity.Code = req.Code
|
||||
entity.Fullname = req.Fullname
|
||||
entity.Type = gconv.Int(req.Type)
|
||||
entity.Pid = gconv.Int(req.Pid)
|
||||
entity.Sort = gconv.Int(req.Sort)
|
||||
entity.Note = req.Note
|
||||
entity.UpdateUser = userId
|
||||
entity.UpdateTime = time.Now().Unix()
|
||||
// 更新记录
|
||||
rows, err := entity.Update()
|
||||
if err != nil || rows == 0 {
|
||||
return 0, err
|
||||
}
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
func (s *deptService) Delete(ids string) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 记录ID
|
||||
idsArr := strings.Split(ids, ",")
|
||||
if len(idsArr) == 1 {
|
||||
// 单个删除
|
||||
entity := model.Dept{Id: gconv.Int(ids)}
|
||||
rows, err := entity.Delete()
|
||||
if err != nil || rows == 0 {
|
||||
return 0, err
|
||||
}
|
||||
return rows, nil
|
||||
} else {
|
||||
// 批量删除
|
||||
count := 0
|
||||
for _, v := range idsArr {
|
||||
id, _ := strconv.Atoi(v)
|
||||
entity := &model.Dept{Id: id}
|
||||
rows, err := entity.Delete()
|
||||
if rows == 0 || err != nil {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
}
|
||||
return int64(count), nil
|
||||
}
|
||||
}
|
||||
|
||||
// 获取子级菜单
|
||||
func (s *deptService) GetDeptTreeList() ([]*vo.DeptTreeNode, error) {
|
||||
var deptNode vo.DeptTreeNode
|
||||
// 查询列表
|
||||
list := make([]model.Dept, 0)
|
||||
utils.XormDb.Where("mark=1").Cols("id,name,pid").OrderBy("sort asc").Find(&list)
|
||||
makeDeptTree(list, &deptNode)
|
||||
return deptNode.Children, nil
|
||||
}
|
||||
|
||||
// 递归生成分类列表
|
||||
func makeDeptTree(cate []model.Dept, tn *vo.DeptTreeNode) {
|
||||
for _, c := range cate {
|
||||
if c.Pid == tn.Id {
|
||||
child := &vo.DeptTreeNode{}
|
||||
child.Dept = c
|
||||
tn.Children = append(tn.Children, child)
|
||||
makeDeptTree(cate, child)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 数据源转换
|
||||
func (s *deptService) MakeList(data []*vo.DeptTreeNode) map[int]string {
|
||||
deptList := make(map[int]string, 0)
|
||||
if reflect.ValueOf(data).Kind() == reflect.Slice {
|
||||
// 一级栏目
|
||||
for _, val := range data {
|
||||
deptList[val.Id] = val.Name
|
||||
|
||||
// 二级栏目
|
||||
for _, v := range val.Children {
|
||||
deptList[v.Id] = "|--" + v.Name
|
||||
|
||||
// 三级栏目
|
||||
for _, vt := range v.Children {
|
||||
deptList[vt.Id] = "|--|--" + vt.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return deptList
|
||||
}
|
106
app/service/dict.go
Normal file
106
app/service/dict.go
Normal file
@@ -0,0 +1,106 @@
|
||||
/**
|
||||
* 字典-服务类
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : dict
|
||||
*/
|
||||
package service
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/gconv"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var Dict = new(dictService)
|
||||
|
||||
type dictService struct{}
|
||||
|
||||
func (s *dictService) GetList() []model.Dict {
|
||||
// 创建查询对象
|
||||
query := utils.XormDb.
|
||||
Where("mark=1").
|
||||
OrderBy("sort asc")
|
||||
// 对象转换
|
||||
var list []model.Dict
|
||||
query.FindAndCount(&list)
|
||||
return list
|
||||
}
|
||||
|
||||
func (s *dictService) Add(req *dto.DictAddReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 实例化对象
|
||||
var entity model.Dict
|
||||
entity.Name = req.Name
|
||||
entity.Code = req.Code
|
||||
entity.Sort = req.Sort
|
||||
entity.Note = req.Note
|
||||
entity.CreateUser = userId
|
||||
entity.CreateTime = time.Now().Unix()
|
||||
entity.Mark = 1
|
||||
|
||||
// 插入记录
|
||||
return entity.Insert()
|
||||
}
|
||||
|
||||
func (s *dictService) Update(req *dto.DictUpdateReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 查询记录
|
||||
entity := &model.Dict{Id: req.Id}
|
||||
has, err := entity.Get()
|
||||
if err != nil || !has {
|
||||
return 0, err
|
||||
}
|
||||
if entity == nil {
|
||||
return 0, errors.New("记录不存在")
|
||||
}
|
||||
|
||||
// 设置对象
|
||||
entity.Name = req.Name
|
||||
entity.Code = req.Code
|
||||
entity.Sort = req.Sort
|
||||
entity.Note = req.Note
|
||||
entity.UpdateUser = userId
|
||||
entity.UpdateTime = time.Now().Unix()
|
||||
|
||||
return entity.Update()
|
||||
}
|
||||
|
||||
func (s *dictService) Delete(ids string) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 记录ID
|
||||
idsArr := strings.Split(ids, ",")
|
||||
if len(idsArr) == 1 {
|
||||
// 单个删除
|
||||
entity := &model.Dict{Id: gconv.Int(ids)}
|
||||
rows, err := entity.Delete()
|
||||
if err != nil || rows == 0 {
|
||||
return 0, errors.New("删除失败")
|
||||
}
|
||||
return rows, nil
|
||||
} else {
|
||||
// 批量删除
|
||||
count := 0
|
||||
for _, v := range idsArr {
|
||||
id, _ := strconv.Atoi(v)
|
||||
entity := &model.Dict{Id: id}
|
||||
rows, err := entity.Delete()
|
||||
if rows == 0 || err != nil {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
}
|
||||
return int64(count), nil
|
||||
}
|
||||
}
|
115
app/service/dict_data.go
Normal file
115
app/service/dict_data.go
Normal file
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* 字典数据-服务类
|
||||
* @author
|
||||
* @since 2021/11/13
|
||||
* @File : dict_data
|
||||
*/
|
||||
package service
|
||||
|
||||
import (
|
||||
"easygoadmin/app/dto"
|
||||
"easygoadmin/app/model"
|
||||
"easygoadmin/utils"
|
||||
"easygoadmin/utils/gconv"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
var DictData = new(dictDataService)
|
||||
|
||||
type dictDataService struct{}
|
||||
|
||||
func (s *dictDataService) GetList(req *dto.DictDataPageReq) ([]model.DictData, int64, error) {
|
||||
// 创建查询对象
|
||||
query := utils.XormDb.Where("dict_id=?", req.DictId).Where("mark=1")
|
||||
// 查询条件
|
||||
if req != nil {
|
||||
// 字典项名称
|
||||
if req.Name != "" {
|
||||
query = query.Where("name like ?", "%"+req.Name+"%")
|
||||
}
|
||||
}
|
||||
// 排序
|
||||
query = query.OrderBy("sort asc")
|
||||
// 分页
|
||||
offset := (req.Page - 1) * req.Limit
|
||||
query = query.Limit(req.Limit, offset)
|
||||
// 对象转换
|
||||
var list []model.DictData
|
||||
count, err := query.FindAndCount(&list)
|
||||
return list, count, err
|
||||
}
|
||||
|
||||
func (s *dictDataService) Add(req *dto.DictDataAddReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 实例化对象
|
||||
var entity model.DictData
|
||||
entity.DictId = gconv.Int(req.DictId)
|
||||
entity.Name = req.Name
|
||||
entity.Code = req.Code
|
||||
entity.Sort = gconv.Int(req.Sort)
|
||||
entity.Note = req.Note
|
||||
entity.CreateUser = userId
|
||||
entity.CreateTime = time.Now().Unix()
|
||||
entity.Mark = 1
|
||||
|
||||
// 插入记录
|
||||
return entity.Insert()
|
||||
}
|
||||
|
||||
func (s *dictDataService) Update(req *dto.DictDataUpdateReq, userId int) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 查询记录
|
||||
entity := &model.DictData{Id: gconv.Int(req.Id)}
|
||||
has, err := entity.Get()
|
||||
if err != nil || !has {
|
||||
return 0, err
|
||||
}
|
||||
// 设置对象
|
||||
entity.DictId = gconv.Int(req.DictId)
|
||||
entity.Name = req.Name
|
||||
entity.Code = req.Code
|
||||
entity.Sort = gconv.Int(req.Sort)
|
||||
entity.Note = req.Note
|
||||
entity.UpdateUser = userId
|
||||
entity.UpdateTime = time.Now().Unix()
|
||||
|
||||
// 更新记录
|
||||
return entity.Update()
|
||||
}
|
||||
|
||||
func (s *dictDataService) Delete(ids string) (int64, error) {
|
||||
if utils.AppDebug() {
|
||||
return 0, errors.New("演示环境,暂无权限操作")
|
||||
}
|
||||
// 记录ID
|
||||
idsArr := strings.Split(ids, ",")
|
||||
if len(idsArr) == 1 {
|
||||
// 单个删除
|
||||
entity := &model.DictData{Id: gconv.Int(ids)}
|
||||
rows, err := entity.Delete()
|
||||
if err != nil || rows == 0 {
|
||||
return 0, errors.New("删除失败")
|
||||
}
|
||||
return rows, nil
|
||||
} else {
|
||||
// 批量删除
|
||||
count := 0
|
||||
for _, v := range idsArr {
|
||||
id, _ := strconv.Atoi(v)
|
||||
entity := &model.DictData{Id: id}
|
||||
rows, err := entity.Delete()
|
||||
if rows == 0 || err != nil {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
}
|
||||
return int64(count), nil
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user