wanggangtao il y a 5 ans
Parent
commit
6e4e28028b

+ 3 - 8
api/v1.0/demo/index_any_day.html

@@ -16,7 +16,7 @@
         $(function(){
             $('#btn').click(function(){
                 var method = $('input[name="method"]').val();
-                var index_type = $('input[name="index_type"]').val();
+                var code = $('input[name="code"]').val();
                 var date = $('input[name="date"]').val();
                 var timestamp = $('input[name="timestamp"]').val();
                 var sign = $.md5(method+timestamp);
@@ -25,7 +25,7 @@
                     type         : 'POST',
                     data         : {
                         'method' :method,
-                        'index_type' :index_type,
+                        'code' :code,
                         'date' :date,
 
                         'timestamp' :timestamp,
@@ -70,7 +70,7 @@
 
             <p>
                 <span>code</span>
-                <input type="text" class="input-text"  name="code" value="600008"/>
+                <input type="text" class="input-text"  name="code" value="399006"/>
             </p>
 
 
@@ -78,11 +78,6 @@
                 <span>date</span>
                 <input type="text" class="input-text"  name="date" value=20201201 />
             </p>
-            <p>
-                <span>index_type:0:表示全部指数,1:上证指数,2:深成指数 3:上证50指数 4:沪深300 5:创业板指数 6:科创50指数 </span>
-                <input type="text" class="input-text"  name="index_type" value=0 />
-            </p>
-
 
             <p>
 

+ 5 - 9
api/v1.0/demo/index_current_day.html

@@ -16,7 +16,7 @@
         $(function(){
             $('#btn').click(function(){
                 var method = $('input[name="method"]').val();
-                var index_type = $('input[name="index_type"]').val();
+                var code = $('input[name="code"]').val();
                 var timestamp = $('input[name="timestamp"]').val();
                 var sign = $.md5(method+timestamp);
                 $('#sign').val(sign);
@@ -24,7 +24,7 @@
                     type         : 'POST',
                     data         : {
                         'method' :method,
-                        'index_type' :index_type,
+                        'code' :code,
                         'timestamp' :timestamp,
                         'sign'   : sign
                     },
@@ -45,7 +45,7 @@
     </script>
 </head>
 <body>
-<div id="head"><p>指数当数据</p></div>
+<div id="head"><p>指数当天的数据</p></div>
 <div id="content">
     <div id="left">
         <div class ="message"><p>接口返回:</p></div>
@@ -66,14 +66,10 @@
 
 
             <p>
-                <span>index_type:0:表示全部指数,1:上证指数,2:深成指数 3:上证50指数 4:沪深300 5:创业板指数 6:科创50指数 </span>
-                <input type="text" class="input-text"  name="index_type" value=0 />
+                <span>code: </span>
+                <input type="text" class="input-text"  name="code" value="399006" />
             </p>
 
-
-            <p>
-
-            </p>
             <p><span>校验码:</span><input type="text" class="input-text" id="sign" readonly/></p>
             <p><button class="button success small" id="btn" type="button">发送请求</button></p>
         </form>

Fichier diff supprimé car celui-ci est trop grand
+ 1 - 1
api/v1.0/index_any_day.php


Fichier diff supprimé car celui-ci est trop grand
+ 1 - 1
api/v1.0/index_current_day.php


Fichier diff supprimé car celui-ci est trop grand
+ 1 - 1
api/v1.0/stock_any_day.php


+ 2 - 2
lib/index_day_k.class.php

@@ -75,10 +75,10 @@ class Index_day_k {
         return $Table_index_day_k->getIndexListHistroy($start_date,$end_date,$index_type,$num,$order);
     }
 
-    static public function get_current_day_index($index_type,$date)
+    static public function get_current_day_index($code,$date)
     {
         $Table_index_day_k = new Table_index_day_k();
-        return $Table_index_day_k->get_current_day_index($index_type,$date);
+        return $Table_index_day_k->get_current_day_index($code,$date);
     }
 
 

+ 8 - 25
lib/table/table_index_day_k.class.php

@@ -71,43 +71,26 @@ class Table_index_day_k extends Table {
      * wanggangtao
      * 获取某天的指数代码
      */
-    public function get_current_day_index($index_type,$date)
+    public function get_current_day_index($code,$date)
     {
         //查询语句必须用sql_check_input检查参数
-        $stock_code = $this->pdo->sql_check_input(array('number', $index_type));//类型是字符串,那一定要在条件中将数据使用引号引用起来,否则不使用索引
+        $stock_code = $this->pdo->sql_check_input(array('string', $code));//类型是字符串,那一定要在条件中将数据使用引号引用起来,否则不使用索引
         $sql = "select * from ". $this->table_fullname ;
 
         $where=" where 1=1 ";
-        if($index_type==1){
-            $stock_code="000001";
-            $where.=" and index_day_k_code=".$stock_code ;
-        }else if($index_type==2){
-            $stock_code="399001";
-            $where.=" and index_day_k_code=".$stock_code ;
-        }else if($index_type==3){
-            $stock_code="000016";
-            $where.=" and index_day_k_code=".$stock_code ;
-        }else if($index_type==4){
-            $stock_code="399300";
-            $where.=" and index_day_k_code=".$stock_code ;
-        }else if($index_type==5){
-            $stock_code="399006";
-            $where.=" and index_day_k_code=".$stock_code ;
-        }else if($index_type==6){
-            $stock_code="000688";
-            $where.=" and index_day_k_code=".$stock_code ;
-        }
+        $where.=" and index_day_k_code=".$stock_code ;
 
-
-        if($date==0){//获取的是当天的数据
+        if($date==0){//获取的是当天的数据,最近一天的交易日的数据
             $date = date("Ymd",time());
-            $where.=" and index_day_k_date = ".$date;
+            $where.=" and index_day_k_date <= ".$date;
 
-        }else{//获取某一天的数据
+        }else{//获取某一天的数据,不是交易日则返回空
             $date = $this->pdo->sql_check_input(array('number', $date));
             $where.=" and index_day_k_date =".$date;
         }
         $sql.=$where;
+        $order=" order by index_day_k_date desc limit 1 ";
+        $sql.=$order;
 
         $rs = $this->pdo->sqlQuery($sql);
         $r  = array();