import time, json
def getHomeData(self, request): userid = None user = None ticket = request.META.get('HTTP_TICKET') if ticket: result = RedisTokenHandler(key=ticket).redis_dict_get() if result: userid = result.get("userid") print("用户代码:{}".format(userid)) rdata = {"banners": [], "newgoods": []} #轮播图数据 rdata['banners'] = [ dict(id=item['id'], url=item['url']) for item in RedisCaCheHandler( method="filter", serialiers="BannerModelSerializerToRedis", table="banner", filter_value={}).run() ] if userid: user = Users.objects.get(userid=userid) #新品数据 for item in RedisCaCheHandler(method="filter", serialiers="GoodsModelSerializerToRedis", table="goods", filter_value={ "gdstatus": "0" }).run(): obj = RedisCaCheHandler( method="get", serialiers="GoodsCateGoryModelSerializerToRedis", table="goodscategory", must_key_value=item.get('gdcgid')).run() if userid and user.isvip == '1' and item['isvip'] == '0' and obj[ 'status'] == '0': rdata['newgoods'].append( dict(gdid=item['gdid'], gdname=item['gdname'], gdimg=item['gdimg'], gdtext=item['gdtext'], gdprice=item['gdprice'], sort=item['sort'])) if obj['status'] == '0' and item['isvip'] != '0': rdata['newgoods'].append( dict(gdid=item['gdid'], gdname=item['gdname'], gdimg=item['gdimg'], gdtext=item['gdtext'], gdprice=item['gdprice'], sort=item['sort'])) if len(rdata['newgoods']) >= 6: rdata['newgoods'] = rdata['newgoods'][:6] else: rdata['newgoods'] = rdata['newgoods'][:len(rdata['newgoods'])] rdata['newgoods'].sort(key=lambda k: (k.get('sort', 0)), reverse=False) return {"data": rdata}