示例#1
0
def mine_info():
    # " 我的" 页面所需要的数据信息
    u_data = request.get_json()
    token = u_data.get('token')
    if check_token(token):
        user_id = get_token_user_id(token)
        print(user_id)
        user_data = UserDao().get_profile(user_id)  # 查询用户详细信息
        vou_data = VouDao().check_vouchers(user_id)  # 查询优惠卷信息
        coll_data1 = GoodsDao().check_collect_goods(user_id)  # 收藏的商品信息
        coll_data2 = GoodsDao().check_collect_shops(user_id)  # 收藏的店铺信息
        goods_list = GoodsDao().check_goods()  # 从商品详情表中取20组商品信息,元组类型
        print(user_data, vou_data, coll_data1, coll_data2, goods_list)
        if all((user_data, vou_data, coll_data1, coll_data2, goods_list)):
            re_data = {
                "accountInfo": {
                    "userID": user_id,
                    "userName": user_data[0]['user_name'],  # 用户名
                    "userPhoto": user_data[0]['u_img'],  # 头像
                },
                "assetInfo": {
                    "vouchers": vou_data[0]['cop_id'],  # 优惠卷
                    "balance": user_data[0]['asset'],  # 余额
                    "integral": user_data[0]['u_intg'],  # 积分
                    "redPacket": 80
                },
                "browseInfo": {
                    "collectProduct": len(coll_data1),  # 收藏的商品的数量
                    "collectShop": len(coll_data2),  # 收藏的店铺的数量
                    "footprint": 16
                },
                "productList": goods_list[:20]  # 20 组商品信息
            }
            return jsonify({'code': 200, 'data': re_data})
        else:
            re_data = {
                "accountInfo": {
                    "userID": user_id,
                    "userName": user_data[0]['user_name'],  # 用户名
                    "userPhoto": user_data[0]['u_img'],  # 头像
                },
                "assetInfo": {
                    "vouchers": 0,  # 优惠卷
                    "balance": 0,  # 余额
                    "integral": 100,  # 积分
                    "redPacket": 80
                },
                "browseInfo": {
                    "collectProduct": 0,  # 收藏的商品的数量
                    "collectShop": 0,  # 收藏的店铺的数量
                    "footprint": 16
                },
                "productList": goods_list[:20]  # 20 组商品信息
            }
            return jsonify({'code': 200, 'data': re_data})
    else:
        return jsonify({'code': 400, 'msg': 'token验证失败!'})
示例#2
0
def collects():
    # 收藏商品或店铺
    req_data = request.get_json()
    token = req_data.get('token')
    if check_token(token):
        user_id = get_token_user_id(token)
        clt_id = req_data.get('clt_id')
        type_id = req_data.get('type_id')
        if (clt_id and type_id) is not None:
            dao = BaseDao()
            save_data = {
                'user_id': user_id,
                'clt_id': clt_id,
                'type_id': type_id
            }
            result = dao.save('u_clt', **save_data)
            if result:
                return jsonify({'code': 200, 'msg': '收藏成功!'})
            else:
                return jsonify({'code': 400, 'msg': '查询数据库失败!'})
        elif clt_id is not None and type_id is None:  # 取消收藏
            if clt_id:
                dao = GoodsDao()
                delet = dao.del_collect(clt_id)
                if delet:
                    return jsonify({'code': 200, 'msg': '该收藏信息已删除!'})
                else:
                    return jsonify({'code': 400, 'msg': '删除失败!'})
            else:
                return jsonify({'code': 400, 'msg': '未接收到需要删除的ID!'})
        else:
            return jsonify({'code': 400, 'msg': '请上传商铺或商品ID和type类型!'})
    else:
        return jsonify({'code': 400, 'msg': 'token验证失败!'})
示例#3
0
文件: shop.py 项目: e-dianzi01/jd-api
def pomotion_product(shopid):
    dao = GoodsDao()
    product_sql = "select goods_id as productID,goods_img as img,goods_name as title,goods_prices as oldPrice," \
                  "kill_prices as price from goods_details where m_id_id='{}' and label='热销' limit 0,15".format(shopid)
    productList = dao.query(product_sql)

    # 顶部图
    shop_sql = "select m_id,m_img as img,m_name as tit,clt as collect from jd_shopper where m_id=%s" % shopid
    shop_info = dao.query(shop_sql)
    shop_info = {
        "shopID": shopid,
        "header": {
            "img": shop_info[0]['img'],
            "tit": shop_info[0]['tit'],
            "collect": shop_info[0]['collect']
        },
    }
    return jsonify({**shop_info, "productList": productList})
示例#4
0
文件: shop.py 项目: e-dianzi01/jd-api
def shop_classify(shopid):
    dao = GoodsDao()

    # 获取顶部图
    shop_sql = "select m_id,m_img as img,m_name as tit,clt as collect from jd_shopper where m_id=%s" % shopid
    shop_info = dao.query(shop_sql)
    shop_info = {
        "shopID": shopid,
        "header": {
            "img": shop_info[0]['img'],
            "tit": shop_info[0]['tit'],
            "collect": shop_info[0]['collect']
        },
    }

    # 获取商铺分类导航
    left_sql = "select type_name from shopper_type where m_id_id = %s" % shopid
    left = dao.query(left_sql)
    left_info = [item['type_name'].split("#") for item in left]
    print(len(left_info), left_info)
    if len(left_info) > 0:
        left = left_info[0]
    else:
        print("暂无数据")
    # 商品分类
    goods_detils = []

    for g_type in left:
        items = {}
        sql = "SELECT gd.goods_id AS productID,gd.goods_img AS img,gd.goods_name AS text,gd.goods_prices AS price," \
              "gd.evaluate AS evaluate,gd.rate AS evaluateRate FROM jd_shopper AS js JOIN goods_details AS gd ON " \
              "js.m_id = gd.m_id_id  WHERE gd.label='{}' and gd.m_id_id = '{}' ".format(g_type, shopid)
        goods_type = dao.query(sql)
        items['text'] = g_type
        items['children'] = goods_type
        goods_detils.append(items)

    return jsonify({**shop_info, "items": goods_detils})
示例#5
0
def collect_pro():
    # “我的” 页面查看收藏的商品和店铺
    req_data = request.get_json()
    token = req_data.get('token')
    if check_token(token):
        user_id = get_token_user_id(token)
        print(user_id, 111111111111111111111111111111111111)
        data1 = GoodsDao().check_collect_goods(user_id)
        data2 = GoodsDao().check_collect_shops(user_id)
        if all((data1, data2)):
            list1 = []
            list2 = []
            list3 = []
            list4 = []
            for i in range(len(data1)):
                list1.append(data1[i]['clt_id'])
            for j in list1:
                list2.append(GoodsDao().check_goods2(j))
            for m in range(len(data2)):
                list3.append(data2[m]['clt_id'])
            for n in list3:
                list4.append(GoodsDao().search_shop(n))
            if all((list2, list4)):
                return jsonify({
                    'code': 200,
                    'msg': '查询成功!',
                    'myAttentionList': list2,
                    'myAttentionShop': list4
                })
            else:
                return jsonify({'code': 400, 'msg': '查询数据库失败!'})

        else:
            return jsonify({'code': 400, 'msg': '你还没有收藏数据!'})
    else:
        return jsonify({'code': 400, 'msg': 'token验证失败!'})
示例#6
0
文件: shop.py 项目: e-dianzi01/jd-api
def shop(shopid):
    dao = GoodsDao()
    # 获取 shopid ,img, tit(店铺名字) coolect
    shop_sql = "select m_id,m_img as img,m_name as tit,clt as collect from jd_shopper where m_id=%s" % shopid
    shop_info = dao.query(shop_sql)

    # 获取商铺轮播图
    banner_sql = "select img from  shopper_img where remark='首页轮播图' and m_id_id = %s" % shopid
    banner = dao.query(banner_sql)

    # 获取主页推荐图
    rec_img_sql = "select img from  shopper_img where remark='推荐' and m_id_id = %s" % shopid
    imgs = dao.query(rec_img_sql)

    # 获取5个商品id
    product_sql = "select goods_id as productID from " \
                  "goods_details where m_id_id=%s limit 0,5" % shopid
    product_id = dao.query(product_sql)

    # 获取商品列表10
    product_sql = "select goods_id as productID,goods_img as img,goods_name as tit,goods_prices as pic,evaluate,rate" \
                  " from goods_details where  label !='拍卖'  and  m_id_id=%s limit 0,10 " % shopid
    productList = dao.query(product_sql)
    if len(shop_info) > 0:
        shop_info = {
            "shopID": shopid,
            "header": {
                "img": shop_info[0]['img'],
                "tit": shop_info[0]['tit'],
                "collect": shop_info[0]['collect']
            },
        }
        imgs1 = (imgs[0]['img'].split("#"))[0:2]
        # print("imgs1",imgs1)
        imgs2 = (imgs[0]['img'].split("#"))[2:3]
        # print("imgs2", imgs2)

    else:
        print("为获取到数据")
    banner = banner[0]['img'].split("#")
    productModel = {
        "img": imgs2,
        "productIDList": [i['productID'] for i in product_id],
    }
    return jsonify({
        **shop_info, "banner": banner,
        "imgs": imgs1,
        "productModel": productModel,
        "roductList": productList
    })
示例#7
0
def groupbuy():
    dao = GoodsDao()
    bnr_sql = "select img_urls from slideshow where page_name='首页'"
    gb1 = gbDao().check(bnr_sql,3)
    bnr = []
    for g1 in gb1:
        bnr.append(g1['img_urls'])

    gBC_sql = "select img_urls as img,page_text as text from nav"
    gb2 = gbDao().check(gBC_sql,10)


    gBe_sql = "select goods_details.goods_img as img,group_buy.gbp as groupBuyPeople," \
              "group_buy.buy_price as groupBuyPrice,group_buy.gbn as groupBuyNum " \
              "from group_buy join goods_details " \
              "on group_buy.goods_id_id = goods_details.goods_id "
    gb3 = gbDao().check(gBe_sql,15)
    # n = 3
    # list3= [gb3[i:i + n] for i in range(0, len(gb3), n)]
    # dict3 = {}
    # list33 = []
    # dict3['banner'] = list3
    # list33.append(dict3)
    # print(list3)
    # print(gb3)

    gBE_sql = "SELECT goods_details.goods_img as img," \
              "goods_details.goods_name as goodsdescribe," \
              "group_buy.gbn as numberofpersons," \
              "group_buy.buy_price as price," \
              "goods_type2.two_type_name as productType," \
              "goods_details.goods_id as productID " \
              "FROM (group_buy JOIN goods_details " \
              "ON group_buy.goods_id_id = goods_details.goods_id)" \
              "JOIN goods_type2 ON goods_details.two_category_id = goods_type2.two_type_id"

    gb4 = gbDao().check(gBE_sql,10)
    return jsonify({
        "code":200,
        'msg': '拼购页',
        'banner':bnr,
        'grouyBuyClassify':gb2,
        'groupBuyeveryone':gb3,
        'groupBuyEveryone':gb4
    })
示例#8
0
文件: shop.py 项目: e-dianzi01/jd-api
def product_all(shopid):
    dao = GoodsDao()
    product_sql = "select goods_id as productID,goods_img as img,goods_name as tit,goods_prices as pic,evaluate " \
                  "as evaluate,rate as rate  from goods_details where label !='拍卖' AND m_id_id='{}' ORDER by " \
                  "goods_id desc ".format(
        shopid)
    productList = dao.query(product_sql)

    # 获取顶部图
    shop_sql = "select m_id,m_img as img,m_name as tit,clt as collect from jd_shopper where m_id=%s" % shopid
    shop_info = dao.query(shop_sql)
    shop_info = {
        "shopID": shopid,
        "header": {
            "img": shop_info[0]['img'],
            "tit": shop_info[0]['tit'],
            "collect": shop_info[0]['collect']
        },
    }

    # 销量降序
    desc_sql = "select goods_id as productID,goods_img as img,goods_name as tit,goods_prices as pic,evaluate " \
               "as evaluate,rate as rate  from goods_details where  m_id_id='{}' ORDER by sales desc ".format(shopid)
    salesList = dao.query(desc_sql)

    # 价格升序
    price_sql = "select goods_id as productID,goods_img as img,goods_name as tit,goods_prices as pic,evaluate " \
                "as evaluate,rate as rate  from goods_details where  m_id_id='{}' ORDER by goods_prices asc ".format(
        shopid)
    priceList = dao.query(price_sql)

    return jsonify({
        **shop_info,
        "productList": productList,
        "salesList": salesList,
        "priceList": priceList,
    })
示例#9
0
文件: app_goods.py 项目: nancb/mywk
from flask import Blueprint, jsonify, request

from dao.goods_dao import GoodsDao

bule_goods = Blueprint('goods_api', __name__)

dao = GoodsDao()


@bule_goods.route('/show_goods/', methods=('GET', ))  #展示所有商品
def show_order():
    print("****")
    goods_list = dao.show_goods()
    goods_big = dao.show_biggoods()
    for goods in goods_list:
        goodsDetails = goods['goodsDetails']
        goodsDescribe = goods['goodsDescribe']
        goodsSpecification = goods['goodsSpecification']
        g = goodsDetails.split(',')
        d = goodsDescribe.split(';')
        a = goodsSpecification.split(';')
        goods['goodsDetails'] = g
        goods['goodsDescribe'] = d
        goods['goodsSpecification'] = a
    return jsonify({
        'code': 200,
        'msg': '商品详情',
        'goods_list': goods_list,
        'goods_big': goods_big
    })