Esempio n. 1
0
def info():
    resp_data = {}
    req = request.args
    uid = int(req.get('id', 0))
    reback_url = UrlManager.buildUrl("/account/index")
    if uid < 1:
        return redirect(reback_url)

    info = User.query.filter_by(uid=uid).first()
    if not info:
        return redirect(reback_url)

    access_list = AppAccessLog.query.filter_by(uid=uid).order_by(AppAccessLog.id.desc()).limit(10).all()
    resp_data['info'] = info
    resp_data['access_list'] = access_list
    return ops_render("account/info.html", resp_data)
Esempio n. 2
0
File: User.py Progetto: rlzhz/hmsc-1
def login():
    if request.method == 'GET':
        if g.current_user:
            return redirect(UrlManager.buildUrl("/"))
        return ops_render("user/login.html")
        
    # POST请求
    resp = {
        'code':200,
        'msg':'登录成功',
        'data':{}
    }
    req = request.values
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''

    if login_name is None or len(login_name) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入正确的用户名"
        return jsonify(resp)
    if login_pwd is None or len(login_pwd) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入正确的密码"
        return jsonify(resp)
    # 从数据库中取出user
    user_info = User.query.filter_by(login_name=login_name).first()
    if not user_info:
        resp['code'] = -1
        resp['msg'] = "用户不存在"
        return jsonify(resp)
    # 判断密码
    if user_info.login_pwd != UserService.generatePwd(login_pwd,user_info.login_salt):
        resp['code'] = -1
        resp['msg'] = "密码输入错误"
        return jsonify(resp)
    
    # 判断用户状态
    if user_info.status != 1:
        resp['code'] = -1
        resp['msg'] = "用户已经被禁用,请联系管理员处理"
        return jsonify(resp)
    
    
    response = make_response(json.dumps({'code':200,'msg':'登录成功~~~'}))
    # Cookie中存入的信息是user_info.uid,user_info
    response.set_cookie(app.config['AUTH_COOKIE_NAME'],"%s@%s"%(UserService.generateAuthCode(user_info),user_info.uid),60*60*24*15)
    return response
Esempio n. 3
0
def orderInfo():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    req = request.values
    params_goods = req['goods'] if 'goods' in req else None
    memeber_info = g.member_info
    params_goods_list = []
    if params_goods:
        params_goods_list = json.loads(params_goods)

    food_dic = {}
    for item in params_goods_list:
        food_dic[item['id']] = item['number']

    food_ids = food_dic.keys()
    food_list = Food.query.filter(Food.id.in_(food_ids)).all()
    data_food_list = []
    # 运费
    yun_price = pay_price = decimal.Decimal(0.00)
    if food_list:
        for item in food_list:
            tem_data = {
                "id": item.id,
                "name": item.name,
                "price": str(item.price),
                "pic_url": UrlManager.buildImageUrl(item.main_image),
                "number": food_dic[item.id]
            }
            pay_price = pay_price + item.price * int(food_dic[item.id])
            data_food_list.append(tem_data)

    address_info = MemberAddress.query.filter_by(is_default=1).first()
    default_address = {
        "name":
        address_info.nickname,
        "mobile":
        address_info.mobile,
        "address":
        "%s,%s,%s,%s" % (address_info.province_str, address_info.city_str,
                         address_info.area_str, address_info.address),
    }
    print('----------', default_address)
    resp['data']['food_list'] = data_food_list
    resp['data']['pay_price'] = str(pay_price)
    resp['data']['yun_price'] = str(yun_price)
    resp['data']['total_price'] = str(pay_price + yun_price)
    resp['data']['default_address'] = default_address
    return jsonify(resp)
Esempio n. 4
0
File: User.py Progetto: wgf0210/hmsx
def login():
    print('123')
    if request.method == 'GET':
        if g.current_user:
            return redirect(UrlManager.buildUrl('/'))
        return ops_render('user/login.html')
    resp = {'code': 200, 'msg': '登陆成功!', 'data': {}}
    req = request.values
    login_name = req['login_name']
    login_pwd = req['login_pwd']
    # 后端校检 不为空,长度不小于1
    if login_name is None or len(login_name) < 1:
        resp['code'] = -1
        resp['msg'] = '请输入正确的用户名'
        return jsonify(resp)
    if login_pwd is None or len(login_pwd) < 1:
        resp['code'] = -1
        resp['msg'] = '请输入正确的密码'
        return jsonify(resp)
    # 数据库比对
    user_info = User.query.filter_by(login_name=login_name).first()
    print(user_info.login_name)
    if not user_info:
        resp['code'] = -1
        resp['msg'] = '用户不存在'
        return jsonify(resp)
    if user_info.status != 1:
        resp['code'] = -1
        resp['msg'] = '账号已被禁用,请联系管理员处理'
        return jsonify(resp)
    if user_info.login_pwd != Userservice.generatepwd(login_pwd,
                                                      user_info.login_salt):
        resp['code'] = -1
        resp['msg'] = '密码错误'
        return jsonify(resp)
    print('账号密码正确')
    # 将用户信息存入到浏览器的cookie中
    # json.dumps()他只能处理dict和list类型,经过处理之后可以直接在前端/浏览器中使用
    response = make_response(json.dumps({'code': 200, 'msg': '登陆成功!'}))
    # name,value,过期时间
    # value包括login_name,login_pwd,login_salt,uid
    response.set_cookie(
        app.config['AUTH_COOKIE_NAME'],
        '%s@%s' % (Userservice.generateAuthCode(user_info), user_info.uid),
        60 * 60 * 24 * 5)

    return response
Esempio n. 5
0
def info():
    # 要把current-user传进来,用于layout 中的个人设置页面
    current_user = session.current_user

    req = request.args  #request.args 方法只获得GET方法获得的值,并且可以用req.get直接获取
    uid = int(req.get('id', 0))  #用get直接获取GET方法获得的值,同时设置一个初始值为0
    return_url = UrlManager.buildUrl("/account/index")
    if uid < 1:
        return redirect(return_url)  #如果没有该用户则跳转到用户栏首页

    info = User.query.filter_by(uid=uid).first()  #查一下是否在数据库中有该用户
    if not info:
        return redirect(return_url)  #如果没有该数据那就直接跳回用户栏首页

    return render_template("account/info.html",
                           current_user=current_user,
                           info=info)
Esempio n. 6
0
def myOrderInfo():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    member_info = g.member_info
    req = request.values
    order_sn = req['order_sn'] if 'order_sn' in req else ''
    pay_order_info = PayOrder.query.filter_by(member_id=member_info.id,
                                              order_sn=order_sn).first()
    if not pay_order_info:
        resp['code'] = -1
        resp['msg'] = "系统繁忙,请稍后再试~~"
        return jsonify(resp)

    express_info = {}
    if pay_order_info.express_info:
        express_info = json.loads(pay_order_info.express_info)

    tmp_deadline = pay_order_info.created_time + datetime.timedelta(minutes=30)
    info = {
        "order_sn": pay_order_info.order_sn,
        "status": pay_order_info.pay_status,
        "status_desc": pay_order_info.status_desc,
        "pay_price": str(pay_order_info.pay_price),
        "yun_price": str(pay_order_info.yun_price),
        "total_price": str(pay_order_info.total_price),
        "address": express_info,
        "goods": [],
        "deadline": tmp_deadline.strftime("%Y-%m-%d %H:%M")
    }

    pay_order_items = PayOrderItem.query.filter_by(
        pay_order_id=pay_order_info.id).all()
    if pay_order_items:
        food_ids = select_filter_obj(pay_order_items, "food_id")
        food_map = get_dict_filter_field(Food, Food.id, "id", food_ids)
        for item in pay_order_items:
            tmp_food_info = food_map[item.food_id]
            tmp_data = {
                "name": tmp_food_info.name,
                "price": str(item.price),
                "unit": item.quantity,
                "pic_url":
                UrlManager.build_image_url(tmp_food_info.main_image),
            }
            info['goods'].append(tmp_data)
    resp['data']['info'] = info
    return jsonify(resp)
Esempio n. 7
0
def info():
    resp_data = {}
    req = request.args
    id = int(req.get("id", 0))
    reback_url = UrlManager.buildUrl("/member/index")
    if id < 1:
        return redirect(reback_url)
    info = Member.query.filter_by(id=id).first()
    if not info:
        return redirect(reback_url)

    if info.status != 1:
        return redirect(reback_url)

    resp_data['info'] = info
    resp_data['current'] = 'info'
    return ops_render("member/info.html", resp_data)
Esempio n. 8
0
def uploadImage():
    resp = {'state': 'SUCCESS', 'url': '', 'title': '', 'original': ''}
    file_target = request.files
    upfile = file_target['upfile'] if 'upfile' in file_target else ''
    if upfile is None:
        resp['status'] = '上传失败'
        return jsonify(resp)
    # 上传文件的操作,使用统一封装好的类
    ret = UploadService.uploadByFile(upfile)

    if ret['code'] != 200:
        resp['state'] = '上传失败' + ret['msg']
        return jsonify(resp)

    # 设置返回图片的url地址
    resp['url'] = UrlManager.buildImageUrl(ret['data']['file_key'])
    return jsonify(resp)
Esempio n. 9
0
def set():
    if request.method == "GET":
        req = request.args
        resp_data = {}
        resp_data['current'] = "index"
        id = int(req.get("id", 0))
        reback_url = UrlManager.buildUrl("/member/index")

        if id < 1:
            return redirect(reback_url)

        info = Member.query.filter_by(id=id).first()
        if not info:
            return redirect(reback_url)

        if info.status != 1:
            return redirect(reback_url)

        resp_data['info'] = info
        return ops_render( "member/set.html", resp_data)

    resp = {
        'code': 200,
        'msg': '操作成功',
        'data': {}
    }

    req = request.values
    id = req['id'] if 'id' in req else 0
    nickname = req['nickname'] if 'nickname' in req else ''
    if nickname is None or len(nickname) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的姓名"
        return jsonify(resp)

    member_info = Member.query.filter_by(id=id).first()
    if not member_info:
        resp['code'] = -1
        resp['msg'] = "指定的会员不存在"
        return jsonify(resp)

    member_info.nickname = nickname
    member_info.update_time = getCurrentDate()
    db.session.add(member_info)
    db.session.commit()
    return jsonify(resp)
Esempio n. 10
0
def login():
    if request.method == 'GET':
        if g.current_user:
            return redirect(UrlManager.buildUrl("/"))
        return render_template('user/login.html')
    resp = {'code': 200, 'msg': '登陆成功', 'data': {}}
    req = request.values
    login_name = req['login_name']
    login_pwd = req['login_pwd']
    # 后端校检 不为空 长度不小于1
    if login_name is None or len(login_name) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入正确的用户名~~~"
        return jsonify(resp)
    if login_pwd is None or len(login_pwd) < 1:
        resp['code'] = -1
        resp['msg'] = '请输入正确的密码~~~'
        return jsonify(resp)

    # 数据库比对
    user_info = User.query.filter_by(login_name=login_name).first()
    if not user_info:
        resp['code'] = -1
        resp['msg'] = '用户不存在'
        return jsonify(resp)
    if user_info.status != 1:
        resp['code'] = -1
        resp['msg'] = '账号已经被禁用,请联系管理员处理'
        return jsonify(resp)
    if user_info.login_pwd != UserService.generatePwd(login_pwd,
                                                      user_info.login_salt):
        resp['code'] = -1
        resp['msg'] = '密码错误'
        return jsonify(resp)

    # 将用户信息存入到浏览器的Cookie中
    # json.dumps()处理dict,list类型,经过处理后可以直接在浏览器中使用
    response = make_response(json.dumps({'code': 200, 'msg': '登录成功~~'}))
    # name value 过期时间
    # value包括login_name login_pwd login_uid
    response.set_cookie(
        app.config['AUTH_COOKIE_NAME'],
        '%s@%s' % (UserService.generateAuthCode(user_info), user_info.uid),
        60 * 60 * 24 * 5)

    return response
Esempio n. 11
0
def before_request():
    ignore_urls = app.config['IGNORE_URLS']
    ignore_check_login_urls = app.config['IGNORE_CHECK_LOGIN_URLS']
    path = request.path
    pattern = re.compile('%s' % '|'.join(ignore_check_login_urls))
    if pattern.match(path):
        return
    user_info = check_login()
    g.current_user = None
    if user_info:
        g.current_user = user_info
    pattern = re.compile('%s' % '|'.join(ignore_urls))
    if pattern.match(path):
        return
    if not user_info:
        return redirect(UrlManager.buildUrl("/user/login"))
    return
Esempio n. 12
0
def info():
    resp_data = {}
    req = request.args
    id = int(req.get('id', 0))
    app.logger.info(req)
    reback_url = UrlManager.buildUrl("/member/index")
    if id < 1:
        return redirect(reback_url)
    info = Member.query.filter_by(id=id).first()
    if not info:
        return redirect(reback_url)

    order_list = PayOrder.query.filter_by(member_id=id).order_by(PayOrder.id.desc()).limit(10).all()
    resp_data['info'] = info
    resp_data['order_list'] = order_list
    app.logger.info(order_list)
    return ops_render('member/info.html',resp_data)
Esempio n. 13
0
def before_request():
    g.current_user = None
    ignore_urls = app.config["IGNORE_URLS"]
    ignore_check_login_urls = app.config["IGNORE_CHECK_LOGIN_URLS"]
    path = request.path
    pattern = re.compile("%s" % "|".join(ignore_check_login_urls))
    if pattern.match(path):
        return
    pattern = re.compile("%s" % "|".join(ignore_urls))
    if pattern.match(path):
        return
    user_info = check_login()
    if not user_info:
        return redirect(UrlManager.buildUrl("/user/login"))
    g.current_user = user_info
    LogService.addAccessLog()
    return
Esempio n. 14
0
def info():
    resp_data = {}
    req = request.values
    id = int(req['id']) if 'id' in req else 0

    reback_url = UrlManager.buildUrl("/finance/index")

    # 重定向
    if id < 1:
        return redirect(reback_url)

    pay_order_info = PayOrder.query.filter_by(id=id).first()
    if not pay_order_info:
        return redirect(reback_url)

    member_info = Member.query.filter_by(id=pay_order_info.member_id).first()
    if not member_info:
        return redirect(reback_url)

    # 同样通过item 查找,food name。不如新建一个view。
    order_item_list = PayOrderItem.query.filter_by(
        pay_order_id=pay_order_info.id).all()
    data_order_item_list = []
    if order_item_list:
        food_map = getDictFilterField(
            Food, Food.id, "id", selectFilterObj(order_item_list, "food_id"))
        for item in order_item_list:
            tmp_food_info = food_map[item.food_id]
            tmp_data = {
                "quantity": item.quantity,
                "price": item.price,
                "name": tmp_food_info.name
            }
            data_order_item_list.append(tmp_data)

    address_info = {}
    if pay_order_info.express_info:
        address_info = json.loads(pay_order_info.express_info)

    resp_data['pay_order_info'] = pay_order_info
    resp_data['pay_order_items'] = data_order_item_list
    resp_data['member_info'] = member_info
    resp_data['address_info'] = address_info
    resp_data['current'] = 'index'
    return ops_render("finance/pay_info.html", resp_data)
Esempio n. 15
0
def info():
    resp_data = {}
    req = request.values
    id = int(req['id']) if 'id' in req else 0

    reback_url = UrlManager.buildUrl("/finance/index")

    if id < 1:
        return redirect( reback_url )

    pay_order_info = PayOrder.query.filter_by( id = id ).first()
    if not pay_order_info:
        return redirect(reback_url)

    member_info = Member.query.filter_by( id = pay_order_info.member_id ).first()
    if not member_info:
        return redirect(reback_url)

    order_item_list = PayOrderItem.query.filter_by( pay_order_id = pay_order_info.id ).all()
    data_order_item_list = []
    if order_item_list:
        food_map = getDictFilterField(Food, Food.id, "id", selectFilterObj(order_item_list, "food_id"))
        for item in order_item_list:
            tmp_food_info = food_map[ item.food_id ]
            tmp_data = {
                "quantity":item.quantity,
                "price":item.price,
                "name":tmp_food_info.name
            }
            data_order_item_list.append( tmp_data )

    address_info = MemberAddress.query.filter_by(id=pay_order_info.express_address_id).first()
    if address_info:
        address_info = {
            'mobile': address_info.mobile,
            'nickname': address_info.nickname,
            "address": "%s%s%s%s" % (
                address_info.province_str, address_info.city_str, address_info.area_str, address_info.address)
        }
    resp_data['pay_order_info'] = pay_order_info
    resp_data['pay_order_items'] = data_order_item_list
    resp_data['member_info'] = member_info
    resp_data['address_info'] = address_info
    resp_data['current'] = 'index'
    return render_template_ops( "finance/pay_info.html",resp_data )
Esempio n. 16
0
def login():
    """
    登录控制器处理
    :return: 登录页面视图
    """
    if request.method == "GET":
        if g.current_user:
            return redirect(UrlManager.build_url("/"))
        return ops_render("user/login.html")

    resp = {'code': 200, 'msg': '登录成功~~', 'data': {}}
    req = request.values
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''

    if login_name is None or len(login_name) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入正确的登录用户名~~"
        return jsonify(resp)

    if login_pwd is None or len(login_pwd) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入正确的邮箱密码~~"
        return jsonify(resp)

    user_info = User.query.filter_by(login_name=login_name).first()
    if not user_info:
        resp['code'] = -1
        resp['msg'] = "请输入正确的登录用户名和密码-1~~"
        return jsonify(resp)

    if user_info.login_pwd != UserService.generate_password(login_pwd, user_info.login_salt):
        resp['code'] = -1
        resp['msg'] = "请输入正确的登录用户名和密码-2~~"
        return jsonify(resp)

    if user_info.status != 1:
        resp['code'] = -1
        resp['msg'] = "账号已被禁用,请联系管理员处理~~"
        return jsonify(resp)

    response = make_response(json.dumps({'code': 200, 'msg': '登录成功~~'}))
    response.set_cookie(app.config['AUTH_COOKIE_NAME'], '%s#%s' % (
        UserService.generate_auth_code(user_info), user_info.uid), 60 * 60 * 24 * 120)  # 保存120天
    return response
Esempio n. 17
0
def uploadImage():
    # 统一的返回格式
    resp = {'state': 'SUCCESS', 'url': '', 'title': '', 'original': ''}
    file_target = request.files
    # 取出文件对象
    upfile = file_target['upfile'] if 'upfile' in file_target else None
    if upfile is None:
        resp['state'] = '上传失败'
        return jsonify(resp)
    # 调用保存方法
    ret = UploadService.uploadByFile(upfile)
    if ret['code'] != 200:
        resp['state'] = '上传失败' + ret['msg']
        return jsonify(resp)

    resp['url'] = ret['data']['file_key']
    resp['url'] = UrlManager.buildImage(resp['url'])
    return jsonify(resp)
Esempio n. 18
0
def course_index():
    '''返回首页的banner信息以及相应的课程'''
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    food_list = Food.query.filter_by( status = 1 )\
        .order_by( Food.total_count.desc(),Food.id.desc() ).limit(5).all()
    data_food_list = []
    if food_list:
        for item in food_list:
            tmp_data = {
                'id': item.id,
                'pic_url': UrlManager.buildImageUrl(item.main_image),
                'food_name': item.name,
                'total': item.total_count
            }
            data_food_list.append(tmp_data)

    resp['data']['banner_list'] = data_food_list
    return jsonify(resp)
Esempio n. 19
0
def list_image():
    res = {'state': 'SUCCESS', 'list': [], 'start': 0, 'total': 0}
    req_data = request.values
    start = int(req_data['start']) if 'start' in req_data else 0
    page_size = int(req_data['size']) if 'size' in req_data else 20
    query = Image.query
    if start > 0:
        query = query.fileter(Image.id < start)
    image_list = query.order_by(Image.id.desc()).limit(page_size).all()
    images = []
    if image_list:
        for item in image_list:
            images.append({'url': UrlManager.buildImageUrl(item.file_key)})
            start = item.id
    res['list'] = images
    res['start'] = start
    res['total'] = len(images)
    return jsonify(res)
Esempio n. 20
0
def listImage():
    resp = {'state': 'SUCCESS', 'url': '', 'title': '', 'original': ''}
    req = request.values
    start = int(req['start']) if 'start' in req else 0
    page_size = int(req['size']) if 'size' in req else 20
    query = Image.query
    if start > 0:
        query = query.filter(Image.id < start)
    list = query.order_by(Image.id.desc()).offset(start).limit(page_size).all()
    images = []
    if list:
        for item in list:
            images.append({'url': UrlManager.buildImageUrl(item.file_key)})
            start = item.id
    resp['list'] = images
    resp['start'] = start
    resp['total'] = len(images)
    return jsonify(resp)
Esempio n. 21
0
def info():
    res_data = {}
    req = request.args
    uid = int(req.get('id', 0))
    reback_url = UrlManager.buildUrl('/account/index')
    if uid < 1:
        return redirect(reback_url)

    info = User.query.filter_by(uid=uid).first()
    if not info:
        return redirect(reback_url)
    res_data['info'] = info

    access_count = app.config['ACCESS_COUNT']
    access_list = AppAccessLog.query.filter_by(uid=uid).order_by(
        desc(AppAccessLog.created_time)).all()[0:access_count]
    res_data['access_list'] = access_list
    return ops_render("account/info.html", res_data)
Esempio n. 22
0
def info():
    resp_data = {}
    req = request.args
    id = int(req.get('id', 0))
    reback_url = UrlManager.buildUrl('/food/index')

    if id < 1:
        return redirect(reback_url)
    info = Food.query.filter_by(id=id).first()
    if not info:
        return redirect(reback_url)

    stock_change_list = FoodStockChangeLog.query.filter(FoodStockChangeLog.food_id == id)\
        .order_by(FoodStockChangeLog.id.desc()).all()
    resp_data['current'] = 'info'
    resp_data['stock_change_list'] = stock_change_list
    resp_data['info'] = info
    return ops_render("food/info.html", resp_data)
Esempio n. 23
0
def info():
    resp_data = {}
    req = request.args
    uid = int(req.get('id', 0))
    reback_url = UrlManager.buildUrl("/account/index")
    if uid < 1:
        return redirect(reback_url)

    info = User.query.filter_by(uid=uid).first()
    if not info:
        return redirect(reback_url)
    error_log = AppAccessLog.query.filter_by(uid=uid)\
    .order_by(AppAccessLog.uid.desc()).all()[:AppAccessLog.query.filter_by(uid=uid).count() if AppAccessLog.query.filter_by(uid=uid).count() < 5 else 5]
    # access_list = AppAccessLog.query.filter_by( uid = uid).order_by(AppAccessLog.id.desc() ).limit(10).all()
    resp_data['info'] = info
    # resp_data['access_list'] = access_list
    resp_data['error_log'] = error_log
    return render_template_ops("account/info.html", resp_data)
Esempio n. 24
0
def getInvoiceDetail(invoice):
    if not invoice:
        return {}
    data = {
        "id": invoice.invoice_id,
        "address": invoice.address,
        "phone": invoice.phone,
        "notes": invoice.notes,
        "del_flag": invoice.del_flag,
        "amount": float(invoice.amount),
        "create_time": invoice.create_time.strftime("%d/%m/%Y"),
        "update_time": invoice.update_time,
        "status": invoice.status,
        "file_path": UrlManager.buildImageUrl(invoice.file_path),
        "group_name": invoice.group_name
    }

    return data
Esempio n. 25
0
def info():
    resp_data = {}
    req = request.values
    id = int(req['id']) if 'id' in req and req['id'].isdigit() else 0
    reback_url = UrlManager.buildUrl('/food/index')
    if not id:
        return redirect(reback_url)
    food_info = Food.query.filter_by(id=id).first()
    if not food_info:
        return redirect(reback_url)

    stock_change_list = FoodStockChangeLog.query.filter(FoodStockChangeLog.food_id==id)\
            .order_by(FoodStockChangeLog.id.desc()).all()

    resp_data['stock_change_list'] = stock_change_list
    resp_data['food_info'] = food_info
    resp_data['current'] = 'index'
    return ops_render('food/info.html', resp_data)
Esempio n. 26
0
def set():
    # 展示账户详情
    if request.method == 'GET':
        resp_data = {}
        req = request.args
        id = int(req.get('id',0))
        reback_url = UrlManager.buildUrl('/member/index')
        if id < 1:
            return redirect(reback_url)
        info = Member.query.filter_by(id=id).first()
        if not info:
            return redirect(reback_url)

        if info.status != 1:
            return redirect(reback_url)

        resp_data['info'] = info
        resp_data['current'] = 'index'
        return ops_render( "member/set.html",resp_data )

    # 修改用户名
    req = request.values
    resp = {'code':200,'msg':'操作成功','data':{}}

    id = req['id'] if 'id' in req else ''
    nickname = req['nickname'] if 'nickname' in req else ''
    if nickname is None or len(nickname)<1 :
        resp['code'] = -1
        resp['msg'] = '请输入符合规范的姓名~~'
        return jsonify(resp)

    member_info = Member.query.filter_by(id=id).first()
    if not member_info:
        resp['code'] = -1
        resp['msg'] = '指定会员不存在~~'
        return jsonify(resp)

    member_info.nickname = nickname
    member_info.updated_time = getCurrentDate()

    db.session.add(member_info)
    db.session.commit()

    return jsonify(resp)
Esempio n. 27
0
def foodSearch():
    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    req = request.values
    cat_id = int(req['cat_id']) if 'cat_id' in req else 0
    mix_kw = str(req['mix_kw']) if 'mix_kw' in req else ''
    p = int(req['p']) if 'p' in req else 1

    if p < 1:
        p = 1

    page_size = 10
    offset = (p - 1) * page_size
    query = Food.query.filter_by(status=1)
    if cat_id > 0:
        query = query.filter_by(cat_id=cat_id)

    if mix_kw:
        rule = or_(Food.name.ilike("%{0}%".format(mix_kw)),
                   Food.tags.ilike("%{0}%".format(mix_kw)),
                   Food.speaker.ilike("%{0}%".format(mix_kw)),
                   Food.speaker_address.ilike("%{0}%".format(mix_kw)),
                   Food.lecture_time.ilike("%{0}%".format(mix_kw)))
        query = query.filter(rule)

    food_list = query.order_by(Food.total_count.desc(), Food.id.desc())\
        .offset( offset ).limit( page_size ).all()

    data_food_list = []
    if food_list:
        for item in food_list:
            count_Cart = MemberCart.query.filter_by(food_id=item.id).count()

            tmp_data = {
                'id': item.id,
                'name': "%s" % (item.name),
                'speaker': "%s" % (item.speaker),
                'speaker_address': "%s" % (item.speaker_address),
                'pic_url': UrlManager.buildImageUrl(item.main_image),
                'count_cart': count_Cart
            }
            data_food_list.append(tmp_data)
    resp['data']['list'] = data_food_list
    resp['data']['has_more'] = 0 if len(data_food_list) < page_size else 1
    return jsonify(resp)
Esempio n. 28
0
def courseSearch():
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    #获取前台发来的值
    req = request.values
    cat_id = int(req['cat_id']) if 'cat_id' in req else 0
    mix_kw = str(req['mix_kw']) if 'mix_kw' in req else ''
    #分页相关
    p = int(req['p']) if 'p' in req else 1
    if p < 1:
        p = 1
    page_size = 10
    offset = (p - 1) * page_size
    #通过种类和关键字进行query
    query = Course.query.filter_by(status=1)
    if cat_id > 0:
        query = query.filter_by(cat_id=cat_id)

    if mix_kw:
        rule = or_(Course.name.ilike("%{0}%".format(mix_kw)),
                   Course.tags.ilike("%{0}%".format(mix_kw)))
        query = query.filter(rule)
        #与分页相关的两个限定值,offset 与 limit
    course_list = query.order_by(
        Course.total_count.desc(),
        Course.id.desc()).offset(offset).limit(page_size).all()

    #组装返回的数据列表
    data_course_list = []
    if course_list:
        for item in course_list:
            tmp_data = {
                'id': item.id,
                'name': item.name,
                'course_date': item.course_date,
                'location': item.location,
                'price': str(item.price),
                'pic_url': UrlManager.buildImageUrl(item.main_image)
            }
            data_course_list.append(tmp_data)

    resp['data']['list'] = data_course_list
    # 分页后判断数据是否已经没有了
    resp['data']['has_more'] = 0 if len(data_course_list) < 1 else 1
    return jsonify(resp)
Esempio n. 29
0
def orderInfo():
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    req = request.values
    params_goods = req['goods'] if 'goods' in req else None
    member_info = g.member_info
    params_goods_list = []
    if params_goods:
        params_goods_list = json.loads(params_goods)
    food_dic = {}
    for item in params_goods_list:
        food_dic[item['id']] = item['number']

    food_ids = food_dic.keys()
    food_list = Food.query.filter(Food.id.in_(food_ids)).all()
    data_food_list = []
    yun_price = pay_price = decimal.Decimal(0.00)
    if food_list:
        for item in food_list:
            tmp_data = {
                'id': item.id,
                'name': item.name,
                'price': item.price,
                'pic_url': UrlManager.buildImageUrl(item.main_image),
                'number': food_dic[item.id],
            }
            pay_price = pay_price + item.price * int(food_dic[item.id])
            data_food_list.append(tmp_data)

    address_info = MemberAddress.query.filter_by(status=1,is_default=1,member_id=member_info.id).first()
    default_address = ''
    if address_info:
        default_address = {
            'id': address_info.id,
            'name': address_info.nickname,
            'mobile': address_info.mobile,
            'address': "%s%s%s%s"%(address_info.province_str,address_info.city_str,address_info.area_str,address_info.address),
        }
    resp['data']['food_list'] = data_food_list
    resp['data']['pay_price'] = str(pay_price)
    resp['data']['yun_price'] = str(yun_price)
    resp['data']['total_price'] = str(yun_price + pay_price)
    resp['data']['default_address'] = default_address

    return jsonify(resp)
Esempio n. 30
0
def uploadImage():
    # http://192.168.153.155:8999/upload/ueditor?action=uploadimage&encode=utf-8
    # post
    resp = {'state': 'SUCCESS', 'url': '', 'title': '', 'original': ''}
    file_target = request.files
    print("###################################")
    print(file_target)
    upfile = file_target['upfile'] if 'upfile' in file_target else None
    if upfile is None:
        resp['state'] = '上传失败'
        return jsonify(resp)

    ret = UploadService.uploadByFile(upfile)
    if ret['code'] != 200:
        resp['state'] = '上传失败' + ret['msg']
        return jsonify(resp)

    resp['url'] = UrlManager.buildImageUrl(ret['data']['file_key'])
    return jsonify(resp)