ソースを参照

调整框架里面table

chenbo 5 年 前
コミット
5323fc261c
共有2 個のファイルを変更した72 個の追加38 個の削除を含む
  1. 41 9
      lib/table/table.class.php
  2. 31 29
      lib/table/table_stock.class.php

+ 41 - 9
lib/table/table.class.php

@@ -48,15 +48,6 @@ abstract class Table {
 	//@param $attr array -- 键值同struct()返回的数组
 	abstract public function add($attr);
 
-	//获取列表(分页)
-	//$count、$page和$pagesize都为0时,返回全部结果(适用于无需分页的情况)
-	//
-	//@param $filter array -- 过滤条件,格式见Table::filterToWhere
-	//@param $count -- 0:返回列表 1:返回结果数量
-	//@param $page -- 当前第几页
-	//@param $pagesize -- 每页数量
-	abstract public function getList($filter = array(), $count = 0, $page = 0, $pagesize = 0);
-
 
 	///////////////////////////////////////////////////////////////
 	/**************非抽象方法,用于继承,也可以重载***************/
@@ -81,6 +72,47 @@ abstract class Table {
         }
 	}
 
+    //获取列表(分页)
+    //$count、$page和$pagesize都为0时,返回全部结果(适用于无需分页的情况)
+    //
+    //@param $filter array -- 过滤条件,格式见Table::filterToWhere
+    //@param $count -- 0:返回列表 1:返回结果数量
+    //@param $page -- 当前第几页
+    //@param $pagesize -- 每页数量
+    public function getList($filter = array(), $count = 0, $page = 0, $pagesize = 0){
+        $where = $this->filterToWhere($filter);
+
+        if($count == 0){//列表
+            $sql = "select * from ". $this->table_fullname ." $where order by ".$this->table_id." desc";
+
+            if($page > 0){//分页
+                $startrow = ($page - 1) * $pagesize;
+                $sql_limit = " limit $startrow, $pagesize";
+                $sql .= $sql_limit;
+            }
+
+            $rs  = $this->pdo->sqlQuery($sql);
+            $r   = array();
+            if($rs){
+                foreach($rs as $key => $val){
+                    $r[$key] = $this->dataToAttr($val);
+                }
+                return $r;
+            }else{
+                return $r;
+            }
+
+        }else{//统计
+            $sql = "select count(*) as c from ". $this->table_fullname . " $where ";
+            $rs  = $this->pdo->sqlQuery($sql);
+            if($rs){
+                return $rs[0]['c'];
+            }else{
+                return 0;
+            }
+        }
+    }
+
 	//删
 	public function del($id){
 		$where = array(

+ 31 - 29
lib/table/table_stock.class.php

@@ -14,47 +14,49 @@ class Table_stock extends Table {
     protected $table_id         = 'stock_id';//指定ID字段名称,必须
     protected $table_status     = '';//指定状态字段名称,如果有
     protected $table_order      = '';//指定排序字段名称,如果有
+
 	//数据库结构
 	protected function struct(){
 		$attr = array();
-		
-		$attr['id']           = 'stock_id';
-		$attr['date']         = 'stock_code';
-		$attr['open_price']         = 'stock_name';
-		$attr['close_price']        = 'stock_desc';
-        $attr['tradable_amount']           = 'stock_tradable_amount';
-        $attr['tradable_value']         = 'stock_tradable_value';
-        $attr['total_amount']         = 'stock_total_amount';
-        $attr['total_value']        = 'stock_total_value';
-        $attr['profitable']        = 'stock_profitable';
-        $attr['pb']        = 'stock_pb';
+		$attr['id']               = 'stock_id';
+		$attr['code']             = 'stock_code';
+		$attr['name']             = 'stock_name';
+		$attr['desc']             = 'stock_desc';
+        $attr['tradable_amount']  = 'stock_tradable_amount';
+        $attr['tradable_value']   = 'stock_tradable_value';
+        $attr['total_amount']     = 'stock_total_amount';
+        $attr['total_value']      = 'stock_total_value';
+        $attr['profitable']       = 'stock_profitable';
+        $attr['pb']               = 'stock_pb';
         $attr['pe_static']        = 'stock_pe_static';
-        $attr['pe_dynamic']        = 'stock_pe_dynamic';
-        $attr['pe_ttm']        = 'stock_pe_ttm';
-        $attr['exchange']        = 'stock_exchange';
-        $attr['sector']        = 'stock_sector';
+        $attr['pe_dynamic']       = 'stock_pe_dynamic';
+        $attr['pe_ttm']           = 'stock_pe_ttm';
+        $attr['exchange']         = 'stock_exchange';
+        $attr['sector']           = 'stock_sector';
 		return $attr;
 	}
 
     public function add($attr){
         $param = array (
-
-             'admingroup_name'    => array('string', $attr['name'])
-
+            'stock_code'            => array('string', $attr['code']),
+            'stock_name'            => array('string', $attr['name']),
+            'stock_desc'            => array('string', $attr['desc']),
+            'stock_tradable_amount' => array('number', $attr['tradable_amount']),
+            'stock_tradable_value'  => array('number', $attr['tradable_value']),
+            'stock_ total _amount'  => array('number', $attr['total_amount']),
+            'stock_total_value'     => array('number', $attr['total_value']),
+            'stock_profitable'      => array('number', $attr['profitable']),
+            'stock_pb'              => array('number', $attr['pb']),
+            'stock_pe_static'       => array('number', $attr['pe_static']),
+            'stock_pe_dynamic'      => array('number', $attr['pe_dynamic']),
+            'stock_pe_ttm'          => array('number', $attr['pe_ttm']),
+            'stock_exchange'        => array('string', $attr['exchange']),
+            'stock_sector'          => array('number', $attr['sector']),
         );
+
         return $this->pdo->sqlinsert($this->table_fullname, $param);
     }
 
-    //获取列表(分页)
-    //$count、$page和$pagesize都为0时,返回全部结果(适用于无需分页的情况)
-    //
-    //@param $filter array -- 过滤条件,格式见Table::filterToWhere
-    //@param $count -- 0:返回列表 1:返回结果数量
-    //@param $page -- 当前第几页
-    //@param $pagesize -- 每页数量
-    public function getList($filter = array(), $count = 0, $page = 0, $pagesize = 0)
-    {
-
-    }
+    
 }
 ?>