Пример #1
0
    def process_request(sel, req, resp):
        if '/user/access_token' in req.path or '/console/' in req.path:
            watchdog.info(
                "skipped in WebAppAccountMiddleware. req.path: {}".format(
                    req.path))
            return

        corp_id = req.params.get('woid')
        if not corp_id:
            corp_id = req.params.get('corp_id')
        req.context['corp'] = Corporation(corp_id)
        CorporationFactory.set(req.context['corp'])
Пример #2
0
    def get_candidate_products_for_category(self,
                                            category_id,
                                            target_page,
                                            filters=None):
        """
		获得商品分组的候选商品集合
		"""
        #商品详情填充选项
        fill_options = {
            'with_price': True,
            'with_shelve_status': True,
            'with_sales': True
        }

        if filters is None:
            filters = {}
        filters['__f-status-in'] = [
            mall_models.PP_STATUS_OFF, mall_models.PP_STATUS_ON
        ]

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

        if category_id == '0' or category_id == 0:
            products, pageinfo = CorporationFactory().get(
            ).product_pool.get_products(target_page,
                                        fill_options,
                                        filters=filters,
                                        options=options)
        else:
            #获取category的可选商品
            product_relations = mall_models.CategoryHasProduct.select(
            ).dj_where(category_id=category_id)
            product_ids = [
                relation.product_id for relation in product_relations
            ]

            enhanced_filters = {'__f-id-notin': product_ids}
            if filters:
                enhanced_filters.update(filters)
            products, pageinfo = CorporationFactory().get(
            ).product_pool.get_products(target_page,
                                        fill_options,
                                        filters=enhanced_filters,
                                        options=options)

        #创建CategoryProduct对象
        category_products = []
        for product in products:
            category_product = CategoryProduct(product)
            category_products.append(category_product)

        return category_products, pageinfo
Пример #3
0
    def __get_category_products_for_category_product_relations(
            self, product_relations):
        """
		根据一批CategoryHasProduct model对象获取CategoryProduct对象集合
		"""
        product_ids = []
        product2relation = {}
        if product_relations:
            product_ids = [
                relation.product_id for relation in product_relations
            ]
            product2relation.update(
                dict([(relation.product_id, relation)
                      for relation in product_relations]))

        fill_options = {
            'with_price': True,
            'with_product_model': True,
            'with_shelve_status': True,
            'with_category': True,
            'with_sales': True
        }
        products = CorporationFactory.get().product_pool.get_products_by_ids(
            product_ids, fill_options)
        category_products = []
        for product in products:
            category_product = CategoryProduct(product)
            relation = product2relation[product.id]
            category_product.set_display_index(relation.display_index)
            category_product.set_created_at(relation.created_at)
            category_products.append(category_product)

        return category_products
Пример #4
0
    def disable(self):
        """
		禁用支付接口
		"""
        corp_id = CorporationFactory.get().id
        mall_models.PayInterface.update(is_active=False).dj_where(
            owner_id=corp_id, id=self.id).execute()
Пример #5
0
 def is_used(self):
     corp = CorporationFactory.get()
     relation_models = mall_models.ProductModelHasPropertyValue.select(
     ).dj_where(property_id=self.id)
     if relation_models.count() > 0:
         product_model_ids = [
             relation_model.model_id for relation_model in relation_models
         ]
         product_model_data_models = mall_models.ProductModel.select(
         ).dj_where(id__in=product_model_ids, is_deleted=0)
         if product_model_data_models.count() > 0:
             product_ids = [
                 model_data.product_id
                 for model_data in product_model_data_models
             ]
             product_pool_relations = mall_models.ProductPool.select(
             ).dj_where(woid=corp.id,
                        product_id__in=product_ids,
                        status__in=[
                            mall_models.PP_STATUS_OFF,
                            mall_models.PP_STATUS_ON
                        ])
             if product_pool_relations.count() > 0:
                 return True
     return False
Пример #6
0
    def get(args):
        corp = CorporationFactory.get()
        end_id = args['end_id']

        product_classifications = corp.product_classification_repository.get_product_classification_tree_by_end(
            end_id)

        datas = []
        for product_classification in product_classifications:
            qualifications = product_classification.get_qualifications()
            datas.append({
                'id':
                product_classification.id,
                'name':
                product_classification.name,
                'level':
                product_classification.level,
                'father_id':
                product_classification.father_id,
                'product_count':
                product_classification.product_count,
                'created_at':
                product_classification.created_at.strftime('%Y-%m-%d %H:%M'),
                'qualification_infos': [{
                    "id": qualification.id,
                    "name": qualification.name,
                    'created_at': qualification.created_at,
                    'index': i
                } for i, qualification in enumerate(qualifications)]
            })

        return {'product_classifications': datas}
Пример #7
0
 def post(args):
     corp = args['corp']
     id = args['id']
     name = args['name']
     limit_provinces = json.loads(args.get('limit_provinces', '[]'))
     limit_cities = json.loads(args.get('limit_cities', '[]'))
     if corp.is_self_run_platform():
         weizoom_corp = CorporationFactory.get_weizoom_corporation()
         CorporationFactory.set(weizoom_corp)
         limit_zone = weizoom_corp.limit_zone_repository.get_limit_zone_by_id(
             id)
         CorporationFactory.set(corp)
     else:
         limit_zone = corp.limit_zone_repository.get_limit_zone_by_id(id)
     limit_zone.update(name, limit_provinces, limit_cities)
     return {}
Пример #8
0
	def add_products(self, product_ids):
		"""
		向分组中添加一组商品

		先过滤出CategoryHasProduct表中已经存在的<category_id, product_id>对,只向表中添加新的<category_id, product_id>对
		"""
		if product_ids:
			relations = mall_models.CategoryHasProduct.select().dj_where(product_id__in=product_ids, category_id=self.id)
			existed_product_ids = set([relation.product_id for relation in relations])

			product_ids = set(product_ids)
			new_product_ids = product_ids - existed_product_ids

			if new_product_ids:
				for product_id in new_product_ids:
					mall_models.CategoryHasProduct.create(
						product = product_id,
						category = self.id
					)

				Category.update_product_count(self.id)

				msgutil.send_message(
					TOPIC['product'],
					'add_products_to_category',
					{
						'corp_id': CorporationFactory.get().id,
						'product_ids': list(new_product_ids),
						'category_id': self.id
					}
				)
Пример #9
0
    def create(args):
        from business.mall.logistics.express_delivery_repository import ExpressDeliveryRepository
        company = ExpressDeliveryRepository.get().get_company(
            args['company_id'])

        corp_id = CorporationFactory.get().id

        #确定display_index
        express_deliverys = list(
            express_models.ExpressDelivery.select().dj_where(
                owner_id=corp_id).order_by(
                    express_models.ExpressDelivery.display_index.desc()))
        if len(express_deliverys) > 0:
            display_index = express_deliverys[0].display_index + 1
        else:
            display_index = 1

        #创建ExpressDelivery对象
        express_delivery = express_models.ExpressDelivery.create(
            owner=corp_id,
            name=company.name,
            express_number=company.company_id,
            express_value=company.value,
            display_index=display_index,
            remark=args.get('remark', ' '))
        return ExpressDelivery(express_delivery)
Пример #10
0
	def update(self, params):
		"""
		更新模板

		Args:
          title: 属性模板标题
          new_properties: 需要新建的property集合
          update_properties: 需要更新的property集合
          deleted_property_ids: 需要删除的property的id集合
		"""
		corp = CorporationFactory.get()
		template_id = self.id

		#更新template name
		name = params['title']
		mall_models.ProductPropertyTemplate.update(name=name).dj_where(owner_id=corp.id, id=template_id).execute()

		#更新已存在的template property
		update_properties = params['update_properties']
		for template_property in update_properties:
			mall_models.TemplateProperty.update(name=template_property['name'], value=template_property['value']).dj_where(owner_id=corp.id, template_id=template_id, id=template_property['id']).execute()

		#创建新的template property
		new_properties = params['new_properties']
		for template_property in new_properties:
			mall_models.TemplateProperty.create(
				owner = corp.id,
				template = template_id,
				name = template_property['name'],
				value = template_property['value']
			)

		#删除需要删除的template property
		deleted_property_ids = params['deleted_property_ids']
		mall_models.TemplateProperty.delete().dj_where(owner_id=corp.id, template_id=template_id, id__in=deleted_property_ids).execute()
def step_impl(context, user, classification_name):
    datas = json.loads(context.text)
    #获得该商品分类的所有资质
    classification_id = __classification_name2id(classification_name)
    weizoom_corp = CorporationFactory.get_weizoom_corporation()
    classification = weizoom_corp.product_classification_repository.get_product_classification(
        classification_id)
    all_qualifications = classification.get_qualifications()
    #去除将要删除的资质
    for data in datas:
        name = data['qualification_name']
        for qualification in all_qualifications:
            if qualification.name == name:
                all_qualifications.remove(qualification)

    response = context.client.put(
        '/mall/product_classification_qualification/', {
            'corp_id':
            bdd_util.get_user_id_for(user),
            'classification_id':
            classification_id,
            'qualification_infos':
            json.dumps([{
                'id': q.id,
                'name': q.name
            } for q in all_qualifications])
        })

    bdd_util.assert_api_call_success(response)
Пример #12
0
    def get(args):
        corp = CorporationFactory.get()
        product_label_groups = corp.product_label_group_repository.get_label_groups(
        )

        product_labels = corp.product_label_repository.get_labels_by_group_ids(
            [p.id for p in product_label_groups])
        product_label_group_id2labels = dict()

        for label in product_labels:
            if not product_label_group_id2labels.has_key(label.label_group_id):
                product_label_group_id2labels[label.label_group_id] = [label]
            else:
                product_label_group_id2labels[label.label_group_id].append(
                    label)

        datas = []
        for group in product_label_groups:
            group_has_labels = product_label_group_id2labels.get(group.id, [])
            labels = [{
                "label_id": label.id,
                "label_name": label.name
            } for label in group_has_labels]
            datas.append({
                'label_group_id': group.id,
                'label_group_name': group.name,
                'labels': labels
            })
        return {'product_label_groups': datas}
Пример #13
0
    def update_display_index(self, direction):
        """
		更新display index
		"""
        corp_id = CorporationFactory.get().id
        models = list(
            express_models.ExpressDelivery.select().dj_where(owner_id=corp_id))
        models.sort(lambda x, y: cmp(y.display_index, x.display_index))

        src_index = -1
        for index, model in enumerate(models):
            if model.id == self.id:
                src_index = index
                break

        if direction == 'up':
            dst_index = src_index - 1
        else:
            dst_index = src_index + 1

        #交换两个数据的display index
        src_id = models[src_index].id
        src_display_index = models[src_index].display_index
        dst_id = models[dst_index].id
        dst_display_index = models[dst_index].display_index
        express_models.ExpressDelivery.update(
            display_index=dst_display_index).dj_where(id=src_id).execute()
        express_models.ExpressDelivery.update(
            display_index=src_display_index).dj_where(id=dst_id).execute()
Пример #14
0
    def update(self, update_params):
        """
		更新积分规则
		"""
        corp = CorporationFactory.get()
        member_models.IntegralStrategySettings.update(
            integral_each_yuan=update_params['integral_each_yuan'],
            be_member_increase_count=update_params['be_member_increase_count'],
            click_shared_url_increase_count=0,
            buy_award_count_for_buyer=update_params[
                'buy_award_count_for_buyer'],
            order_money_percentage_for_each_buy=update_params[
                'order_money_percentage_for_each_buy'],
            buy_via_shared_url_increase_count_for_author=0,
            buy_via_offline_increase_count_for_author=update_params[
                'buy_via_offline_increase_count_for_author'],
            buy_via_offline_increase_count_percentage_for_author=update_params[
                'buy_via_offline_increase_count_percentage_for_author'],
            use_ceiling=update_params['use_ceiling'],
            review_increase=update_params['review_increase']).dj_where(
                webapp_id=corp.webapp_id).execute()

        msg_name = 'webapp_owner_info_updated'
        topic_name = TOPIC['mall_config']
        data = {
            "corp_id": corp.id,
        }
        msgutil.send_message(topic_name, msg_name, data)
Пример #15
0
    def enable(self):
        """
		启用支付接口
		"""
        corp_id = CorporationFactory.get().id
        mall_models.PayInterface.update(is_active=True).dj_where(
            owner_id=corp_id, id=self.id).execute()
        self.__send_message_to_topic()
Пример #16
0
 def get(args):
     corp = args['corp']
     if corp.is_self_run_platform():
         weizoom_corp = CorporationFactory.get_weizoom_corporation()
         CorporationFactory.set(weizoom_corp)
         limit_zone = weizoom_corp.limit_zone_repository.get_limit_zone_by_id(
             args['id'])
         CorporationFactory.set(corp)
     else:
         limit_zone = corp.limit_zone_repository.get_limit_zone_by_id(
             args['id'])
     data = {
         'id': limit_zone.id,
         'name': limit_zone.name,
         'zones': limit_zone.zones
     }
     return data
Пример #17
0
    def delete(args):
        """
		删除标签
		"""
        corp = CorporationFactory.get()
        corp.product_label_repository.delete_labels([args['label_id']])

        return {}
Пример #18
0
    def update(self, args):
        update_params = self.__build_update_params(args)

        corp = CorporationFactory.get()
        mall_models.MallConfig.update(**update_params).dj_where(
            owner_id=corp.id).execute()
        msgutil.send_message(TOPIC['product'], 'mall_config_updated',
                             {'corp_id': corp.id})
Пример #19
0
 def __send_message_to_topic(self):
     corp_id = CorporationFactory.get().id
     msg_name = 'webapp_owner_info_updated'
     topic_name = TOPIC['mall_config']
     data = {
         "corp_id": corp_id,
     }
     msgutil.send_message(topic_name, msg_name, data)
Пример #20
0
	def update_v3_config(self, args):
		corp_id = CorporationFactory.get().id
		mall_models.UserWeixinPayOrderConfig.update(
			app_id=args['app_id'].strip(),
			pay_version=mall_models.WEIXIN_PAY_V3,
			partner_id=args['mch_id'].strip(),
			partner_key=args['api_key'].strip(),
			paysign_key=args['paysign_key'].strip(),
		).dj_where(owner=corp_id).execute()
Пример #21
0
 def get(args):
     corp = CorporationFactory.get()
     labels = corp.product_label_repository.get_labels()
     return [{
         'id': label.id,
         'name': label.name,
         'label_group_id': label.label_group_id,
         'created_at': label.created_at.strftime('%Y-%m-%d %H:%M:%S')
     } for label in labels]
Пример #22
0
    def set_used(self):
        """
			将当前发货人设置为"使用"
			"""
        corp_id = CorporationFactory.get().id
        mall_models.Shipper.update(is_active=False).dj_where(
            id__not=self.id, owner_id=corp_id).execute()
        mall_models.Shipper.update(is_active=True).dj_where(
            id=self.id).execute()
Пример #23
0
    def get_nav(self):
        """
		商品分类层级
		"""
        corp = CorporationFactory.get()
        classifications = corp.product_classification_repository.get_product_classification_tree_by_end(
            self.id)
        return '--'.join(
            [classification.name for classification in classifications])
Пример #24
0
 def can_enable_integral_ceiling(self):
     # TODO 应该有promotion_respository提供
     corp = CorporationFactory.get()
     starting_promotion_count = promotion_models.Promotion.select()\
      .dj_where(type=promotion_models.PROMOTION_TYPE_INTEGRAL_SALE,
          status=promotion_models.PROMOTION_STATUS_STARTED,
          owner_id=corp.id).count()
     if starting_promotion_count:
         return False
     return True
    def put(args):
        classification_id = args['classification_id']
        qualification_infos = args['qualification_infos']

        corp = CorporationFactory.get()
        classification = corp.product_classification_repository.get_product_classification(
            classification_id)
        classification.set_qualifications(qualification_infos)

        return {}
Пример #26
0
    def delete(args):
        """
		删除标签分类
		:return:
		"""
        corp = CorporationFactory.get()
        corp.product_label_group_repository.delete_label_group(
            args['label_group_id'])

        return {}
Пример #27
0
 def create(args):
     config = mall_models.UserAlipayOrderConfig.create(
         owner=CorporationFactory.get().id,
         partner=args.get('partner', ''),
         key=args.get('key', ''),
         private_key=args.get('private_key', ''),
         ali_public_key=args.get('ali_public_key', ''),
         seller_email=args.get('seller_email', ''),
         pay_version=mall_models.ALI_PAY_V5)
     return AliPayConfig(config)
Пример #28
0
    def __load_postag_config(corp, product_id=None):
        """
		获取创建/查看商品时候,运费模板配置信息
		"""
        # 普通平台,商品使用平台设置的,自应平台应该显示商品的供货商的默认运费模板
        if not corp.is_self_run_platform():
            postage_config = corp.postage_config_repository.get_corp_used_postage_config(
            )
            return {'id': postage_config.id, 'name': postage_config.name}
        else:
            if not product_id:
                return {'id': '', 'name': ''}
            weizoom_corp = CorporationFactory.get_weizoom_corporation()
            CorporationFactory.set(weizoom_corp)
            product = corp.product_pool.get_product_by_id(product_id)
            postage_config = weizoom_corp.postage_config_repository.get_supplier_used_postage_config(
                product.supplier_id)
            CorporationFactory.set(corp)
            return {'id': postage_config.id, 'name': postage_config.name}
Пример #29
0
    def update(self, email_addresses, black_member_ids):
        """
		"""
        email_addresses = '|'.join(email_addresses)
        black_member_ids = '|'.join(black_member_ids)

        corp_id = CorporationFactory.get().id
        mall_models.UserOrderNotifySettings.update(
            emails=email_addresses,
            black_member_ids=black_member_ids).dj_where(user_id=corp_id,
                                                        id=self.id).execute()
Пример #30
0
 def delete_label_group(self, label_group_id):
     #查询出需要删除的分类中的标签
     deleted_labels = mall_models.ProductLabel.select().dj_where(
         label_group_id=label_group_id)
     deleted_label_ids = [str(l.id) for l in deleted_labels]
     #首先删除所有的标签
     corp = CorporationFactory.get()
     corp.product_label_repository.delete_labels(deleted_label_ids)
     #然后删除分组
     mall_models.ProductLabelGroup.update(is_deleted=True).dj_where(
         id=label_group_id).execute()