浏览代码

修改bug

chenbo 4 年之前
父节点
当前提交
153649916d

+ 1 - 1
api/v1.0/index_info.php

@@ -9,7 +9,7 @@
 try {
 
     $code = isset($_GET['code'])?safeCheck($_GET['code'],1):'0';
-    $index_info=Index::get_index_info($code);
+    $index_info=Index::getInfoByCode($code);
 
     if(!empty($index_info))
     {

+ 1 - 1
api/v1.0/index_list.php

@@ -8,7 +8,7 @@
 
 try {
 
-    $index_list=Index::getIndexList();
+    $index_list=Index::getAllList();
     if(!empty($index_list))
     {
         foreach($index_list as $key=>$value){

+ 15 - 46
lib/index.class.php

@@ -1,76 +1,45 @@
 <?php
 
 /***
- * Class Index_sh50
+ * Class Index
  *  * @author		王刚涛
  * 日线数据
  */
 
 class Index {
 
-    public function __construct()
-    {
-
-    }
-
-    /**
-     * @return mixed
-     * wanggangtao
-     * 获取指数的基本信息
-     */
-    static public function get_index_info($code)
+    static public function getInfoById($id)
     {
         $Table_index = new Table_index();
-        return $Table_index->get_index_info($code);
+        return $Table_index->getInfoById($id);
     }
 
-
-    /***
-     * @return array
-     * wanggangtao
-     * 获取指数列表
-     */
-    static public function getIndexList()
+    static public function getInfoByCode($code)
     {
         $Table_index = new Table_index();
-        return $Table_index->getIndexList();
+        return $Table_index->getInfoByCode($code);
     }
 
-
-    /**
-     * @return mixed
-     * 各种指数入库
-     */
-    static public function get_index($code,$exchange)
+    static public function getList($filter = array(), $count=0, $page=0, $pagesize=0, $order=0)
     {
         $Table_index = new Table_index();
-        return $Table_index->get_index($code,$exchange);
+        return $Table_index->getList($filter, $count, $page, $pagesize, $order);
     }
 
-
-
-
-
-    static public function getInfoById($id)
-    {
-        $Table_index = new Table_index();
-        return $Table_index->getInfoById($id);
-    }
-    static public function insert($attrs)
+    static public function getAllList()
     {
-        if (empty($attrs)) throw new Exception('参数不能为空', 102);
         $Table_index = new Table_index();
-        $id = $Table_index->insert($attrs);
-        return $id;
+        return $Table_index->getList();
     }
 
-    static public function add($attrs){
-        if (empty($attrs)) throw new Exception('参数不能为空', 102);
+    static public function addOrUpdateByCode($attrs)
+    {
+        if (empty($attrs)) throw new Exception('参数不能为空', 101);
+        if (empty($attrs['code'])) throw new Exception('股票代码不能为空', 102);
         $Table_index = new Table_index();
-        $id = $Table_index->add($attrs);
+        $id = $Table_index->addOrUpdateByCode($attrs);
         return $id;
     }
-
-
+    
 }
 ?>

+ 7 - 60
lib/table/table_index.class.php

@@ -14,80 +14,27 @@ class Table_index extends Table {
     protected $table_id         = 'index_id';//指定ID字段名称,必须
     protected $table_status     = '';//指定状态字段名称,如果有
     protected $table_order      = '';//指定排序字段名称,如果有
+
 	//数据库结构
 	protected function struct(){
 		$attr = array();
-		
 		$attr['id']           = 'index_id';
 		$attr['code']         = 'index_code';
 		$attr['name']         = 'index_name';
-		$attr['exchange']        = 'index_exchange';
-        $attr['sector']           = 'index_sector';
+		$attr['exchange']     = 'index_exchange';
+        $attr['sector']       = 'index_sector';
 		return $attr;
 	}
 
-
     public function add($attr){
         $param = array (
-            'index_date'    => array('number', $attr['date']),
-            'index_open_price'    => array('number', $attr['open_price']),
-            'index_close_price'    => array('number', $attr['close_price']),
-            'index_highest_price'    => array('number', $attr['highest_price']),
-            'index_lowest_price'    => array('number', $attr['lowest_price']),
-            'index_increase_value'    => array('number', $attr['increase_value']),
-            'index_increase_price'    => array('number', $attr['increase_price']),
-            'index_amount'    => array('number', $attr['amount']),
-            'index_value'    => array('number', $attr['value']),
+            'index_code'            => array('string', $attr['code']),
+            'index_name'            => array('string', $attr['name']),
+            'index_exchange'        => array('string', $attr['exchange']),
+            'index_sector'          => array('number', $attr['sector']),
         );
         return $this->pdo->sqlinsert($this->table_fullname, $param);
     }
 
-
-    /****
-     * @return array
-     * wanggangtao
-     *
-     */
-    public function getIndexList(){
-
-        $where="where 1=1";
-        $sql = "select "."`*`". "from ". $this->table_fullname ." $where order by ".$this->table_id." asc";
-        $rs = $this->pdo->sqlQuery($sql);
-        $r  = array();
-        if($rs){
-            foreach($rs as $key => $val){
-                $r[$key] = $this->dataToAttr($val);
-            }
-            return $r;
-        }else{
-            return $r;
-        }
-    }
-
-    /***
-     * @param $code
-     * @return array
-     * 获取指数的基本信息
-     */
-    public function get_index_info($code){
-
-        $where=" where 1=1 ";
-        $sql = "select "."`*`". "from ". $this->table_fullname . $where ;
-        $sql.=" and index_code=".$code ;
-        $rs = $this->pdo->sqlQuery($sql);
-        $r  = array();
-        if($rs){
-            foreach($rs as $key => $val){
-                $r[$key] = $this->dataToAttr($val);
-            }
-            return $r[0];
-        }else{
-            return $r;
-        }
-    }
-
-
-
-
 }
 ?>

+ 1 - 1
task/task_get_day_k_index.php

@@ -7,7 +7,7 @@
  * 获取指数的当天数据,一天大概6条数据入库
  */
 require('../init.php');
-$indexList=Index::getIndexList();//获取指数代码
+$indexList=Index::getAllList();//获取指数代码
 foreach ($indexList as $key=>$value){
     Input_sina_index::get_day_k_index($value["code"],$value["exchange"]);
 }

+ 1 - 1
task/task_get_history_index.php

@@ -10,7 +10,7 @@ require('../init.php');
 
 $start_date=20140101;
 $end_date=date("Ymd",time());
-$indexList=Index::getIndexList();//获取指数代码
+$indexList=Index::getAllList();//获取指数代码
 foreach ($indexList as $key=>$value){
     Input_163_index::get_history_index($value["code"],$start_date,$end_date);
 }