예제 #1
0
    def collected_products(self):
        """
		[property] 会员收藏商品的集合
		"""
        webapp_owner = self.context['webapp_owner']

        ids = [
            memner_product_wish.product_id
            for memner_product_wish in mall_models.MemberProductWishlist.
            select().dj_where(owner_id=webapp_owner.id,
                              member_id=self.member.id,
                              is_collect=True).order_by(
                                  -mall_models.MemberProductWishlist.add_time)
        ]

        products = Product.from_ids({
            'webapp_owner': webapp_owner,
            'member': self.member,
            'product_ids': ids
        })
        products_dict_list = []
        for id in ids:
            for product in products:
                if product.id == id:
                    products_dict_list.append(product.to_dict())
                    break

        return products_dict_list
예제 #2
0
	def __fill_product_info(self):
		model = self.context['db_model'] 
		webapp_owner = self.context['webapp_owner']
		product_mode = model.order_has_product.product
		product = Product.from_model({
			'webapp_owner': webapp_owner,
			'model': product_mode,
			'fill_options': {}

			})
		self.product = product.to_dict()
예제 #3
0
    def __fill_detail(self, webapp_user, product_info):
        """
		填充购物车商品的详情
		"""
        product = Product.from_id({
            "webapp_owner": self.context['webapp_owner'],
            "member": webapp_user.member,
            "product_id": product_info['id']
        })
        self.context['product'] = product

        self.type = product.type
        self.id = product.id
        self.is_deleted = product.is_deleted
        self.shelve_type = product.shelve_type
        self.name = product.name
        self.thumbnails_url = product.thumbnails_url
        self.is_use_custom_model = product.is_use_custom_model
        self.shopping_cart_id = product_info['shopping_cart_id']

        #获取商品规格信息
        model = product.get_specific_model(product_info['model_name'])
        self.is_model_deleted = model.is_deleted
        self.price = model.price
        self.original_price = model.price
        self.weight = model.weight
        if not hasattr(product, 'min_limit'):
            self.min_limit = model.stocks
        self.model_name = product_info['model_name']
        self.stock_type = model.stock_type
        self.stocks = model.stocks
        self.model = model

        self.product_model_id = '%s_%s' % (product_info['id'],
                                           product_info['model_name'])
        self.purchase_count = product_info['count']

        self.is_member_product = product.is_member_product

        #获取促销
        product_promotion = product.promotion
        if product_promotion and product_promotion.is_active(
        ) and product.promotion.can_use_for(webapp_user):
            self.promotion = product.promotion
        else:
            self.promotion = None

        if product.is_member_product:
            _, discount_value = webapp_user.member.discount
            self.member_discount = member_discount / 100.0
        else:
            self.member_discount = 1.00
        self.price = round(self.price * self.member_discount, 2)  #折扣后的价格
예제 #4
0
	def __make_compatible_to_old_version(self, purchase_info, premium_products):
		"""
		兼容老的数据格式(后台管理系统会使用)
		"""
		from business.mall.product import Product
		webapp_owner = purchase_info.webapp_owner
		for premium_product in self.premium_products:
			premium_product['count'] = premium_product['premium_count']
			product = Product.from_id({
				'webapp_owner': webapp_owner,
				'product_id': premium_product['premium_product_id']
			})
			premium_product['price'] = product.price_info['min_price']
예제 #5
0
    def get(args):
        """
		获取商品详情

		@param member
		@param product_id
		"""
        product = Product.from_id({
            'woid': args['woid'],
            'member': args['member'],
            'product_id': args['product_id']
        })

        return product.to_dict()
예제 #6
0
    def __fill_detail(self, webapp_user, product_info):
        """
		填充购物车商品的详情
		"""
        product = Product.from_id({
            "webapp_owner": self.context['webapp_owner'],
            "member": webapp_user.member,
            "product_id": product_info['id']
        })
        self.context['product'] = product

        self.can_use_coupon = True
        self.type = product.type
        self.id = product.id
        self.is_deleted = product.is_deleted
        self.shelve_type = product.shelve_type
        self.name = product.name
        self.thumbnails_url = product.thumbnails_url
        self.is_use_custom_model = product.is_use_custom_model
        self.shopping_cart_id = product_info.get('shopping_cart_id', 0)
        self.integral_sale = product.integral_sale
        self.is_use_cod_pay_interface = product.is_use_cod_pay_interface
        self.min_limit = product.min_limit
        self.is_enable_bill = product.is_enable_bill
        self.purchase_price = product.purchase_price

        self.model_name = product_info['model_name']
        self.expected_promotion_id = product_info.get('expected_promotion_id',
                                                      0)
        self.product_model_id = '%s_%s' % (product_info['id'],
                                           product_info['model_name'])
        self.purchase_count = product_info['count']
        self.is_member_product = product.is_member_product

        self.postage_type = product.postage_type
        self.unified_postage_money = product.unified_postage_money
        self.is_delivery = product.is_delivery
        #获取商品规格信息
        model = product.get_specific_model(product_info['model_name'])
        self.is_model_deleted = model.is_deleted
        self.price = model.price
        # 已区分original_price和price的定义,original_price是供货价
        self.original_price = model.original_price
        self.weight = model.weight
        self.stock_type = model.stock_type
        self.stocks = model.stocks
        self.model = model
        if model.purchase_price > 0:
            self.purchase_price = model.purchase_price

        self.product_model_name_texts = []

        for p in model.property_values if model.property_values else []:
            self.product_model_name_texts.append(p['name'])

        self.total_price = self.price * int(self.purchase_count)

        #获取商品当前的promotion
        product_promotion = product.promotion
        if product_promotion and product_promotion.is_active(
        ) and product.promotion.can_use_for(webapp_user):
            self.promotion = product.promotion
            self.used_promotion_id = self.promotion.id
        else:
            self.promotion = None
            self.used_promotion_id = 0
        self.promotion_saved_money = 0.0
        self.limit_zone_type = product.limit_zone_type
        self.limit_zone = product.limit_zone

        #获取促销
        # promotion_id = product_info.get('promotion_id', 0)
        # if promotion_id == 0:
        # 	#没有指定promotion,获取商品当前的promotion
        # 	product_promotion = product.promotion
        # 	if product_promotion and product_promotion.is_active() and product.promotion.can_use_for(webapp_user):
        # 		self.promotion = product.promotion
        # 		self.used_promotion_id = self.promotion.id
        # 	else:
        # 		self.promotion = None
        # 		self.used_promotion_id = 0
        # else:
        # 	#指定了promotion,获取指定的promotion
        # 	self.promotion = {}
        # 	self.used_promotion_id = 0

        if product.is_member_product:
            _, discount_value = webapp_user.member.discount
            self.member_discount = discount_value / 100.0
        else:
            self.member_discount = 1.00
        self.price = round(self.price * self.member_discount, 2)  #折扣后的价格

        self.context['is_disable_discount'] = False
예제 #7
0
        def inner_func():
            webapp_owner_id = webapp_owner.id
            watchdog.warning({
                'uuid': 'product_list_cahce',
                'hint': '商品列表页未命中缓存',
                'woid': webapp_owner_id
            })

            product_models = self.__get_products(webapp_owner_id, 0)

            categories = mall_models.ProductCategory.select().dj_where(
                owner=webapp_owner_id)

            product_ids = [
                product_model.id for product_model in product_models
            ]
            category_has_products = mall_models.CategoryHasProduct.select(
            ).dj_where(product__in=product_ids)
            product2categories = dict()
            for relation in category_has_products:
                product2categories.setdefault(relation.product_id,
                                              set()).add(relation.category_id)

            try:
                categories = [{
                    "id": category.id,
                    "name": category.name
                } for category in categories]

                # Fill detail
                product_datas = []
                # jz 2015-11-26
                # member = webapp_user.member

                products = Product.from_models({
                    'webapp_owner': webapp_owner,
                    'models': product_models,
                    'fill_options': {
                        "with_price": True,
                        "with_product_promotion": True,
                        "with_selected_category": True
                    }
                })
                # for product_model in product_models:
                # 	product = Product.from_model({
                # 		'webapp_owner': webapp_owner,
                # 		'model': product_model,
                # 		'fill_options': {
                # 			"with_price": True,
                # 			"with_product_promotion": True,
                # 			"with_selected_category": True
                # 		}
                # 	})
                #
                for product in products:
                    product_datas.append({
                        "id":
                        product.id,
                        "name":
                        product.name,
                        "is_member_product":
                        product.is_member_product,
                        "display_price":
                        product.price_info['display_price'],
                        "promotion_js":
                        json.dumps(product.promotion.to_dict())
                        if product.promotion else json.dumps(None),
                        "thumbnails_url":
                        product.thumbnails_url,
                        "supplier":
                        product.supplier,
                        "categories":
                        list(product2categories.get(product.id, []))
                    })

                # delete by bert at 2016715
                # for product_data in product_datas:
                # 	product_data['categories'] = list(product2categories.get(product_data['id'], []))

                return {
                    'value': {
                        "products": product_datas,
                        "categories": categories
                    }
                }
            except:
                from eaglet.core.exceptionutil import unicode_full_stack
                msg = {
                    'traceback': unicode_full_stack(),
                    'hint': u'获取商品列表mysql数据失败',
                    'msg_id': 'spdb123',
                    'woid': webapp_owner_id
                }
                watchdog.alert(msg)
                if settings.DEBUG:
                    raise
                else:
                    return None
예제 #8
0
    def __fill_detail(self, webapp_user, product_info):
        """
		根据商品信息填充相应的商品详情
		"""
        product = Product.from_id({
            "webapp_owner": self.context['webapp_owner'],
            "member": webapp_user.member,
            "product_id": product_info['id']
        })
        self.context['product'] = product

        self.price = product_info['price']
        self.total_price = product_info['total_price']
        self.discount_money = product_info['discount_money']
        self.promotion_money = product_info['promotion_money']
        self.purchase_count = product_info['count']
        self.model_name = product_info['model_name']
        self.product_model_id = '%s_%s' % (product_info['id'],
                                           product_info['model_name'])
        self.purchase_count = product_info['count']
        self.used_promotion_id = product_info['promotion_id']
        self.is_discounted = (self.discount_money != 0)
        self.is_use_integral_sale = product_info['integral_sale_id'] > 0
        self.rid = product_info['rid']

        if product_info['promotion_result']:
            #self.promotion = {PromotionRepository.get_promotion_from_dict_data(product_info['promotion_result'])}
            promotion_result = product_info['promotion_result']
            self.promotion = {
                'type_name':
                promotion_result['type'],
                'promotioned_product_price':
                promotion_result.get('promotion_price', -1),
            }

        self.id = product.id
        self.type = product.type
        self.name = product.name
        self.thumbnails_url = product.thumbnails_url
        self.pic_url = product.pic_url
        self.shelve_type = product.shelve_type
        self.supplier = product.supplier
        self.supplier_name = product.supplier_name
        self.supplier_user_id = product.supplier_user_id

        model = product.get_specific_model(product_info['model_name'])
        if model:
            self.original_price = model.price
            self.weight = model.weight
            self.stock_type = model.stock_type
            if not hasattr(product, 'min_limit'):
                self.min_limit = model.stocks
            self.stocks = model.stocks
        else:
            watchdog.error({
                'msg_id':
                'no_specific_model',
                'msg':
                "none model product id {},model_name:{},woid:{},webapp_user_id:{}"
                .format(product.id, product_info['model_name'],
                        self.context['webapp_owner'].id,
                        self.context['webapp_user'].id)
            })
            self.original_price = product.price
            self.weight = product.weight
            self.stock_type = product.stock_type
            if not hasattr(product, 'min_limit'):
                self.min_limit = 1
            self.stocks = 0
        self.model = model
예제 #9
0
	def get(args):
		"""
		获取商品详情

		@param product_id 商品ID

		@note 从Weapp中迁移过来
		@see  mall_api.get_product_detail(webapp_owner_id, product_id, webapp_user, member_grade_id)
		"""

		product_id = args['product_id']
		webapp_owner = args['webapp_owner']
		webapp_user = args['webapp_user']

		param_data = {'pid': product_id, 'woid': webapp_owner.id, 'member_id': webapp_user.member.id}


		resp = Resource.use('marketapp_apiserver').get({
			'resource':GroupBuyOPENAPI['group_buy_product'],
			'data':param_data
		})


		if resp and resp['code'] == 200:
			data = resp['data']

			if data['is_in_group_buy']:
				return {
					'is_in_group_buy': True,
					'activity_url': data['activity_url']
				}

		product = Product.from_id({
			'webapp_owner': webapp_owner,
			# 'member': member,
			'product_id': args['product_id']
		})
		
		if product.is_deleted:
			return {'is_deleted': True}
		else:
			# product.apply_discount(args['webapp_user'])

			if product.promotion:
				#检查促销是否能使用
				if not product.promotion.can_use_for(webapp_user):
					product.promotion = None
					product.promotion_title = product.product_promotion_title


			param_data = {'woid':webapp_owner.id, 'product_id':product_id}
			reviews = []
			resp = Resource.use('marketapp_apiserver').get({
				'resource': 'evaluate.get_product_evaluates',
				'data': param_data
			})

			if resp:
				code = resp["code"]
				if code == 200:

					reviews = resp["data"]['product_reviews']

			result = product.to_dict(extras=['hint'])

			result['webapp_owner_integral_setting'] = {
				'integarl_per_yuan': webapp_owner.integral_strategy_settings.integral_each_yuan
			}
			result['product_reviews'] = reviews
		result['is_in_group_buy'] = False
		result['activity_url'] = ''
		if result['limit_zone_type']:
			template = ProductLimitZoneTemplate.from_id({'id': result['limit_zone']})
			result['limit_zone_detail'] = template.limit_zone_detail()
		if result['supplier']:
			try:
				result['supplier_postage_config'] = SupplierPostageConfig.from_suppler_id({'supplier_id': result['supplier']})['factor']
			except:
				result['supplier_postage_config'] = {}
		return result