function __construct($account_id = null) { if (!empty($account_id)) { $account_model = new AccountDao(); $account = $account_model->get($account_id); if ($account) { $this->account_id = $account_id; // 市场类名 $market_name = $account->market['name']; $market_name = 'Market\\' . $market_name; // 市场配置 $account_config = array(); $account_config_model = new AccountConfigDao(); foreach ($account_config_model->getConfigListByAccountId($account['id']) as $config) { $account_config[$config['name']] = format_val($config['value']); } try { $this->market = new $market_name($account_config); } catch (Exception $e) { throw new Exception("API {$market_name} not found."); } } else { throw new Exception('Account not found.'); } } }
public function getAction() { $account_dao = new AccountDao(); $account_group_dao = new AccountGroupDao('account-group'); $params = $this->getRequest()->getParams(); $param_id = array_search('edit', $params); if (!empty($param_id) && $params[$param_id] === 'edit') { $account_dao = new AccountDao(); $market_dao = new MarketDao(); $account_config_dao = new AccountConfigDao('account_config'); $account_group_list = $account_group_dao->getList(); $account = $account_dao->get($param_id); $market = $market_dao->get($account['market_id']); //account config $account_config_list = $account_config_dao->getConfigListByAccountId($param_id); $this->getView()->assign('account', $account); $this->getView()->assign('account_group_list', $account_group_list); $this->getView()->assign('account_config_list', $account_config_list); $this->getView()->assign('market', $market); $this->getView()->display('accounts-edit.phtml'); exit; } if (array_key_exists('new', $params)) { $account_group_dao = new AccountGroupDao('account-group'); $market_dao = new MarketDao(); $account_group_list = $account_group_dao->getList(); $market_list = $market_dao->getList(); //account config $account_config_list = array(); foreach ($market_list as $market) { $account_config_list[$market['name']] = get_account_config_keys($market['name']); } $this->getView()->assign('account_group_list', $account_group_list); $this->getView()->assign('account_config_list', $account_config_list); $this->getView()->assign('market_list', $market_list); $this->getView()->display('accounts-new.phtml'); exit; } $this->getView()->assign('account_list', $account_dao->getAccountList()); $this->getView()->display('accounts.phtml'); }