示例#1
0
	def get(args):
		corp = args['corp']
		filters = json.loads(args.get('filters', '{}'))
		fill_options = json.loads(args.get('fill_options', '{}'))
		
		target_page = PageInfo.create({
			"cur_page": int(args.get('cur_page', 1)),
			"count_per_page": int(args.get('count_per_page', 15))
		})
		if not fill_options:
			fill_options = {
				'with_price': True,
				'with_image': True,
			}
		products, page_info = corp.insale_shelf.get_simple_products(target_page, filters, fill_options)
		encode_product_service = EncodeProductService.get(corp)
		data = []
		for product in products:
			base_info = encode_product_service.get_base_info(product)
			models_info = encode_product_service.get_models_info(product)
			image_info = encode_product_service.get_image_info(product)
			data.append({
				"id": product.id,
				"name": base_info['name'],
				"created_at": product.created_at.strftime("%Y-%m-%d %H:%M") if product.created_at else '',
				"models_info": models_info,
				'image_info': image_info,
			})

		return {
			'products': data,
			'page_info': page_info.to_dict()
		}
示例#2
0
	def get(args):
		corp = args['corp']
		ids = [args['id']]
		fill_options = {
			'with_category': True,
			'with_image': True,
			'with_product_model': True,
			'with_model_property_info': True,
			'with_property': True,
			'with_supplier_info': True,
			'with_classification': True,
			'with_product_promotion': True
		}
		products = corp.product_pool.get_products_by_ids(ids, fill_options)
		if len(products) == 0:
			return {}
		else:
			product = products[0]
			encode_product_service = EncodeProductService.get()

			data = {
				"id": product.id,
				"base_info": encode_product_service.get_base_info(product),
				"categories": encode_product_service.get_categories(product),
				"image_info": encode_product_service.get_image_info(product),
				"models_info": encode_product_service.get_models_info(product),
				"pay_info": encode_product_service.get_pay_info(product),
				'properties': encode_product_service.get_properties(product),
				"logistics_info": encode_product_service.get_logistics_info(product),
				"supplier": encode_product_service.get_supplier_info(product),
				"classifications": encode_product_service.get_classifications(product),
				"promotions": encode_product_service.get_promotions(product)
			}

			return data
示例#3
0
	def get(args):
		corp = args['corp']

		fill_options = {
			'with_product_model': True,
			'with_model_property_info': True,
			'with_cps_promotion_info': True
		} if not args.get('fill_options') else args['fill_options']

		products = corp.product_pool.get_all_products(fill_options, args.get('product_ids'))

		encode_product_service = EncodeProductService.get(corp)
		datas = []
		for product in products:
			base_info = encode_product_service.get_base_info(product)
			models_info = encode_product_service.get_models_info(product)
			gross_profit_info = encode_product_service.get_gross_profit_info(product)
			cps_promotion_info = encode_product_service.get_cps_promotion_info(product)

			data = {
				"id": product.id,
				"name": base_info['name'],
				"models_info": models_info,
				"created_at": base_info['created_at'],
				'gross_profit_info': gross_profit_info,
				"cps_promotion_info": cps_promotion_info
			}

			datas.append(data)

		return datas
		
示例#4
0
    def get(args):
        corp = args['corp']
        category_id = args['category_id']
        fill_options = json.loads(args.get('fill_options', '{}'))

        target_page = PageInfo.create({
            "cur_page":
            int(args.get('cur_page', 1)),
            "count_per_page":
            int(args.get('count_per_page', 15))
        })
        category = corp.category_repository.get_category(category_id)
        products, page_info = CategoryProductRepository.get(category)\
         .get_on_shelf_products_for_category(category_id, corp.id, fill_options=fill_options, target_page=target_page)

        encode_product_service = EncodeProductService.get(corp)

        data = []
        for product in products:
            temp_value = dict()
            temp_value['id'] = product.id

            if 'with_base' in fill_options:
                base_info = encode_product_service.get_base_info(product)
                temp_value['base_info'] = base_info
            data.append(temp_value)
            # 其他一次类推
        return {"products": data, 'page_info': page_info.to_dict()}
示例#5
0
    def get_products_info(self, promotion):
        """
		获得促销中的商品信息
		"""
        if promotion.products:
            result = []
            for product in promotion.products:
                encode_product_service = EncodeProductService.get(self.corp)
                base_info = encode_product_service.get_base_info(product)
                models_info = encode_product_service.get_models_info(product)
                supplier = encode_product_service.get_supplier_info(product)
                classifications = encode_product_service.get_classifications(
                    product)
                image_info = encode_product_service.get_image_info(product)
                categories = encode_product_service.get_categories(product)

                data = {
                    "id": product.id,
                    "name": base_info['name'],
                    "create_type": base_info['create_type'],
                    "is_member_product": base_info['is_member_product'],
                    "image": image_info['thumbnails_url'],
                    "models_info": models_info,
                    "bar_code": base_info['bar_code'],
                    "display_index": base_info['display_index'],
                    'supplier': supplier,
                    'classifications': classifications,
                    "categories": categories,
                    "sales": base_info['sales'],
                    "created_at": base_info['created_at'],
                    "sync_at": base_info['sync_at'],
                }
                result.append(data)
            return result
示例#6
0
    def get(args):
        """
		:param product_status insale: 在售, forsale: 下架 , pool: 商品池列表
		"""
        corp = args['corp']
        target_page = PageInfo.create({
            "cur_page":
            int(args.get('cur_page', 1)),
            "count_per_page":
            int(args.get('count_per_page', 10))
        })
        filters = json.loads(args.get('filters', '{}'))
        product_status = args.get('product_status')

        if product_status == 'insale':
            insale_shelf = corp.insale_shelf

            products, pageinfo = insale_shelf.search_cps_promoted_products(
                filters, target_page)
        elif product_status == 'forsale':
            forsale_shelf = corp.forsale_shelf

            products, pageinfo = forsale_shelf.search_cps_promoted_products(
                filters, target_page)
        else:
            products, pageinfo = corp.product_pool.search_promoted_products(
                filters, target_page)

        encode_product_service = EncodeProductService.get(corp)

        datas = []
        for product in products:
            base_info = encode_product_service.get_base_info(product)
            models_info = encode_product_service.get_models_info(product)
            supplier = encode_product_service.get_supplier_info(product)
            classifications = encode_product_service.get_classifications(
                product)
            image_info = encode_product_service.get_image_info(product)
            categories = encode_product_service.get_categories(product)
            labels = encode_product_service.get_labels(product)
            cps_promotion_info = encode_product_service.get_cps_promotion_info(
                product)

            data = {
                "id": product.id,
                "models_info": models_info,
                'supplier': supplier,
                'image_info': image_info,
                "categories": categories,
                'classifications': classifications,
                'base_info': base_info,
                'labels': labels,
                'cps_promotion_info': cps_promotion_info,
                "sync_at": base_info['sync_at'],
            }

            datas.append(data)

        return {'pageinfo': pageinfo.to_dict(), 'products': datas}
示例#7
0
	def get(args):
		corp = args['corp']

		target_page = PageInfo.create({
			"cur_page": int(args.get('cur_page', 1)),
			"count_per_page": int(args.get('count_per_page', 10))
		})

		filters = json.loads(args.get('filters', '{}'))
		if filters:
			products, pageinfo = corp.insale_shelf.search_products(filters, target_page)
		else:
			products, pageinfo = corp.insale_shelf.get_products(target_page)

		encode_product_service = EncodeProductService.get(corp)
		datas = []
		for product in products:
			base_info = encode_product_service.get_base_info(product)
			models_info = encode_product_service.get_models_info(product)
			supplier = encode_product_service.get_supplier_info(product)
			classifications = encode_product_service.get_classifications(product)
			image_info = encode_product_service.get_image_info(product)
			categories = encode_product_service.get_categories(product)
			promotions = encode_product_service.get_promotions(product)
			gross_profit_info = encode_product_service.get_gross_profit_info(product)
			cps_promotion_info = encode_product_service.get_cps_promotion_info(product)

			data = {
				"id": product.id,
				"name": base_info['name'],
				"create_type": base_info['create_type'],
				"is_member_product": base_info['is_member_product'],
				"image": image_info['thumbnails_url'],
				"swipe_images": image_info['images'],
				"models_info": models_info,
				"bar_code": base_info['bar_code'],
				"display_index": base_info['display_index'],
				'supplier': supplier,
				'classifications': classifications,
				"categories": categories,
				"sales": base_info['sales'],
				"created_at": base_info['created_at'],
				"sync_at": base_info['sync_at'],
				'promotions': promotions,
				'gross_profit_info': gross_profit_info,
				"cps_promotion_info": cps_promotion_info
			}

			datas.append(data)

		return {
			'pageinfo': pageinfo.to_dict(),
			'products': datas
		}
示例#8
0
    def put(args):

        corp = args['corp']

        product_id = args.get('product_id')
        money = args.get('money')
        stock = args.get('stock')
        time_from = args.get('time_from')
        time_to = args.get('time_to')

        sale_count = args.get('sale_count', 0)
        total_money = args.get('total_money', 0)

        product = corp.product_pool.get_product_by_id(product_id)
        if product:
            product.apply_cps_promotion(money, stock, time_from, time_to,
                                        sale_count, total_money)
            encode_product_service = EncodeProductService.get(corp)

            cps_promotion_info = encode_product_service.get_cps_promotion_info(
                product)
            return {'id': product.id, 'cps_promotion_info': cps_promotion_info}
        return 500, {}
	def get(args):
		corp = args['corp']
		
		target_page = PageInfo.create({
			"cur_page": int(args.get('cur_page', 1)),
			"count_per_page": int(args.get('count_per_page', 10))
		})

		filters = json.loads(args.get('filters', '{}'))
		filters['__f-status-equal'] = mall_models.PP_STATUS_ON_POOL

		fill_options = {
			'with_category': True,
			'with_product_model': True,
			'with_model_property_info': True,
			'with_shelve_status': True,
			'with_supplier_info': True,
			'with_classification': True,
			'with_sales': True,
			'with_product_label': True,
			'with_cps_promotion_info': True,
		}

		options = {
			'order_options': ['display_index', '-id']
		}

		products, pageinfo = corp.product_pool.get_products(target_page, fill_options, options, filters)

		encode_product_service = EncodeProductService.get(corp)
		datas = []
		for product in products:
			base_info = encode_product_service.get_base_info(product)
			models_info = encode_product_service.get_models_info(product)
			supplier = encode_product_service.get_supplier_info(product)
			classifications = encode_product_service.get_classifications(product)
			image_info = encode_product_service.get_image_info(product)
			categories = encode_product_service.get_categories(product)
			labels = encode_product_service.get_labels(product)
			cps_promotion_info = encode_product_service.get_cps_promotion_info(product)

			data = {
				"id": product.id,
				"name": base_info['name'],
				"create_type": base_info['create_type'],
				"image": image_info['thumbnails_url'],
				"models_info": models_info,
				"bar_code": base_info['bar_code'],
				"display_index": base_info['display_index'],
				'supplier': supplier,
				'classifications': classifications,
				"categories": categories,
				"sales": base_info['sales'],
				"created_at": base_info['created_at'],
				"sync_at": base_info['sync_at'],
				'labels': labels,
				'cps_promotion_info': cps_promotion_info,

			}

			datas.append(data)

		return {
			'pageinfo': pageinfo.to_dict(),
			'products': datas
		}
示例#10
0
    def get(args):
        # corp = args['corp']
        fill_options = json.loads(args.get('fill_options', '{}'))
        weizoom_corp = CorporationFactory.get_weizoom_corporation()

        target_page = PageInfo.create({
            "cur_page":
            int(args.get('cur_page', 1)),
            "count_per_page":
            int(args.get('count_per_page', 10))
        })

        options = {'order_options': ['display_index', '-id']}
        options['request_source'] = 'unshelf_consignment'
        if not fill_options:
            fill_options = {
                'with_product_model': True,
                'with_model_property_info': True,
                'with_shelve_status': True,
                'with_supplier_info': True,
                'with_classification': True,
                'with_product_label': True,
            }

        #TODO: 寻找更优雅的切换公司的解决方案
        #将公司设置为weizoom corp
        CorporationFactory.set(weizoom_corp)
        filters = json.loads(args.get('filters', '{}'))
        products, pageinfo = weizoom_corp.product_pool.get_products(
            target_page, fill_options, options, filters)
        #恢复当前公司
        # CorporationFactory.set(corp)

        encode_product_service = EncodeProductService.get(weizoom_corp)
        datas = []
        for product in products:
            base_info = encode_product_service.get_base_info(product)
            data = {
                'id': product.id,
                'name': base_info['name'],
                "create_type": base_info['create_type'],
                "image": base_info['thumbnails_url'],
                "bar_code": base_info['bar_code'],
                "display_index": base_info['display_index'],
            }
            if fill_options.get('with_product_model'):
                models_info = encode_product_service.get_models_info(product)
                data['models_info'] = models_info
                if product.is_use_custom_model:
                    data['stock_type'] = 'combined'
                    data['stocks'] = -1
                    data['price'] = 'todo'
                else:
                    standard_model = product.standard_model
                    data['stock_type'] = standard_model.stock_type
                    data['stocks'] = standard_model.stocks
                    data['price'] = standard_model.price
            if fill_options.get('with_supplier_info'):
                supplier = encode_product_service.get_supplier_info(product)
                data['supplier'] = supplier
            if fill_options.get('with_classification'):
                classifications = encode_product_service.get_classifications(
                    product)
                data['classifications'] = classifications
            # if fill_options.get('with_image'):
            # 	image_info = encode_product_service.get_image_info(product)
            if fill_options.get('with_product_label'):
                labels = encode_product_service.get_labels(product)
                data['labels'] = labels

            datas.append(data)

        return {'pageinfo': pageinfo.to_dict(), 'products': datas}