完善生鲜系统

生鲜系统之加密支付

1.买家添加评论

路由

# 用户评论商品
    path('hit_btn/', hit_btn),
    #删除当前用户的评论
    path('delete_content/', delete_content),

后端添加评论

# 用户点击按钮进行评论
def hit_btn(request):
    if request.method == 'GET':
        #获取商品编号
        goods_num = request.GET.get('goods_num')
        goods_obj = Goods.objects.filter(goods_num=goods_num).first()
        return render(request, 'buyer/hit_btn.html', locals())
    if request.method == 'POST':
        print(request.POST)
        #获取商品id
        id = request.POST.get('id')
        #获取评论内容
        content = request.POST.get('content')
        print(request.POST)
        # 创建
        models.Comment.objects.create(send=request.session['buyer_name_session'], goods=id, content=content).save()
        return redirect('/buyer/goods_details/?id=' + id)

跳转页面

{% load static %}
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>全球生鲜买家评论页面</title>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="{% static 'seller/css/font.css' %}">
    <link rel="stylesheet" href="{% static 'seller/css/xadmin.css' %}">

</head>
<body class="login-bg">
<div class="login layui-anim layui-anim-up">
    <div class="message">对{{ goods_obj.goods_name }}的评论</div>
    <div id="darkbannerwrap"></div>

    <form method="post" class="layui-form" action="/buyer/hit_btn/">
        <input name="content" placeholder="评论内容" type="text" lay-verify="requicred" class="layui-input">
        <hr class="hr15">
        <input type="hidden" value="{{ goods_obj.id }}" name="id">
        <input type="hidden" name="login_valid" value="login_valid">
        <hr class="hr15">
        <input value="提交评论" lay-submit lay-filter="login" style="width:100%;" type="submit">
        <hr class="hr20">
    </form>
</div>
</body>
</html>

删除当前用户的评论

# 删除当前用户评论的内容
def delete_content(request):
    # 获取商品id
    id = request.GET.get('id')
    name = request.GET.get('name')
    print(id)
    #获取评论用户名
    send = request.session.get('buyer_name_session')
    a = models.Comment.objects.filter(id=id).first()
    if a.send == send:
        models.Comment.objects.filter(id=id).delete()
    return redirect('/buyer/goods_details/?id='+name)

在这里插入图片描述

2.‘显示购物车商品数量

def car_jump(request):
    if request.method == 'POST':
        print(request.POST)
        # 商品id
        goods_id = request.GET.get('id')
        # 商品数量
        count = request.POST.get('count')
        # 商品名称
        goods_name = request.POST.get('goods_name')
        # 商品价格
        goods_xprice = request.POST.get('goods_xprice')
        # 商品缩略图
        goods_img_path = request.POST.get('goods_img_path')
        car_id = request.session['car']
        if models.Buycar.objects.filter(goods_id=goods_id, buyer_id=request.session['buyer_id_session']):
            print(goods_id)
        else:
            car_id += 1
            request.session['car'] = car_id
        # 判断购物车是否有当前商品;如果有,则在此基础上课增加数量;如果不存在,则加入购物车
        is_car = models.Buycar.objects.filter(goods_id=goods_id, buyer_id=request.session['buyer_id_session']).first()
        if is_car:
            is_car.goods_count += int(count)
            is_car.save()
        else:
            models.Buycar.objects.create(
                goods_name=goods_name,
                goods_price=goods_xprice,
                goods_count=count,
                goods_img=goods_img_path,
                goods_id=goods_id,
                buyer_id=request.session['buyer_id_session']
            ).save()
        return redirect(f'/buyer/car_jump/?id={goods_id}')
    goods_id = request.GET.get('id')
    buycar_obj = models.Buycar.objects.filter(goods_id=int(goods_id),
                                              buyer_id=request.session['buyer_id_session']).first()
    goods_xj = buycar_obj.goods_count * buycar_obj.goods_price
    return render(request, 'buyer/car_jump.html', locals())

在这里插入图片描述

3.显示卖家订单数,会员数,商品数

def index(request):
    if request.method == 'GET':
        ip = request.META.get('REMOTE_ADDR')
        now_time = datetime.datetime.now()
        # 版本
        ver = '1.0.0'
        # 服务器地址
        ip = ip
        # winnt
        WINNT = 'WINNT'
        # django版本号
        django = '3.0.3'
        user = len(Buyer.objects.all())
        goods = len(models.Goods.objects.filter(seller_id=request.session['seller_id_session']).all())
        count = 0
        for i in models.Goods.objects.filter(seller_id=request.session['seller_id_session']):
            for j in Order.objects.filter(order_status=1):
                for k in j.goods_order_set.all():
                    if int(i.goods_num) == int(k.goods_num):
                        count +=k.goods_count
        return render(request, 'seller/index.html', locals())

在这里插入图片描述
4.买家和卖家账号

# 买家退出
def logout(request):
    del request.session['buyer_name_session']
    # del request.session['buyer_phone_session']
    # del request.session['buyer_email_session']
    # request.session.flush()
    return redirect('/buyer/register/')
# 卖家退出
class Quit_login(View):
    def get(self, request):
        #删除session指定key
        del request.session['seller_id_session']
        del request.session['seller_user_session']
        del request.session['seller_nickname_session']
        # request.session.flush()  #      清空session 内所有数据
        return redirect('/seller/login_seller/')

买家和卖家同时登录
在这里插入图片描述
卖家退出后,买家用户依旧存在
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值