def get_accounts(openid, webapp_id): today = datetime.today() date_str = datetime.today().strftime('%Y-%m-%d') key = 'member_{webapp:%s}_{openid:%s}' % (webapp_id, openid) data = cache_util.get_from_cache(key, get_accounts_for_cache(openid, webapp_id)) if data['date_time'] != date_str: delete_member_cache(openid, webapp_id) data = cache_util.get_from_cache( key, get_accounts_for_cache(openid, webapp_id)) member = member_models.Member.from_dict(data['member']) webapp_user = member_models.WebAppUser.from_dict(data['webapp_user']) social_account = social_account_models.SocialAccount.from_dict( data['social_account']) return webapp_user, social_account, member
def get_auto_qa_message_material(user_profile, query): if not query or query == '': return None key = 'auto_qa_message_webapp_id_%s_query_%s' % (user_profile.webapp_id, query.lower()) reply_rule = cache_util.get_from_cache( key, get_auto_qa_message_material_for_cache(user_profile, query)) return _parse_rule(user_profile, reply_rule)
def get_auto_reply_message_by_type(user_profile, reply_type): if not reply_type or reply_type == '': return None key = 'auto_qa_message_webapp_id_%s_type_%s' % (user_profile.webapp_id, reply_type) reply_rule = cache_util.get_from_cache( key, get_auto_reply_message_by_type_for_cache(user_profile, reply_type)) return _parse_rule(user_profile, reply_rule)
def get_webapp_product_model_properties(webapp_owner_id): """ 管理product model缓存 """ key = 'webapp_product_model_properties_{wo:%s}' % webapp_owner_id data = cache_util.get_from_cache( key, mall_api.get_product_model_properties_for_cache(webapp_owner_id)) id2property = data['id2property'] id2value = data['id2value'] return id2property, id2value
def get_webapp_postage_configs(webapp_owner_id): """ 管理postage config缓存 获取运费配置的缓存 """ key = 'webapp_postage_configs_{wo:%s}' % webapp_owner_id data = cache_util.get_from_cache( key, mall_api.get_postage_configs_for_cache(webapp_owner_id)) postage_configs = mall_models.PostageConfig.from_list(data) return postage_configs
def get_user_product(user): """ 获取用户对应的产品 @param user User对象 """ key = 'webapp_user_product_{wo:%s}' % user.id # print "user in get_user_product(): %s %s" % (user.id, user) # 如果没有缓存的数据,则调用_get_user_product_from_db()的函数获取数据库中的数据 data = cache_util.get_from_cache(key, _get_user_product_from_db(key, owner=user)) #print("data: {}".format(data)) return UserHasProduct.from_dict(data)
def get_component_auth(component, appid): # today = datetime.today() # date_str = datetime.today().strftime('%Y-%m-%d') key = 'component_{appid:%s}' % appid data = cache_util.get_from_cache(key, get_component_auth_for_cache(component, appid)) obj = Object() obj.user_profile = UserProfile.from_dict(data['user_profile']) obj.component_authed_appid = ComponentAuthedAppid.from_dict(data['component_authed_appid']) obj.mpuser = WeixinMpUser.from_dict(data['mpuser']) if data['integral_strategy_settings']: obj.integral_strategy_settings = member_models.IntegralStrategySttings.from_dict(data['integral_strategy_settings']) else: obj.integral_strategy_settings = None obj.default_tag = member_models.MemberTag.from_dict(data['default_tag']) obj.default_grade = member_models.MemberGrade.from_dict(data['default_grade']) return obj
def get_webapp_product_detail(webapp_owner_id, product_id, member_grade_id=None): """ 管理product detail缓存 获取商品详情的缓存 """ key = 'webapp_product_detail_{wo:%s}_{pid:%s}' % (webapp_owner_id, product_id) data = cache_util.get_from_cache( key, mall_api.get_product_detail_for_cache(webapp_owner_id, product_id)) product = mall_models.Product.from_dict(data) # 解决商品不存在以及商品在店铺间的串号问题 # 微众商城代码 if product.is_deleted or product.owner_id != webapp_owner_id: product.is_deleted = True return product # Set member's discount of the product if hasattr(product, 'integral_sale') and product.integral_sale \ and product.integral_sale['detail'].get('rules', None): for i in product.integral_sale['detail']['rules']: if i['member_grade_id'] == member_grade_id: product.integral_sale['detail']['discount'] = str( i['discount']) + "%" break promotion_data = data['promotion'] if promotion_data and len(promotion_data) > 0: product.promotion_model = promotion_models.Promotion.from_dict( promotion_data) else: product.promotion_model = dict() integral_sale_data = data['integral_sale'] if integral_sale_data and len(integral_sale_data) > 0: product.integral_sale_model = promotion_models.Promotion.from_dict( integral_sale_data) else: product.integral_sale_model = None product.master_promotion_title = data.get('master_promotion_title', None) product.integral_sale_promotion_title = data.get( 'integral_sale_promotion_title', None) mall_models.Product.fill_display_price([product]) ## 填充价格 return product
def get_order_stats(webapp_user_id): """ 获取订单的统计数据 @param webapp_user_id webapp_user_id 缓存的key :webapp_order_stats_{wu:`<webapp_user_id>`} 缓存的数据: - 总订单数 - 待支付订单数 @note 缓存失效条件:订单统计数据的缓存会在以下情况失效 - Order.save的时候会由信号触发回调函数 `update_webapp_order_cache()`,导致订单对应的 `webapp_user_id` 用户订单统计数据失效。 """ # 借助缓存 key = get_order_stats_cache_key(webapp_user_id) stats = cache_util.get_from_cache( key, _get_order_stats_fromdb(key, webapp_user_id)) if stats is not None: return (stats["total_count"], stats["not_paid"], stats["not_ship_count"], stats["shiped_count"], stats["review_count"]) else: # 总订单数 history_order_count = Order.by_webapp_user_id(webapp_user_id).count() # "待支付"订单数量 not_payed_order_count = Order.by_webapp_user_id(webapp_user_id).filter( status=ORDER_STATUS_NOT).count() # "待发货"订单数量 not_ship_order_count = Order.by_webapp_user_id(webapp_user_id).filter( status=ORDER_STATUS_PAYED_NOT_SHIP).count() # "已发货"订单数量 shiped_order_count = Order.by_webapp_user_id(webapp_user_id).filter( status=ORDER_STATUS_PAYED_SHIPED).count() # "待评价" 订单数量 review_count = get_count_of_unfinished_product_review_picture( webapp_user_id) return (history_order_count, not_payed_order_count, not_ship_order_count, shiped_order_count, review_count)
def get_forbidden_coupon_product_ids(webapp_owner_id): """ 获取商家的禁用全场优惠券的商品id列表 duhao """ key = 'forbidden_coupon_products_%s' % (webapp_owner_id) dict_forbidden_coupon_products = cache_util.get_from_cache( key, get_forbidden_coupon_product_ids_for_cache(webapp_owner_id)) forbidden_coupon_products = [] for dict_forbidden_coupon_product in dict_forbidden_coupon_products: forbidden_coupon_products.append( promotion_models.ForbiddenCouponProduct.from_dict( dict_forbidden_coupon_product)) product_ids = [] for product in forbidden_coupon_products: if product.is_active: product_ids.append(product.product_id) return product_ids
def get_webapp_by_appid(appid): key = 'webapp_appid_%s' % appid return cache_util.get_from_cache(key, get_webapp_from_db(appid=appid))
def get_webapp_mall_config(webapp_owner_id): key = 'webapp_mall_config_{wo:%s}' % webapp_owner_id data = cache_util.get_from_cache( key, mall_api.get_mall_config_for_cache(webapp_owner_id)) return mall_models.MallConfig.from_dict(data)
def get_webapp_categories_from_cache(webapp_owner_user_profile): # 商城下所有的分类,存放id,name,之后更改包括商品数量等信息,主要参考ProductCategory categories_key = '{wo:%s}_categories' % webapp_owner_user_profile.user_id return cache_util.get_from_cache( categories_key, get_webapp_categories_for_cache(webapp_owner_user_profile))
def get_weixin_mp_user_by_owner_id(owner_id): key = 'weixin_mp_user_owner_id_%s' % owner_id return cache_util.get_from_cache( key, get_weixin_mp_user_from_db(owner_id=owner_id))
def get_mpuser_preview_info_by_mpuser_id(mpuser_id): key = 'account_mpuser_preview_info_mpuser_id_%s' % mpuser_id return cache_util.get_from_cache( key, get_mpuser_preview_info_from_db(mpuser_id=mpuser_id))
def get_unship_order_count_from_cache(request): webapp_id = request.manager.get_profile().webapp_id key = 'webapp_unread_order_count_{wa:%s}' % webapp_id count = cache_util.get_from_cache(key, __get_unship_order_count_from_db(key, webapp_id, request.manager.id, request.user_profile.webapp_type)) return count