Esempio n. 1
0
    def post(self, request):
        try:
            # 参数校验
            user = request.user
            order_no = request.POST.get('order_no')
            if not user:
                return response_utils.wrapper_400('获取用户对象失败')
            if not order_no:
                return response_utils.wrapper_400('缺少参数order_no')

            order = Order().order.get(order_no=order_no,
                                      user=user,
                                      trade_status=0)  # trade_status交易状态为等待支付
            if not order:
                return response_utils.wrapper_400('订单无效')

            url = self._ali_pay(order_no, order.total_price)
            if not url:
                return response_utils.wrapper_400('获取支付订单失败')

            data = {}
            data['url'] = url

            return response_utils.wrapper_200(data=data)
        except Exception as e:
            logger.error(traceback.format_exc())
            return response_utils.wrapper_500('获取支付订单失败,系统内部错误')
Esempio n. 2
0
    def post(self, request):
        '''处理notify_url接收到的请求'''
        try:
            processed_dict = {}  # 定义一个字典,用来存放支付宝发来的信息,后面用起来方便
            for key, value in request.POST.items():
                processed_dict[key] = value

            # 取出签名进行验证
            sign = processed_dict.pop('sign', None)

            verify_result = self.alipay.verify(
                processed_dict,
                sign)  # verify方法会解析所接收的数据,得到是否支付成功的结果,True or False
            if not verify_result:
                return response_utils.wrapper_400('验签失败')

            order_no = processed_dict.get('out_trade_no', None)  # 订单号
            trade_no = processed_dict.get('trade_no', None)  # 支付宝交易号
            trade_status = processed_dict.get('trade_status', None)  # 交易状态
            tran_id = transaction.savepoint()
            try:
                order_res = self.modify_order_handler(order_no, trade_status,
                                                      trade_no)
                account_res = self.modify_account_status(order_no)
                if order_res and account_res:
                    pass
                else:
                    transaction.savepoint_rollback(tran_id)
            except Exception:
                transaction.savepoint_rollback(tran_id)
            return response_utils.wrapper_200()  # 最后记着给支付宝返回一个信息
        except Exception as e:
            logger.error(traceback.format_exc())
            return response_utils.wrapper_500()
Esempio n. 3
0
    def post(self, request):
        # 用户及参数校验
        order_no = request.POST.get('order_no')
        if not order_no:
            return response_utils.wrapper_400('缺少参数order_no')

        res = self._ali_pay(order_no)
        if not res:
            return response_utils.wrapper_400('查询失败')

        return response_utils.wrapper_200()
Esempio n. 4
0
    def get(self, request):
        try:
            user = request.user
            page_id = request.GET.get('page', 1)
            limit = request.GET.get('limit', 10)
            if not user:
                return response_utils.wrapper_400('获取用户对象失败')

            orders = Order().order.gets(user=user)  # 条件:用户
            if not orders:
                return response_utils.wrapper_400('无订单信息')

            orders_list = []
            for index, order in enumerate(orders):
                order_dic = {}
                order_dic.setdefault('id', index + 1)
                order_dic.setdefault('order_no', order.order_no)
                order_dic.setdefault('price', str(order.price))
                order_dic.setdefault('total_price', order.total_price)
                order_dic.setdefault('count', order.count)
                order_dic.setdefault(
                    'add_time', order.add_time.strftime('%Y-%m-%d %H:%M:%S'))
                order_dic.setdefault('trade_status',
                                     order.get_trade_status_display())
                order_dic.setdefault('trade_no', order.trade_no)
                order_dic.setdefault('trade_type',
                                     order.get_pay_mode_display())
                orders_list.append(order_dic)

            try:
                paginator = Paginator(orders_list, limit)  # 分页,每页显示limit个
                order_list = paginator.page(int(page_id))
                order_list = [i for i in order_list]  # 将数据从Page对象中遍历出来
                page_count = paginator.count
            except:
                logger.error(traceback.format_exc())
                return response_utils.wrapper_400('分页失败')

            return response_utils.wrapper_200(data=order_list,
                                              args=('count', page_count))
        except Exception as e:
            logger.error(traceback.format_exc())
            return response_utils.wrapper_500('获取订单记录失败,系统内部错误')
Esempio n. 5
0
    def get(self, request):
        try:
            # 获取参数
            page_id = request.GET.get('page', 1)
            order_no = request.GET.get('order_no', None)
            limit = request.GET.get('limit', 5)

            # 条件:用户、订单、交易状态
            accounts = Goods().account.gets(Q(order__trade_status=2)
                                            | Q(order__trade_status=3),
                                            order__order_no=order_no)
            if not accounts:
                return response_utils.wrapper_400('无商品信息')

            goods_list = []
            for index, account in enumerate(accounts):
                account_dic = {}
                info = str(account.price).split(':')
                account_dic.setdefault('id', index + 1)
                account_dic.setdefault('order_no', order_no)
                account_dic.setdefault('type', info[0])
                account_dic.setdefault('account_str', account.account_str)
                account_dic.setdefault('price', info[1])
                account_dic.setdefault(
                    'sale_time',
                    account.sale_time.strftime('%Y-%m-%d %H:%M:%S'))
                goods_list.append(account_dic)

            try:
                paginator = Paginator(goods_list, limit)  # 分页,每页显示limit个
                good_list = paginator.page(int(page_id))
                good_list = [i for i in good_list]  # 将数据从Page对象中遍历出来
                page_count = paginator.count  # 页码总数
            except Exception as e:
                logger.error(traceback.format_exc())
                return response_utils.wrapper_400('分页失败')

            return response_utils.wrapper_200(data=good_list,
                                              args=('count', page_count))
        except Exception as e:
            logger.error(traceback.format_exc())
            return response_utils.wrapper_500('获取订单详情信息失败,系统内部错误')