from api import api from api.views.auth import Auth api.add_url_rule('/register', methods=['POST'], view_func=Auth.register, strict_slashes=False) api.add_url_rule('/login', methods=['POST'], view_func=Auth.login, strict_slashes=False)
return "" class VoiceWordAPI(MethodView): @login_required def get(self): rdata = RequestData() data = rpc.invbox.get_voice_words(page=rdata.page, query=rdata.condition, page_size=rdata.page_size) return jsonify(data) class RedeemAPI(MethodView): @login_required def get(self): rdata = RequestData() data = rpc.invbox.get_redeems(page=rdata.page, query=rdata.condition, page_size=rdata.page_size) return jsonify(data) api.add_url_rule('/admin/redeemactivity', view_func=RedeemActivityAPI.as_view('redeemactivity')) api.add_url_rule('/admin/voiceactivity', view_func=VoiceActivityAPI.as_view('voiceactivity')) api.add_url_rule('/admin/redeem', view_func=RedeemAPI.as_view('redeem')) api.add_url_rule('/admin/voiceword', view_func=VoiceWordAPI.as_view('voiceword'))
if current_user.get("role") == 1: return jsonify({"resultCode": 1, "resultMsg": "补货员没有订单查看权限"}) admin_info = {"id": current_user["id"], "role": current_user["role"]} data = rpc.invbox.get_orders(page=rdata.page, page_size=rdata.page_size, query=rdata.condition, base_url=app.config["DOMAIN"], admin_info=admin_info) return jsonify(data) @api.route("/admin/order/overview") @login_required def order_overview(): now = dte.now() page = int(request.args.get("page", "1")) start_date = request.args.get("startDate", "") end_date = request.args.get("endDate", "") if not start_date: start_date = "%4d-%02d-%02d" % (now.year, now.month, 1) if not end_date: end_date = "%4d-%02d-%02d" % (now.year, now.month, now.day) data = rpc.invbox.order_overview(start_date, end_date, page=page) return jsonify(data) api.add_url_rule('/admin/order', view_func=OrderAPI.as_view('order'))
class SupplyListAPI(MethodView): @login_required def get(self): rdata = RequestData() lists = rpc.invbox.get_supplylist(page=rdata.page, page_size=rdata.page_size) return jsonify(lists) @login_required def post(self): rdata = RequestData() new = rpc.invbox.add_supplylist(rdata["device"], rdata["itemInfo"]) if new["resultCode"]: raise HttpError(400, new["resultMsg"]) del new["resultCode"] del new["resultMsg"] return jsonify(new) api.add_url_rule('/admin/addresstype', view_func=AddressTypeAPI.as_view('addresstypes')) api.add_url_rule('/admin/road', view_func=RoadAPI.as_view('road')) api.add_url_rule('/admin/devicegroup', view_func=DeviceGroupAPI.as_view('devicegroups')) api.add_url_rule('/admin/devicecategory', view_func=DeviceCategoryAPI.as_view('devicecategory')) api.add_url_rule('/admin/supplylist', view_func=SupplyListAPI.as_view('supplylist'))
class AdvertisementAPI(MethodView): @login_required def get(self): page = int(request.args.get("page", "1")) device = int(request.args.get("device", 0)) data = rpc.invbox.get_ads(device=device, page=page, base_url=app.config["DOMAIN"]) return jsonify(data) @login_required def put(self): rdata = RequestData() params = [] for d in rdata: params.append(d) res = rpc.invbox.modify_ads(params) if res["resultCode"]: raise HttpError(400, res["resultMsg"]) return "" api.add_url_rule('/admin/adimage', view_func=ADImageAPI.as_view('adimage')) api.add_url_rule('/admin/advideo', view_func=ADVideoAPI.as_view('advideo')) api.add_url_rule('/admin/advertisement', view_func=AdvertisementAPI.as_view('advertisement'))
@login_required def delete(self): rdata = RequestData() data = rpc.invbox.delete_items(rdata.array) if data["resultCode"]: raise HttpError(400, data["resultMsg"]) return "" @login_required def put(self): rdata = RequestData() params = [] for d in rdata: if int(d["basicPrice"]) <= 0 or int(d["costPrice"]) <= 0: raise HttpError(400, "价格必须为正数") params.append(d) res = rpc.invbox.modify_items(params) if res["resultCode"]: raise HttpError(400, res["resultMsg"]) return "" api.add_url_rule('/admin/itemcategory', view_func=CategoryAPI.as_view('itemcategory')) api.add_url_rule('/admin/itembrand', view_func=BrandAPI.as_view('itembrand')) api.add_url_rule('/admin/item', view_func=ItemAPI.as_view('item'))
@simple.route('/') @simple.route('/hello') def hello(): """Renders a sample page.""" return "Hello World!" @simple.route('/test', methods = ['GET']) def get_tasks(): return make_response('Test successful!', 200) class EchoRoute(MethodView): def get(self, id=None): if not id: return make_response('No id provided', 200) else: return make_response('The id is {}'.format(id), 200) def post(self): ''' Post in json format to return the same json file ''' if request.json == None: return make_response('Please set the Content-Type to application/json', 406) return jsonify(request.json) echo_route = EchoRoute.as_view('echo_route') api.add_url_rule( '/echo', view_func=echo_route, methods=['GET', 'POST'] ) api.add_url_rule( '/echo/<int:id>', view_func=echo_route, methods=['GET'] )
from api import api from api.views import index from . import auth api.add_url_rule('/', endpoint='homepage', view_func=index, methods=['GET'], strict_slashes=False)
@api.route("/admin/dashboard/<string:scale>") @login_required def dashboard(scale): data = {} if scale == "flows": data = rpc.invbox.dashboard_flow_volume() if scale == "flowsRank": data = rpc.invbox.dashboard_flow_volume_rank() if scale == "userStats": data = rpc.invbox.dashboard_user_stats() if scale == "deviceStats": data = rpc.invbox.dashboard_device_stats() if scale == "salesStats": data = rpc.invbox.dashboard_sales_stats() if scale == "itemDeviceRank": data = rpc.invbox.dashboard_item_device_rank() if scale == "payConversionTrend": data = rpc.invbox.dashboard_pay_conversion_trend() return jsonify(data) api.add_url_rule('/admin/stat/overview', view_func=OverviewAPI.as_view('StatOverview')) api.add_url_rule('/admin/stat/trend', view_func=TrendAPI.as_view('StatTrend')) api.add_url_rule('/admin/stat/table', view_func=TableAPI.as_view('StatTable')) api.add_url_rule('/admin/stat/conversion', view_func=ConversionAPI.as_view('StatConversion'))
if mobile: if not is_mobile(d["mobile"]): raise HttpError(400, "手机号码格式不正确") if new_pwd: if not new_pwd == com_pwd: raise HttpError(400, "两次输入密码不一致") if role: if int(role) not in [1, 2, 3]: raise HttpError(400, "不存在的角色") params.append({ "id": id, "name": name, "mobile": mobile, "password": new_pwd, "role": int(role), "admin_range": admin_range, "info_list": info_list }) res = rpc.invbox.modify_accounts(params) if res["resultCode"]: raise HttpError(400, res["resultMsg"]) return jsonify(res) api.add_url_rule('/admin/supplyer', view_func=SupplyerAPI.as_view('supplers')) api.add_url_rule('/admin/user', view_func=UserAPI.as_view('users')) api.add_url_rule('/admin/usergroup', view_func=UserGroupAPI.as_view('usergroups')) api.add_url_rule('/admin/account', view_func=AccountAPI.as_view('accounts'))