Ejemplo n.º 1
0
def get_agent_sub_advertiser():
    dbg('get_agent_sub_advertiser')
    reply ,status_code = {'code': 0, 'msg': ''}, 200

    try:
        data     = request.get_json()
        agent_id = data['agent_id']
        page  = request.args.get('page', 1, type=int)
        psize = request.args.get('psize', 10, type=int)
    except:
        print_exception_info()
        raise ApiError('ERROR_PARAM', error.ERROR_PARAM)

    count, advertisers = dbapi.get_advertiser(hook_agent_id=agent_id, page=page, psize=psize)

    data = []
    if count:
        for advertiser in advertisers:
            info = {
                'id': advertiser.id,
                'name': advertiser.name,
                'phone': advertiser.phone,
                'email': advertiser.email,
                'desc': advertiser.desc,
                'address': advertiser.address,
                'remark': advertiser.remark
            }
            data.append(info)

    reply['data'] = {
        'count': count,
        'advertisers': data
    }

    return make_response(jsonify(reply), status_code)
Ejemplo n.º 2
0
def get_advertiser_info():
    dbg('get_advertiser_info')
    reply ,status_code = {'code': 0, 'msg': ''}, 200

    try:
        data     = request.get_json()
        advertiser_id = data['advertiser_id']
    except:
        print_exception_info()
        raise ApiError('ERROR_PARAM', error.ERROR_PARAM)

    advertiser = dbapi.get_advertiser(id=advertiser_id)
    if not advertiser:
        raise ApiError('ERROR_ADVERTISER_NOT_FOUND', error.ERROR_ADVERTISER_NOT_FOUND)

    reply['data'] = {
        'id': advertiser.id,
        'name': advertiser.name,
        'phone': advertiser.phone,
        'email': advertiser.email,
        'desc': advertiser.desc,
        'address': advertiser.address,
        'remark': advertiser.remark
    }
    return make_response(jsonify(reply), status_code)
Ejemplo n.º 3
0
def add_advertiser():
    dbg('add_advertiser')
    reply ,status_code = {'code': 0, 'msg': ''}, 200
    try:
        data    = request.get_json()
        name    = data['name']
        email   = data['email']
        phone   = data['phone']
        address = data['address']
        desc    = data['desc']
        remark  = data['remark']
    except:
        print_exception_info()
        raise ApiError('ERROR_PARAM', error.ERROR_PARAM)

    target_advertiser = dbapi.get_advertiser(phone=phone)
    if target_advertiser:
        raise ApiError('ERROR_PHONE_EXISTS', error.ERROR_PHONE_EXISTS)

    agent = dbapi.get_agent(phone=phone)
    if agent:
        raise ApiError('ERROR_PHONE_EXISTS', error.ERROR_PHONE_EXISTS)

    openluat_user = dbapi.get_openluat_user(phone=phone)
    if not openluat_user:
        openluat_user = dbapi.make_new_openluat_user(name, email, phone)
        db.session.commit()

    agent_id = current_user.agent_id
    hook_agent_id = agent_id
    new_agent = dbapi.make_new_advertiser(openluat_user.id, hook_agent_id,
        name, phone, email, desc, address, remark)
    db.session.commit()

    return make_response(jsonify(reply), status_code)
Ejemplo n.º 4
0
def add_coupon():
    dbg('add_coupon')
    reply ,status_code = {'code': 0, 'msg': ''}, 200

    try:
        advertiser_id = request.form['advertiser_id']
        title       = request.form['title']
        desc        = request.form['desc']
        price       = request.form['price']
        total       = request.form['total']

        imag_file   = request.files['0']

    except:
        print_exception_info()
        raise ApiError('ERROR_PARAM', error.ERROR_PARAM)

    advertiser = dbapi.get_advertiser(id=int(advertiser_id))
    if not advertiser:
        raise ApiError('ERROR_ADVERTISER_NOT_FOUND', error.ERROR_ADVERTISER_NOT_FOUND)

    # check img
    im = Image.open(imag_file)
    w, h = im.size
    ratio = w / h

    if ratio > 0.53 or ratio < 0.47:
        raise ApiError('ERROR_IMG_SIZE_NOT_MATCH', error.ERROR_IMG_SIZE_NOT_MATCH)

    # 创建product
    value, cat = 0, dbapi.PRODUCT_CAT_COUPON
    product = dbapi.make_new_product(advertiser.hook_agent_id, title,
        desc, value, cat, price, total)
    db.session.commit()

    # 创建订单
    pay_mode = 1 # 默认微信支付
    trade_no = gen_coupon_order_no(advertiser.openluat_user_id, pay_mode)
    data = wechat_qrcode_make_new_pay(product, trade_no, advertiser.openluat_user_id)

    # 创建coupon
    coupon_img = get_coupon_img(advertiser.id, im, 'jpg')
    prefix = gen_coupon_prefix(title+desc)
    if not prefix:
        raise ApiError('gen prefix failed')
    pay_id = data['id']
    agent_id = current_user.agent_id
    coupon = dbapi.make_new_coupon(agent_id, advertiser.id, product.id, pay_id, 
        title, desc, prefix, total, coupon_img)

    db.session.commit()

    return make_response(jsonify(reply), status_code)
Ejemplo n.º 5
0
def get_cur_advertiser():
    dbg('get_cur_advertiser')
    reply ,status_code = {'code': 0, 'msg': ''}, 200

    advertiser = dbapi.get_advertiser(user_id=user_id)
    if not advertiser:
        raise ApiError('ERROR_AGENT_NOT_FOUND', error.ERROR_AGENT_NOT_FOUND)
    reply['data'] = {
        'id': advertiser.id,
        'name': advertiser.name,
        'phone': advertiser.phone,
        'email': advertiser.email,
        'desc': advertiser.desc,
        'address': advertiser.address,
        'remark': advertiser.remark
    }
    return make_response(jsonify(reply), status_code)
Ejemplo n.º 6
0
def update_advertiser():
    dbg('update_advertiser')
    reply ,status_code = {'code': 0, 'msg': ''}, 200
    try:
        data     = request.get_json()
        advertiser_id = data['advertiser_id']
        update   = data['update']
        keys = ('desc', 'address', 'remark')
        for k in update:
            assert(k in keys)
    except:
        print_exception_info()
        raise ApiError('ERROR_PARAM', error.ERROR_PARAM)

    advertiser = dbapi.get_advertiser(id=advertiser_id)
    if not advertiser:
        raise ApiError('ERROR_ADVERTISER_NOT_FOUND', error.ERROR_ADVERTISER_NOT_FOUND)

    advertiser = dbapi.update_advertiser(advertiser, **update)
    db.session.commit()

    return make_response(jsonify(reply), status_code)
Ejemplo n.º 7
0
def query_order():
    dbg('query_order')
    reply ,status_code = {'code': 0, 'msg': ''}, 200
    try:
        data    = request.get_json()
        start   = datetime.fromtimestamp(int(data['start']))
        end     = datetime.fromtimestamp(int(data['end']))
        status  = data.get('status')
        address = data.get('address')
        imei    = data.get('imei')
        pay_mode = data.get('pay_mode')
        page    = request.args.get('page', 1, type=int)
        psize   = request.args.get('psize', 10, type=int)
    except:
        print_exception_info()
        raise ApiError('query order error', error.ERROR_PARAM)

    agent_id = current_user.agent_id
    if current_user.cur_agent.salesman:
        count, res = dbapi.query_orders_salesman(start, end, psize, page, agent_id, status, address, imei, pay_mode)
        # agent = dbapi.get_agent(id=current_user.cur_agent.hook_agent_id)
        # salesman = agent.salesman
        # count = 0
        # while salesman:
        #     agent = dbapi.get_agent(id=agent.hook_agent_id)
        #     salesman = agent.salesman
        #     if count == 3:
        #         break
        #     count += 1
        # agent_id = agent.id
    else:
        count, res = dbapi.query_orders(start, end, psize, page, agent_id, status, address, imei, pay_mode)
    data = []
    if count and res:
        for r in res:
            pay, device, device_address = r
            agent = dbapi.get_agent(id=device.owner_agent_id)
            pay_way = ''
            if pay.cat == 100:
                user = dbapi.get_advertiser(user_id=pay.user_id)
                user.nickname = user.name
            else:
                user = dbapi.get_user(user_id=pay.user_id)
            username = ''
            if pay.pay_mode == 1:
                pay_way = '微信'
                if user:
                    username = user.nickname
            if pay.pay_mode == 2:
                pay_way = '支付宝'
                if user:
                    username = user.name
            if pay.pay_mode == 3:
                pay_way = '钱包支付'
                if user:
                    username = user.nickname or user.name
            address = ''
            if device_address:
                address = device_address.address
            info = {
                'id'        : pay.id,
                'username'  : username,
                'time'      : int(pay.ctime.timestamp()),
                'trade_no'  : pay.trade_no,
                'total_fee' : pay.total_fee,
                'pay_way'   : pay_way,
                'status'    : pay.status,
                'device_id' : device.id,
                'imei'      : device.imei,
                'cat'       : device.cat,
                'address'   : address,
                'operator'  : agent.name,
            }
            data.append(info)
    reply['data'] = {
        'orders': data,
        'count' : count
    }
    return make_response(jsonify(reply), status_code)
Ejemplo n.º 8
0
 def wrapper(*args, **kws):
     advertiser = dbapi.get_advertiser(user_id=current_user.id)
     if not advertiser:
         raise ApiError('ERROR_ADVERTISER_NOT_FOUND', error.ERROR_ADVERTISER_NOT_FOUND)
     current_user.cur_advertiser = advertiser
     return func(*args, **kws)
Ejemplo n.º 9
0
def web_login():
    dbg('web_login')
    reply, status_code = {'code': 0, 'msg': ''}, 200
    try:
        data = request.get_json()
        phone = data['phone']
        pswd = data['pswd']
    except:
        print_exception_info()
        raise ApiError('ERROR_PARAM', error.ERROR_PARAM)

    openluat_user = dbapi.get_openluat_user(phone=phone)
    if not openluat_user:
        raise ApiError('ERROR_NO_USER', error.ERROR_NO_USER)

    if not openluat_user.verify_password(pswd):
        raise ApiError('ERROR_WRONG_PSWD', error.ERROR_WRONG_PSWD)

    login_user(openluat_user)

    openluat_role = openluat_user.role[5]
    user_id = openluat_user.id
    data = {'role': 0}
    if openluat_role == '0':
        agent = dbapi.get_agent(user_id=user_id)
        if agent:
            god_info = get_god_info_common(agent)
            data['common'] = {
                'logo': url_for('static', filename=god_info.logo),
                'title': god_info.title
            }
            agent_id = agent.id
            joinup = check_joinup_available(agent_id)
            joinuped = get_joinup_status(agent_id)
            data['role'] = 2
            data['agent'] = {
                'id': agent.id,
                'salesman': agent.salesman,
                'level': agent.level,
                'slevel': agent.slevel,
                'expandable': agent.expandable,
                'withdrawable': agent.withdrawable,
                'name': agent.name,
                'phone': agent.phone,
                'email': agent.email,
                'desc': agent.desc,
                'address': agent.address,
                'remark': agent.remark,
                'joinup': joinup,
                'joinuped': joinuped
            }
        else:
            advertiser = dbapi.get_advertiser(user_id=user_id)
            if advertiser:
                god_info = get_god_info_common(advertiser)
                data['common'] = {
                    'logo': url_for('static', filename=god_info.logo),
                    'title': god_info.title
                }
                top_agent = get_top_agent(advertiser)
                data['role'] = 3
                data['advertiser'] = {
                    'id': advertiser.id,
                    'name': advertiser.name,
                    'phone': advertiser.phone,
                    'email': advertiser.email,
                    'desc': advertiser.desc,
                    'address': advertiser.address,
                    'remark': advertiser.remark
                }
    elif openluat_role in ('1', '2'):
        god = dbapi.get_god(openluat_user_id=user_id)
        if god:
            god_info = get_god_info_common(god)
            data['common'] = {
                'logo': url_for('static', filename=god_info.logo),
                'title': god_info.title
            }
            data['role'] = 1
            data['god'] = {
                'level': int(openluat_role),
                'id': god.id,
                'name': god.name
            }

    reply['data'] = data

    return make_response(jsonify(reply), status_code)
Ejemplo n.º 10
0
def get_cur_user_info():
    dbg('get_cur_user_info')
    reply, status_code = {'code': 0, 'msg': ''}, 200
    """
        role: 1god 2agent 3advertiser 0other
    """

    openluat_role = current_user.role[5]
    user_id = current_user.id
    data = {'role': 0}
    if openluat_role == '0':
        agent = dbapi.get_agent(user_id=user_id)
        if agent:
            god_info = get_god_info_common(agent)
            data['common'] = {
                'logo': url_for('static', filename=god_info.logo),
                'title': god_info.title
            }
            agent_id = agent.id
            joinup = check_joinup_available(agent_id)
            joinuped = get_joinup_status(agent_id)
            data['role'] = 2
            data['agent'] = {
                'id': agent.id,
                'salesman': agent.salesman,
                'level': agent.level,
                'slevel': agent.slevel,
                'expandable': agent.expandable,
                'withdrawable': agent.withdrawable,
                'name': agent.name,
                'phone': agent.phone,
                'email': agent.email,
                'desc': agent.desc,
                'address': agent.address,
                'remark': agent.remark,
                'joinup': joinup,
                'joinuped': joinuped
            }
        else:
            advertiser = dbapi.get_advertiser(user_id=user_id)
            if advertiser:
                god_info = get_god_info_common(advertiser)
                data['common'] = {
                    'logo': url_for('static', filename=god_info.logo),
                    'title': god_info.title
                }
                data['role'] = 3
                data['advertiser'] = {
                    'id': advertiser.id,
                    'name': advertiser.name,
                    'phone': advertiser.phone,
                    'email': advertiser.email,
                    'desc': advertiser.desc,
                    'address': advertiser.address,
                    'remark': advertiser.remark
                }
    elif openluat_role in ('1', '2'):
        god = dbapi.get_god(openluat_user_id=user_id)
        if god:
            god_info = get_god_info_common(god)
            data['common'] = {
                'logo': url_for('static', filename=god_info.logo),
                'title': god_info.title
            }
            data['role'] = 1
            data['god'] = {
                'level': int(openluat_role),
                'id': god.id,
                'name': god.name
            }

    reply['data'] = data

    return make_response(jsonify(reply), status_code)