Пример #1
0
def deletebiz(bizid):
    try:
        BizDAO.update({'disabled': 1}, id=bizid)
        return '', 204

    except Exception as e:
        raise RuntimeException('删除套餐异常',
                               extra={'bizid': bizid}) \
            from e
Пример #2
0
def updatebiz(bizid, **kwargs):
    try:
        with transaction():
            BizDAO.update({**kwargs}, id=bizid)
            return '', 204

    except Exception as e:
        raise RuntimeException('修改套餐异常',
                               extra={'bizid': bizid,
                                      **kwargs}) \
            from e
Пример #3
0
def biz_preview(bizid, sourcename=None, sourcemobile=None):
    try:
        biz = BizDAO.first_or_default(id=bizid)

        if biz is None:
            logger.warning('用户访问一个不存在的套餐. bizid=%d', bizid)
            return flask.render_template('404.html', message='套餐不存在'), 404

        operator = OperatorDAO.first_or_default(id=biz['operator'])
        if operator is None:
            logger.warning('用户访问一个供应商不存在的套餐, bizid=%d', bizid)
            return flask.render_template('404.html', message='套餐不存在'), 404

        biz['operatorname'] = operator['name']
        biz['boards'] = ujson.loads(biz['boards'])

        return flask.render_template('bizpreview.html',
                                     biz=biz,
                                     n=sourcename,
                                     m=sourcemobile,
                                     t=config['corp']['customerserver']['tel'])

    except:
        logger.exception('套餐预览页面异常 %d', bizid)
        return flask.render_template('500.html'), 500
Пример #4
0
def bizs(sourcename=None, sourcemobile=None):
    try:
        operators = OperatorDAO.all('id', disabled=0)
        bizs = BizDAO.all(disabled=0)

        operatordict = {o['id']: o for o in operators}

        for o in operators:
            o['bizs'] = []
            o.pop('id')
            o.pop('disabled')

        for b in bizs:
            operatordict[b['operator']]['bizs'].append(b)
            b.pop('boards')
            b.pop('disabled')
            b.pop('operator')

        return ujson.dumps({'operators': operators,
                            'source': {'name': sourcename,
                                       'mobile': sourcemobile},
                            'customerservice': {'tel': config['corp']['customerserver']['tel']}
                            })

    except Exception:
        logger.exception('获取套餐列表异常')
        return '接口错误', 500
Пример #5
0
def createbiz(**kwargs):
    try:
        with transaction():
            bizid = BizDAO.insert({**kwargs})
            return str(bizid), 201

    except Exception as e:
        raise RuntimeException('创建套餐异常',
                               extra={**kwargs}) \
            from e
Пример #6
0
def operatorbizs(operatorid):
    try:
        operator = OperatorDAO.first_or_default(id=operatorid)
        if operator is None:
            return '供应商不存在', 404

        bizs = BizDAO.all('id', operator=operatorid, disabled=0)

        return ujson.dumps({'operatorid': operatorid,
                            'operatorname': operator['name'],
                            'bizs': bizs})

    except Exception as e:
        raise RuntimeException('获取供应商套餐异常',
                               extra={'operatorid': operatorid}) \
            from e
Пример #7
0
def getbiz(bizid):
    try:
        biz = BizDAO.first_or_default(id=bizid)

        if biz is None:
            return '套餐不存在', 404

        operator = OperatorDAO.first_or_default(id=biz['operator'])

        if operator is None:
            return '套餐的供应商%d不存在' % biz['operator'], 404

        biz['operator'] = operator['id']
        biz['operatorname'] = operator['name']
        biz['boards'] = ujson.loads(biz['boards'])

        return ujson.dumps(biz)

    except Exception as e:
        raise RuntimeException('获取套餐详情异常',
                               extra={'bizid': bizid}) \
            from e
Пример #8
0
def get_orderdetail(orderid: int):
    order = OrderDAO.first_or_default(id=orderid)

    if order is None:
        return None

    # 套餐
    biz = BizDAO.first_or_default(id=order['biz'])
    if biz is None:
        logger.error('订单没有对应的套餐. order=%s, biz=%s', orderid, order['biz'])
        return None

    order['bizname'] = biz['name']

    # 供应商
    operator = OperatorDAO.first_or_default(id=biz['operator'])
    if operator is None:
        logger.error('订单没有对应的供应商. order=%s, biz=%s, operator=%d', orderid,
                     order['biz'], biz['operator'])
        return None

    order['operatorname'] = operator['name']

    return order