Пример #1
0
def create_qrcode(name: str = None, owner: str = None, remark: str = None):
    try:
        with transaction():
            record = {
                'name': name,
                'owner': owner,
                'remark': remark,
                'imagename': ''
            }
            qrcodeid = QrCodeDAO.insert(record)
            qrcodeservice.generate_qrcode(qrcodeid=qrcodeid,
                                          imagename='%d.jpg' % qrcodeid)
            QrCodeDAO.update({'imagename': '%d.jpg' % qrcodeid}, id=qrcodeid)

            return str(qrcodeid), 201

    except BusinessException as e:
        logger.exception('创建二维码业务错误')
        return e.msg, e.errcode

    except Exception as e:
        raise RuntimeException('创建二维码异常',
                               extra={'name': name,
                                      'owner': owner,
                                      'remark': remark}) \
            from e
Пример #2
0
def update_qrcode(qrcodeid,
                  name: str = None,
                  owner: str = None,
                  remark: str = None):
    try:
        record = {'name': name, 'owner': owner, 'remark': remark}
        QrCodeDAO.update(record, id=qrcodeid)
        return '', 204

    except Exception as e:
        raise RuntimeException('更新二维码异常',
                               extra={'name': name,
                                      'owner': owner,
                                      'remark': remark}) \
            from e
Пример #3
0
def qrcode_preview(qrcodeid):
    try:
        qrcode = QrCodeDAO.first_or_default(id=qrcodeid)

        if qrcode is None:
            logger.warning('用户访问一个不存在的二维码. %d', qrcodeid)
            return flask.render_template('404.html', message='二维码不存在'), 404

        return flask.render_template('qrcodepreview.html',
                                     imagepath=qrcodeservice.get_qrcode_url_path(qrcode['imagename']))

    except Exception:
        logger.exception('二维码预览页面异常, qrcodeid: %s', qrcodeid)
        return flask.render_template('500.html'), 500
Пример #4
0
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
Пример #5
0
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
Пример #6
0
def createorder(**kwargs):
    try:
        with transaction():
            created_date = datetime_utils.utc8now().date()

            orderid = OrderDAO.insert({'biz': kwargs.get('biz'),
                                       'status': OrderStatus.WAITING.value,
                                       'realname': kwargs.get('realname'),
                                       'nickname': kwargs.get('nickname'),
                                       'headimgurl': kwargs.get('headimgurl'),
                                       'mobile': kwargs.get('mobile'),
                                       'address': kwargs.get('address'),
                                       'lon': kwargs.get('lon'),
                                       'lat': kwargs.get('lat'),
                                       'installtime': kwargs.get('installtime'),
                                       'created_date': created_date.strftime('%Y-%m-%d'),
                                       'source': kwargs.get('source')})

            OrderRecordDAO.insert({'orderid': orderid,
                                   'operation': OrderOperation.CREATE.value,
                                   'opname': kwargs.get('realname')})

            # 获取发送通知的对象
            notifyusersids = set(userservice.get_taged_usersids(tagname=UserTag.ORDERMANAGER.name))
            if kwargs.get('source'):
                qrcode = QrCodeDAO.first_or_default(id=kwargs.get('source'))
                if qrcode:
                    notifyusersids.add(qrcode['owner'])

            tousers = '|'.join(notifyusersids)

            # 发送通知
            order_utils.send_order_notify_message(title='新订单通知',
                                                  message='有新订单了',
                                                  tousers=tousers,
                                                  orderid=orderid,
                                                  realname=kwargs.get('realname'),
                                                  mobile=kwargs.get('mobile'),
                                                  address=kwargs.get('address'),
                                                  operatorname=kwargs.get('operatorname'),
                                                  bizname=kwargs.get('bizname'))

            return str(orderid), 201

    except Exception as e:
        raise RuntimeException('提交订单异常', extra={**kwargs}) from e
Пример #7
0
def _get_notify_users_when_finish_or_close(order):
    """ 完成或关闭订单时发送通知的对象 """

    # 订单管理员
    managers_ids = userservice.get_taged_usersids(UserTag.ORDERMANAGER.name)
    touserids = set(managers_ids)

    # 二维码来源
    source = order.get('source')
    if source:
        qrcode = QrCodeDAO.first_or_default(id=source)
        if qrcode:
            touserids.add(qrcode['owner'])

    # 订单处理人
    handler = order.get('handler')
    if handler:
        touserids.add(handler)

    return '|'.join(touserids)
Пример #8
0
        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)