Beispiel #1
0
    def to_rescind(cls, request, user, bank):
        # user = request.user
        data = {}
        data['frame_id'] = cls.__frame_id
        data['user_name'] = user.username
        sign_in_data = {}
        sign_in_data['inst_fund_acc'] = AbSignInOutContractHomeView.get_inst_fund_acc_id(user)

        sign_in_data['client_no'] = bank.client_no
        sign_in_data['bank_account'] = bank.bank_account

        r = AbSignInContractLog.objects.filter(user=user, status=1).order_by('modified_time').last()
        if r:
            sign_in_data['client_name'] = r.client_name
            sign_in_data['cert_id'] = r.cert_id
            sign_in_data['cert_type'] = r.cert_type
        else:
            sign_in_data['client_name'] = user.userprofile.real_name
            sign_in_data['cert_id'] = user.userprofile.identification_card_number
            sign_in_data['cert_type'] = '110001' if r.cert_type!=1 else '610001'

        sign_in_data['inst_serial'] = MarketSignContractService.create_ab_inst_serial()
        d = cls.log_to_db(user, sign_in_data)

        ret = {'code': 0, 'msg': '', 'data': data, }

        try:
            r = RescindContractService().do_event(data=sign_in_data)
            resp = r['data']
            d.code = resp['code']
            d.info = resp['info']
            if r['status']['code'] == 0:  # 成功
                d.client_no = resp['client_no']
                d.serial_no = resp['serial_no']
                d.summary = resp['summary']
                d.status = 1
                bank.is_rescinded = True
                bank.save()
                tpl = 'customer/finance/ab/rescind/suc.html'
            else:
                d.status = 2
                d.sys_comment = r['data']
                data['msgs'] = [r['status']['msg']]
                # tpl = 'customer/finance/ab/rescind/failed.html'

                ret['code'] = ResultCode.FIN_RETURN_ERROR
                ret['msg'] = resp.get('info', '')
            # return HttpResponseRedirect('')
            d.save()
            # return render(request, tpl, data)
            return ret

        except Exception as e:
            logging.exception(e)
            d.status = 2
            d.sys_comment = e
            d.save()
            data = {'msgs': [u'网络异常']}
            # tpl = 'customer/finance/ab/rescind/failed.html'
            # return render(request, tpl, data)
            ret['code'] = ResultCode.NET_ERROR
            return ret
Beispiel #2
0
    def to_sign_in(cls, request, is_json_format=False):
        user = request.user
        post_data = request.data

        data = {e[0]: e[1] for e in post_data.items()}
        data['frame_id'] = cls.__class__.__frame_id
        data['user_name'] = user.username
        data['inst_fund_acc'] = cls.get_inst_fund_acc_id(user)

        sign_in_data = {}
        ret = {'code': 0, 'msg': '', 'data': data, }
        try:
            sign_in_data['bank_account'] = data['bank_account_no']
            if data['account_type'] == '0' or not data['account_type'] or data['account_type'].startswith('0'):  # 个人
                is_business_account = False
                sign_in_data['bank_password'] = data['bank_account_pwd'].encode('utf8')
                sign_in_data['cert_type'] = '110001'
                check_flag = 1
            else:   # 公司
                is_business_account = True
                sign_in_data['trade_password'] = data['bank_account_pwd'].encode('utf8')
                sign_in_data['have_pwd'] = '1'
                sign_in_data['cert_type'] = '610001'
                check_flag = 2

            if user.userprofile.audit_status == 2:
                data['bank_account_name'] = user.userprofile.real_name
                data['cert_id'] = user.userprofile.identification_card_number
                data['cert_type'] = user.userprofile.cert_type
                check_flag = 0
        except (KeyError, ValueError):
            flag = 1
        else:
            flag = cls.check_input_data(data, check_flag)

        if flag != 0:  # error
            ret['code'] = ResultCode.ERROR_PARAM

            data['bank_account_pwd'] = ''
            if user.userprofile.audit_status == 2:
                data['cert_id'] = mask_id_card_no(user.userprofile.identification_card_number)

            return ret

        sign_in_data['inst_fund_acc'] = data['inst_fund_acc']
        sign_in_data['inst_branch'] = AgriculturalBankTradeConstData.DEFAULT_INST_BRANCH
        sign_in_data['transfer_limit'] = '0'
        sign_in_data['client_name'] = data['bank_account_name']
        sign_in_data['cert_id'] = data['cert_id']
        sign_in_data['inst_serial'] = MarketSignContractService.create_ab_inst_serial()
        # sign_in_data['client_kind'] = 0  # 0,个人;1:机构
        for item in cls.__class__.__optional_items:
            sign_in_data[item] = data.get(item, '')
        d = cls.log_to_db(user, sign_in_data)
        try:
            r = MarketSignContractService().do_event(data=sign_in_data)

            resp = r['data']
            d.code = resp['code']
            d.info = resp['info']
            d.client_no = resp['client_no']
            d.serial_no = resp['serial_no']
            d.summary = resp['summary']

            if r['status']['code'] == 0:  # 成功

                d.status = 1
                UserBank(user=user, bank_name=u'中国农业银行',
                         bank_account=d.bank_account, tel=d.tel_no,
                         client_no=d.client_no, client_name=d.client_name,
                         is_enable=True, is_business_account=is_business_account).save()
                user_profile = UserProfile.objects.get(user=user)
                if not user_profile.identification_card_number:
                    user_profile.identification_card_number = sign_in_data['cert_id']
                if not user_profile.real_name:
                    user_profile.real_name = sign_in_data['client_name']
                user_profile.cert_type = 0 if sign_in_data['cert_type'] == '110001' else 1
                user_profile.audit_status = 2
                user_profile.save()

                request._request.method = "GET"
                ret['code'] = ResultCode.SUCCESS
                # tpl = 'customer/finance/ab/sign_in/ab_sign_in_contract_suc.html'

            else:
                ret['code'] = ResultCode.FIN_RETURN_ERROR
                ret['msg'] = resp.get('info', '')
                # tpl = 'customer/finance/ab/sign_in/ab_sign_in_contract_failed.html'
                #5010 出入金关系已经存在
                if r['status']['code'] == '5010':
                    if resp['inst_fund_acc'] != sign_in_data['inst_fund_acc'] or UserBank.objects.filter(bank_account=sign_in_data['bank_account'], is_rescinded=False, bank_name=u'中国农业银行').exists():
                        data['msgs'] = [u'该银行账户已经被其他用户签约']
                        ret['code'] = data['msgs']
                    else:
                        bank_pwd = sign_in_data['bank_password'] if sign_in_data['bank_password'] else sign_in_data['trade_password']
                        query_data = {'client_no': d.client_no, 'bank_account': sign_in_data['bank_account'],
                                      'inst_fund_acc': sign_in_data['inst_fund_acc'],
                                      'bank_password': bank_pwd}
                        r2 = AccountBalanceQueryService().do_event(data=query_data)
                        if r['status']['code'] == 0 and not UserBank.objects.filter(user=user, is_rescinded=False, bank_name=u'中国农业银行').exists():

                            UserBank(user=user, bank_name=u'中国农业银行',
                                     bank_account=d.bank_account, tel=d.tel_no,
                                     client_no=d.client_no, client_name=d.client_name,
                                     is_enable=True, is_business_account=is_business_account).save()
                            ret['code'] = ResultCode.SUCCESS
                            # tpl = 'customer/finance/ab/sign_in/ab_sign_in_contract_suc.html'

                d.status = 2
                d.sys_comment = r['data']
                data['msgs'] = [r['status']['msg']]

            d.save()

            return ret
        except Exception as e:
            logging.exception(e)
            d.status = 2
            d.sys_comment = e
            d.save()

            ret['code'] = ResultCode.NET_ERROR

            data = {'msgs': [u'网络异常']}
            # tpl = 'customer/finance/ab/sign_in/ab_sign_in_contract_failed.html'
            # return render(request, tpl, data)
            return ret