Beispiel #1
0
	def post(args):
		product_data = args
		product_id = product_data['id']
		update_product_service = UpdateProductService.get(args['corp'])
		update_product_service.update_product(product_id, product_data)

		return {}
Beispiel #2
0
	def post(args):
		product_id = args['id']

		update_product_service = UpdateProductService.get(args['corp'])
		update_product_service.update_product_position(product_id, args['position'])

		return {}
Beispiel #3
0
    def post(args):
        product_id = args['id']
        changed_count = args['changed_count']

        update_product_service = UpdateProductService.get(args['corp'])
        update_product_service.update_product_sale(product_id, changed_count)

        return {}
Beispiel #4
0
    def post(args):
        product_id = args['id']
        stock_infos = json.loads(args['stock_infos'])

        update_product_service = UpdateProductService.get(args['corp'])
        update_product_service.update_product_stock(product_id, stock_infos)

        return {}
Beispiel #5
0
	def post(args):
		product_id = args['id']
		price_infos = json.loads(args['price_infos'])

		update_product_service = UpdateProductService.get(args['corp'])
		update_product_service.update_product_price(product_id, price_infos)

		return {}
Beispiel #6
0
    def release(self, delivery_item_id, from_status, to_status):
        """
		当处理的是出货单时,需要决策是否处理以及如何处理订单
		对于db层面有没有出货单的订单,db操作已经在出货单完成,只用发送消息通知
		@param delivery_item_id:
		@param from_status:
		@param to_status:
		@return:
		"""

        fill_options = {'with_products': True}
        corp = self.corp
        delivery_item = corp.delivery_item_repository.get_delivery_item(
            delivery_item_id, fill_options)

        if delivery_item.has_db_record:
            is_paid = (from_status != mall_models.ORDER_STATUS_NOT
                       )  # 已经支付过的订单,已增加过销量

            delivery_item_products = delivery_item.products
            # product_ids = [p.id for p in delivery_item_products]
            # product_id2delivery_item_product = {p.id: p for p in delivery_item_products}
            #
            # products = corp.product_pool.get_products_by_ids(product_ids)
            #
            # for delivery_item_product in delivery_item_products:
            # 	product = corp.product_pool.get_products_by_ids([delivery_item_product.id])[0]
            #
            # 	product.update_sales(delivery_item_product.count)

            for delivery_item_product in delivery_item_products:
                # delivery_item_product = product_id2delivery_item_product[product.id]

                # 更新销量库存
                # product.update_stock(delivery_item_product.product_model_name, delivery_item_product.count)
                update_product_service = UpdateProductService.get(corp)
                stock_infos = [{
                    'model_id': delivery_item_product.model_id,
                    'changed_count': delivery_item_product.count
                }]
                update_product_service.add_product_stock(
                    delivery_item_product.id, stock_infos)

                # 更新销量,赠品不算销量
                if is_paid and delivery_item_product.promotion_info[
                        'type'] != "premium_sale:premium_product":
                    update_product_service.update_product_sale(
                        delivery_item_product.id,
                        0 - delivery_item_product.count)
Beispiel #7
0
    def post(args):
        product_id = args['product_id']

        update_product_service = UpdateProductService.get(args['corp'])
        result = update_product_service.update_product(
            product_id, {
                'corp': args['corp'],
                'base_info': args['base_info'],
                'models_info': args['models_info'],
                'logistics_info': args['logistics_info'],
                'image_info': args['image_info']
            })

        if result:
            return {}
        else:
            return 500, 'existed'
Beispiel #8
0
	def pay(self, corp):
		"""
		@param corp:
		@return:
		"""
		if self.status != mall_models.ORDER_STATUS_NOT:
			return False, 'Error Status'

		action_text = u"支付"
		from_status = self.status
		to_status = mall_models.ORDER_STATUS_PAYED_NOT_SHIP
		payment_time = datetime.now()

		self.status = to_status
		self.payment_time = payment_time

		# 更新首单信息
		if mall_models.Order.select().dj_where(
				webapp_id=self.webapp_id,
				webapp_user_id=self.webapp_user_id,
				is_first_order=True).count() == 0:
			self.is_first_order = True

		self.__record_operation_log(self.bid, corp.username, action_text)
		self.__recode_status_log(self.bid, corp.username, from_status, to_status)
		self.__save()

		fill_options = {
			'with_products': True
		}
		Order.__fill_delivery_items([self], fill_options)

		delivery_item_products = self.get_all_products()
		update_product_service = UpdateProductService.get(corp)

		for product in delivery_item_products:
			update_product_service.update_product_sale(product.id, product.count)

		for delivery_item in self.delivery_items:
			delivery_item.pay(payment_time, corp)

		self.__send_msg_to_topic('order_paid', from_status, to_status)

		return True, ''
Beispiel #9
0
	def verify_modifications(self):
		"""
		审核通过商品的编辑内容
		"""
		product_id = self.id
		product_data = json.loads(mall_models.ProductUnverified.select().dj_where(product_id=product_id).get().product_data)
		mall_models.Product.update(is_updated=False, status=mall_models.PRODUCT_STATUS['NOT_YET']).dj_where(id=self.id).execute()
		from business.product.update_product_service import UpdateProductService
		corp = self.get_owner_corp()
		update_product_service = UpdateProductService.get(corp)
		update_product_service.update_product(self.id, {
			'corp': corp,
			'base_info': product_data['base_info'],
			'models_info': product_data['models_info'],
			'logistics_info': product_data['logistics_info'],
			'image_info': product_data['image_info']
		})

		send_product_message.send_product_update_cache(product_id)
Beispiel #10
0
    def release(self, order_id, from_status, to_status):
        """
		当处理的是出货单时,需要决策是否处理以及如何处理订单
		对于db层面有没有出货单的订单,db操作已经在出货单完成,只用发送消息通知
		@param order_id:
		@param from_status:
		@param to_status:
		@return:
		"""

        fill_options = {
            'with_member': True,
            'with_weizoom_card': True,
            'with_member_card': True,
            'with_delivery_items': {
                'with_products': True,
            }
        }
        corp = self.corp
        order = corp.order_repository.get_order(order_id, fill_options)
        print('-----from_status', from_status)
        is_paid = (from_status != mall_models.ORDER_STATUS_NOT
                   )  # 已经支付过的订单,已增加过销量

        delivery_item_products = order.get_all_products()
        # product_ids = [p.id for p in delivery_item_products]
        # product_id2delivery_item_product = {p.id: p for p in delivery_item_products}
        #
        # products = corp.product_pool.get_products_by_ids(product_ids)
        #
        # for delivery_item_product in delivery_item_products:
        # 	product = corp.product_pool.get_products_by_ids([delivery_item_product.id])[0]
        #
        # 	product.update_sales(delivery_item_product.count)

        for delivery_item_product in delivery_item_products:
            # delivery_item_product = product_id2delivery_item_product[product.id]

            # 更新销量库存
            # product.update_stock(delivery_item_product.product_model_name, delivery_item_product.count)
            update_product_service = UpdateProductService.get(corp)
            stock_infos = [{
                'model_id': delivery_item_product.model_id,
                'changed_count': delivery_item_product.count
            }]
            update_product_service.add_product_stock(delivery_item_product.id,
                                                     stock_infos)

            # 更新销量,赠品不算销量
            if is_paid and delivery_item_product.promotion_info[
                    'type'] != "premium_sale:premium_product":
                update_product_service.update_product_sale(
                    delivery_item_product.id, 0 - delivery_item_product.count)
            # product.update_sales(0 - delivery_item_product.count)

        if to_status == mall_models.ORDER_STATUS_REFUNDED and order.is_weizoom_order > 0:
            # 微众订单退款成功时不自动返还资源
            pass
        else:
            # 退款微众卡
            if order.weizoom_card_money:
                trade_id = order.weizoom_card_info['trade_id']
                data = {
                    'trade_id': trade_id,
                    'trade_type': 1  # 普通退款
                }
                resp = Resource.use('card_apiserver').delete({
                    'resource': 'card.trade',
                    'data': data
                })

            # 退还会员卡
            if order.member_card_money:
                trade_id = order.member_card_info['trade_id']
                data = {
                    'trade_id': trade_id,
                    'trade_type': 1  # 普通退款
                }
                resp = Resource.use('card_apiserver').delete({
                    'resource': 'card.trade',
                    'data': data
                })

                if resp and resp['code'] == 200:
                    log = member_models.MemberCardLog.select().dj_where(
                        order_id=order.bid, reason=u'下单').first()
                    if log:
                        member_models.MemberCardLog.create(
                            member_card=log.member_card_id,
                            trade_id=trade_id,
                            order_id=order.bid,
                            reason=u"取消下单或下单失败",
                            price=log.price)

            # 退还优惠券
            if order.coupon_id:
                coupon = corp.coupon_repository.get_coupon_by_id(
                    order.coupon_id)
                if coupon:
                    coupon.refund(order)

            # 退还积分
            if order.integral:
                Integral.increase_member_integral({
                    'integral_increase_count':
                    order.integral,
                    'webapp_user_id':
                    order.webapp_user_id,
                    'member_id':
                    order.member_info['id'],
                    'event_type':
                    member_models.RETURN_BY_CANCEl_ORDER,
                    'corp':
                    corp,
                })