예제 #1
0
    def put(args):
        """
		openapi 取消订单操作(退款)

		@param id 商品ID

		更改订单状态
		"""
        order_id = args['order_id']

        msg = ''
        try:
            order = Order.from_id({
                'webapp_user': args['webapp_user'],
                'webapp_owner': args['webapp_owner'],
                'order_id': order_id
            })
            msg, success = order.refund()

            info = u"openapi apiserver中修改订单状态失败, order_id:{}, cause:\n{}".format(
                args['order_id'], msg)
            watchdog.info(info)

            if msg:
                return 500, {'msg': msg, 'success': False}
            else:
                return 200, {'msg': msg, 'success': True}
        except:
            notify_message = u"openapi apiserver中修改订单状态失败, order_id:{}, cause:\n{}".format(
                args['order_id'], unicode_full_stack())
            watchdog.alert(notify_message)
            return 500, {'msg': msg, 'success': False}
예제 #2
0
    def put(args):
        """
		@warning: 对外网开放的支付接口,只接受从h5支付方式列表发起的货到付款,高风险,改动需慎重
		"""

        webapp_user = args['webapp_user']
        webapp_owner = args['webapp_owner']

        order_id = args['order_id'].split('-')[0]
        pay_interface_type = int(args['pay_interface_type'])

        # 此接口只可使用货到付款

        if pay_interface_type != mall_models.PAY_INTERFACE_COD:
            watchdog.alert('货到付款接口被异常调用,woid:%s,webapp_user_id:%s',
                           (webapp_owner.id, webapp_user.id))
            return 500, {}
        order = Order.from_id({
            'webapp_owner': webapp_owner,
            'webapp_user': webapp_user,
            'order_id': order_id
        })
        try:
            is_success, msg = order.pay(
                pay_interface_type=mall_models.PAY_INTERFACE_COD)
        except:
            is_success = False
            msg = unicode_full_stack()
            watchdog.alert(msg)
        return {
            'order_id': args['order_id'],
            'is_success': is_success,
        }
예제 #3
0
    def get(args):
        """
		获取订单微信支付的package参数信息

		@param order_id
		"""

        order = None
        order_id = args['order_id']
        config = int(args['config'])

        if order_id.startswith('vip_'):  #如果是会员卡的订单,则特殊处理
            order = MemberCardPayOrder.from_order_id({
                'webapp_owner':
                args['webapp_owner'],
                'webapp_user':
                args['webapp_user'],
                'order_id':
                order_id
            })
        else:  #普通商城订单
            order = Order.from_id({
                'webapp_owner': args['webapp_owner'],
                'webapp_user': args['webapp_user'],
                'order_id': args['order_id'].split('-')[0]
            })

        package_info = order.wx_package_for_pay_module(config=config)
        return package_info
예제 #4
0
    def get(args):
        """
		获取订单微信支付的参数信息

		@param order_id
		"""

        order = None
        order_id = args['order_id']

        if order_id.startswith('vip_'):  #如果是会员卡的订单,则特殊处理
            order = MemberCardPayOrder.from_order_id({
                'webapp_owner':
                args['webapp_owner'],
                'webapp_user':
                args['webapp_user'],
                'order_id':
                order_id
            })
        else:  #普通商城订单
            order = Order.from_id({
                'webapp_owner': args['webapp_owner'],
                'webapp_user': args['webapp_user'],
                'order_id': order_id
            })

        pay_info = order.pay_info_for_pay_module(
            pay_interface_type=mall_models.PAY_INTERFACE_WEIXIN_PAY)
        return pay_info
예제 #5
0
	def get(args):
		"""
		获取物流详情
		@param order_id
		@return
		结果示例:
		```
		{
		  "code": 200,
		  "data": {
		    "express_details": [
		      {
		        "status": "2",
		        "express_id": 13241234,
		        "created_at": "2015-12-22 17:04:54",
		        "display_index": 2,
		        "ftime": "2015-12-22",
		        "context": "哈哈1",
		        "time": "2015-12-22 17:04:39",
		        "id": 2
		      },
		      {
		        "status": "1",
		        "express_id": 147258368,
		        "created_at": "2015-12-22 16:22:39",
		        "display_index": 1,
		        "ftime": "2015-12-22",
		        "context": "嘻嘻2",
		        "time": "2015-12-22 16:22:15",
		        "id": 1
		      }
		    ]
		  },
		  "errMsg": "",
		  "innerErrMsg": ""
		}
		```
		"""
		webapp_owner = args['webapp_owner']
		webapp_user = args['webapp_user']

		order = Order.from_id({
			'webapp_owner': webapp_owner,
			'webapp_user': webapp_user,
			'order_id': args['order_id']
			})
		express_details = order.express_details
		for detail in express_details:
			print(detail.id, detail.content, detail.status)

		data = [AExpressDetails.to_dict(detail) for detail in express_details]
		
		return {
			"order_id": args['order_id'],
			"status": order.status_text, 
			"express_company_name": order.readable_express_company_name,
			"express_number": order.express_number,
			"express_details": data
		}
예제 #6
0
    def get(args):
        """
		获取购物车项目

		@param id 商品ID
		"""
        webapp_user = args['webapp_user']
        webapp_owner = args['webapp_owner']
        order_id = args['order_id']
        interface_id = args['pay_id']
        is_oauthed = ('code' in args)

        pay_interface = PayInterface.from_id({
            'webapp_owner': webapp_owner,
            'interface_id': interface_id
        })
        weixin_pay_config = pay_interface.pay_config

        order = Order.from_id({
            'webapp_owner': webapp_owner,
            'webapp_user': webapp_user,
            'order_id': order_id
        })

        data = {}
        data['app_id'] = weixin_pay_config['app_id']
        data['partner_id'] = weixin_pay_config['partner_id']
        data['partner_key'] = weixin_pay_config['partner_key']
        data['paysign_key'] = weixin_pay_config['paysign_key']
        data['app_secret'] = weixin_pay_config['app_secret']
        data['pay_version'] = weixin_pay_config['pay_version']
        data['total_fee_display'] = order.final_price
        data['total_fee'] = int(order.final_price * 100)

        if data['pay_version'] == 0 or (bool(is_oauthed)
                                        and data['pay_version'] != 0):
            product_outlines = order.product_outlines

            product_names = ','.join(
                [product_outline.name for product_outline in product_outlines])
            if len(product_names) > 127:
                product_names = product_names[:127]

            if order.edit_money:
                data['order_id'] = '{}-{}'.format(
                    order_id,
                    str(order.edit_money).replace('.', '').replace('-', ''))
            else:
                data['order_id'] = order_id
            data['domain'] = settings.PAY_HOST
            data['webapp_owner_id'] = webapp_owner.id
            data['pay_interface_type'] = pay_interface.type
            data[
                'pay_interface_related_config_id'] = pay_interface.related_config_id
            data['product_names'] = product_names
            data['user_ip'] = '181.181.181.181'

        return data
예제 #7
0
    def get(args):
        """
		获取支付结果页面

		@param id 订单order_id
		"""
        webapp_user = args['webapp_user']
        webapp_owner = args['webapp_owner']

        order_id = args['order_id'].split('-')[0]

        order = Order.from_id({
            'webapp_owner': webapp_owner,
            'webapp_user': webapp_user,
            'order_id': order_id
        })

        if not order.is_valid():
            msg = u'订单({})不存在'.format(order_id)
            error_msg = u'weixin pay, stage:[get_pay_result], result:{}, exception:\n{}'.format(
                msg, msg)
            watchdog.alert(error_msg)
            return 500, {'msg': error_msg}

        is_show_red_envelope = False
        red_envelope_rule_id = 0
        red_envelope = webapp_owner.red_envelope
        if RedEnvelope.can_show_red_envelope(order, red_envelope):
            # 是可以显示分享红包按钮
            is_show_red_envelope = True
            red_envelope_rule_id = red_envelope['id']

        order_config = OrderConfig.get_order_config(
            {'webapp_owner': webapp_owner})

        qrcode_img = webapp_owner.qrcode_img
        activity_url = ''
        if order.is_group_buy:
            activity_url = order.order_group_info[
                'activity_url'] + '&from=pay_result'

        return {
            'is_trade_success': True,
            'order': order.to_dict('is_group_buy'),
            'is_show_red_envelope': is_show_red_envelope,
            'red_envelope_rule_id': red_envelope_rule_id,
            'qrcode_img': qrcode_img,
            'activity_url': activity_url,
            'order_config': order_config
        }
예제 #8
0
	def get(args):

		# 兼容修改价格后订单从支付模块返回的跳转(支付模块会添加edit_money)
		order_id = args['order_id'].split('-')[0].split('^')[0]

		order = Order.from_id({
			'webapp_owner': args['webapp_owner'],
			'webapp_user': args['webapp_user'],
			'order_id': order_id
		})
		order_data = AOrder.to_dict(order)
		if order_data['order'].has_key('sub_orders'):
			order_data['order']['sub_orders'] = sorted(order_data['order']['sub_orders'], key=lambda order:"%d-%d" % (order['supplier'], order['supplier_user_id']))
		order_data.update({'mall_type': args['webapp_owner'].user_profile.webapp_type})
		return order_data
예제 #9
0
    def get(args):
        """
		获取订单微信支付的参数信息

		@param order_id
		"""

        order = Order.from_id({
            'webapp_owner': args['webapp_owner'],
            'webapp_user': args['webapp_user'],
            'order_id': args['order_id']
        })

        pay_info = order.pay_info_for_pay_module(
            pay_interface_type=mall_models.PAY_INTERFACE_ALIPAY)
        return pay_info
예제 #10
0
    def put(args):
        """
		微信支付、支付宝回调接口
		@return:
		"""

        webapp_user = args['webapp_user']
        webapp_owner = args['webapp_owner']

        order_id = args['order_id'].split('-')[0]
        if order_id.startswith('vip_'):  #如果是会员卡的订单,则特殊处理
            order = MemberCardPayOrder.from_order_id({
                'webapp_owner':
                args['webapp_owner'],
                'webapp_user':
                args['webapp_user'],
                'order_id':
                order_id
            })
            order.pay()
            is_success = True
            msg = ''
        else:  #普通商城订单
            pay_interface_type = int(args['pay_interface_type'])
            order = Order.from_id({
                'webapp_owner': webapp_owner,
                'webapp_user': webapp_user,
                'order_id': order_id
            })

            try:
                is_success, msg = order.pay(
                    pay_interface_type=pay_interface_type)
            except:
                is_success = False
                msg = unicode_full_stack()
                watchdog.alert(msg)

        return {
            'order_id': args['order_id'],
            'is_success': is_success,
            'msg': msg
        }
예제 #11
0
	def post(args):
		"""
		更改订单状态
		@todo 目前取消订单和确认收货都是通过此接口,需要分离
		"""
		# if not get_wapi_lock(lockname='order_post_' + str(args['webapp_user'].id), lock_timeout=2):
		# 	watchdog.alert('wapi接口被刷,wapi:%s,webapp_user_id:%s' % ('mall.order_post', str(args['webapp_user'].id)))
		# 	reason_dict = {
		# 		"is_success": False,
		# 		"msg":  u'请勿短时间连续下单',
		# 		"type": "coupon"    # 兼容性type
		# 	}
		# 	return 500, {'detail': [reason_dict]}

		# 兼容修改价格后订单从支付模块返回的跳转(支付模块会添加edit_money)
		order_id = args['order_id'].split('-')[0]

		try:
			order = Order.from_id({
				'webapp_user': args['webapp_user'],
				'webapp_owner': args['webapp_owner'],
				'order_id': order_id
			})

			action = args['action']

			validate_result, reason = order.validate_order_action(action, args['webapp_user'].id)

			msg = u"apiserver中修改订单状态失败, order_id:{}, action:{}, cause:\n{}".format(args['order_id'], args['action'], reason)
			watchdog.info(msg)

			if not validate_result:
				return 500, {'msg': reason}

			if action == 'cancel':
				order.cancel()
			elif action == 'finish':
				order.finish()
		except:
			notify_message = u"apiserver中修改订单状态失败, order_id:{}, action:{}, cause:\n{}".format(args['order_id'], args['action'], unicode_full_stack())
			watchdog.alert(notify_message)
			return 500, ''