wanggangtao 4 anni fa
parent
commit
7188b131e5

+ 6 - 1
api/v1.0/demo/index.html

@@ -115,7 +115,12 @@
 		<td class="n3"><a href="index_day_k.html" target="_blank">查看Demo</a></td>
 		<td class="n4"><a href="#" target="_blank">下载文档</a></td>
 	</tr>
-
+	<tr>
+		<td class="n1">1.13</td>
+		<td class="n2"><a href="stock_least_day.html" target="_blank">股票某天最近的交易日的数据</a></td>
+		<td class="n3"><a href="stock_least_day.html" target="_blank">查看Demo</a></td>
+		<td class="n4"><a href="#" target="_blank">下载文档</a></td>
+	</tr>
 
 </table>
 </body>

+ 94 - 0
api/v1.0/demo/stock_least_day.html

@@ -0,0 +1,94 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+    <title>指数某天接口</title>
+    <script type="text/javascript" src="js/jquery.1.9.1.min.js"></script>
+    <script type="text/javascript" src="js/func.common.js"></script>
+    <script type="text/javascript" src="js/func.js"></script>
+    <script type="text/javascript" src="js/jquery.md5.js">//$.md5()</script>
+    <script type="text/javascript" src="js/jquery.base64.js">//$.base64.encode()</script>
+    <script src="js/c.js" type="text/javascript"></script>
+    <script src="js/urchin.js" type="text/javascript"></script>
+    <link href="css/s.css" type="text/css" rel="stylesheet">
+    <link href="css/base.css" type="text/css" rel="stylesheet">
+    <script type="text/javascript">
+        $(function(){
+            $('#btn').click(function(){
+                var method = $('input[name="method"]').val();
+                var code = $('input[name="code"]').val();
+                var date = $('input[name="date"]').val();
+                var fq_price = $('input[name="fq_price"]').val();
+                var timestamp = $('input[name="timestamp"]').val();
+                var sign = $.md5(method+timestamp);
+                $('#sign').val(sign);
+                $.ajax({
+                    type         : 'GET',
+                    data         : {
+                        'method' :method,
+                        'code' :code,
+                        'date' :date,
+                        'fq_price' :fq_price,
+                        'timestamp' :timestamp,
+                        'sign'   : sign
+                    },
+                    url : "../api.php",
+                    beforeSend :  function(data){
+
+                        $('#Canvas').html('<p>请求处理中...</p>');
+                    },
+                    success :     function(data){
+                        Process(data);
+                    },
+                    error :       function(request, errtext, e){
+                        $('#Canvas').html('<p><b>发生错误</b></p><p>'+request.status+'<br/>'+errtext+'</p>');
+                    }
+                });
+            });
+        });
+    </script>
+</head>
+<body>
+<div id="head"><p>数据中心向回朔系统最近交易日日k数据</p></div>
+<div id="content">
+    <div id="left">
+        <div class ="message"><p>接口返回:</p></div>
+        <div id="Canvas" class="Canvas"></div>
+    </div>
+    <div id="right">
+        <div class ="message"><p>请求数据:</p></div>
+        <form>
+            <p>
+                <span>method:</span>
+                <input type="text" class="input-text"  name="method" value="stock_least_day"/>
+            </p>
+
+            <p>
+                <span>timestamp:</span>
+                <input type="text" class="input-text"  name="timestamp" value="11111111" />
+            </p>
+
+
+            <p>
+                <span>code</span>
+                <input type="text" class="input-text"  name="code" value="600004"/>
+            </p>
+
+
+            <p>
+                <span>date</span>
+                <input type="text" class="input-text"  name="date" value=20201210 />
+            </p>
+            <p>
+                <span>fq_price:前复权-1,不复权-0</span>
+                <input type="text" class="input-text"  name="fq_price" value=1 />
+            </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>
+    </div>
+</div>
+
+
+</body>
+</html>

+ 109 - 0
api/v1.0/stock_least_day.php

@@ -0,0 +1,109 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: wanggagtao
+ * Date: 2019/4/18
+ * Time: 10:47 AM
+ * 获取某天的数据,当改天数据不存在,返回离该天最近的天的数据
+ * 获取某天的数据,当某天数据不存在,返回空
+ */
+require_once('debug_log.php');
+
+try {
+    $code = isset($_GET['code'])?safeCheck($_GET['code'],1):0;
+    $date = isset($_GET['date'])?safeCheck($_GET['date'],1):0;
+    $fq_price = isset($_GET['fq_price'])?safeCheck($_GET['fq_price'],1):0;
+
+
+    if(empty($code))
+    {
+        echo action_msg("code参数不能为空",101);
+        return ;
+    }
+    else if($fq_price!=0 && $fq_price!=1)
+    {
+        echo action_msg("fq_price参数不正确",101);
+        return ;
+    }
+    else  if(empty($date))
+    {
+        echo action_msg("date参数不能为空",101);
+        return ;
+    }
+
+    $stock_info=Day_k::get_least_day_k($code,$date,$fq_price);
+
+    if(!empty($stock_info))
+    {
+        $params=array();
+        if($fq_price==1)
+        {
+            $params['message_code']=API::SUCCESS;
+            $params['message']=API::SUCCESS_MSG;
+            $params["code"]=$stock_info["code"];
+            $params["name"]=$stock_info["name"];
+            $params["date"]=$stock_info["date"];//取数据的时期
+
+            $params["fg_price"]=$fq_price;
+            $params["open_price"]=$stock_info["qfq_open_price"];
+            $params["close_price"]=$stock_info["qfq_close_price"];
+            $params["highest_price"]=$stock_info["qfq_highest_price"];
+            $params["lowest_price"]=$stock_info["qfq_lowest_price"];
+
+            $params["amount"]=$stock_info["amount"];
+            $params["value"]=$stock_info["value"];
+
+            $params["increase_sign"]="";
+            $params["up_price"]="";
+            $params["down_price"]="";
+            $params["if_st"]="";
+
+            $params["increase_ratio"]=$stock_info["increase_ratio"];
+            $params["increase_price"]=$stock_info["increase_price"];
+            $params["m5"]=$stock_info["m5"];
+            $params["m10"]=$stock_info["m10"];
+            $params["m20"]=$stock_info["m20"];
+            $params["m30"]=$stock_info["m30"];
+            $params["m60"]=$stock_info["m60"];
+            $params["m233"]=$stock_info["m233"];
+
+        }
+        else if($fq_price==0)
+        {
+            $params['message_code']=API::SUCCESS;
+            $params['message']=API::SUCCESS_MSG;
+            $params["code"]=$stock_info["code"];
+            $params["name"]=$stock_info["name"];
+            $params["date"]=$stock_info["date"];//取数据的时期
+
+            $params["fg_price"]=$fq_price;
+            $params["open_price"]=$stock_info["open_price"];
+            $params["close_price"]=$stock_info["close_price"];
+            $params["highest_price"]=$stock_info["highest_price"];
+            $params["lowest_price"]=$stock_info["lowest_price"];
+            $params["amount"]=$stock_info["amount"];
+            $params["value"]=$stock_info["value"];    //不复权价格
+
+            $params["increase_sign"]="";
+            $params["up_price"]="";
+            $params["down_price"]="";
+            $params["if_st"]="";
+
+            $params["increase_ratio"]=$stock_info["increase_ratio"];
+            $params["increase_price"]=$stock_info["increase_price"];
+            $params["m5"]=$stock_info["m5"];
+            $params["m10"]=$stock_info["m10"];
+            $params["m20"]=$stock_info["m20"];
+            $params["m30"]=$stock_info["m30"];
+            $params["m60"]=$stock_info["m60"];
+            $params["m233"]=$stock_info["m233"];
+        }
+        echo action_array($params);
+    }
+    else
+    {
+        echo action_msg(API::EMPTY_STOCK_MSG,API::EMPTY_STOCK);
+    }
+}catch (MyException $e){
+    $api->ApiError($e->getCode(), $e->getMessage());
+}

+ 5 - 1
lib/day_k.class.php

@@ -53,7 +53,11 @@ class Day_k {
         $Table_day_k = new Table_day_k();
         return $Table_day_k->get_current_day_k($code,$date,$fq_price);
     }
-
+    static public function get_least_day_k($code,$date,$fq_price)
+    {
+        $Table_day_k = new Table_day_k();
+        return $Table_day_k->get_least_day_k($code,$date,$fq_price);
+    }
 
     /***
      * @param $attrs

+ 51 - 0
lib/table/table_day_k.class.php

@@ -423,6 +423,57 @@ class Table_day_k extends Table {
 
     }
 
+    public function get_least_day_k($code,$date,$fq_price=0)
+    {
+        if($fq_price==0)//不复权
+        {
+            //查询语句必须用sql_check_input检查参数
+            $stock_code = $this->pdo->sql_check_input(array('string', $code));//类型是字符串,那一定要在条件中将数据使用引号引用起来,否则不使用索引
+            $sql = "select * from ". $this->table_fullname ." where 1=1 ";
+            $where =" and day_k_code=".$stock_code  ;
+            $where.=" and day_k_date <= ".$date;
+
+            $sql.=$where;
+            $order=" order by day_k_date desc limit 1 ";
+            $sql.=$order;
+            $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;
+            }
+
+        }else if($fq_price==1)//  复权
+        {
+//查询语句必须用sql_check_input检查参数
+            $stock_code = $this->pdo->sql_check_input(array('string', $code));//类型是字符串,那一定要在条件中将数据使用引号引用起来,否则不使用索引
+            $sql = "select * from ". $this->table_fullname ." where 1=1 ";
+            $where =" and day_k_code=".$stock_code  ;
+            $where.=" and day_k_date <= ".$date;
+            $sql.=$where;
+            $order=" order by day_k_date desc limit 1 ";
+            $sql.=$order;
+            $sql=" select * from(".$sql.")a left join boniu_day_k_qfq b on a.day_k_code=b.day_k_qfq_code and b.day_k_qfq_date=a.day_k_date ";
+            $rs = $this->pdo->sqlQuery($sql);
+            $r  = array();
+            if($rs){
+                foreach($rs as $key => $val){
+
+
+                    $r[$key] = $this->dataToAttr2($val);
+                }
+                return $r[0];
+            }else{
+                return $r;
+            }
+        }
+
+    }
 
 }
 ?>