Пример #1
0
    def update_acc_n_bal_record(user_id,new_bal,rem_credit,trans_type):
        try: 
            update_account_bal_of(user_id,new_bal) #F3       
            log_record(user_id,rem_credit,trans_type) #F1
        except Exception as e:

            print('update_acc_n_bal_record ERROR',e)
Пример #2
0
    def save(self, *args, **kwargs):
        ''' Overrride internal model save method to update balance on staking  '''
        if not self.stake_placed:
            try:
                market_id = max((obj.id for obj in WheelSpin.objects.all()))
                this_wheelspin = WheelSpin.objects.get(id =market_id )
            except Exception as mae:
                this_wheelspin,_ = WheelSpin.objects.get_or_create(id =1)
                pass
                  
            # create on demand
            if not this_wheelspin.place_stake_is_active:
                WheelSpin.objects.create(id = market_id+1)
                this_wheelspin = WheelSpin.objects.get(id =market_id+1 )
                
            # end create market on demand

            if this_wheelspin.place_stake_is_active:# 

                self.market = this_wheelspin
                try:
                    current_user_account_bal = current_account_bal_of(self.user.id) # F2
                    if self.amount <= current_user_account_bal: # no staking more than account balance
                        if not self.stake_placed:
                            new_bal = current_user_account_bal - float(self.amount)
                            self.current_bal = new_bal
                            update_account_bal_of(self.user_id,new_bal)# F3
                            self.stake_placed = True
                    
                    else: 
                        raise Exception ('insufficient funds')
                        # return 'Not enough balance to stake'

                except Exception as e:
                    print('STAKE:',e)
                    return e
            else:
                print('INACTIVE MARKET!')
                return # no saving record if market is inactive

            try:
                if not self.has_record:
                    log_record(self.user_id,self.amount,'Stake')
                    
                    self.has_record = True
            except:
                pass

            super().save(*args, **kwargs)
Пример #3
0
    def update_reference_account(user_id, ref_credit, trans_type):
        print(user_id, ref_credit, trans_type)

        try:
            this_user = User.objects.get(id=user_id)

            this_user_ReferCode = this_user.daru_code  # first name is used as referer code
            if not this_user_ReferCode:
                this_user_ReferCode = 'DADMIN'  # settings

            referer_users = User.objects.filter(my_code=this_user_ReferCode)
            for referer in referer_users:
                print(referer, 'RefererUser')

                refer_credit_create(referer, this_user.username,
                                    ref_credit)  #F4
                log_record(referer.id, ref_credit, 'ref_credit')  # F1

        except Exception as e:
            print('update_reference_account ERROR', e)
Пример #4
0
    def save(self, *args, **kwargs):
        ''' Overrride internal model save method to update balance on staking  '''
        if not self.stake_placed:
            market_id = max((obj.id for obj in WheelSpin.objects.all()
                             ))  #  check if generator can help #ER/empty gen
            this_wheelspin = WheelSpin.objects.get(id=market_id)

            if this_wheelspin.place_stake_is_active:  #

                self.market = this_wheelspin
                try:
                    current_user_account_bal = current_account_bal_of(
                        self.user.id)  # F2
                    if self.amount <= current_user_account_bal:  # no staking more than account balance
                        if not self.stake_placed:
                            new_bal = current_user_account_bal - float(
                                self.amount)
                            self.current_bal = new_bal
                            update_account_bal_of(self.user_id, new_bal)  # F3
                            self.stake_placed = True

                    else:
                        raise Exception('No cash')
                        # return 'Not enough balance to stake'

                except Exception as e:
                    print('STAKE:', e)
                    return
            else:
                print('INACTIVE MARKET!')
                return  # no saving record if market is inactive

            try:
                if not self.has_record:
                    log_record(self.user_id, self.amount, 'Stake')

                    self.has_record = True
            except:
                pass

            super().save(*args, **kwargs)