def wrapper(*args, **kwargs): if not flask.request.is_json: return '要提交 application/json', 400 if not flask.request.data: return '报文内容不能为空', 400 json = flask.request.json if 'operation' not in json: return 'operation 不能为空', 400 operation = json['operation'] allowoperations = [ OrderOperation.DISPATCH, OrderOperation.DEALWITH, OrderOperation.FINISH, OrderOperation.CLOSE ] if operation not in [o.value for o in allowoperations]: return 'operation 值非法. %s' % operation, 400 operation = OrderOperation(operation) kwargs['operation'] = operation if operation == OrderOperation.DISPATCH: if 'handler' not in json: return '指派订单时必须选定一个用户', 400 handler = json.get('handler') if not handler or not isinstance(handler, str): return '用户ID不合法' handler = userservice.get_user_detail(handler) if not handler: return '指定用户不存在', 400 kwargs['handler'] = handler userid = userservice.get_context_userid() user = userservice.get_user_detail(userid) kwargs['user'] = user return func(*args, **kwargs)
def user_detail(): app.logger.info('Start Fetching User') token = request.headers['Authorization'] user = database.user app.logger.info('Start Fetching User Inner') res = get_user_detail(token, user) response = Response(headers=RESPONSE_HEADERS, content_type='application/json') app.logger.info('End Fetching User Inner') response.data = res[0] response.status_code = res[1] app.logger.info('End Fetching User') return response
def get_qrcodelist(): try: qrcodelist = QrCodeDAO.all('id') for qrcode in qrcodelist: owner = userservice.get_user_detail(qrcode['owner']) if not owner: qrcode['owner'] = None qrcode['ownername'] = None else: qrcode['ownername'] = owner['name'] return ujson.dumps(qrcodelist) except Exception as e: raise RuntimeException('获取二维码列表异常') from e
def orderdetail(orderid: int): try: order = orderservice.get_orderdetail(orderid) if order is None: return flask.make_response(('订单不存在', 404)) order['installtime'] = order['installtime'].strftime( '%Y-%m-%d %H:%M:00') # 根据 source 和 userid 来判断当前用户可执行的操作,添加到返回 header 中 # 管理员可以派发订单也可以自己接单,二维码来源的订单可以由二维码的负责人接单, # 订单负责人和管理员可以完成订单,管理员可以关闭订单 userid = userservice.get_context_userid() # 管理员 ordermanagers = userservice.get_taged_usersids( tagname=UserTag.ORDERMANAGER.name) order['ismanager'] = userid in ordermanagers # 处理人 order['ishandler'] = userid == order['handler'] if order['handler']: handler = userservice.get_user_detail(order['handler']) order['handlername'] = handler['name'] if handler else '未知用户' # 二维码来源 source = order.get('source') if source: qrcode = QrCodeDAO.first_or_default(id=source) if not qrcode: logger.warning('订单的二维码来源不存在. order=%s, source=%s', orderid, source) order['issource'] = False order['sourcename'] = None else: order['issource'] = qrcode['owner'] == userid order['sourcename'] = qrcode['name'] return ujson.dumps(order) except Exception as e: raise RuntimeException('获取订单详情异常', extra={'orderid': orderid}) \ from e
def wrapper(*args, **kwargs): user, sourcename, sourcemobile = None, None, None source = flask.request.args.get('source') if source and source.isdigit(): qrcode = QrCodeDAO.first_or_default(id=int(source)) if qrcode and qrcode.get('owner'): user = userservice.get_user_detail(qrcode.get('owner')) if user: sourcename = user['name'] sourcemobile = user['mobile'] if not sourcename or not sourcemobile: sourcename = config['corp']['manager']['name'] sourcemobile = config['corp']['manager']['mobile'] kwargs['sourcename'] = sourcename[0] + '经理' kwargs['sourcemobile'] = sourcemobile return func(*args, **kwargs)
def user_detail(): app.logger.info('Processing Find User...') token = request.json['headers']['Authorization'] user = database.user return get_user_detail(token, user)