Пример #1
0
class BaseAudit(models.Model):

    CURRENT_STATE_CHOICE = (
        (BitStatesUtils.STATE_NORMAL(), '未审核'),
        (BitStatesUtils.STATE_AUDIT(), '审核通过'),
        (BitStatesUtils.STATE_REJECT(), '审核拒绝'),
    )
    remark = models.TextField(max_length=40,
                              null=True,
                              blank=True,
                              verbose_name='审核备注')
    state = models.IntegerField(choices=CURRENT_STATE_CHOICE,
                                default=0,
                                blank=True,
                                verbose_name='审核状态',
                                null=True)
    applier = models.ForeignKey(UserProfile,
                                null=True,
                                blank=True,
                                verbose_name=u"申请人",
                                on_delete=models.CASCADE)
    auditor = models.CharField(max_length=10,
                               null=True,
                               blank=True,
                               verbose_name='审核人')
    applyTime = models.DateTimeField(auto_now_add=True, verbose_name=u"申请时间")
    audiTime = models.DateTimeField(blank=True,
                                    null=True,
                                    verbose_name=u"审核时间")

    class Meta:
        abstract = True
Пример #2
0
    def save_models(self):
        #获取保持对象
        obj = self.new_obj
        obj.save()
        if obj is not None:
            bid_audit = obj
            bid_audit.auditor = self.user.username
            bid_audit.audiTime = timezone.now()
            bid_request = bid_audit.bidRequestId
            #如果审核成功
            if bid_audit.state == BitStatesUtils.STATE_AUDIT():
                #给标添加状态信息
                bid_request.bidRequestState = BidConst.GET_BIDREQUEST_STATE_APPROVE_PENDING_2() #满标二审状态
                bid_request.note = bid_audit.remark
                #添加满标二审历史
                self.createBrAuditHistory(bid_request)
            elif bid_audit.state == BitStatesUtils.STATE_REJECT():
                #审核失败,修改借款状态
                bid_request.bidRequestState = BidConst.GET_BIDREQUEST_STATE_REJECTED() #满标审核拒绝
                #进行退款
                self.retureMoney(bid_request)
                #移出借款人借款状态码
                bid_request.createUser.userProfile.removeState(BitStatesUtils.GET_OP_HAS_BIDREQUEST_PROCESS())
                bid_request.createUser.userProfile.save()

            #保存模型
            bid_request.save()
            bid_audit.save()
Пример #3
0
    def save_models(self):
        #获取保持对象
        obj = self.new_obj
        obj.save()
        if obj is not None:
            bid_audit = obj
            bid_audit.auditor = self.user.username
            bid_audit.audiTime = timezone.now()
            user_profile_obj = bid_audit.applier
            #如果审核成功
            if bid_audit.state == BitStatesUtils.STATE_AUDIT():
                #给标添加状态信息
                bid_request = bid_audit.bidRequestId
                bid_request.bidRequestState = BidConst.GET_BIDREQUEST_STATE_BIDDING()
                bid_request.note = bid_audit.remark
                #保存模型
                bid_request.save()

                #给申请用户添加借款标状态
                user_profile_obj.addState(BitStatesUtils.GET_OP_HAS_BIDREQUEST_PROCESS())
            else:
                #审核失败,移出用户招标状态
                user_profile_obj.removeState(BitStatesUtils.GET_OP_HAS_BIDREQUEST_PROCESS())

            user_profile_obj.save()
            bid_audit.save()
Пример #4
0
 def save_models(self):
     #获取保持对象
     obj = self.new_obj
     obj.save()
     if obj is not None:
         vedio_auth = obj
         vedio_auth.auditor = self.user.username
         vedio_auth.audiTime = timezone.now()
         #添加视频认证状态位
         user_profile = UserProfile.objects.filter(
             username=vedio_auth.applier).first()
         user_profile.bitState = BitStatesUtils.addState(
             user_profile.bitState, BitStatesUtils.GET_OP_VEDIO_AUTH())
         user_profile.save()
Пример #5
0
 def save_models(self):
     #获取保持对象
     obj = self.new_obj
     obj.save()
     if obj is not None:
         charge_obj = obj
         charge_obj.auditor = self.user.username
         charge_obj.audiTime = timezone.now()
         #如果审核成功
         if charge_obj.state == BitStatesUtils.STATE_AUDIT():
             #得到申请人的账户对象
             user_account = Account.objects.get(userProfile=charge_obj.applier)
             #增加账户可用余额
             user_account.usableAmount = user_account.usableAmount + charge_obj.amount
             user_account.save()
             #生成流水
             account_flow = AccountFlow.objects.create(accountId=user_account)#添加用户账户
             account_flow.accountType = BidConst.GET_ACCOUNT_ACTIONTYPE_RECHARGE_OFFLINE()#充值类型
             account_flow.amount = charge_obj.amount #添加变化金额
             account_flow.freezedAmount = user_account.freezedAmount #添加冻结金额
             account_flow.note = '线下充值成功,充值金额:'+str(charge_obj.amount)
             account_flow.tradeTime = timezone.now() #添加时间
             account_flow.usableAmount = user_account.usableAmount #添加可用金额
             account_flow.save()
         charge_obj.save()
Пример #6
0
    def save_models(self):
        #获取保持对象
        obj = self.new_obj
        obj.save()
        if obj is not None:
            real_auth = obj
            real_auth.auditor = self.user.username
            real_auth.audiTime = timezone.now()

            user_profile = UserProfile.objects.filter(
                username=real_auth.applier).first()
            #审核成功给用户添加审核成功状态位
            if real_auth.state == BitStatesUtils.STATE_AUDIT():
                # user_profile = UserProfile.objects.filter(username=real_auth.applier).first()
                user_profile.real_auth_id = real_auth.id
                # 添加审核通过状态位
                user_profile.bitState = BitStatesUtils.addState(
                    user_profile.bitState, BitStatesUtils.GET_OP_REAL_AUTH())
                user_profile.save()

            else:
                # user_profile = UserProfile.objects.filter(username=real_auth.applier).first()
                #用户的实名认证取消
                user_profile.real_auth_id = None
                #状态位更改
                if BitStatesUtils.hasState(user_profile.bitState,
                                           BitStatesUtils.GET_OP_REAL_AUTH()):
                    user_profile.bitState = BitStatesUtils.removeState(
                        user_profile.bitState,
                        BitStatesUtils.GET_OP_REAL_AUTH())

                user_profile.save()

            # real_auth.course_nums = Course.objects.filter(course_org=course_org).count()
            real_auth.save()
Пример #7
0
    def get(self, request):
        #页面bid, 用户详情
        bid = request.GET.get('bid')
        bid_request = BidRequest.objects.get(id=bid)
        user_profile = bid_request.createUser.userProfile
        user_files = UserFile.objects.filter(
            Q(applier=user_profile) & Q(state=BitStatesUtils.STATE_AUDIT()))
        user_real_authes = RealAuth.objects.filter(
            Q(applier=user_profile) & Q(state=BitStatesUtils.STATE_AUDIT()))

        #投标用户账户
        loan_user_account = Account.objects.get(userProfile=request.user)
        return render(
            request, "borrow_info.html", {
                'loan_user_account': loan_user_account,
                'bid_request': bid_request,
                'user_profile': user_profile,
                'user_files': user_files,
                'user_real_auths': user_real_authes
            })
Пример #8
0
    def post(self,request):
        code = request.POST.get('code')
        mobile = request.POST.get('mobile')
        message = self.validate_code(code=code,mobile=mobile)

        if message == "True":
            #给user账户添加手机号
            userProfile = request.user
            userProfile.contact_number = mobile
            #修改用户状态位
            userProfile.addState(BitStatesUtils.GET_OP_BIND_PHONE())
            userProfile.save()
            return JsonResponse({"status": "success", "message": "手机认证成功"})
        return JsonResponse({"status": "failure", "message": message})
Пример #9
0
    def save_models(self):
        #获取保持对象
        obj = self.new_obj
        obj.save()
        if obj is not None:
            withdraw_audit = obj
            withdraw_audit.auditor = self.user.username
            withdraw_audit.audiTime = timezone.now()
            account = Account.objects.get(userProfile=withdraw_audit.applier)
            #如果审核成功
            if withdraw_audit.state == BitStatesUtils.STATE_AUDIT():
                # // 1, 对借款要做什么事情?
                # // ** 1.1
                # // 3, 如果审核通过
                # // 1, 冻结金额减少(减少手续费), 增加提现支付手续费流水;
                account.freezedAmount = account.freezedAmount - withdraw_audit.charge
                self.generateWithDrawChargeFeeFlow(w=withdraw_audit, account=account)
                # // 2, 系统账户增加可用余额, 增加收取提现手续费流水;
                self.generateChargeWithdrawFeeFlow(w=withdraw_audit)

                # // 3, 冻结金额减少(减少提现金额);增加提现成功流水;
                realWithdrawFee = withdraw_audit.moneyAmount - withdraw_audit.charge
                account.freezedAmount = account.freezedAmount - realWithdrawFee
                self.generateWithDrawSuccessFlow(realWithdrawFee=realWithdrawFee,account=account)

            elif withdraw_audit.state == BitStatesUtils.STATE_REJECT():
                # // 4, 如果审核拒绝
                # // 1, 取消冻结金额, 可用余额增加, 增加去掉冻结流水
                account.freezedAmount = account.freezedAmount - withdraw_audit.moneyAmount
                account.usableAmount = account.usableAmount + withdraw_audit.moneyAmount
                self.generateWithDrawFailedFlow(w=withdraw_audit,account=account)

            account.save()
            # 去除用户的提现状态码
            withdraw_audit.applier.removeState(BitStatesUtils.GET_HAS_MONEYWITHDRAW_PROCESS())
            withdraw_audit.save()
Пример #10
0
 def save(self, user_profile, commit=False):
     user_bank_info = super(UserBanknInfoForm, self).save(commit=False)
     user_bank_info.userProfile = user_profile
     # 修改用户状态码
     user_profile.addState(BitStatesUtils.GET_OP_BIND_BANKINFO())
     user_profile.save()
     user_bank_info.save()
     #开通账户
     account = Account.objects.create(userProfile=user_profile)
     account.save()
     #添加一万元授信
     account.remainBorrowLimit = Decimal('10000.0000')
     #最大授信额度
     account.borrowLimit = Decimal('10000.0000')
     account.save()
     return user_bank_info
Пример #11
0
    def save(self, user):
        bid_request = super(BidRequestForm, self).save(commit=False)
        bid_request.bidRequestType = BidConst.GET_BIDREQUEST_TYPE_NORMAL()
        bid_request.createUser = user.get_borrower()
        bid_request.totalRewardAmount = CalculatetUtil.calTotalInterest(
            self.cleaned_data.get('returnType'),
            self.cleaned_data.get('bidRequestAmount'),
            self.cleaned_data.get('currentRate'),
            self.cleaned_data.get('monthes2Return'))
        #保存
        bid_request.save()

        #给用户 添加一个状态码
        user.addState(BitStatesUtils.GET_OP_HAS_BIDREQUEST_PROCESS())
        user.save()

        #创建标的审核对象
        bid_request_auditHistory = BidRequestAuditHistory.objects.create(
            bidRequestId=bid_request)
        bid_request_auditHistory.applier = user
        bid_request_auditHistory.save()

        return bid_request
Пример #12
0
    def save(self, user_profile, account, commit=False):
        money_with_draw = super(MoneyWithdrawViewForm, self).save(commit=False)
        user_bank_info = UserBanknInfo.objects.get(userProfile=user_profile)
        money_with_draw.charge = Decimal(BidConst.MONEY_WITHDRAW_CHARGEFEE())
        money_with_draw.bankName = user_bank_info.bankForkName
        money_with_draw.accountName = user_bank_info.accountName
        money_with_draw.accountNumber = user_bank_info.accountNumber
        money_with_draw.bankForkName = user_bank_info.bankForkName
        money_with_draw.applier = user_profile
        #用户添加状态码
        user_profile.addState(BitStatesUtils.GET_HAS_MONEYWITHDRAW_PROCESS())
        user_profile.save()

        #生成提现流水
        account.usableAmount = account.usableAmount - Decimal(
            self.cleaned_data.get('moneyAmount'))
        account.freezedAmount = account.freezedAmount + Decimal(
            self.cleaned_data.get('moneyAmount'))
        self.generateMoneyWithDrawApplyFlow(account=account,
                                            money_with_draw=money_with_draw)

        account.save()
        money_with_draw.save()
        return money_with_draw
Пример #13
0
def is_real_audit_normal(user_profile):
    if not (user_profile.bitState is None):
        if BitStatesUtils.hasState(user_profile.bitState,
                                   BitStatesUtils.GET_OP_REAL_AUTH()):
            return True
    return False
Пример #14
0
 def addState(self, value):
     self.bitState = BitStatesUtils.addState(self.bitState, value)
Пример #15
0
 def isCheckInBasicInfo(self):
     return BitStatesUtils.hasState(self.bitState,
                                    BitStatesUtils.GET_OP_BASIC_INFO())
Пример #16
0
 def isRealAuth(self):
     return BitStatesUtils.hasState(self.bitState,
                                    BitStatesUtils.GET_OP_REAL_AUTH())
Пример #17
0
 def isVedioAuth(self):
     return BitStatesUtils.hasState(self.bitState,
                                    BitStatesUtils.GET_OP_VEDIO_AUTH())
Пример #18
0
 def queryset(self):
     qs = super(FullAuditOneAdmin, self).queryset()
     qs = qs.filter(Q(auditType=BidRequestAuditHistory.FULL_AUDIT_1)&Q(state=BitStatesUtils.STATE_NORMAL()))
     return qs
Пример #19
0
 def queryset(self):
     qs = super(RechargeOfflineAdmin, self).queryset()
     qs = qs.filter(state=BitStatesUtils.STATE_NORMAL())
     return qs
Пример #20
0
 def isHasBidRequestProcess(self):
     return BitStatesUtils.hasState(
         self.bitState, BitStatesUtils.GET_OP_HAS_BIDREQUEST_PROCESS())
Пример #21
0
 def queryset(self):
     qs = super(PublishBidAauditAdmin, self).queryset()
     #未审核且标的申请存在
     qs = qs.filter(Q(auditType=BidRequestAuditHistory.PUBLISH_AUDIT)&Q(state=BitStatesUtils.STATE_NORMAL()))
     return qs
Пример #22
0
 def isBindBankInfo(self):
     return BitStatesUtils.hasState(self.bitState,
                                    BitStatesUtils.GET_OP_BIND_BANKINFO())
Пример #23
0
    def save_models(self):
        #获取保持对象
        obj = self.new_obj
        obj.save()
        if obj is not None:
            bid_audit = obj
            bid_audit.auditor = self.user.username
            bid_audit.audiTime = timezone.now()
            bid_request = bid_audit.bidRequestId
            #如果审核成功
            if bid_audit.state == BitStatesUtils.STATE_AUDIT():
                # // 1, 对借款要做什么事情?
                # // ** 1.1
                # 修改借款状态(还款中)
                bid_request.bidRequestState = BidConst.GET_BIDREQUEST_STATE_PAYING_BACK() #还款状态
                bid_request.note = bid_audit.remark
                #添加满标二审历史
                self.createBrAuditHistory(bid_request)

                # // 2, 对借款人要做什么事情?
                # // ** 2.1
                # 借款人收款操作
                borrow_account = Account.objects.get(userProfile=bid_request.createUser.userProfile)
                # // ** *2.1.1 账户余额增加,
                borrow_account.usableAmount = borrow_account.usableAmount + bid_request.bidRequestAmount
                # // ** *2.1.2生成收款流水;
                self.generateBorrowSuccessFlow(borrow_account=borrow_account,br=bid_request)
                # // ** *2.1.3修改待还本息;
                borrow_account.unReturnAmount = borrow_account.unReturnAmount + bid_request.bidRequestAmount + bid_request.totalRewardAmount
                # // ** *2.1.4修改可用信用额度;
                borrow_account.remainBorrowLimit = borrow_account.remainBorrowLimit - bid_request.bidRequestAmount
                # // ** 2.2移除借款人借款进行中状态码;
                bid_request.createUser.userProfile.removeState(BitStatesUtils.GET_OP_HAS_BIDREQUEST_PROCESS())
                bid_request.createUser.userProfile.save()
                # // ** 2.3支付借款手续费计算
                manage_charge_fee = CalculatetUtil.calAccountManagementCharge(bid_request.bidRequestAmount)
                # // ** *2.3.1可用余额减少
                borrow_account.usableAmount = borrow_account.usableAmount - manage_charge_fee
                borrow_account.save()
                # // ** *2.3.2生成支付借款手续费流水;
                self.generateBorrowChargeFeeFlow(borrow_account=borrow_account,br=bid_request,manageChargeFee=manage_charge_fee)
                # // ** *2.3.3平台收取借款手续费;
                self.systemReceiveChargeFeeFromBorrow(br=bid_request,manage_charge_fee=manage_charge_fee)

                # // 3, 对投资人要做什么事情?
                # // ** 3.1遍历投标;
                bids = bid_request.bids.values_list('bidUser')
                # 取出所有投标用户id, 并去重
                bid_user_ids = list(set((list(zip(*bids)))[0]))
                # // 汇总利息, 用于最后一个投标的用户的利息计算
                totalBidInterest = Decimal('0')
                for idx, bid_user_id in enumerate(bid_user_ids):
                    #获取投资人
                    bids_temp_query = bid_request.bids.filter(bidUser_id=bid_user_id)
                    # 获取相同投资人投的标数量
                    # 统计投资金额
                    available_amount_total = bids_temp_query.aggregate(Sum('availableAmount'))
                    # 获取投资人账户
                    investor_account = Account.objects.get(userProfile=bids_temp_query.first().bidUser.userProfile)
                    # 冻结余额减少
                    investor_account.freezedAmount = investor_account.freezedAmount - available_amount_total['availableAmount__sum']
                    # // ** 3.3生成成功投标流水
                    self.bidSuccessFlow(bid=bids_temp_query.first(),account=investor_account, total_bid_amount=available_amount_total['availableAmount__sum'])
                     # // ** 3.4计算待收利息和待收本金
                    # // ** 3.4.1待收本金
                    investor_account.unReceivePrincipal = investor_account.unReceivePrincipal + available_amount_total['availableAmount__sum']
                    #临时利息变量
                    bidInterest = Decimal('0')
                    # // ** 3.4.2待收利息
                    # // 待收利息 = 投标金额 / 借款总金额 * 借款总回报利息
                    # // 如果当前投标是整个投标列表中的最后一个投标;这个投标的利息 = 借款总回报利息 - 累加的投标利息
                    if idx == len(bid_user_ids) - 1:
                        #计算最后投标人的利息
                        bidInterest = bid_request.totalRewardAmount - totalBidInterest
                    else:
                        bidInterest = (available_amount_total['availableAmount__sum'] / bid_request.bidRequestAmount) * bid_request.totalRewardAmount
                        bidInterest =  DecimalFormatUtil.formatBigDecimal(bidInterest, BidConst.STORE_SCALE())
                        #累加总的利息 用于最后利息的计算
                        totalBidInterest = totalBidInterest + bidInterest
                    investor_account.unReceiveInterest = investor_account.unReceiveInterest + bidInterest
                    investor_account.save()
            # // 4, 思考满标二审之后的流程(还款)对满标二审有什么影响
            # // ** 4生成还款对象和回款对象
                self.createPaymentSchedules(bid_request)
            elif bid_audit.state == BitStatesUtils.STATE_REJECT():
                #审核失败,修改借款状态
                bid_request.bidRequestState = BidConst.GET_BIDREQUEST_STATE_REJECTED() #满标审核拒绝
                #进行退款
                self.retureMoney(bid_request)
                # 审核失败,移出用户招标状态
                bid_request.createUser.userProfile.removeState(BitStatesUtils.GET_OP_HAS_BIDREQUEST_PROCESS())
                bid_request.createUser.userProfile.save()
            #保存模型
            bid_request.save()
            bid_audit.save()
Пример #24
0
 def isMoneyWithoutProcess(self):
     return BitStatesUtils.hasState(
         self.bitState, BitStatesUtils.GET_HAS_MONEYWITHDRAW_PROCESS())
Пример #25
0
 def queryset(self):
     qs = super(RealAuthAdmin, self).queryset()
     qs = qs.filter(
         Q(state=BitStatesUtils.STATE_NORMAL())
         | Q(state=BitStatesUtils.STATE_REJECT()))
     return qs
Пример #26
0
 def removeState(self, value):
     self.bitState = BitStatesUtils.removeState(self.bitState, value)
Пример #27
0
 def queryset(self):
     qs = super(RealAuthAudittedAdmin, self).queryset()
     qs = qs.filter(state=BitStatesUtils.STATE_AUDIT())
     return qs