Пример #1
0
 def get(self):
     data = parameter_required(('pbid',))
     pbid = data.get('pbid')
     product_brand = ProductBrand.query.filter_by({'PBid': pbid}).first_('品牌不存在')
     product_brand.fill('pbstatus_en', ProductStatus(product_brand.PBstatus).name)
     self._fill_brand(product_brand, new_product=True, banner_show=True)
     return Success(data=product_brand)
Пример #2
0
 def validate_status(self, value):
     try:
         if value.data in [ProductStatus.all.value, ProductStatus.auditing.value, None]:
             raise Exception
         ProductStatus(value.data)
     except Exception as e:
         raise ValidationError(message='状态错误')
     self.status = value
Пример #3
0
    def list(self):
        """个人购物车列表"""
        usid = request.user.id
        my_carts = self.scart.get_card_list({'USid': usid})
        pb_list = []
        new_cart_list = []
        product_num = 0
        for cart in my_carts:
            pbid = cart.PBid
            product = self.sproduct.get_product_by_prid(cart.PRid)  # 商品
            if not product:
                continue
            product.PRattribute = json.loads(product.PRattribute)
            pb = self.sproduct.get_product_brand_one({'PBid': pbid})
            if not pb:
                continue
            cart_sku = self.sproduct.get_sku_one({'SKUid': cart.SKUid})   # 购物车的sku
            if not cart_sku:
                continue
            cart_sku.SKUattriteDetail = json.loads(cart_sku.SKUattriteDetail)
            # skuvalue = self.sproduct.get_sku_value({'PRid': cart.PRid})   # 商品的skuvalue
            # 填充商品
            product.hide('PRdesc')
            product.fill('PRstatus_en', ProductStatus(product.PRstatus).name)
            # 商品sku
            skus = self.sproduct.get_sku({'PRid': product.PRid})
            sku_value_item = []
            for sku in skus:
                sku.SKUattriteDetail = json.loads(sku.SKUattriteDetail)
                sku_value_item.append(sku.SKUattriteDetail)
            product.fill('skus', skus)
            # 商品sku value
            sku_value_item_reverse = []
            for index, name in enumerate(product.PRattribute):
                value = list(set([attribute[index] for attribute in sku_value_item]))
                value = sorted(value)
                temp = {
                    'name': name,
                    'value': value
                }
                sku_value_item_reverse.append(temp)
            product.fill('SkuValue', sku_value_item_reverse)

            # 填充购物车
            cart.fill('sku', cart_sku)
            cart.fill('product', product)
            # 小计
            # cart.subtotal =
            # 数量
            product_num += 1
            # 店铺分组
            if pbid not in pb_list:
                new_cart_list.append({'cart': [cart], 'pb': pb})
                pb_list.append(pbid)
            else:
                index = pb_list.index(pbid)
                new_cart_list[index]['cart'].append(cart)
        return Success(data=new_cart_list).get_body(product_num=product_num)