示例#1
0
文件: model.php 项目: fchaose/qeephp
 /**
  * 生成代码
  */
 function getCode($class_name, $table_name)
 {
     $arr = explode('.', $table_name);
     if (isset($arr[1])) {
         $table_name = $arr[1];
         $schema = $arr[0] . '.';
     } else {
         $table_name = $arr[0];
         $schema = '';
     }
     $dbo = QDB::getConn();
     $prefix = $dbo->getTablePrefix();
     if ($prefix && substr($table_name, 0, strlen($prefix)) == $prefix) {
         $table_name = substr($table_name, strlen($prefix));
     }
     $table_name = "{$schema}{$table_name}";
     $config = array('name' => $table_name);
     $table = new QDB_Table($config);
     $meta = $table->columns();
     $pk = array();
     foreach ($meta as $field) {
         if ($field['pk']) {
             $pk[] = $field['name'];
         }
     }
     $viewdata = array('class_name' => $class_name, 'table_name' => $table_name, 'meta' => $meta, 'pk' => $pk);
     return $this->_parseTemplate('model', $viewdata);
 }
示例#2
0
 public function __construct($dsn, $id)
 {
     if (!is_array($dsn)) {
         $dsn = QDB::parseDSN($dsn);
     }
     parent::__construct($dsn, $id);
 }
示例#3
0
 function actionIndex()
 {
     #return $this->msg($tip = null,url('default::default'),2);
     $msg = $this->_app->getFlashMessage();
     $this->_view['_MSG'] = $msg ? $msg : '我们为广大站长提供稳定高速的加速服务,承诺每台服务器最多15位用户,我们对利用该服务进行非法活动、下载(包含但不限于BT/PT)等行为,立即删号处理。';
     $account = QDB::getConn()->getOne($sql = "SELECT count(`groupname`) as total FROM radusergroup WHERE groupname !=  'NOP'");
     $this->_view['account_left'] = 15 - $account;
 }
示例#4
0
 function __construct($dsn, $id)
 {
     if (!is_array($dsn)) {
         $dsn = QDB::parseDSN($dsn);
     }
     parent::__construct($dsn, $id);
     $this->_schema = $dsn['database'];
 }
示例#5
0
 protected function setUp()
 {
     $dsn = Q::ini('db_dsn_pool/default');
     if (empty($dsn)) {
         Q::changeIni('db_dsn_pool/default', Q::ini('db_dsn_mysql'));
     }
     $this->dbo = QDB::getConn();
     $this->dbo->connect();
 }
示例#6
0
文件: test.php 项目: fchaose/qeephp
 protected function setUp()
 {
     $dsn = Q::getIni('db_dsn_pool/default');
     if (empty($dsn)) {
         Q::setIni('db_dsn_pool/default', Q::getIni('db_dsn_mysql'));
     }
     $this->_conn = QDB::getConn();
     $this->_conn->startTrans();
 }
示例#7
0
 function __construct($dsn, $id)
 {
     if (!is_array($dsn)) {
         $dsn = QDB::parseDSN($dsn);
     }
     parent::__construct($dsn, $id);
     if (isset($dsn['schema']) && !empty($dsn['schema'])) {
         $this->_schema = $dsn['schema'];
     }
 }
示例#8
0
 protected function setUp()
 {
     $dsn = Q::ini('db_dsn_pool/default');
     if (empty($dsn)) {
         Q::changeIni('db_dsn_pool/default', Q::ini('db_dsn_mysql'));
     }
     $conn = QDB::getConn();
     $params = array('name' => 'posts', 'pk' => 'post_id', 'conn' => $conn);
     $this->table = new QDB_Table($params);
 }
示例#9
0
 function actionTraffic()
 {
     $sql = "SELECT SUM( acctinputoctets + acctoutputoctets ) as total FROM radacct WHERE UserName =  '******'";
     $traffic_total = QDB::getConn()->getOne($sql);
     $this->_view['traffic_total'] = $traffic_total;
     $page = (int) $this->_context->get('page', 1);
     $orm = Radacct::find('username =?', $this->_user_name)->order('radacctid desc');
     $orm->limitPage($page, 12);
     $this->_view['rs'] = $orm->getAll();
     $this->_view['pg'] = $orm->getPag();
 }
示例#10
0
 function actionIndex()
 {
     //新进订单
     $order = Order::find()->order('order_id DESC')->get(5);
     //新进帐号
     #$users = Account::find()->order('user_id DESC')->get(5);
     $this->_view['order'] = $order;
     #$this->_view['users'] = $users;
     $sql = "SELECT SUM( acctinputoctets + acctoutputoctets ) as total FROM radacct WHERE 1";
     $traffic_total = QDB::getConn()->getOne($sql);
     $this->_view['traffic_total'] = $traffic_total;
     /*
     $ttt = Invoice::find('trade_status = ?','TRADE_FINISHED')->getAll();
     foreach($ttt as $t)
     {
         $t->due_time = ($t->per_day * 24 * 3600) + $t->trade_time;
         $t->save();
     }
     */
     $nowt = time();
     $dayt = 24 * 3600;
     $tips = $nowt - 25 * $dayt;
     $sql = "SELECT i.`order_id`,i.`total_fee`,i.`per_day`,i.`due_time`,i.`order_number` FROM `vpn_invoice` i, `vpn_order` o WHERE i.`order_id` = o.`order_id` AND o.`status` IN ('expired','approve') AND i.`is_expired` = '0' AND i.`trade_status` = 'TRADE_FINISHED' AND i.`due_time` < " . $tips;
     $niv = QDB::getConn()->getAll($sql);
     // 这里的 due_time 其实不用设置,因为这系统账单不会过期。。。当用户付款后,自动更新下期账单时间。
     foreach ($niv as $new) {
         $old = $new['order_number'];
         $due_time = $nowt > $new['due_time'] ? $nowt : $new['due_time'];
         $new['due_time'] = $due_time + $new['per_day'] * $dayt;
         $new['order_number'] = 'x' . date('YmdHis') . rand(111, 999);
         $test = QDB::getConn()->getOne("SELECT `order_number` FROM `vpn_invoice` WHERE `order_id` = {$new['order_id']} AND `trade_status` LIKE 'WAIT_BUYER_PAY'");
         // 如果不存在未支付的账单,则生成之。
         if (!$test) {
             $new_sql = "INSERT INTO `vpn_invoice` (`order_id`, `order_number`, `buyer_email`, `total_fee`, `trade_time`, `trade_status`, `trade_no`, `trade_ip`, `per_day`, `due_time`, `created`, `updated`) VALUES ({$new['order_id']}, '{$new['order_number']}', '0', {$new['total_fee']}, 0, 'WAIT_BUYER_PAY', '0', '0', {$new['per_day']}, {$new['due_time']}, {$nowt}, 0);";
             #QDB::getConn()->execute($new_sql);
             //设置上一账单失效。
             $ext_sql = "UPDATE `vpn_invoice` SET `is_expired` = '1' WHERE `order_number` = '{$old}'";
             QDB::getConn()->execute($ext_sql);
             #dump($ext_sql);
         }
     }
     #exit;
     // 过期用户
     $exts = $nowt - 30 * $dayt;
     $sql = "SELECT o.`username`,o.`order_id` FROM `vpn_invoice` i, `vpn_order` o WHERE i.`order_id` = o.`order_id` AND i.`is_expired` = '0' AND i.`trade_status` = 'TRADE_FINISHED' AND o.`status` != 'expired' AND i.`due_time` < " . $exts;
     $ext = QDB::getConn()->getAll($sql);
     foreach ($ext as $tmp) {
         $old_sql = "UPDATE `vpn_order` SET `status` = 'expired' WHERE `order_id` = {$tmp['order_id']}";
         $nop_sql = "UPDATE `radusergroup` SET `groupname` = 'NOP' WHERE `username` = '{$tmp['username']}'";
         QDB::getConn()->execute($old_sql);
         QDB::getConn()->execute($nop_sql);
     }
 }
示例#11
0
 /**
  * 开启一个查询,并根据提供的参数设置查询对象
  *
  * @param array $args
  *
  * @return QDB_Select
  */
 function findByArgs(array $args = array())
 {
     $select = new QDB_Select(QDB::getConn($this->_dsn));
     $select->setSQL($this->_find_sql)->asColl()->asObject($this->class_name);
     $c = count($args);
     if ($c > 0) {
         if ($c == 1 && is_int($args[0]) && $this->idname_count == 1) {
             $select->where(array(reset($this->idname) => $args[0]));
         } else {
             call_user_func_array(array($select, 'where'), $args);
         }
     }
     return $select;
 }
示例#12
0
 function actionMigrationOut()
 {
     $this->_pathway->addStep('数据迁出');
     QLog::log('开始数据迁出!');
     try {
         $db = QDB::getConn();
         $db->startTrans();
         $db->completeTrans();
     } catch (QException $ex) {
         QLog::log($ex->getMessage(), QLog::ERR);
     }
     echo '正在迁移,请稍后...<br/>';
     for ($i = 0; $i < 100; $i++) {
         QLog::log('正在迁出数据:' . $i);
         echo $i . '<br/>';
     }
     QLog::log('数据迁出完成!');
     return '迁出成功';
 }
示例#13
0
 function setUp()
 {
     $this->_conn = QDB::getConn();
     $this->_conn->startTrans();
 }
示例#14
0
文件: table.php 项目: fchaose/qeephp
 /**
  * 设置表数据入口使用的数据库访问对象
  *
  * 继承类可以覆盖此方法来自行控制如何设置数据库访问对象。
  */
 protected function _setupConn()
 {
     if (!is_null($this->_conn)) {
         return;
     }
     $this->setConn(QDB::getConn());
 }
示例#15
0
文件: DB.php 项目: jasny/Q
 /**
  * Apply defaults to field properties.
  * (Don't call this outside of Q\DB classes)
  *
  * @param array  $properties  Table properties or field properties
  * @param string $index       Fieldname (when table properties are specified)
  */
 public static function applyFieldDefaults(&$properties, $index = null)
 {
     if (!isset(self::$fnApplyFieldDefaults) && self::$functionCache) {
         if (!self::$functionCache instanceof Cache) {
             load_class('Q\\Cache');
             self::$functionCache = Cache::with(self::$functionCache, array('none-is-ok' => true));
         }
         self::$fnApplyFieldDefaults = self::$functionCache->get('QDB-fnApplyFieldDefaults');
         self::$dfpUsedForFunction = self::$functionCache->get('QDB-dfpUsedForFunction');
     }
     if (self::$defaultFieldProperties !== self::$dfpUsedForFunction) {
         if (empty(self::$defaultFieldProperties)) {
             self::$fnApplyFieldDefaults = false;
         } else {
             $code = self::generateCode_ApplyDefaultProperties('Field', '$index');
             self::$fnApplyFieldDefaults = create_function('&$properties, $index', $code);
         }
         self::$dfpUsedForFunction = self::$defaultFieldProperties;
     }
     if (isset($index)) {
         $p =& $properties;
     } else {
         $p[null] =& $properties;
     }
     if (empty($p[$index]['datatype'])) {
         $p[$index]['datatype'] = $p[$index]['type'];
     }
     if (!empty(self::$fnApplyFieldDefaults)) {
         $fn = self::$fnApplyFieldDefaults;
         $fn($p, $index);
     }
     if (empty($p[$index]['description'])) {
         $p[$index]['description'] = ucfirst(str_replace("_", " ", !empty($p[$index]['orm']) ? $p[$index]['orm'] : $p[$index]['name']));
     }
     if (empty($p[$index]['caption'])) {
         $p[$index]['caption'] = $p[$index]['description'];
     }
 }
示例#16
0
 protected function setUp()
 {
     Q::import(FIXTURE_DIR . '/orm');
     $this->_conn = QDB::getConn();
     $this->_conn->startTrans();
 }
示例#17
0
文件: lite.php 项目: Debenson/openwan
 /**
  * 设置连接
  *
  * @param string|QDB_Adapter_Abstract $conn
  *
  * @return QDB_Adapter_Abstract
  */
 protected static function _setupConnection($conn)
 {
     if (is_string($conn)) {
         $conn = QDB::getConn($conn);
     }
     if (!$conn instanceof QDB_Adapter_Abstract) {
         throw new QDB_Table_Exception('Argument must be of type QDB_Adapter_Abstract, or dsn name');
     }
     return $conn;
 }
示例#18
0
 function lastLogin()
 {
     $sql = "SELECT authdate FROM radpostauth WHERE username =  '******' and `reply` = 'Access-Accept' ORDER BY authdate desc";
     $str = QDB::getConn()->getOne($sql);
     return $str ? $str : '-';
 }