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
09261a14
Commit
09261a14
authored
Jan 13, 2022
by
Aeolus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
1c904553
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
57 additions
and
19 deletions
+57
-19
config/commen_config.py
+5
-0
models/models.py
+1
-0
myapps/automat/__init__.py
+2
-2
myapps/automat/api/__init__.py
+8
-8
myapps/automat/api/card_edit_portal.py
+0
-0
myapps/automat/api/hatch_portal.py
+0
-0
myapps/automat/api/machine_portal.py
+0
-0
myapps/automat/api/nfc_card_portal.py
+0
-0
myapps/automat/api/rent_portal.py
+23
-1
myapps/automat/api/tallyman_portal.py
+0
-0
myapps/automat/api/upload_portal.py
+0
-0
myapps/automat/api/wx_auth_portal.py
+0
-0
myapps/pc_management/api/machine_portal.py
+15
-5
sukang_app.py
+1
-1
utils/jwt_util.py
+2
-2
utils/middlewares.py
+0
-0
No files found.
config/commen_config.py
View file @
09261a14
...
@@ -58,3 +58,8 @@ ACCOUNT_STATUS = {
...
@@ -58,3 +58,8 @@ ACCOUNT_STATUS = {
'on_use'
:
1
,
'on_use'
:
1
,
'delete'
:
-
1
'delete'
:
-
1
}
}
DISCOUNTS_TYPES
=
{
0
:
"暂无折扣"
,
1
:
"每日收单免费"
,
}
models/models.py
View file @
09261a14
...
@@ -145,6 +145,7 @@ class Machine(Base):
...
@@ -145,6 +145,7 @@ class Machine(Base):
created_at
=
Column
(
TIMESTAMP
,
nullable
=
False
,
server_default
=
text
(
"CURRENT_TIMESTAMP"
))
created_at
=
Column
(
TIMESTAMP
,
nullable
=
False
,
server_default
=
text
(
"CURRENT_TIMESTAMP"
))
updated_at
=
Column
(
TIMESTAMP
,
nullable
=
False
,
server_default
=
text
(
"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
))
updated_at
=
Column
(
TIMESTAMP
,
nullable
=
False
,
server_default
=
text
(
"CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
))
command_time
=
Column
(
INTEGER
(
1
),
nullable
=
False
,
server_default
=
text
(
"'1'"
))
command_time
=
Column
(
INTEGER
(
1
),
nullable
=
False
,
server_default
=
text
(
"'1'"
))
discounts_id
=
Column
(
INTEGER
(
11
),
nullable
=
False
,
server_default
=
text
(
"'0'"
),
comment
=
"折扣活动"
)
class
MachineProduction
(
Base
):
class
MachineProduction
(
Base
):
...
...
myapps/
sukang24h
/__init__.py
→
myapps/
automat
/__init__.py
View file @
09261a14
...
@@ -22,7 +22,7 @@ def create_app(config_name):
...
@@ -22,7 +22,7 @@ def create_app(config_name):
load_dotenv
(
dotenv_path
=
env_path
,
verbose
=
True
,
override
=
True
)
load_dotenv
(
dotenv_path
=
env_path
,
verbose
=
True
,
override
=
True
)
set_logger
()
set_logger
()
app
=
Flask
(
"
sukang24h
"
)
app
=
Flask
(
"
automat
"
)
from
config.app_config
import
config
from
config.app_config
import
config
app
.
config
.
from_object
(
config
[
config_name
])
app
.
config
.
from_object
(
config
[
config_name
])
CORS
(
app
)
CORS
(
app
)
...
@@ -40,6 +40,6 @@ def create_app(config_name):
...
@@ -40,6 +40,6 @@ def create_app(config_name):
app
.
after_request
(
close_db_session
)
app
.
after_request
(
close_db_session
)
# todo register blueprint
# todo register blueprint
from
myapps.
sukang24h
.api
import
register_sukang_blueprint
from
myapps.
automat
.api
import
register_sukang_blueprint
register_sukang_blueprint
(
app
)
register_sukang_blueprint
(
app
)
return
app
return
app
myapps/
sukang24h
/api/__init__.py
→
myapps/
automat
/api/__init__.py
View file @
09261a14
...
@@ -7,17 +7,17 @@ author:Aeolus
...
@@ -7,17 +7,17 @@ author:Aeolus
"""
"""
from
flask
import
Flask
from
flask
import
Flask
from
myapps.
sukang24h
.api.wx_auth_portal
import
wx_auth_route
from
myapps.
automat
.api.wx_auth_portal
import
wx_auth_route
from
myapps.
sukang24h
.api.hatch_portal
import
hatch_route
from
myapps.
automat
.api.hatch_portal
import
hatch_route
from
myapps.
sukang24h
.api.rent_portal
import
rent_route
from
myapps.
automat
.api.rent_portal
import
rent_route
from
myapps.
sukang24h
.api.tallyman_portal
import
tallyman_route
from
myapps.
automat
.api.tallyman_portal
import
tallyman_route
from
myapps.
sukang24h
.api.machine_portal
import
machine_route
from
myapps.
automat
.api.machine_portal
import
machine_route
from
myapps.
sukang24h
.api.nfc_card_portal
import
nfc_card_route
from
myapps.
automat
.api.nfc_card_portal
import
nfc_card_route
from
myapps.
sukang24h
.api.card_edit_portal
import
card_edit_route
from
myapps.
automat
.api.card_edit_portal
import
card_edit_route
def
register_sukang_blueprint
(
app
:
Flask
):
def
register_sukang_blueprint
(
app
:
Flask
):
prefix
=
"/
sukang
"
prefix
=
"/
automat
"
app
.
register_blueprint
(
wx_auth_route
,
url_prefix
=
prefix
+
"/wx_auth"
)
app
.
register_blueprint
(
wx_auth_route
,
url_prefix
=
prefix
+
"/wx_auth"
)
app
.
register_blueprint
(
hatch_route
,
url_prefix
=
prefix
+
"/hatch"
)
app
.
register_blueprint
(
hatch_route
,
url_prefix
=
prefix
+
"/hatch"
)
app
.
register_blueprint
(
rent_route
,
url_prefix
=
prefix
+
"/rent"
)
app
.
register_blueprint
(
rent_route
,
url_prefix
=
prefix
+
"/rent"
)
...
...
myapps/
sukang24h
/api/card_edit_portal.py
→
myapps/
automat
/api/card_edit_portal.py
View file @
09261a14
File moved
myapps/
sukang24h
/api/hatch_portal.py
→
myapps/
automat
/api/hatch_portal.py
View file @
09261a14
File moved
myapps/
sukang24h
/api/machine_portal.py
→
myapps/
automat
/api/machine_portal.py
View file @
09261a14
File moved
myapps/
sukang24h
/api/nfc_card_portal.py
→
myapps/
automat
/api/nfc_card_portal.py
View file @
09261a14
File moved
myapps/
sukang24h
/api/rent_portal.py
→
myapps/
automat
/api/rent_portal.py
View file @
09261a14
...
@@ -15,7 +15,7 @@ from functools import reduce
...
@@ -15,7 +15,7 @@ from functools import reduce
from
flask
import
Blueprint
,
request
,
jsonify
,
g
from
flask
import
Blueprint
,
request
,
jsonify
,
g
from
sqlalchemy
import
func
from
sqlalchemy
import
func
from
config.commen_config
import
USER_RENT_PREPAY_ID
,
RENT_SALE_LOCK
from
config.commen_config
import
USER_RENT_PREPAY_ID
,
RENT_SALE_LOCK
,
DISCOUNTS_TYPES
from
config.wechat_config
import
platform_appid_config_list
,
pay_config_list
from
config.wechat_config
import
platform_appid_config_list
,
pay_config_list
from
models.base_model
import
db
from
models.base_model
import
db
from
models.models
import
Machine
,
Hatch
,
Rent
,
WxUser
,
RentDetail
from
models.models
import
Machine
,
Hatch
,
Rent
,
WxUser
,
RentDetail
...
@@ -31,6 +31,28 @@ logger = logging.getLogger(__name__)
...
@@ -31,6 +31,28 @@ logger = logging.getLogger(__name__)
rent_route
=
Blueprint
(
'rent'
,
__name__
)
rent_route
=
Blueprint
(
'rent'
,
__name__
)
@rent_route.route
(
"discounts_info"
,
methods
=
[
"POST"
])
def
get_discount_info
():
json_data
=
request
.
get_json
()
machine_no
=
json_data
[
"machine_no"
]
user
=
g
.
user
# 验证机柜是否存在
machine
=
Machine
.
query
.
filter_by
(
machine_no
=
machine_no
)
.
first
()
if
not
machine
:
return
jsonify
(
MACHINE_NOT_EXIST_ERROR
)
if
machine
.
discounts_id
==
1
:
rent
=
Rent
.
query
.
filter
(
db
.
cast
(
Rent
.
created_at
,
db
.
DATE
)
==
db
.
cast
(
datetime
.
datetime
.
now
(),
db
.
DATE
))
.
first
()
if
rent
:
is_used
=
1
else
:
is_used
=
0
return_data
=
{
"discounts_id"
:
machine
.
discounts_id
,
"discounts_name"
:
DISCOUNTS_TYPES
[
int
(
machine
.
discounts_id
)],
"is_used"
:
is_used
}
return
BaseResponse
(
data
=
return_data
)
@rent_route.route
(
"rent"
,
methods
=
[
"POST"
])
@rent_route.route
(
"rent"
,
methods
=
[
"POST"
])
def
create_rent
():
def
create_rent
():
json_data
=
request
.
get_json
()
json_data
=
request
.
get_json
()
...
...
myapps/
sukang24h
/api/tallyman_portal.py
→
myapps/
automat
/api/tallyman_portal.py
View file @
09261a14
File moved
myapps/
sukang24h
/api/upload_portal.py
→
myapps/
automat
/api/upload_portal.py
View file @
09261a14
File moved
myapps/
sukang24h
/api/wx_auth_portal.py
→
myapps/
automat
/api/wx_auth_portal.py
View file @
09261a14
File moved
myapps/pc_management/api/machine_portal.py
View file @
09261a14
...
@@ -12,6 +12,7 @@ import logging
...
@@ -12,6 +12,7 @@ import logging
from
flask
import
Blueprint
,
g
,
request
,
jsonify
from
flask
import
Blueprint
,
g
,
request
,
jsonify
from
config.commen_config
import
DISCOUNTS_TYPES
from
models.base_model
import
db
from
models.base_model
import
db
from
models.models
import
AdminMachine
,
Machine
from
models.models
import
AdminMachine
,
Machine
from
utils.error_code
import
MACHINE_NOT_EXIST_ERROR
from
utils.error_code
import
MACHINE_NOT_EXIST_ERROR
...
@@ -36,7 +37,7 @@ def run_machine_list():
...
@@ -36,7 +37,7 @@ def run_machine_list():
admin
=
g
.
user
admin
=
g
.
user
select_sql
=
"""select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status,
select_sql
=
"""select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status,
machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id,
machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id,
place.place_name
place.place_name
, machine.discounts_id
"""
"""
count_sql
=
"select count(machine.id) as total_count"
count_sql
=
"select count(machine.id) as total_count"
from_sql
=
""" from machine left join place on machine.place_id = place.id
from_sql
=
""" from machine left join place on machine.place_id = place.id
...
@@ -67,7 +68,9 @@ def run_machine_list():
...
@@ -67,7 +68,9 @@ def run_machine_list():
return_data
.
append
(
return_data
.
append
(
{
"machine_no"
:
info
.
machine_no
,
"device_id"
:
info
.
device_id
,
"place_name"
:
info
.
place_name
,
{
"machine_no"
:
info
.
machine_no
,
"device_id"
:
info
.
device_id
,
"place_name"
:
info
.
place_name
,
"mac"
:
info
.
mac
,
"power"
:
info
.
power
,
"hatch_number"
:
info
.
hatch_number
,
"type"
:
info
.
type
,
"mac"
:
info
.
mac
,
"power"
:
info
.
power
,
"hatch_number"
:
info
.
hatch_number
,
"type"
:
info
.
type
,
"status"
:
info
.
status
,
"place_id"
:
info
.
place_id
"status"
:
info
.
status
,
"place_id"
:
info
.
place_id
,
"discounts_id"
:
info
.
discounts_id
,
"discounts_name"
:
DISCOUNTS_TYPES
[
int
(
info
.
discounts_id
)],
})
})
return
BaseResponse
({
"list"
:
return_data
,
"page"
:
page
,
"pageSize"
:
page_size
,
"total_count"
:
total_count
})
return
BaseResponse
({
"list"
:
return_data
,
"page"
:
page
,
"pageSize"
:
page_size
,
"total_count"
:
total_count
})
...
@@ -89,6 +92,7 @@ def run_add_machine():
...
@@ -89,6 +92,7 @@ def run_add_machine():
hatch_number
=
json_data
.
get
(
"hatch_number"
,
None
)
hatch_number
=
json_data
.
get
(
"hatch_number"
,
None
)
place_id
=
json_data
.
get
(
"place_id"
,
None
)
place_id
=
json_data
.
get
(
"place_id"
,
None
)
type
=
json_data
.
get
(
"type"
,
1
)
type
=
json_data
.
get
(
"type"
,
1
)
discounts_id
=
json_data
.
get
(
"type"
,
0
)
machine_model
=
Machine
()
machine_model
=
Machine
()
machine_model
.
machine_no
=
machine_no
machine_model
.
machine_no
=
machine_no
...
@@ -101,6 +105,7 @@ def run_add_machine():
...
@@ -101,6 +105,7 @@ def run_add_machine():
machine_model
.
mch_platform
=
1
machine_model
.
mch_platform
=
1
machine_model
.
hatch_number
=
hatch_number
machine_model
.
hatch_number
=
hatch_number
machine_model
.
type
=
type
machine_model
.
type
=
type
machine_model
.
discounts_id
=
discounts_id
db
.
session
.
add
(
machine_model
)
db
.
session
.
add
(
machine_model
)
admin_machine
=
AdminMachine
()
admin_machine
=
AdminMachine
()
...
@@ -130,6 +135,7 @@ def run_edit_machine():
...
@@ -130,6 +135,7 @@ def run_edit_machine():
place_id
=
json_data
.
get
(
"place_id"
,
None
)
place_id
=
json_data
.
get
(
"place_id"
,
None
)
type
=
json_data
.
get
(
"type"
,
None
)
type
=
json_data
.
get
(
"type"
,
None
)
status
=
json_data
.
get
(
"status"
,
None
)
status
=
json_data
.
get
(
"status"
,
None
)
discounts_id
=
json_data
.
get
(
"discounts_id"
,
None
)
machine_model
=
Machine
.
query
.
filter_by
(
machine_no
=
machine_no
)
.
first
()
machine_model
=
Machine
.
query
.
filter_by
(
machine_no
=
machine_no
)
.
first
()
if
not
machine_model
:
if
not
machine_model
:
...
@@ -153,6 +159,8 @@ def run_edit_machine():
...
@@ -153,6 +159,8 @@ def run_edit_machine():
machine_model
.
type
=
type
machine_model
.
type
=
type
if
status
:
if
status
:
machine_model
.
status
=
status
machine_model
.
status
=
status
if
discounts_id
:
machine_model
.
discounts_id
=
discounts_id
db
.
session
.
add
(
machine_model
)
db
.
session
.
add
(
machine_model
)
db
.
session
.
commit
()
db
.
session
.
commit
()
...
@@ -171,7 +179,7 @@ def get_machine_detail():
...
@@ -171,7 +179,7 @@ def get_machine_detail():
admin
=
g
.
user
admin
=
g
.
user
select_sql
=
"""select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status,
select_sql
=
"""select machine.id, machine.machine_no, machine.device_id, machine.qrcode_no,machine.status,
machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id,
machine.mac, machine.power, machine.hatch_number, machine.type,machine.place_id,
place.place_name
place.place_name
, machine.discounts_id
"""
"""
from_sql
=
""" from machine left join place on machine.place_id = place.id
from_sql
=
""" from machine left join place on machine.place_id = place.id
where machine.machine_no in ( select machine_no from admin_machine where
where machine.machine_no in ( select machine_no from admin_machine where
...
@@ -187,6 +195,8 @@ def get_machine_detail():
...
@@ -187,6 +195,8 @@ def get_machine_detail():
info
=
result
[
0
]
info
=
result
[
0
]
return
BaseResponse
(
data
=
{
"machine_no"
:
info
.
machine_no
,
"device_id"
:
info
.
device_id
,
"place_name"
:
info
.
place_name
,
return
BaseResponse
(
data
=
{
"machine_no"
:
info
.
machine_no
,
"device_id"
:
info
.
device_id
,
"place_name"
:
info
.
place_name
,
"mac"
:
info
.
mac
,
"power"
:
info
.
power
,
"hatch_number"
:
info
.
hatch_number
,
"mac"
:
info
.
mac
,
"power"
:
info
.
power
,
"hatch_number"
:
info
.
hatch_number
,
"type"
:
info
.
type
,
"type"
:
info
.
type
,
"status"
:
info
.
status
,
"place_id"
:
info
.
place_id
,
"status"
:
info
.
status
,
"place_id"
:
info
.
place_id
"discounts_id"
:
info
.
discounts_id
,
"discounts_name"
:
DISCOUNTS_TYPES
[
int
(
info
.
discounts_id
)],
})
})
sukang_app.py
View file @
09261a14
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
"""
"""
import
os
import
os
import
logging
import
logging
from
myapps.
sukang24h
import
create_app
from
myapps.
automat
import
create_app
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
app
=
create_app
(
os
.
getenv
(
'RUN_ENV'
,
'prod'
))
app
=
create_app
(
os
.
getenv
(
'RUN_ENV'
,
'prod'
))
...
...
utils/jwt_util.py
View file @
09261a14
#!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)
#!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
\ No newline at end of file
...
...
utils/middlewares.py
View file @
09261a14
This diff is collapsed.
Click to expand it.
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