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() }
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()}
def get(args): page_info = PageInfo.create({ "cur_page": int(args.get('cur_page', 1)), "count_per_page": int(args.get('count_per_page', 15)) }) page_info, corps = CorporationRepository().filter_corps( args, page_info) rows = [{ 'corp_id': corp.id, 'name': corp.details.name, 'company_name': corp.details.company_name, 'username': corp.username, 'is_weizoom_corp': corp.is_weizoom_corp(), 'max_product_count': corp.details.max_product_count, 'classification_ids': corp.details.classification_ids, 'settlement_type': corp.details.settlement_type, 'divide_rebate': corp.details.divide_rebate, 'clear_period': corp.details.clear_period, 'status': corp.details.status } for corp in corps] return {'rows': rows, 'pageinfo': page_info.to_dict()}
def get(args): category_id = int(args['category_id']) corp = args['corp'] #分页信息 cur_page = int(args.get('page', 1)) count_per_page = int(args.get('count_per_page', 10)) target_page = PageInfo(cur_page, count_per_page) filters = json.loads(args['filters']) category_products, pageinfo = CategoryProductRepository.get(corp).get_candidate_products_for_category(category_id, target_page, filters) datas = [] for category_product in category_products: data = { "id": category_product.id, "name": category_product.name, "sales": category_product.sales, "status": category_product.status, "updated_at": category_product.created_at.strftime('%Y-%m-%d %H:%M'), "price": category_product.price } datas.append(data) return { 'pageinfo': pageinfo.to_dict(), 'products': datas }
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)) }) fill_options = {'with_detail': True, 'with_product': True} filters = json.loads(args.get('filters', '{}')) promotions, page_info = corp.promotion_repository.search_flash_sale_promotions( target_page, fill_options=fill_options, filters=filters) datas = [] encode_promotion_service = EncodePromotionService.get(corp) for promotion in promotions: base_info = encode_promotion_service.get_base_info(promotion) products_info = encode_promotion_service.get_products_info( promotion) detail_info = encode_promotion_service.get_detail_info(promotion) data = { 'promotion_info': base_info, 'products_info': products_info, 'detail': detail_info } datas.append(data) return { 'page_info': page_info.to_dict(), 'flase_sale_promotions': datas }
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}
def get(args): corp = args['corp'] fill_options = { 'with_price': True, 'with_image': True, 'with_product_model': True, 'with_model_property_info': True, 'with_classification': True, 'with_product_label': True if args['corp'].is_weizoom_corp() else False, 'with_sales': True, 'with_supplier_info': True, 'with_shelve_status': False } page_info = PageInfo.create({ "cur_page": int(args.get('cur_page', 1)), "count_per_page": int(args.get('count_per_page', 15)) }) pageinfo, pre_products = corp.global_product_repository.filter_products(args, page_info, fill_options) rows = [] for pre_product in pre_products: owner_corp_info = pre_product.supplier_info labels = sorted(pre_product.labels, lambda x,y: cmp(x.id, y.id)) rows.append({ 'id': pre_product.id, 'owner_id': pre_product.owner_id, 'owner_name': owner_corp_info['company_name'] if owner_corp_info else '', 'company_name': owner_corp_info['company_name'] if owner_corp_info else '', 'axe_sales_name': owner_corp_info['axe_sales_name'] if owner_corp_info else '', 'classification_id': pre_product.classification_id, 'promotion_title': pre_product.promotion_title, 'models': { 'standard_model': pre_product.standard_model, 'custom_models': pre_product.custom_models }, 'has_multi_models': pre_product.has_multi_models, 'name': pre_product.name, 'price_info': pre_product.price_info, 'total_sales': pre_product.sales, 'stocks': pre_product.stocks, 'status': pre_product.status, 'shelve_type': pre_product.shelve_type, 'classification_nav': pre_product.classification_nav, 'is_updated': pre_product.is_updated, 'is_accepted': pre_product.is_accepted, 'refuse_reasons': pre_product.refuse_reasons, 'detail': pre_product.detail, 'created_at': pre_product.created_at.strftime('%Y-%m-%d %H:%M:%S'), 'images': pre_product.swipe_images, 'label_names': [label.name for label in labels] }) return { 'rows': rows, 'pageinfo': pageinfo.to_dict() }
def get(args): corp = args['corp'] material_repository = corp.material_repository news_repository = corp.weixin_news_repository target_page = PageInfo.create({ "cur_page": int(args.get('cur_page', 1)), "count_per_page": int(args.get('count_per_page', 4)) }) selected_material_id = int(args.get('selected_material_id', 0)) data = { 'selected_material_id': selected_material_id, 'query': args.get('query', None), 'share_from': args.get('from', ''), 'sort_attr': args.get('sort_attr', '-id') } # 获取素材 pageinfo, materials = material_repository.get_materials( data, target_page) material_ids = [] id2material = {} for material in materials: material_ids.append(material.id) material.newses = [] id2material[material.id] = material # 获取图文消息 news = news_repository.get_news_by_material_ids(material_ids) # for new in news: id2material[new.material_id].newses.append({ "id": new.id, "title": new.title }) datas = [] for material in materials: datas.append({ "id": material.id, "created_at": material.created_at.strftime("%Y-%m-%d %H:%M:%S"), "type": 'single' if material.type == u'单图文消息' else 'multi', "newses": material.newses, "isChecked": True if material.id == selected_material_id else False }) return {'page_info': pageinfo.to_dict(), 'materials': datas}
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 }
def get(args): should_return_product = (args.get('return_product', 'false') == 'true') target_page = PageInfo.create({ "cur_page": int(args.get('cur_page', 1)), "count_per_page": int(args.get('count_per_page', 10)) }) corp = args['corp'] filters = json.loads(args.get('filters', '{}')) if filters: categories, pageinfo = corp.category_repository.search_categories( filters, target_page) else: categories, pageinfo = corp.category_repository.get_all_categories( target_page) datas = [] for category in categories: data = { "id": category.id, "name": category.name, "product_count": category.product_count, "products": [], "created_at": category.created_at.strftime('%Y-%m-%d %H:%M') } if should_return_product: for category_product in category.top_ten_products: data['products'].append({ "id": category_product.id, "name": category_product.name, "price": category_product.price, "display_index": category_product.display_index, "status": category_product.status, "sales": category_product.sales, "created_at": category_product.created_at.strftime('%Y-%m-%d %H:%M') }) datas.append(data) return { 'pageinfo': pageinfo.to_dict() if pageinfo else None, 'categories': datas }
def __load_categories(corp): """ 获取分类集合 """ target_page = PageInfo(1, 1000) categories, _ = corp.category_repository.get_all_categories( target_page) datas = [] for category in categories: datas.append({"id": category.id, "name": category.name}) return datas
def get(args): filters = json.loads(args.get('filters', '{}')) corp = args['corp'] delivery_item_repository = corp.delivery_item_repository target_page = PageInfo.create({ "cur_page": int(args.get('cur_page', 1)), "count_per_page": int(args.get('count_per_page', 10)) }) fill_options = { 'with_products': True, # 'with_refunding_info': True, 'with_express_details': True, # 'with_supplier': True, # 'with_operation_logs': True } pageinfo, delivery_items = delivery_item_repository.get_delivery_items( filters, target_page, fill_options) encode_delivery_item_service = EncodeDeliveryItemService.get(corp) datas = [] for delivery_item in delivery_items: data = {} data.update( encode_delivery_item_service.get_base_info(delivery_item)) # data.update(encode_delivery_item_service.get_refunding_info(delivery_item)) data.update( encode_delivery_item_service.get_express_details( delivery_item)) # data.update(encode_delivery_item_service.get_supplier(delivery_item)) delivery_has_products_data = encode_delivery_item_service.get_products( delivery_item) data.update(delivery_has_products_data) delivery_price = 0 for product in delivery_has_products_data['products']: delivery_price += product['total_origin_price'] data.update({'delivery_total_price': delivery_price}) # data.update(encode_delivery_item_service.get_operation_logs(delivery_item)) datas.append(data) # order_dicts = [order.to_dict() for order in orders] return {'page_info': pageinfo.to_dict(), 'delivery_items': datas}
def get_top_n_products(self, n): """ 获得排序靠前的n个商品 """ from business.common.page_info import PageInfo if n == UNLIMITED: n = 9999 target_page = PageInfo.create({"cur_page": 1, "count_per_page": n}) category_products, _ = self.get_products(target_page) return category_products
def search_categories(self, filters, target_page): """ 搜索商品分组 """ pageinfo = None result_categories = None if '__f-product_name-contain' in filters: product_filters = FilterParser.get().extract_by_keys( filters, {'__f-product_name-contain': '__f-name-contain'}) max_page = PageInfo.get_max_page() products, _ = self.corp.product_pool.get_products( max_page, filters=product_filters) product_ids = [product.id for product in products] category_ids = [ relation.category_id for relation in mall_models.CategoryHasProduct.select(). dj_where(product_id__in=product_ids) ] result_categories = mall_models.ProductCategory.select().dj_where( id__in=category_ids, owner_id=self.corp.id) pageinfo, result_categories = paginator.paginate( result_categories, target_page.cur_page, target_page.count_per_page) if '__f-name-contain' in filters: filter_parse_result = FilterParser.get().parse_key( filters, '__f-name-contain') params = { "owner_id": self.corp.id, } params.update(filter_parse_result) categories = mall_models.ProductCategory.select().dj_where( **params) if result_categories: #搜索场景:同时搜索“分组名”和“分组商品名”,基本不常用 #这里分页的逻辑非常复杂,所以,这种情况暂不支持分页 category_id_set = [category.id for category in categories] result_categories = [ category for category in result_categories if category.id in category_id_set ] else: pageinfo, result_categories = paginator.paginate( categories, target_page.cur_page, target_page.count_per_page) return [ Category.from_model({'db_model': category}) for category in result_categories ], pageinfo
def get(args): filters = json.loads(args.get('filters', '{}')) corp = args['corp'] order_repository = corp.order_repository target_page = PageInfo.create({ "cur_page": int(args.get('cur_page', 1)), "count_per_page": int(args.get('count_per_page', 10)) }) delivery_fill_options = { 'with_products': True, 'with_refunding_info': True, 'with_express_details': True, 'with_supplier': True } fill_options = { 'with_refunding_info': True, 'with_group_buy_info': True, 'with_member': True, 'with_coupon': True, 'with_full_money_info': True, 'with_delivery_items': delivery_fill_options } pageinfo, orders = order_repository.get_orders(filters, target_page, fill_options) encode_order_service = EncodeOrderService.get(corp) datas = [] for order in orders: data = {} data.update(encode_order_service.get_base_info(order)) data.update(encode_order_service.get_extra_coupon_info(order)) data.update(encode_order_service.get_group_buy_info(order)) data.update(encode_order_service.get_refunding_info(order)) data.update(encode_order_service.get_full_money_info(order)) data.update(encode_order_service.get_member_info(order)) data.update( encode_order_service.get_delivery_items( order, delivery_fill_options)) datas.append(data) # order_dicts = [order.to_dict() for order in orders] return {'page_info': pageinfo.to_dict(), 'orders': datas}
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)) }) fill_options = {'with_detail': True, 'with_product': True} filters = json.loads(args.get('filters', '{}')) # filters['__f-product_name-contains'] = '酒' promotions, page_info = corp.promotion_repository.search_premium_sale_promotions( target_page, fill_options=fill_options, filters=filters) datas = [] encode_promotion_service = EncodePromotionService.get(corp) for promotion in promotions: base_info = encode_promotion_service.get_base_info(promotion) products_info = encode_promotion_service.get_products_info( promotion) detail_info = encode_promotion_service.get_detail_info(promotion) data = { 'id': base_info['id'], 'name': base_info['name'], 'promotion_title': base_info['promotion_title'], 'type': base_info['type'], 'type_name': base_info['type_name'], 'status': base_info['status'], 'start_date': base_info['start_date'], 'end_date': base_info['end_date'], 'member_grade_id': base_info['member_grade_id'], 'created_at': base_info['created_at'], 'products_info': products_info, 'detail': detail_info, } datas.append(data) return { 'page_info': page_info.to_dict(), 'premium_sale_promotions': datas }
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)) }) category = corp.category_repository.get_category(args['category_id']) category_products, pageinfo = category.get_products(target_page) data = { "id": category.id, "name": category.name, "pageinfo": pageinfo.to_dict(), "products": [], "created_at": category.created_at.strftime('%Y-%m-%d %H:%M') } for category_product in category_products: data['products'].append({ "id": category_product.id, "name": category_product.name, "price": category_product.price, "display_index": category_product.display_index, "status": category_product.status, "sales": category_product.sales, "categories": category_product.categories, "created_at": category_product.created_at.strftime('%Y-%m-%d %H:%M') }) return data
def get(args): corp = CorporationFactory.get_weizoom_corporation() product_id = args['product_id'] target_page = PageInfo.create({ "cur_page": int(args.get('cur_page', 1)), "count_per_page": int(args.get('count_per_page', 15)) }) categories, page_info = corp.category_repository.get_product_categories(product_id, target_page) data = [] for category in categories: data.append({ 'id': category.id, "owner_id": category.owner_id, 'name': category.name }) return { "categories": data, 'page_info': page_info.to_dict() }
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 }
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}