Exemple #1
0
async def get_vehicle_attribute(code):
    """
    获取车型属性信息
    :param code:
    :return:
    """
    if code:
        vehicle_attribute = RedisCache.hmget(KEY_CODE_VEHICLE_ATTRIBUTE,
                                             (code, ))[0]
        if not vehicle_attribute:
            vehicle_attribute = await VehicleAttribute.find_one(dict(code=code)
                                                                )
            RedisCache.hmset(KEY_CODE_VEHICLE_ATTRIBUTE, {
                code:
                pickle.dumps(vehicle_attribute, pickle.HIGHEST_PROTOCOL)
            })
            return vehicle_attribute
        else:
            return pickle.loads(vehicle_attribute)
    return None
Exemple #2
0
    async def post(self):
        r_dict = {'code': 0}
        try:
            category = self.get_argument('category', None)
            if category:
                attribute_list = RedisCache.hmget(
                    KEY_CATEGORY_VEHICLE_ATTRIBUTE_CACHE, (category, ))[0]
                if attribute_list:
                    attribute_list = pickle.loads(attribute_list)
                else:
                    category = int(category)
                    parent_code = self.get_argument('parent_code')
                    if parent_code and parent_code.strip() == '':
                        parent_code = None
                    attribute_list = await VehicleAttribute.find(
                        dict(category=category,
                             parent_code=parent_code)).to_list(length=None)
                    for attribute in attribute_list:
                        child_attribute_list = await self.get_child_attribute(
                            attribute.code)
                        if child_attribute_list:
                            attribute.child_attr_list = child_attribute_list
                    # 缓存结果
                    RedisCache.hmset(
                        KEY_CATEGORY_VEHICLE_ATTRIBUTE_CACHE, {
                            category:
                            pickle.dumps(attribute_list,
                                         pickle.HIGHEST_PROTOCOL)
                        })
                r_dict['attribute_list'] = attribute_list
                r_dict['code'] = 1
            else:
                r_dict['code'] = -1
                r_dict['msg'] = u'Please specify a category.'
        except RuntimeError:
            logger.error(traceback.format_exc())

        return r_dict
Exemple #3
0
 async def push_sign_in_msg(self, open_id, service_id):
     msg_xml = ''
     member = await Member.find_one(filtered={
         'open_id': open_id,
         'status': STATUS_USER_ACTIVE
     })
     if member:
         now = datetime.datetime.now()
         old_member = RedisCache.hmget(KEY_OLD_MEMBER_CACHE,
                                       (member.cid, ))[0]
         if not old_member:
             integral_detail_list = await MemberIntegralDetail.find({
                 "member_cid":
                 member.cid
             }).sort([('reward_datetime', ASCENDING)]).to_list(1)
             if integral_detail_list:
                 integral_detail = integral_detail_list[0]
                 if integral_detail.reward_datetime < now + datetime.timedelta(
                         days=-3):
                     RedisCache.hmset(KEY_OLD_MEMBER_CACHE,
                                      {member.cid: True})
                     old_member = True
         # 老用户回归
         if old_member:
             now = datetime.datetime.now()
             start_datetime = (now + datetime.timedelta(days=-3)).replace(
                 hour=0, minute=0, second=0, microsecond=0)
             end_datetime = (start_datetime +
                             datetime.timedelta(days=2)).replace(
                                 hour=23,
                                 minute=59,
                                 second=59,
                                 microsecond=999)
             count = await MemberIntegralDetail.count(
                 filtered={
                     '$and': [{
                         "member_cid": member.cid
                     }, {
                         "source":
                         SOURCE_MEMBER_INTEGRAL_LOGIN_EVERYDAY
                     }, {
                         "reward_datetime": {
                             '$gte': start_datetime
                         }
                     }, {
                         "reward_datetime": {
                             '$lte': end_datetime
                         }
                     }]
                 })
             if count == 0:
                 status, m_integral = await do_integral_reward(
                     member.cid, SOURCE_MEMBER_INTEGRAL_USER_RETURN)
                 if m_integral:
                     msg_xml = get_a_passive_txt_message(
                         open_id, service_id,
                         u'签到成功,恭喜您获得【%s个】积分奖励!' % m_integral)
                 else:
                     msg_xml = get_a_passive_txt_message(
                         open_id, service_id, u'签到失败,请重试!' % m_integral)
                 return msg_xml
         # 每日签到
         start_datetime = datetime.datetime.now().replace(hour=0,
                                                          minute=0,
                                                          second=0,
                                                          microsecond=0)
         end_datetime = datetime.datetime.now().replace(hour=23,
                                                        minute=59,
                                                        second=59,
                                                        microsecond=999)
         count = await MemberIntegralDetail.count(
             filtered={
                 '$and': [{
                     "member_cid": member.cid
                 }, {
                     "source": {
                         '$in': [
                             SOURCE_MEMBER_INTEGRAL_LOGIN_EVERYDAY,
                             SOURCE_MEMBER_INTEGRAL_USER_RETURN
                         ]
                     }
                 }, {
                     "reward_datetime": {
                         '$gte': start_datetime
                     }
                 }, {
                     "reward_datetime": {
                         '$lte': end_datetime
                     }
                 }]
             })
         if count == 0:
             status, m_integral = await do_integral_reward(
                 member.cid, SOURCE_MEMBER_INTEGRAL_LOGIN_EVERYDAY)
             if m_integral:
                 msg_xml = get_a_passive_txt_message(
                     open_id, service_id,
                     u'签到成功,恭喜您获得【%s个】积分奖励!' % m_integral)
             else:
                 msg_xml = get_a_passive_txt_message(
                     open_id, service_id, u'签到失败,请重试!' % m_integral)
         else:
             msg_xml = get_a_passive_txt_message(open_id, service_id,
                                                 u'每天只能签到一次,请明天再来!')
     else:
         msg_xml = get_a_passive_txt_message(
             open_id, service_id, u'您还没有完成认证,点击【我是车主>>车主认证】完成认证!')
     return msg_xml