Пример #1
0
 /**
  * @author Tuzki
  * @param integer
  * @desc 将改组账号的配置设置到对象的属性中,new 出账号组的账号对象
  */
 private function init()
 {
     Logger::Log("Initialize account group from db.");
     $this->accounts = array();
     $this->config = null;
     $this->name = null;
     $this->holding_btc_weight_total = 0;
     $account_dao = new AccountDao();
     $account_group_dao = new AccountGroupDao();
     $account_group = $account_group_dao->get($this->id);
     if ($account_group) {
         $this->name = $account_group['name'];
     } else {
         throw new Exception('Account Group is not found.');
     }
     $this->id = $account_group['id'];
     $this->config = new ConfigModel($this->id);
     $accounts = $account_dao->getAccountListByAccountGroupId($this->id);
     foreach ($accounts as $account) {
         $account = new AccountModel($account['id']);
         //持币权重之和(后面用于计算交易类型)
         $this->holding_btc_weight_total += $account->market->holding_btc_weight;
         $this->accounts[] = $account;
     }
 }
Пример #2
0
 public function getAction()
 {
     $account_group_dao = new AccountGroupDao('account_group');
     $params = $this->getRequest()->getParams();
     $handle = array_search('edit', $params);
     if (!empty($handle) && $params[$handle] === 'edit') {
         $account_group = $account_group_dao->get($handle);
         if (empty($account_group)) {
             $this->redirect('/account-group');
             exit;
         }
         $config_dao = new ConfigDao();
         $config_list = $config_dao->getConfigListByAccountGroupId($account_group['id']);
         $this->getView()->assign('config_list', $config_list);
         $this->getView()->assign('account_group', $account_group);
         $this->getView()->display('account-group-edit.phtml');
         exit;
     }
     if (array_key_exists('new', $params)) {
         $config_list = get_config_keys();
         $this->getView()->assign('config_list', $config_list);
         $this->getView()->display('account-group-new.phtml');
         exit;
     }
     $redis = Yaf\Registry::get('redis');
     if (!empty($params) && count($params) === 1) {
         $id = array_keys($params)[0];
         $config_dao = new ConfigDao();
         $config_list = $config_dao->getConfigListByAccountGroupId($id);
         $account_group_config = array();
         foreach ($config_list as $row) {
             $account_group_config[$row['name']] = $row['value'];
         }
         $account_dao = new AccountDao();
         $account_list = $account_dao->getAccountListByAccountGroupId($id);
         $market_dao = new MarketDao();
         $account_info_list = array();
         foreach ($account_list as $account) {
             $key = 'AccountInfo_' . $account['id'];
             $market = $market_dao->get($account['market_id']);
             $account_info_list[] = array_merge(json_decode($redis->get($key), true), array('market_name' => $market['name']));
         }
         $btc_price = json_decode($redis->get('Market\\HuoLPrice'), true)['buy'][0][0];
         $this->getView()->assign('btc_price', $btc_price);
         $this->getView()->assign('account_group_config', $account_group_config);
         $this->getView()->assign('account_info_list', $account_info_list);
         $this->getView()->display('account-group-view.phtml');
         exit;
     }
     $this->getView()->assign('account_group_list', $account_group_dao->getList());
     $this->getView()->display('account-group.phtml');
 }