Exemplo n.º 1
0
 def __set_cache(cls, path, token):
     key = cls.set + token
     user = r.hgetall(key)
     if user:
         user['header'] = path
         r.hmset(key, user)
         r.expire(key, 15 * 24 * 60 * 60)
Exemplo n.º 2
0
 def __set_cache(cls, username, token):
     key = 'user:token:' + token
     user = r.hgetall(key)
     if user:
         user['username'] = username
         r.hmset(key, user)
         r.expire(key, 15 * 24 * 60 * 60)
Exemplo n.º 3
0
 def _data_deal(cls, args):
     # 数据处理类,需重写
     data = {}
     keys = r.keys(pattern='group_category:*')
     for key in keys:
         data[key.split(':')[-1]] = r.hgetall(key)
     return data
Exemplo n.º 4
0
 def _data_deal(cls, args):
     good_id = args['good_id']
     data = {}
     group = []
     pattern = cls.set + '*:' + good_id
     good = r.hgetall(r.keys(pattern=pattern)[0])
     if good:
         keys = r.keys(pattern=cls.group_info + good_id + ':*')
         for k in keys:
             group_info = r.hgetall(k)
             group.append(group_info)
         data = {
             'group_price': good['group_price'],
             'group': group,
             'people_count': good['people_count']
         }
     return data
Exemplo n.º 5
0
 def group_valid(cls, group_id, good_id, phone):
     # 验证团购订单是否合法
     group = r.hgetall(cls.set + good_id + ":" + group_id)
     if group:
         if r.keys(pattern='group_good:*' + ':' +
                   group['good']) and group['phone'] != phone:
             return True
     else:
         return False
Exemplo n.º 6
0
 def _data_deal(cls, args):
     # 数据处理类,需重写
     data = {}
     page = args['page']
     if page:
         keys = r.keys(pattern='home_good:*')
         for key in keys[(int(page) - 1) * 10:int(page) * 10]:
             data[key.split(':')[1]] = r.hgetall(key)
     return data
Exemplo n.º 7
0
 def _data_deal(cls, args, user):
     data = {}
     # 根据用户最近加车商品推荐
     good_list = []
     cart = mongo[cls.collect_set].find_one({'phoneNum': user['phoneNum']})
     cart_list = cart['cart_list'] if cart else {}
     if cart_list:
         # 通过最近加车的5件商品筛选
         cart_list = list(cart_list.keys())[-5:]
         for i in cart_list:
             temp = mongo[cls.category_set].find_one({'item_id': i})
             category = temp['sub_category_id'] if temp else 0
             if category != 0:
                 good_list = good_list + list(
                     mongo[cls.category_set].aggregate([{
                         "$match": {
                             'sub_category_id': category
                         }
                     }, {
                         '$sample': {
                             'size': 5
                         }
                     }]))
         if len(good_list) > 10:
             # 随机取10个商品
             good_list = random.sample(good_list, 10)
         else:
             # 不足10个商品,使用首页上新商品补至10个
             home_good = r.keys(pattern='home_good:*')
             goods = random.sample(home_good, 10 - len(good_list))
             for key in goods:
                 good_list.append(r.hgetall(key))
     else:
         home_good = r.keys(pattern='home_good:*')
         goods = random.sample(home_good, 10)
         for key in goods:
             good_list.append(r.hgetall(key))
     for good in good_list:
         good['_id'] = str(good['_id']) if good['_id'] else ''
         for k in good.keys():
             if not good[k]:
                 good[k] = ''
         data[str(good['item_id'])] = good
     return data
Exemplo n.º 8
0
 def integral_deal(cls, phone, count, type, last_timestamp=0):
     today = datetime.date.today().strftime('%Y-%m-%d')
     if type == 0 and last_timestamp != 0:
         login_time = time.strftime("%Y-%m-%d", time.localtime(int(last_timestamp)))
         if login_time != today:
             cls.__set_integral(phone, count, type)
     elif type == 1:
         signin = r.hgetall(cls.signin_set + phone)
         signin_time = time.strftime("%Y-%m-%d", time.localtime(int(signin['last_signin'])))
         if signin_time != today:
             cls.__set_integral(phone, count, type)
     else:
         cls.__set_integral(phone, count, type)
Exemplo n.º 9
0
 def verify_token(cls, token):
     # 验证token
     if token:
         token_key = cls.token_set + ':' + token
         token = r.hgetall(token_key)
         if len(token) != 0:
             # 每次访问过后重置token过期时间
             cls.last_timestamp = token['timestamp']
             token['timestamp'] = int(time.time())
             r.hmset(token_key, token)
             cls.set_expire(token_key)
             return token
     else:
         return None
Exemplo n.º 10
0
 def _data_deal(cls, args):
     # 数据处理类,需重写
     data = {}
     group_id = args['group_id']
     page = args['page']
     count = args['count']
     if group_id:
         pattern = 'group_good:' + group_id + ':*'
     else:
         pattern = 'group_good:*'
     keys = r.keys(pattern=pattern)
     for key in keys[(int(page) - 1) * 10:int(page) * 10]:
         data[key.split(':')[-1]] = r.hgetall(key)
     return data
Exemplo n.º 11
0
 def __last_time(cls, phone):
     # 验证发送时间间隔,每个号码发送时间间隔为1分钟
     code_keys = r.keys(pattern=cls.key_set + ':' + str(phone) +
                        ':[0123456789]*')
     now = int(time.time())
     s = 1
     if code_keys:
         for key in code_keys:
             code = r.hgetall(key)
             if now - int(code['timestamp']) > 60:
                 pass
             else:
                 s = 0
     if s == 1:
         return True
     else:
         return False
Exemplo n.º 12
0
    def _data_deal(cls, args, user):
        data = {}
        good_list = []
        history_key = cls.history_set + ':' + user['phoneNum']
        history_list = r.lrange(history_key, 0, 5)
        for item in history_list:
            item_id = json.loads(item.replace("'", '"'))['good_id']
            temp = mongo[cls.category_set].find_one({'item_id': item_id})
            category = temp['sub_category_id'] if temp else 0
            if category != 0:
                good_list = good_list + list(mongo[cls.category_set].aggregate(
                    [{
                        "$match": {
                            'sub_category_id': category
                        }
                    }, {
                        '$sample': {
                            'size': 5
                        }
                    }]))

        if len(good_list) > 10:
            # 随机取10个商品
            good_list = random.sample(good_list, 10)
        else:
            home_good = r.keys(pattern='home_good:*')
            goods = random.sample(home_good, 10 - len(good_list))
            for key in goods:
                good_list.append(r.hgetall(key))

        for good in good_list:
            good['_id'] = str(good['_id'])
            for k in good.keys():
                if not good[k]:
                    good[k] = ''
            data[str(good['item_id'])] = good
        return data
Exemplo n.º 13
0
 def verify_message(cls, phone, code):
     # 验证短信验证码是否正确
     if not cls.__wrong_count(phone):
         return 3
     else:
         code_keys = r.keys(pattern=cls.key_set + ':' + str(phone) +
                            ':[0123456789]*')
         for key in code_keys:
             code_val = r.hgetall(key)
             if str(code) == code_val['num']:
                 r.delete(key)
                 return 0
             else:
                 code_val['wrong_count'] = str(
                     int(code_val['wrong_count']) + 1)
                 if int(code_val['wrong_count']) >= 3:
                     r.delete(key)
                     fail_key = cls.key_set + ':' + str(
                         phone) + ':fail_count'
                     fail_count = int(r.get(fail_key))\
                         if(r.get(fail_key)) else 0
                     r.set(fail_key, str(fail_count + 1))
                 else:
                     r.hmset(key, code_val)
Exemplo n.º 14
0
    def _data_deal(cls, args, user):
        phoneNum = user['phoneNum']
        signin = r.hgetall(cls.signin_set + ":" + phoneNum)
        days = 0
        prize_data = ''
        today_checked = 0
        if signin:
            last_signin = time.strftime(
                "%Y-%m-%d", time.localtime(int(signin['last_signin'])))
            today = datetime.date.today().strftime('%Y-%m-%d')
            if today == last_signin:
                days = int(signin['days'])
                today_checked = 1
            else:
                SetIntegral.integral_deal(phoneNum, 1, 1)
                cls.__signin(phoneNum, int(signin['days']) + 1)
                days = int(signin['days']) + 1
                if days == 7:
                    cls.__provide_coupon(phoneNum)
                    prize_data = "您已获得10元代金券,请在我的-代金券页面查看"
                if 1 <= days <= 4:
                    cls.__get_turntable(phoneNum)
                if days == 5 or days == 6:
                    cls.__get_turntable(phoneNum, 2)
        else:
            cls.__signin(phoneNum, 1)
            days = 1

        page_data = mongo[cls.collect_set].find()[0]
        del page_data["_id"]
        page_data['days'] = days
        page_data['today_checked'] = today_checked
        page_data['prize_data'] = prize_data
        page_data['turntable_count'] = mongo[cls.user_info_set].find_one(
            {'phoneNum': phoneNum})['sign_lottery']
        return page_data