Commit d45046ef by Aeolus

新增个人模块列表接口,mongodb相关代码提交

parent 29732f3e
......@@ -4,8 +4,12 @@ import os
is_prod = os.getenv("RUN_ENV", "test") == 'prod'
if is_prod:
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:Boosal2014!!@sh-cdb-kzmpyjqw.sql.tencentcdb.com:63037/suishenwan'
MONGO_DATABASE_URI = "mongodb://suishenwan:Bk9w8Xu4@49.235.36.102:27017/suishenwan?authSource=admin&authMechanism=SCRAM-SHA-256"
MONGO_DATABASE_NAME = "suishenwan"
else:
SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:N58uTiMT#tt*@sh-cdb-9yr5zhu0.sql.tencentcdb.com:61088/suishenwan'
MONGO_DATABASE_URI = "mongodb://dev:aA5nD7fM@49.235.36.102:27017/dev?authSource=admin&authMechanism=SCRAM-SHA-256"
MONGO_DATABASE_NAME = "dev"
SECRET_KEY = "MgwuKKEcAk2UIaGxHAwnf38YvjvXMCqb"
......
......@@ -2,7 +2,6 @@
import os
is_prod = os.getenv("RUN_ENV", "test") == 'prod'
# is_prod = True
ONENET_CONFIG = {
"encoding_AES_key": "XzHtYS3PbRiCDErEaztV286Cf4QmmL21T77tEY4Yb2m",
"he_cloud_token": "suishenwanonenettesttokenhecloud",
......@@ -96,3 +95,8 @@ TAKEOUT_TOOL_TIPS_PHONE = [
# 挪出订单的景区对应编号
move_spot_ids = {16: 50, 42: 51, 48: 49}
PLATFORM = {
"xiaotu": 1,
"xiaodaoyou": 2
}
......@@ -3,12 +3,14 @@ import base64
import datetime
from flask import Blueprint, jsonify, request, g
from pymongo import MongoClient
from Config.base_config import MONGO_DATABASE_URI
from Config.common_config import LOGIN_TYPE, ACCOUNT_STATUS
from Libs.ErrorTips import TOKEN_NOT_VALID_ERROR, TOKEN_EXPIRE_ERROR, PHONE_NOT_NULL_ERROR, PHONE_NOT_VALID_ERROR, \
PHONE_NOT_PERMISSION, USER_NOT_EXIST, LOGIN_ERROR, VERIFICATION_CODE_INVALID_ERROR, VERIFICATION_CODE_ERROR, \
BASE_RESPONSE, ACCOUNT_ALREADY_EXISTS_ERROR, ACCOUNT_NOT_EXISTS_ERROR, ACCOUNT_AGENT_SPOT_NULL_ERROR, \
ACCOUNT_ALREADY_DELETE_ERROR
ACCOUNT_ALREADY_DELETE_ERROR, BASE_SUCCESS_RESPONSE, AGNET_MODULES_ERROR
from Libs.Helper import Helper
from Libs.Logger import logger
from Model.Agent.AgentAccountModel import AgentAccount
......@@ -197,7 +199,8 @@ def send_code():
return jsonify(PHONE_NOT_VALID_ERROR)
sms = SMSService()
sms.phoneSendCode(phone, 92065, '灰兔智能')
result = sms.phoneSendCode(phone, 92065, '灰兔智能')
logger.info(result)
agent_log = AgentLogRecord()
agent_log.phone = phone
......@@ -456,3 +459,17 @@ def login():
data['spot_info'] = AgentService.get_spot_info(agent_info)
return jsonify(BASE_RESPONSE(data=data).to_dict())
@route_account.route('/agent_module_list', methods=['GET', 'POST'])
def get_agent_module_list():
agent_id = g.user.id
platform = g.platform
mongodatabase = MongoClient(MONGO_DATABASE_URI).get_database("suishenwan")
agent_modules = mongodatabase.get_collection("agent_modules")
result = agent_modules.find_one({"agent_id": agent_id, "platform": platform})
return_data = {"agent_id": agent_id, "module_list": result["module_list"]}
if result:
return BASE_SUCCESS_RESPONSE(data=return_data)
else:
return BASE_SUCCESS_RESPONSE(**AGNET_MODULES_ERROR)
# -*- coding: utf-8 -*-
from flask import Response
from flask.json import dumps
class BASE_RESPONSE(object):
def __init__(self, error_code=200, error_message='Success', data=None):
......@@ -10,6 +13,12 @@ class BASE_RESPONSE(object):
return {'error_code': self.error_code, 'error_message': self.error_message, 'data': self.data}
class BASE_SUCCESS_RESPONSE(Response):
def __init__(self, data=None, error_code=0, error_message='Success'):
result = dumps(dict(data=data, error_code=error_code, error_message=error_message))
Response.__init__(self, result, mimetype='application/json')
TOKEN_NOT_VALID_ERROR = {
"error_code": 1001,
"error_message": "无效的token"
......@@ -135,6 +144,11 @@ OPERATE_ERROR = {
"error_message": "操作有误"
}
AGNET_MODULES_ERROR = {
"error_code": 1404,
"error_message": "用户未绑定模块"
}
ACTION_CODE_ERROR = {
"error_code": 1501,
"error_message": "退款操作码错误"
......
from MongoCollection import BaseCollection
class ModulesCollection(BaseCollection):
__collectionname__ = "modules"
class AgentModulesCollection(BaseCollection):
__collectionname__ = "agent_modules"
if __name__ == '__main__':
modules = ModulesCollection()
print(modules.collection)
result = list(modules.collection.insert_one({
"id": 8,
"name": "manual_return",
"platform": 2,
"desc": "我的账号-手动归还",
"parent_id": 3
}))
print(result)
from pymongo import MongoClient
from Config.base_config import MONGO_DATABASE_URI, MONGO_DATABASE_NAME
client = MongoClient(MONGO_DATABASE_URI)
db = client[MONGO_DATABASE_NAME]
class BaseCollection(object):
__collectionname__ = None
def __init__(self):
self.collection = db.get_collection(self.__collectionname__)
# 自增函数
def get_next_id(self):
ret = db["ids"].find_one_and_update({"id": self.__collectionname__}, {"$inc": {"sequence": 1}})
new = ret["sequence"]
return new
def insert_one(self, document: dict, bypass_document_validation=False,
session=None):
document.update({"id": self.get_next_id()})
self.collection.insert_one(document, bypass_document_validation=bypass_document_validation,
session=session)
from flask import Flask, request, url_for, jsonify, g
from flask_cors import CORS
from Config.common_config import PLATFORM
from Libs.ErrorTips import TOKEN_NOT_PROVIDER_ERROR, TOKEN_NOT_VALID_ERROR, TOKEN_EXPIRE_ERROR
from Libs.Logger import logger
from Model.Agent.AgentAccountModel import AgentAccount
......@@ -43,6 +44,12 @@ def log_enter_interface():
@app.before_request
def get_platform():
platform = request.headers.get('platform', None)
g.platform = PLATFORM.get(platform, 0)
@app.before_request
def verify_auth_token():
'''
用户登录验证token
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment