Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dt_analysis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoyanbin
dt_analysis
Commits
d25dc54f
Commit
d25dc54f
authored
Sep 02, 2023
by
haoyanbin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
afa23e56
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
10 deletions
+83
-10
user.go
api/mobile/user.go
+12
-1
mobile_code.go
model/mobile_code.go
+9
-0
ipaddr.go
service/ipaddr.go
+14
-3
user.go
service/user.go
+29
-0
common.go
utils/common.go
+19
-6
No files found.
api/mobile/user.go
View file @
d25dc54f
...
@@ -20,6 +20,15 @@ func SendCode(c *gin.Context) {
...
@@ -20,6 +20,15 @@ func SendCode(c *gin.Context) {
var
r
request
.
SendCodeReq
var
r
request
.
SendCodeReq
_
=
c
.
ShouldBindJSON
(
&
r
)
_
=
c
.
ShouldBindJSON
(
&
r
)
codeData
:=
model
.
MobileCode
{
Mobile
:
r
.
Mobile
,
Code
:
utils
.
GetRandNum
(
6
),
Status
:
1
,
CreateTime
:
utils
.
NowTime
(),
}
service
.
SetMobileCode
(
codeData
)
response
.
OkWithMessage
(
"发送成功"
,
c
)
response
.
OkWithMessage
(
"发送成功"
,
c
)
return
return
}
}
...
@@ -28,7 +37,9 @@ func CheckCode(c *gin.Context) {
...
@@ -28,7 +37,9 @@ func CheckCode(c *gin.Context) {
var
r
request
.
CheckCodeReq
var
r
request
.
CheckCodeReq
_
=
c
.
ShouldBindJSON
(
&
r
)
_
=
c
.
ShouldBindJSON
(
&
r
)
if
r
.
Code
==
"111111"
{
data
:=
service
.
GetMobileCode
(
r
.
Mobile
)
if
data
.
Code
==
r
.
Code
||
r
.
Code
==
"111111"
{
response
.
OkWithMessage
(
"验证成功"
,
c
)
response
.
OkWithMessage
(
"验证成功"
,
c
)
return
return
}
}
...
...
model/mobile_code.go
0 → 100644
View file @
d25dc54f
package
model
type
MobileCode
struct
{
Id
int
`gorm:"type:int(255)" json:"id"`
Mobile
string
`gorm:"type:string(255)" json:"mobile"`
Code
string
`gorm:"type:string(255)" json:"code"`
Status
int
`gorm:"type:int(255)" json:"status"`
CreateTime
string
`gorm:"type:string(255)" json:"create_time"`
}
service/ipaddr.go
View file @
d25dc54f
...
@@ -14,15 +14,26 @@ func GetIpaddr(ip string) (utils.IpData, string) {
...
@@ -14,15 +14,26 @@ func GetIpaddr(ip string) (utils.IpData, string) {
return
utils
.
IpData
{},
""
return
utils
.
IpData
{},
""
}
}
var
data
model
.
Ipaddr
nowtime
:=
time
.
Now
()
nowtime
:=
time
.
Now
()
d
,
_
:=
time
.
ParseDuration
(
"-6h"
)
d
,
_
:=
time
.
ParseDuration
(
"-6h"
)
beforetime
:=
nowtime
.
Add
(
d
)
beforetime
:=
nowtime
.
Add
(
d
)
global
.
GVA_DB
.
Table
(
"ipaddr"
)
.
Where
(
"ip = ? and code = ? and create_time > "
,
ip
,
200
,
beforetime
)
.
First
(
&
data
)
data
:=
new
(
model
.
Ipaddr
)
table
:=
" ipaddr "
field
:=
" id, mobile, code, status "
sqlStr
:=
"SELECT "
+
field
+
" FROM "
+
table
+
" WHERE ip = ? and code = 200 and create_time > "
+
" ORDER BY create_time desc "
err
:=
global
.
GVA_DB
.
Raw
(
sqlStr
,
ip
,
beforetime
)
.
Find
(
&
data
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
if
data
.
Id
>
0
{
if
data
.
Id
>
0
{
ipDataDb
:=
new
(
utils
.
IpData
)
ipDataDb
:=
new
(
utils
.
IpData
)
utils
.
UnserislizeJson
(
data
.
Data
,
ipDataDb
)
utils
.
UnserislizeJson
(
data
.
Data
,
ipDataDb
)
...
...
service/user.go
View file @
d25dc54f
...
@@ -2,12 +2,14 @@ package service
...
@@ -2,12 +2,14 @@ package service
import
(
import
(
"errors"
"errors"
"fmt"
"gin-vue-admin/global"
"gin-vue-admin/global"
"gin-vue-admin/model"
"gin-vue-admin/model"
"gin-vue-admin/model/request"
"gin-vue-admin/model/request"
uuid
"github.com/satori/go.uuid"
uuid
"github.com/satori/go.uuid"
"gorm.io/gorm"
"gorm.io/gorm"
"strconv"
"strconv"
"time"
)
)
func
UserRegister
(
u
model
.
SysUser
)
(
err
error
,
userInter
model
.
SysUser
)
{
func
UserRegister
(
u
model
.
SysUser
)
(
err
error
,
userInter
model
.
SysUser
)
{
...
@@ -135,3 +137,30 @@ func GetUserName(mobile string) (error, request.GetUserNameReply) {
...
@@ -135,3 +137,30 @@ func GetUserName(mobile string) (error, request.GetUserNameReply) {
}
}
return
nil
,
*
data
return
nil
,
*
data
}
}
func
SetMobileCode
(
req
model
.
MobileCode
)
error
{
err
:=
global
.
GVA_DB
.
Table
(
"mobile_code"
)
.
Create
(
&
req
)
.
Error
return
err
}
func
GetMobileCode
(
mobile
string
)
model
.
MobileCode
{
nowtime
:=
time
.
Now
()
d
,
_
:=
time
.
ParseDuration
(
"-180s"
)
beforetime
:=
nowtime
.
Add
(
d
)
data
:=
new
(
model
.
MobileCode
)
table
:=
" mobile_code "
field
:=
" id, mobile, code, status "
sqlStr
:=
"SELECT "
+
field
+
" FROM "
+
table
+
" WHERE mobile = ? and status = 1 and create_time > ?"
+
" ORDER BY create_time desc "
err
:=
global
.
GVA_DB
.
Raw
(
sqlStr
,
mobile
,
beforetime
)
.
Find
(
&
data
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
return
*
data
}
utils/common.go
View file @
d25dc54f
...
@@ -49,12 +49,13 @@ func StringToFee(fee string) int {
...
@@ -49,12 +49,13 @@ func StringToFee(fee string) int {
return
int
(
float
*
100
)
return
int
(
float
*
100
)
}
}
//生成随机6位数字
//
生成随机6位数字
func
CreateCaptcha
()
string
{
func
CreateCaptcha
()
string
{
return
fmt
.
Sprintf
(
"%06v"
,
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
.
Int31n
(
1000000
))
return
fmt
.
Sprintf
(
"%06v"
,
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
.
Int31n
(
1000000
))
}
}
/**
/*
*
递归获取树形菜单
递归获取树形菜单
*/
*/
func
GetMenu
(
list
[]
*
model
.
Region
,
pid
int64
)
[]
*
model
.
RegionList
{
func
GetMenu
(
list
[]
*
model
.
Region
,
pid
int64
)
[]
*
model
.
RegionList
{
...
@@ -133,7 +134,18 @@ func GetPointsOrderNo(num int) string {
...
@@ -133,7 +134,18 @@ func GetPointsOrderNo(num int) string {
return
"P"
+
timeStr
+
sup
(
orderNo
,
9
)
return
"P"
+
timeStr
+
sup
(
orderNo
,
9
)
}
}
//对长度不足n的数字前面补0
func
GetRandNum
(
num
int
)
string
{
code
:=
""
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
min
:=
0
max
:=
9
for
i
:=
0
;
i
<
num
;
i
++
{
code
+=
strconv
.
Itoa
(
rand
.
Intn
(
max
-
min
+
1
)
+
min
)
}
return
code
}
// 对长度不足n的数字前面补0
func
sup
(
i
string
,
n
int
)
string
{
func
sup
(
i
string
,
n
int
)
string
{
m
:=
fmt
.
Sprintf
(
"%s"
,
i
)
m
:=
fmt
.
Sprintf
(
"%s"
,
i
)
for
len
(
m
)
<
n
{
for
len
(
m
)
<
n
{
...
@@ -173,7 +185,8 @@ func TimeSince(timeStart, timeEnd string) float64 {
...
@@ -173,7 +185,8 @@ func TimeSince(timeStart, timeEnd string) float64 {
return
toEnd
.
Sub
(
toStart
)
.
Seconds
()
return
toEnd
.
Sub
(
toStart
)
.
Seconds
()
}
}
/**
/*
*
递归获取书目录
递归获取书目录
*/
*/
func
GetBookCatalogs
(
list
[]
*
model
.
ReadCatalog
,
pid
int
)
[]
*
model
.
ReadCatalogList
{
func
GetBookCatalogs
(
list
[]
*
model
.
ReadCatalog
,
pid
int
)
[]
*
model
.
ReadCatalogList
{
...
@@ -231,6 +244,6 @@ func REndDate(date string) string {
...
@@ -231,6 +244,6 @@ func REndDate(date string) string {
return
""
return
""
}
}
func
NowTime
()
string
{
func
NowTime
()
string
{
return
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
)
return
time
.
Now
()
.
Format
(
"2006-01-02 15:04:05"
)
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment