Exemplo n.º 1
0
def login():
    print('login before session', session)
    form = request.form.to_dict()
    print('form', form)
    # https://api.weixin.qq.com/sns/jscode2session?appid=wx4dea673b058fd1a8&secret=4cf491eb3dfc206fe6a7e5d8d47e8c48&js_code=0611WVUD1mB715023RWD1wOEUD11WVUl&grant_type=authorization_code
    wx_login_url = """https://api.weixin.qq.com/sns/jscode2session?appid={appid}&secret={appSecret}&js_code={code}&grant_type=authorization_code""".format(
        appid=base.appid, appSecret=base.appSecret, code=form.get('code'))
    res = requests.post(wx_login_url).json()
    u = User.login(res)
    # 判断是否为管理员
    is_admin = u.is_admin()
    print('is_admin', is_admin)
    u = u.json()
    session['id'] = u.get('id')
    if is_admin is False:
        return make_response(jsonify(Res.fail(u, msg='不是管理员账户')))
    # 设置 cookie 有效期为 永久
    session.permanent = True
    # 筛选需要返回的数据
    filter_map = ['openid', 'id', 'updated_time', 'identity']
    result = dict()
    for k in u.keys():
        if k in filter_map:
            result[k] = u[k]
    resp = make_response(jsonify(Res.success(result)))
    return resp
Exemplo n.º 2
0
def addProductType():
    # form : product_id, bar_code
    form = request.form.to_dict()
    print('form', form)
    # 上传图片
    file = request.files['file']
    if file is not None:
        # 储存图片获取数据
        data = Img.save_one(file, form)
        print('upload data', data)
        if data['src'] is not None and base_url not in data['src']:
            data['src'] = base_url + '/' + data['src']
            form['cover'] = data['src']
        if data is not None:
            r = Res.success(data)
        else:
            r = Res.fail({}, msg='图片已存在')
    print('新图片', form)
    product = Product.add(form)
    if type(product) is str:
        r = Res.fail(msg=product)
    else:
        all = Product.all()
        print('all', all)
        r = Res.success(all)

    return make_response(jsonify(r))
Exemplo n.º 3
0
def delete_one():
    id = request.json.get('id')
    data = Img.delete_one(id=id)
    if data is None:
        r = Res.success()
    else:
        r = Res.fail()
    return make_response(jsonify(r))
Exemplo n.º 4
0
def queryProductByBarCode():
    form = request.form.to_dict()
    q = ProductAttr.queryByBarCode(form)
    if len(q) is 0:
        r = Res.fail(q.msg)
    else:
        r = Res.success(q)

    return make_response(jsonify(r))
Exemplo n.º 5
0
def delete():
    form = request.json
    data = Img.delete_one(id=form.get('id'))
    print('delete form', data is None)
    if data is None:
        r = Res.success()
    else:
        r = Res.fail(msg='图片删除失败')
    return make_response(jsonify(r))
Exemplo n.º 6
0
def delete_more():
    form = request.json
    print('delete_more form', form)
    data = Img.delete_by_ids(ids=form['ids'])
    print('delete_more len', len(data))
    if len(data) is 0:
        r = Res.success()
    else:
        r = Res.fail()
    return make_response(jsonify(r))
Exemplo n.º 7
0
def addProduct():
    form = request.form.to_dict()
    print('form', form)
    product_attr = ProductAttr.add(form)
    print('product_attr', product_attr)
    if type(product_attr) is str:
        r = Res.fail(msg=product_attr)
    else:
        r = product_attr
        r = Res.success(product_attr)
    return make_response(jsonify(r))
Exemplo n.º 8
0
def upload():
    form = request.files['file']
    # 储存图片获取数据
    data = Img.save_one(form)
    print('upload data', data)
    if data['src'] is not None and base_url not in data['src']:
        data['src'] = base_url + '/' + data['src']
    if data is not None:
        r = Res.success(data)
    else:
        r = Res.fail({}, msg='图片已存在')
    return make_response(jsonify(r))
Exemplo n.º 9
0
def login_by_account():
    form = request.form.to_dict()
    wx_login_url = """https://api.weixin.qq.com/sns/jscode2session?appid={appid}&secret={appSecret}&js_code={code}&grant_type=authorization_code""".format(
        appid=base.appid, appSecret=base.appSecret, code=form.get('code'))
    res = requests.post(wx_login_url).json()
    print('res', res)
    u = User.one(username=form.get('username'),
                 password=form.get('password')).json()
    print('帐号登录', u)
    u = User.update(id=u.get('id'), openid=res.get('openid'))
    if u is None:
        return make_response(jsonify(Res.fail(msg='帐号密码错误')))
    else:
        session['id'] = u.get('id')
        return make_response(jsonify(Res.success(u)))
Exemplo n.º 10
0
def update():
    form = request.json
    print('form', form)
    data = Img.update(id=form['id'], show=str(form['enable']))
    print('data', data)
    r = Res.success(data)
    return make_response(jsonify(r))
Exemplo n.º 11
0
def update():
    form = request.form.to_dict()
    form['editor'] = session.get('id')
    data = Stock.update(**form)
    print('data', data)
    r = Res.success(data)
    return make_response(jsonify(r))
Exemplo n.º 12
0
def uploadFile():
    form = request.form.to_dict()
    id = form.get('id')
    print('上传接受的参数', form)
    print('接收信息', request.files)
    file = request.files['file']
    print('file', type(file), file)
    print('文件名', file.filename)  # 打印文件名
    print('name', file.name)
    f = file.read()  # 文件内容
    data = xlrd.open_workbook(file_contents=f)
    table = data.sheets()[0]
    names = data.sheet_names()  # 返回book中所有工作表的名字

    status = data.sheet_loaded(names[0])  # 检查sheet1是否导入完毕
    print('导入状态', status)
    nrows = table.nrows  # 获取该sheet中的有效行数
    ncols = table.ncols  # 获取该sheet中的有效列数
    # print('nrows',nrows)
    # print('ncols',ncols)
    s = table.col_values(2)  # 第1列数据
    print('尺码', s)
    table_name = names[0]
    Batch.update(id=id, upload=1, excel_name=form.get('excel_name'))
    Stock.delete_by_batch_id(id=id)
    res = formatExcel(table)
    # 根据文件名添加批次
    for r in res:
        r['batch'] = form.get('id')

    r = Stock.add_by_list(res)
    # print('导入结果', r)
    return make_response(jsonify(Res.success(r)))
Exemplo n.º 13
0
def uploadFile():

    print('接收信息', request.files)
    file = request.files['file']
    print('file', type(file), file)
    print('文件名', file.filename)  # 打印文件名
    print('name', file.name)
    f = file.read()  # 文件内容
    data = xlrd.open_workbook(file_contents=f)
    table = data.sheepts()[0]
    names = data.sheet_names()  # 返回book中所有工作表的名字

    status = data.sheet_loaded(names[0])  # 检查sheet1是否导入完毕
    print('导入状态', status)
    nrows = table.nrows  # 获取该sheet中的有效行数
    ncols = table.ncols  # 获取该sheet中的有效列数
    # print('nrows',nrows)
    # print('ncols',ncols)
    s = table.col_values(2)  # 第1列数据
    print('尺码', s)
    table_name = names[0]
    res = formatExcel(table)
    # 根据文件名添加批次
    for r in res:
        r['batch'] = table_name

    r = Stock.add_by_list(res)
    # print('导入结果', r)
    return make_response(jsonify(Res.success(r)))
Exemplo n.º 14
0
def queryByBatch():
    # 查询商品大类
    form = request.form.to_dict()
    id = form.get('id')
    r = Stock.queryAll(id=id)
    r = Res.success(r)
    print('查询所有商品', r)
    return make_response(jsonify(r))
Exemplo n.º 15
0
def current_user():
    log('真正的sesson', session)
    user_id = session.get('id')
    log('current session获取的id', user_id)
    if user_id is not None:
        u = User.one(id=user_id)
        log('查询结果', u)
        return u.json()
    else:
        log('没进去')
        return make_response(jsonify(Res.fail('没有权限')))
Exemplo n.º 16
0
def queryImageByName():
    form = request.args.to_dict()
    print('根据标题搜索数据', form)
    data, count = Img.queryImageByCondition(**form)
    d = dict(
        list=data,
        count=count
    )
    r = Res.success(d)
    print('queryImageByName 结果', r)
    return make_response(jsonify(r))
Exemplo n.º 17
0
    def f():
        log('是否进入登录判断')
        u = current_user()
        log('判断用户', u)
        log('用户权限', u.get('identity'), '管理员权限', identity_map.get('admin'))
        if u.get('identity') == identity_map.get('admin') or u.get(
                'identity') == identity_map.get('tester'):
            log('登录用户', route_function)
            return route_function()

        else:
            log('游客用户')
            r = Res.fail(u, msg='不是管理员用户')
            return make_response(jsonify(r))
Exemplo n.º 18
0
def queryUserInfo(*args, **kwargs):
    print('session', session)
    uid = session.get('user_id')  # uid = 1
    print('queryUserInfo uid', uid)
    u = User.one(id=uid)
    print('queryUserInfo u', u)
    data = dict(
        roles=[u.token],
        name=u.username,
        avatar=u.avatar,
    )
    r = Res.success(data)
    resp = make_response(jsonify(r))
    return resp
Exemplo n.º 19
0
def findAll():
    form = request.args.to_dict()
    page_size = form.get('page_size') or None
    page_index = form.get('page_index') or None
    data, count= Img.all(page_size=page_size, page_index= page_index)
    data_json = [d.json() for d in data]
    for d in data_json:
        # format = '%Y-%m-%d %H:%M:%S'
        ct= d['created_time']
        # d['created_time'] = '{}-{}-{} {}:{}:{}'.format(ct.year, ct.month, ct.day, ct.hour, ct.minute, ct.second)
        d['created_time'] = ct.strftime("%Y-%m-%d %H:%M:%S")

    d = dict(
        list=data_json,
        count=count
    )
    r = Res.success(d)
    resp = make_response(jsonify(r))
    return resp
Exemplo n.º 20
0
def query_config():
    r = DictMap.query_config()
    return make_response(jsonify(Res.success(r)))
Exemplo n.º 21
0
def add_one():
    form = request.form.to_dict()
    print('form in add batch', form)
    r = Batch.new(form).json()
    r = Res.success(r)
    return make_response(jsonify(r))
Exemplo n.º 22
0
def query_all():
    # 查询商品大类
    r = Batch.all()
    r = Res.success(r)
    print('查询所有商品', r)
    return make_response(jsonify(r))
Exemplo n.º 23
0
def queryProdcut():
    # 查询商品大类
    r = Product.queryAll()
    r = Res.success(r)
    print('查询所有商品', r)
    return make_response(jsonify(r))
Exemplo n.º 24
0
def queryProdcutAttr():
    # 查询对应商品子类
    r = ProductAttr.queryAll()
    r = Res.success(r)
    print('查询所有商品')
    return make_response(jsonify(r))