Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
Automat
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
冯佳佳
Automat
Commits
60911711
Commit
60911711
authored
Jan 17, 2022
by
Aeolus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
c54a7e91
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
280 additions
and
128 deletions
+280
-128
config/commen_config.py
+7
-9
models/models.py
+23
-1
myapps/pc_management/api/__init__.py
+2
-0
myapps/pc_management/api/admin_portal.py
+18
-46
myapps/pc_management/api/business_portal.py
+123
-0
myapps/pc_management/api/hatch_portal.py
+2
-1
myapps/pc_management/api/production_portal.py
+2
-2
service/admin_service.py
+87
-67
utils/error_code.py
+0
-0
utils/jwt_util.py
+2
-2
utils/mytools.py
+14
-0
No files found.
config/commen_config.py
View file @
60911711
...
...
@@ -43,15 +43,13 @@ LOGIN_TYPE = {
AGENT_STATUS
=
{
'1'
:
'超级管理员'
,
'2'
:
'出库员'
,
'3'
:
'渠道经理'
,
'4'
:
'财务'
,
'5'
:
'运维管理员'
,
'6'
:
'推销员'
,
'7'
:
'介绍人'
,
'8'
:
'合伙人'
,
'9'
:
'补货员'
,
'10'
:
'场所'
,
'2'
:
'管理员'
,
'3'
:
'业务员'
,
'4'
:
'代理商'
,
'5'
:
'财务'
,
'6'
:
'运维管理员'
,
'7'
:
'补货员'
,
'8'
:
'客服'
,
}
ACCOUNT_STATUS
=
{
...
...
models/models.py
View file @
60911711
...
...
@@ -49,6 +49,18 @@ class AdminBrand(Base):
updated_at
=
Column
(
DateTime
,
nullable
=
False
,
server_default
=
text
(
"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
))
class
AdminBusiness
(
Base
):
__tablename__
=
'admin_business'
id
=
Column
(
INTEGER
(
11
),
primary_key
=
True
)
user_id
=
Column
(
INTEGER
(
11
),
nullable
=
False
)
user_no
=
Column
(
String
(
25
,
'utf8mb4_unicode_ci'
),
nullable
=
False
)
business_id
=
Column
(
INTEGER
(
11
),
nullable
=
False
)
status
=
Column
(
INTEGER
(
1
),
nullable
=
False
,
server_default
=
text
(
"'1'"
))
created_at
=
Column
(
DateTime
,
nullable
=
False
,
server_default
=
text
(
"CURRENT_TIMESTAMP"
))
updated_at
=
Column
(
DateTime
,
nullable
=
False
,
server_default
=
text
(
"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
))
class
AdminLoginRecord
(
Base
):
__tablename__
=
'admin_login_record'
...
...
@@ -68,7 +80,7 @@ class AdminMachine(Base):
id
=
Column
(
INTEGER
(
11
),
primary_key
=
True
)
user_id
=
Column
(
INTEGER
(
11
),
nullable
=
False
)
user_no
=
Column
(
String
(
25
,
'utf8mb4_unicode_ci'
),
nullable
=
False
)
machine_no
=
Column
(
INTEGER
(
11
),
nullable
=
False
)
machine_no
=
Column
(
String
(
40
,
'utf8mb4_unicode_ci'
),
nullable
=
False
)
status
=
Column
(
INTEGER
(
1
),
default
=
1
,
nullable
=
False
)
created_at
=
Column
(
DateTime
,
nullable
=
False
,
server_default
=
text
(
"CURRENT_TIMESTAMP"
))
updated_at
=
Column
(
DateTime
,
nullable
=
False
,
server_default
=
text
(
"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
))
...
...
@@ -121,6 +133,16 @@ class Brand(Base):
updated_at
=
Column
(
TIMESTAMP
,
server_default
=
text
(
"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
))
class
Business
(
Base
):
__tablename__
=
'business'
id
=
Column
(
INTEGER
(
10
),
primary_key
=
True
)
business_name
=
Column
(
VARCHAR
(
191
),
nullable
=
False
,
index
=
True
,
comment
=
'品牌名'
)
status
=
Column
(
TINYINT
(
1
),
default
=
text
(
"'1'"
),
comment
=
'状态: 1正常-1删除'
)
created_at
=
Column
(
TIMESTAMP
,
server_default
=
text
(
"CURRENT_TIMESTAMP"
))
updated_at
=
Column
(
TIMESTAMP
,
server_default
=
text
(
"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
))
class
Hatch
(
Base
):
__tablename__
=
'hatch'
__table_args__
=
(
...
...
myapps/pc_management/api/__init__.py
View file @
60911711
...
...
@@ -17,6 +17,7 @@ from myapps.pc_management.api.machine_portal import machine_route
from
myapps.pc_management.api.file_protal
import
file_route
from
myapps.pc_management.api.production_portal
import
production_route
from
myapps.pc_management.api.hatch_portal
import
hatch_route
from
myapps.pc_management.api.business_portal
import
business_route
def
register_sukang_blueprint
(
app
:
Flask
):
...
...
@@ -27,3 +28,4 @@ def register_sukang_blueprint(app: Flask):
app
.
register_blueprint
(
file_route
,
url_prefix
=
prefix
+
"/file"
)
app
.
register_blueprint
(
production_route
,
url_prefix
=
prefix
+
"/production"
)
app
.
register_blueprint
(
hatch_route
,
url_prefix
=
prefix
+
"/hatch"
)
app
.
register_blueprint
(
business_route
,
url_prefix
=
prefix
+
"/business"
)
myapps/pc_management/api/admin_portal.py
View file @
60911711
...
...
@@ -13,11 +13,12 @@ from utils.error_code import ACCOUNT_AGENT_SPOT_NULL_ERROR, ACCOUNT_NOT_EXISTS_E
OPERATE_LEVEL_ERROR
,
Param_Invalid_Error
,
COMMON_MONGO_ERROR
from
utils.error_code
import
PHONE_NOT_NULL_ERROR
,
PHONE_NOT_VALID_ERROR
,
TOKEN_NOT_VALID_ERROR
,
\
VERIFICATION_CODE_INVALID_ERROR
,
VERIFICATION_CODE_ERROR
,
PASSWORD_ERROR
from
models.base_model
import
db
from
models.models
import
AdminAccount
,
AdminLoginRecord
,
AdminMachine
,
AdminPlace
,
Place
from
models.base_model
import
db
,
Base
from
models.models
import
AdminAccount
,
AdminLoginRecord
,
AdminMachine
,
AdminPlace
,
Place
,
Business
,
AdminBusiness
from
utils.jwt_util
import
verify_jwt
,
generate_jwt
from
utils.my_response
import
BaseResponse
from
service.sms_service
import
SMSService
from
utils.mytools
import
json2obj
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -141,6 +142,10 @@ def add_user():
db
.
session
.
add
(
account
)
db
.
session
.
commit
()
business_ids
=
json_data
.
get
(
"business_ids"
,
[])
if
business_ids
:
AdminService
.
add_or_edit_admin_business
(
account
,
business_ids
)
return
BaseResponse
()
...
...
@@ -151,45 +156,9 @@ def get_account_list():
page_size
=
json_data
.
get
(
"pageSize"
,
None
)
keyword
=
json_data
.
get
(
"keyword"
,
None
)
select_sql
=
"""select admin_account.user_name, admin_account.phone, admin_account.level, admin_account.status,
admin_account.comment,admin_account.parent_id,admin_account.rate, admin_account.created_at,
admin_account.updated_at,admin_account.id, admin_account.user_no
"""
count_sql
=
"select count(admin_account.id) as total_count"
from_sql
=
" from admin_account where admin_account.id in ( select admin_account.id "
from_sql
+=
" from admin_account "
where_sql
=
" where 0=0 and admin_account.level > {} and admin_account.parent_id = {}"
.
format
(
g
.
user
.
level
,
g
.
user
.
id
)
if
keyword
:
where_sql
+=
"""
and CONCAT(admin_account.user_name,admin_account.phone, admin_account.user_no) LIKE '
%
{keyword}
%
'
"""
.
format
(
keyword
=
keyword
)
where_sql
+=
" ) "
order_sql
=
" ORDER BY admin_account.id ASC, admin_account.status ASC"
limit_sql
=
" LIMIT {offset} , {page_size} "
.
format
(
offset
=
(
page
-
1
)
*
page_size
,
page_size
=
page_size
)
count_result
=
db
.
session
.
execute
(
count_sql
+
from_sql
+
where_sql
)
.
fetchone
()
if
not
count_result
:
return
BaseResponse
(
data
=
{
"list"
:
[],
"page"
:
page
,
"pageSize"
:
page_size
,
"total_count"
:
0
})
else
:
total_count
=
count_result
.
total_count
print
(
select_sql
+
from_sql
+
where_sql
+
order_sql
+
limit_sql
)
result
=
db
.
session
.
execute
(
select_sql
+
from_sql
+
where_sql
+
order_sql
+
limit_sql
)
.
fetchall
()
return_data
=
[]
for
info
in
result
:
return_data
.
append
(
{
"user_name"
:
info
.
user_name
,
"phone"
:
info
.
phone
,
"level"
:
info
.
level
,
"status"
:
info
.
status
,
"comment"
:
info
.
comment
,
"user_id"
:
info
.
id
,
"user_no"
:
info
.
user_no
,
"create_time"
:
info
.
created_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
),
"update_time"
:
info
.
updated_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
),
})
return_data
=
AdminService
.
get_admin_account_list
(
keyword
=
keyword
,
page
=
page
,
page_size
=
page_size
)
return
BaseResponse
(
{
"list"
:
return_data
,
"page"
:
page
,
"pageSize"
:
page_size
,
"total_count"
:
total_count
}
)
return
BaseResponse
(
return_data
)
@admin_route.route
(
'/account_detail'
,
methods
=
[
"POST"
])
...
...
@@ -199,14 +168,13 @@ def get_account_detail():
if
phone
==
g
.
user
.
phone
:
admin_info
=
g
.
user
else
:
admin_info
=
AdminAccount
.
query
.
filter
(
AdminAccount
.
phone
==
phone
,
AdminAccount
.
level
>
g
.
user
.
level
,
AdminAccount
.
parent_id
==
g
.
user
.
id
)
.
first
()
if
not
admin_info
:
result
=
AdminService
.
get_admin_account_list
(
phone
=
phone
)
if
result
[
"total_count"
]
!=
1
:
return
BaseResponse
(
**
ACCOUNT_NOT_EXISTS_ERROR
)
admin_info
=
json2obj
(
result
[
"list"
][
0
])
user_info
=
{
"
user_
id"
:
admin_info
.
id
,
"id"
:
admin_info
.
id
,
"user_no"
:
admin_info
.
user_no
,
"user_name"
:
admin_info
.
user_name
,
"phone"
:
admin_info
.
phone
,
...
...
@@ -223,7 +191,7 @@ def edit_user():
json_data
=
request
.
get_json
()
old_phone
=
json_data
[
'old_phone'
]
if
'old_phone'
in
json_data
else
''
new_phone
=
json_data
[
'new_phone'
]
if
'new_phone'
in
json_data
else
''
user_name
=
json_data
[
'user_name'
]
if
'user_name'
in
json_data
else
'
SSW
'
user_name
=
json_data
[
'user_name'
]
if
'user_name'
in
json_data
else
'
XX
'
password
=
json_data
[
'password'
]
if
'password'
in
json_data
else
''
comment
=
json_data
[
'comment'
]
if
'comment'
in
json_data
else
''
level
=
json_data
[
'level'
]
if
'level'
in
json_data
else
''
...
...
@@ -259,6 +227,10 @@ def edit_user():
db
.
session
.
add
(
admin_info
)
db
.
session
.
commit
()
business_ids
=
json_data
.
get
(
"business_ids"
,
[])
if
business_ids
:
AdminService
.
add_or_edit_admin_business
(
account
,
business_ids
)
return
BaseResponse
()
...
...
myapps/pc_management/api/business_portal.py
0 → 100644
View file @
60911711
#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@version:
author:Aeolus
@time: 2022/01/12
@file: place_portal.py
@function:
@modify:
"""
import
logging
from
flask
import
Blueprint
,
g
,
request
,
jsonify
from
models.base_model
import
db
from
models.models
import
AdminPlace
,
Place
,
Business
,
AdminBusiness
from
utils.error_code
import
NO_PLACE_ERROR
,
NO_BUSINESS_ERROR
from
utils.my_response
import
BaseResponse
logger
=
logging
.
getLogger
(
__name__
)
business_route
=
Blueprint
(
'business'
,
__name__
)
@business_route.route
(
"business_list"
,
methods
=
[
"POST"
])
def
run_business_list
():
"""
:return:
"""
json_data
=
request
.
get_json
()
page
=
json_data
.
get
(
"page"
,
1
)
page_size
=
json_data
.
get
(
"pageSize"
,
10
)
keyword
=
json_data
.
get
(
"keyword"
,
None
)
admin
=
g
.
user
select_sql
=
"select business.business_name,business.status, business.id "
count_sql
=
"select count(business.id) as total_count"
from_sql
=
""" from business where business.id in (select business_id from admin_business where
admin_business.user_id = {} and admin_business.status = 1) """
.
format
(
admin
.
id
)
where_sql
=
" "
if
keyword
:
where_sql
+=
""" and CONCAT(business.business_name) LIKE '
%
{keyword}
%
' """
.
format
(
keyword
=
keyword
)
order_sql
=
" ORDER BY business.id ASC, business.status ASC"
limit_sql
=
" LIMIT {offset} , {page_size} "
.
format
(
offset
=
(
page
-
1
)
*
page_size
,
page_size
=
page_size
)
count_result
=
db
.
session
.
execute
(
count_sql
+
from_sql
+
where_sql
)
.
fetchone
()
if
not
count_result
:
return
BaseResponse
(
data
=
{
"list"
:
[],
"page"
:
page
,
"pageSize"
:
page_size
,
"total_count"
:
0
})
else
:
total_count
=
count_result
.
total_count
result
=
db
.
session
.
execute
(
select_sql
+
from_sql
+
where_sql
+
order_sql
+
limit_sql
)
.
fetchall
()
return_data
=
[]
for
info
in
result
:
return_data
.
append
({
"business_name"
:
info
.
place_name
,
"business_id"
:
info
.
id
,
"status"
:
info
.
status
})
return
BaseResponse
({
"list"
:
return_data
,
"page"
:
page
,
"pageSize"
:
page_size
,
"total_count"
:
total_count
})
@business_route.route
(
"add_business"
,
methods
=
[
"POST"
])
def
run_add_place
():
"""
:return:
"""
json_data
=
request
.
get_json
()
business_name
=
json_data
[
"business_name"
]
business_model
=
Business
()
business_model
.
business_name
=
business_name
db
.
session
.
add
(
business_model
)
db
.
session
.
commit
()
admin_business
=
AdminBusiness
()
admin_business
.
user_id
=
g
.
user
.
id
admin_business
.
user_no
=
g
.
user
.
user_no
admin_business
.
business_id
=
business_model
.
id
db
.
session
.
add
(
admin_business
)
db
.
session
.
commit
()
return
BaseResponse
()
@business_route.route
(
"edit_business"
,
methods
=
[
"POST"
])
def
run_edit_business
():
"""
:return:
"""
json_data
=
request
.
get_json
()
business_id
=
json_data
[
"business_id"
]
business_name
=
json_data
.
get
(
"business_name"
,
""
)
status
=
json_data
.
get
(
"status"
,
None
)
business_model
=
Business
.
query
.
filter_by
(
id
=
business_id
)
.
first
()
if
business_name
:
business_model
.
business_name
=
business_name
if
status
:
business_model
.
status
=
status
db
.
session
.
add
(
business_model
)
db
.
session
.
commit
()
return
BaseResponse
()
@business_route.route
(
"business_detail"
,
methods
=
[
"POST"
])
def
get_business_detail
():
"""
:return:
"""
json_data
=
request
.
get_json
()
business_id
=
json_data
[
"business_id"
]
business_model
=
Business
.
query
.
filter_by
(
id
=
business_id
)
.
first
()
if
business_model
:
return
BaseResponse
(
data
=
{
"business_name"
:
business_model
.
business_name
,
"status"
:
business_model
.
status
,
})
else
:
return
jsonify
(
NO_BUSINESS_ERROR
)
myapps/pc_management/api/hatch_portal.py
View file @
60911711
...
...
@@ -52,7 +52,8 @@ def run_hatch_list():
where_sql
=
" "
if
keyword
:
where_sql
+=
"""
and CONCAT(hatch.machine_no,ifnull(hatch.brand_name,''), ifnull(hatch.production_type_name,''))
and CONCAT(hatch.machine_no,ifnull(hatch.brand_name,''), ifnull(hatch.production_type_name,''),
ifnull(hatch.production_name,''))
LIKE '
%
{keyword}
%
'
"""
.
format
(
keyword
=
keyword
)
...
...
myapps/pc_management/api/production_portal.py
View file @
60911711
...
...
@@ -77,7 +77,7 @@ def run_production_list():
return_data
=
[]
for
info
in
result
:
return_data
.
append
(
{
"production_name"
:
info
.
production_name
,
"prod
cu
tion_id"
:
info
.
id
,
"production_no"
:
info
.
production_no
,
{
"production_name"
:
info
.
production_name
,
"prod
uc
tion_id"
:
info
.
id
,
"production_no"
:
info
.
production_no
,
"title"
:
info
.
title
,
"brand_id"
:
info
.
brand_id
,
"brand_name"
:
info
.
brand_name
,
"production_type_id"
:
info
.
production_type_id
,
"production_type_name"
:
info
.
production_type_name
,
"price"
:
info
.
price
,
"original_price"
:
info
.
original_price
,
"weight"
:
info
.
weight
,
...
...
@@ -248,7 +248,7 @@ def get_production_detail():
info
=
result
[
0
]
return
BaseResponse
(
data
=
{
"production_name"
:
info
.
production_name
,
"prod
cu
tion_id"
:
info
.
id
,
"production_no"
:
info
.
production_no
,
data
=
{
"production_name"
:
info
.
production_name
,
"prod
uc
tion_id"
:
info
.
id
,
"production_no"
:
info
.
production_no
,
"title"
:
info
.
title
,
"brand_id"
:
info
.
brand_id
,
"brand_name"
:
info
.
brand_name
,
"production_type_id"
:
info
.
production_type_id
,
"production_type_name"
:
info
.
production_type_name
,
"price"
:
info
.
price
,
"original_price"
:
info
.
original_price
,
"weight"
:
info
.
weight
,
...
...
service/admin_service.py
View file @
60911711
...
...
@@ -5,98 +5,118 @@ import hashlib
import
random
import
string
from
flask
import
g
from
config.commen_config
import
ACCOUNT_STATUS
from
models.models
import
AdminAccount
from
models.models
import
AdminAccount
,
Business
,
AdminBusiness
from
models.base_model
import
db
from
models.models
import
Place
# from models.user_models import AgentAccount
# from service.spot_service import SpotService
class
AdminService
():
@staticmethod
def
gene_salt
(
length
=
16
):
key_list
=
[
random
.
choice
((
string
.
ascii_letters
+
string
.
digits
))
for
i
in
range
(
length
)]
return
(
""
.
join
(
key_list
))
class
AdminService
(
object
):
@staticmethod
def
ge
ne_agent_code
(
agent_info
,
salt
):
def
ge
t_business_id_list
(
):
"""
:param agent_info:
:param salt:
:param business_ids:
:return:
"""
m
=
hashlib
.
md5
()
str
=
"
%
s-
%
s-
%
s-
%
s"
%
(
agent_info
.
id
,
agent_info
.
user_name
,
agent_info
.
phone
,
salt
)
m
.
update
(
str
.
encode
(
"utf-8"
))
return
m
.
hexdigest
()
@staticmethod
def
gene_pwd
(
pwd
,
salt
):
"""
if
g
.
user
.
level
==
1
:
business_list
=
Business
.
query
.
filter
()
.
all
()
if
business_list
:
business_id_list
=
[
i
.
id
for
i
in
business_list
]
else
:
business_id_list
=
[]
:param pwd
:
:param salt:
:return
:
"""
m
=
hashlib
.
md5
()
str
=
"
%
s-
%
s"
%
(
base64
.
encodebytes
(
pwd
.
encode
(
"utf-8"
)),
salt
)
m
.
update
(
str
.
encode
(
"utf-8"
))
return
m
.
hexdigest
()
else
:
admin_business_list
=
AdminBusiness
.
query
.
filter_by
(
user_id
=
g
.
user
.
id
,
status
=
1
)
.
all
()
if
admin_business_list
:
business_id_list
=
[
i
.
business_id
for
i
in
admin_business_list
]
else
:
business_id_list
=
[]
return
business_id_list
@staticmethod
def
check_agent_token
(
token
):
def
add_or_edit_admin_business
(
admin_account
,
business_ids
):
"""
:param
token
:
:param
business_ids
:
:return:
"""
token
=
base64
.
b64decode
(
token
)
.
decode
(
"utf-8"
)
try
:
agent_info
=
AgentAccount
.
query
.
filter_by
(
access_token
=
token
)
.
first
()
except
Exception
as
e
:
return
1
my_business_id_list
=
AdminService
.
get_business_id_list
()
right_busines_ids
=
list
(
set
(
business_ids
)
.
intersection
(
set
(
my_business_id_list
)))
if
not
agent_info
:
return
1
s
=
token
.
split
(
"#"
)
if
len
(
s
)
!=
2
:
return
1
if
AgentService
.
gene_agent_code
(
agent_info
,
agent_info
.
salt
)
!=
s
[
0
]:
return
1
if
agent_info
.
expire_time
<
datetime
.
datetime
.
now
():
return
2
return
agent_info
insert_sql
=
" insert into admin_business (user_id, user_no, business_id) values "
for
i
in
right_busines_ids
:
insert_sql
+=
"('{}','{}','{}'),"
.
format
(
admin_account
.
id
,
admin_account
.
user_no
,
i
)
insert_sql
=
insert_sql
[:
-
1
]
insert_sql
+=
" ON DUPLICATE KEY UPDATE status = 1"
db
.
session
.
execute
(
insert_sql
)
db
.
session
.
commit
()
@staticmethod
def
create_agent_no
():
'''
生成用户编号
:return:
'''
ran_int
=
str
(
random
.
randint
(
1
,
999999
))
.
zfill
(
6
)
return
'ssw'
+
ran_int
@staticmethod
def
get_spot_info
(
agent_info
):
def
get_admin_account_list
(
phone
=
None
,
keyword
=
None
,
page
=
None
,
page_size
=
None
):
"""
:param agent_info:
:return:
"""
spot_info
=
[]
infos
=
db
.
session
.
query
(
AgentSpot
,
Spot
)
.
join
(
Spot
,
Spot
.
id
==
AgentSpot
.
spot_no
)
.
filter
(
AgentSpot
.
agent_no
==
agent_info
.
id
,
AgentSpot
.
status
==
ACCOUNT_STATUS
[
'on_use'
])
.
all
()
for
info
in
infos
:
cur_info
=
{}
cur_info
[
'id'
]
=
info
.
Spot
.
id
cur_info
[
'spotname'
]
=
info
.
Spot
.
spotname
cur_info
[
'letter'
]
=
SpotService
.
get_pinyin
(
info
.
Spot
.
spotname
)
spot_info
.
append
(
cur_info
)
return
spot_info
select_sql
=
"""select admin_account.user_name, admin_account.phone, admin_account.level, admin_account.status,
admin_account.comment,admin_account.parent_id,admin_account.rate, admin_account.created_at,
admin_account.updated_at,admin_account.id, admin_account.user_no
"""
count_sql
=
"select count(admin_account.id) as total_count"
from_sql
=
" from admin_account "
if
g
.
user
.
level
==
1
:
where_sql
=
" where 0=0 "
else
:
where_sql
=
"""
where
admin_account.id in (
select user_id from admin_business where business_id in (
select business_id from admin_business where user_id = {user_id} and status = 1
)
)
and admin_account.level > {level}
"""
.
format
(
user_id
=
g
.
user
.
id
,
level
=
g
.
user
.
level
)
if
phone
:
where_sql
+=
" and phone = {phone}"
.
format
(
phone
=
phone
)
if
keyword
:
where_sql
+=
"""
and CONCAT( admin_account.user_name,
admin_account.phone,
admin_account.user_no) LIKE '
%
{keyword}
%
'
"""
.
format
(
keyword
=
keyword
)
order_sql
=
" ORDER BY admin_account.id ASC, admin_account.status ASC"
if
page
and
page_size
:
limit_sql
=
" LIMIT {offset} , {page_size} "
.
format
(
offset
=
(
page
-
1
)
*
page_size
,
page_size
=
page_size
)
else
:
limit_sql
=
" "
count_result
=
db
.
session
.
execute
(
count_sql
+
from_sql
+
where_sql
)
.
fetchone
()
if
not
count_result
:
return
{
"list"
:
[],
"page"
:
page
,
"pageSize"
:
page_size
,
"total_count"
:
0
}
else
:
total_count
=
count_result
.
total_count
result
=
db
.
session
.
execute
(
select_sql
+
from_sql
+
where_sql
+
order_sql
+
limit_sql
)
.
fetchall
()
return_data
=
[]
for
info
in
result
:
return_data
.
append
(
{
"user_name"
:
info
.
user_name
,
"phone"
:
info
.
phone
,
"level"
:
info
.
level
,
"status"
:
info
.
status
,
"comment"
:
info
.
comment
,
"id"
:
info
.
id
,
"user_no"
:
info
.
user_no
,
"create_time"
:
info
.
created_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
),
"update_time"
:
info
.
updated_at
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
),
})
return
{
"list"
:
return_data
,
"page"
:
page
,
"pageSize"
:
page_size
,
"total_count"
:
total_count
}
utils/error_code.py
View file @
60911711
This diff is collapsed.
Click to expand it.
utils/jwt_util.py
View file @
60911711
#!usr/bin/.env python # -*- coding:utf-8 _*- """ @version: author:Aeolus @time: 2021/03/30 @file: jwt_util.py @function: @modify: """ import jwt from flask import current_app def generate_jwt(payload, expiry, secret=None): """ 生成jwt :param payload: dict 载荷 :param expiry: datetime 有效期 :param secret: 密钥 :return: jwt """ _payload = {'exp': expiry} _payload.update(payload) if not secret: secret = current_app.config['SECRET_KEY'] token = jwt.encode(_payload, secret, algorithm='HS256') return token def verify_jwt(token, secret=None): """ 检验jwt :param token: jwt :param secret: 密钥 :return: dict: payload """ if not secret: secret = current_app.config['SECRET_KEY'] try: payload = jwt.decode(token, secret, algorithms=['HS256']) except jwt.PyJWTError: payload = None return payload if __name__ == '__main__': import time from config.env_path_config import env_path from dotenv import load_dotenv load_dotenv(dotenv_path=env_path, verbose=True, override=True) import os SECRET_KEY = os.getenv('SECRET_KEY') token = generate_jwt({"user_id": 4}, time.time() + 6000, SECRET_KEY) # token = generate_jwt({"user_no": 'SK000007'}, time.time() + 6000, SECRET_KEY) print(token) # for i in range(10): # result = verify_jwt(token, 'secret') # print(result) # print(time.time()) # time.sleep(1)
\ No newline at end of file
#!usr/bin/.env python # -*- coding:utf-8 _*- """ @version: author:Aeolus @time: 2021/03/30 @file: jwt_util.py @function: @modify: """ import jwt from flask import current_app def generate_jwt(payload, expiry, secret=None): """ 生成jwt :param payload: dict 载荷 :param expiry: datetime 有效期 :param secret: 密钥 :return: jwt """ _payload = {'exp': expiry} _payload.update(payload) if not secret: secret = current_app.config['SECRET_KEY'] token = jwt.encode(_payload, secret, algorithm='HS256') return token def verify_jwt(token, secret=None): """ 检验jwt :param token: jwt :param secret: 密钥 :return: dict: payload """ if not secret: secret = current_app.config['SECRET_KEY'] try: payload = jwt.decode(token, secret, algorithms=['HS256']) except jwt.PyJWTError: payload = None return payload if __name__ == '__main__': import time from config.env_path_config import env_path from dotenv import load_dotenv load_dotenv(dotenv_path=env_path, verbose=True, override=True) import os SECRET_KEY = os.getenv('SECRET_KEY') token = generate_jwt({"user_id": 1}, time.time() + 6000, SECRET_KEY) # token = generate_jwt({"user_no": 'SK000007'}, time.time() + 6000, SECRET_KEY) print(token) # for i in range(10): # result = verify_jwt(token, 'secret') # print(result) # print(time.time()) # time.sleep(1)
\ No newline at end of file
...
...
utils/mytools.py
View file @
60911711
# -*- coding: utf-8 -*-
class
UpdateParams
:
def
__init__
(
self
,
**
kwargs
):
self
.
__dict__
.
update
(
kwargs
)
def
__getattr__
(
self
,
item
):
print
(
f
"没有该属性:{item}"
)
return
None
def
json2obj
(
json_data
):
d
=
UpdateParams
.
__new__
(
UpdateParams
)
d
.
__dict__
.
update
(
json_data
)
return
d
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