• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

广告小程序后端开发(15.积分商城:获取积分商品列表,获取积分商品详情) ...

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1.获取积分商品列表

1.在apps/ad/views.py内新建获取积分商品列表类:

class GetPrize(APIView):
    """
    获取奖品
    """
    renderer_classes = [JSONRenderer]  # 渲染器

    def get(self,request):
        token = request.GET.get(\'token\')
        page = request.GET.get(\'page\')
        sheng = request.GET.get(\'sheng\')
        shi = request.GET.get(\'shi\')
        xian = request.GET.get(\'xian\')
        user = UserProfile.objects.filter(token=token).first()
        if user and page:
            page=int(page)
            if sheng:
                # 全省
                num = Area.objects.filter(name=sheng).first().num
                re_list = Prize.objects.filter(area__num__gt=num,area__num__lt=(num+10000)).order_by(\'-add_time\')[0:(10 * page)]
                re=PrizeModelSerializer(re_list,many=True)
                return Response(re.data)
            elif shi:
                # 全市
                num = Area.objects.filter(name=shi).first().num
                # print(num)
                re_list = Prize.objects.filter(area__num__gte=num, area__num__lt=(num + 100)).order_by(\'-add_time\')[0:(10 * page)]
                re = PrizeModelSerializer(re_list, many=True)
                return Response(re.data)
            elif xian:
                # 全县
                num = Area.objects.filter(name=xian).first().num
                # print(num)
                re_list = Prize.objects.filter(area__num=num).order_by(\'-add_time\')[0:(10 * page)]
                re = PrizeModelSerializer(re_list, many=True)
                return Response(re.data)
            else:
                re_list = Prize.objects.all().order_by(\'-add_time\')[0:(10 * page)]
                re = PrizeModelSerializer(re_list, many=True)
                return Response(re.data)
        else:
            return HttpResponse(\'参数不足\')

2.在apps/ad/urls.py内配置路由:

from django.urls import path
from .views import GetCategory,CreateAdOrShop,UpLoadImg,GetPubGoods,GetGoodDesc,GetUserGoods,DelUserGood,EditGood,DelImg,GetPrize

urlpatterns = [
    path(\'getcategory/\',GetCategory.as_view()),
    path(\'createadorshop/\',CreateAdOrShop.as_view()),
    path(\'uploadimg/\',UpLoadImg.as_view()),
    path(\'getpubgoods/\',GetPubGoods.as_view()),
    path(\'getgooddesc/\',GetGoodDesc.as_view()),
    path(\'getusergoods/\',GetUserGoods.as_view()),
    path(\'delusergood/\',DelUserGood.as_view()),
    path(\'editgood/\',EditGood.as_view()),
    path(\'delimg/\',DelImg.as_view()),
    path(\'getprize/\',GetPrize.as_view()),
]

2.获取积分奖品详情

1.在apps/ad/views.py中新建GetPrizeDesc类:

class GetPrizeDesc(APIView):
    """
    获取奖品详情
    """
    renderer_classes = [JSONRenderer]  # 渲染器

    def get(self, request):
        token = request.GET.get(\'token\')
        id=request.GET.get(\'prizeid\')
        user = UserProfile.objects.filter(token=token).first()
        if user and id:
            id=int(id)
            re_obj=Prize.objects.filter(id=id).first()
            re=PrizeModelSerializer(re_obj)
            return Response(re.data)
        else:
            return HttpResponse(\'参数不足\')

2.在apps/ad/urls.py内配置路由

from django.urls import path
from .views import GetCategory,CreateAdOrShop,UpLoadImg,GetPubGoods,GetGoodDesc,GetUserGoods,DelUserGood,EditGood,DelImg,GetPrize,GetPrizeDesc

urlpatterns = [
    path(\'getcategory/\',GetCategory.as_view()),
    path(\'createadorshop/\',CreateAdOrShop.as_view()),
    path(\'uploadimg/\',UpLoadImg.as_view()),
    path(\'getpubgoods/\',GetPubGoods.as_view()),
    path(\'getgooddesc/\',GetGoodDesc.as_view()),
    path(\'getusergoods/\',GetUserGoods.as_view()),
    path(\'delusergood/\',DelUserGood.as_view()),
    path(\'editgood/\',EditGood.as_view()),
    path(\'delimg/\',DelImg.as_view()),
    path(\'getprize/\',GetPrize.as_view()),
    path(\'getprizedesc/\',GetPrizeDesc.as_view()),
]

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
微信小程序使用font-awesome图标库发布时间:2022-07-18
下一篇:
微信小程序api视频课程-基础-系统信息-wx.getSystemInfo的使用发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap