示例#1
0
def check_pay_password(self, user, pwd):
    pay_pwd = pwd
    print("pay_pwd", pay_pwd)
    pay_pwd_ = encryptions.get_sha_encryptions(pay_pwd)
    if user.pay_password != pay_pwd_:
        logger.info(
            '%s url:%s method:%s' %
            (traceback.format_exc(), self.request.path, self.request.method))
        return False
    return True
示例#2
0
 def validate_pay_password(self, pay_password):
     if len(pay_password) > 16:
         raise serializers.ValidationError("密码过长")
     pay_password = encryptions.get_sha_encryptions(pay_password)
     return pay_password
示例#3
0
    def post(self, request, *args, **kwargs):
        print("order_list--------------")
        print(request.data.get("order_list"))
        order_list = request.data.get("order_list")
        ret = {'code': "1000", 'message': ""}
        try:
            pay_pwd = request.data.get("pay_pwd")
            print("pay_pwd", pay_pwd)
            pay_pwd_ = encryptions.get_sha_encryptions(pay_pwd)
            if request.user.pay_password != pay_pwd_:
                ret['code'] = "1001"
                ret['message'] = "密码错误"
                logger.info(
                    '%s url:%s method:%s' %
                    (traceback.format_exc(), request.path, request.method))
                return JsonResponse(ret)
            query_set = trade_models.Order.objects.filter(
                order_number__in=order_list)
            pay_money = 0.0
            for order in query_set:
                if order.order_owner != request.user:
                    # 订单不是该请求用户的跳过
                    continue
                print(order.total_price)
                pay_cur_order_continue = True
                trade_item = trade_models.TradeInfo.objects.filter(
                    order_number=order.order_number).first()
                if trade_item is not None:
                    #  该订单已经有支付记录
                    pay_cur_order_continue = False
                order_goods_query = trade_models.OrderGoods.objects.filter(
                    order=order)
                for order_gooods in order_goods_query:
                    if order_gooods.status != mcommon.status_choices2.get(
                            "待付款"):
                        # 订单有非 待付款的订单 该订单不进行支付
                        pay_cur_order_continue = False
                        break

                if pay_cur_order_continue is False:
                    continue
                data = {
                    "trade_money": order.total_price,
                    "order_number": order.order_number,
                }
                ser = m_serializers.OrderPayBalanceSerializer(
                    data=data, context={'request': request})
                ser.is_valid(raise_exception=True)
                ser.validated_data['trade_number'] = BaseTrade(
                    request.user).get_trade_number()
                ser.validated_data[
                    'trade_source'] = mcommon.trade_source_choices2.get("订单")
                ser.validated_data[
                    'cash_in_out_type'] = mcommon.cash_in_out_type_choices2.get(
                        "支出")
                ser.validated_data['user_balance'] = request.user.balance
                ser.validated_data['add_time'] = time.time() * 1000
                ser.validated_data['message'] = "订单:" + order.order_number

                if request.user.balance >= order.total_price:
                    request.user.balance = Decimal(
                        str(request.user.balance)) - Decimal(
                            str(order.total_price))
                    ser.validated_data['user_balance'] = Decimal(
                        str(request.user.balance))
                    ser.validated_data['is_pass'] = True
                    with transaction.atomic():
                        for order_gooods in order_goods_query:
                            order_gooods.status = mcommon.status_choices2.get(
                                "已付款")
                            order_gooods.save()

                        ser.save()
                        request.user.save()
                else:
                    ret['code'] = "1001"
                    ret['message'] = "余额不足"

        except:
            traceback.print_exc()
            ret['code'] = "1001"
            ret['message'] = "支付失败"
            logger.info('%s url:%s method:%s' %
                        (traceback.format_exc(), request.path, request.method))
        return JsonResponse(ret)