wanggangtao 5 years ago
parent
commit
f2ab9e13c4

+ 0 - 5
data/get_boniu_index_csi300.php

@@ -8,9 +8,4 @@
  */
 require('../init.php');
 
-
-/***
- * 1。获取所有的股票代码
- * 2.遍历股票代码,住区数据,插入到数据库中
- */
 Sina::get_boniu_index_csi300();

+ 20 - 8
data/get_day_k_base.php

@@ -4,18 +4,30 @@
  * User: 王刚涛
  * Date: 2020/11/24
  * Time: 19:16
- * 获取某天的某个股票的数据
+ * 获取某天的某个股票的数据,
  */
 require('../init.php');
 
-
 /***
  * 1。获取所有的股票代码
- * 2.遍历股票代码,住区数据,插入到数据库中
+ * 2.遍历股票代码,获取数据,插入到数据库中
+ * 3.传入日期,若不传如期,则日期为当天
  */
 
-//$date=date('Ym');
-//$code=601006;
-$date = safeCheck($_GET['date'], 0);
-$code = safeCheck($_GET['code'],1);
-Sina::get_day_k_base($code,$date);//默认是今天
+$date = isset($_GET['date'])?safeCheck($_GET['date'],0):'0';//传入日期
+if(empty($date))//不传日期默认是当天
+{
+    $date = date('Ym',time());//202011
+}
+
+$codeList=Stock::getStockCodeList();//获取所有股票代码
+if (empty($codeList))
+{
+    throw new Exception('参数列表不能为空', 102);
+}
+//遍历股票代码
+
+foreach($codeList as $key => $val){
+        $code=intval($val["code"]);
+        Sina::get_day_k_base($code,$date);
+}

+ 9 - 13
lib/sina.class.php

@@ -38,7 +38,6 @@ class Sina
         if (empty($codeList)) {
             return 0;
         }
-
         $curlHandle = curl_init();
         curl_setopt($curlHandle, CURLOPT_URL, $url);
         curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
@@ -103,16 +102,16 @@ class Sina
     {
         if (strncmp($code, "30", 2) == 0) {
             //创业板
-            $code .= "sz";
+            $code= "sz". $code;
         } else if (strncmp($code, "68", 2) == 0) {
             //科创板
-            $code .= "sh";
+            $code= "sh" .$code;
         } else if (strncmp($code, "60", 2) == 0) {
             //主板
-            $code .= "sh";
+            $code = "sh".$code;
         } else if (strncmp($code, "00", 2) == 0) {
             //中小板
-            $code .= "sz";
+            $code= "sz".$code;
         }
         return $code;
 
@@ -267,13 +266,6 @@ class Sina
      * 根据股票代码获取股票的实时信息
      */
     static public function get_info_code($code){
-//        $stock_code = $code;
-//        $f = substr($stock_code, 0, 1);
-//        if ($f == "6"  || $f == "0" ) {
-//            $stock_code = "sh" . $code;
-//        } else {
-//            $stock_code = "sz" . $code;
-//        }
         $stock_code= self::get_boniu_block($code);
         $url = "http://hq.sinajs.cn/list=" . $stock_code;
         $content3=sina::curl_get_data($url);//封装为函数,执行url获取结果并解析
@@ -299,8 +291,12 @@ class Sina
         $stock_code= self::get_boniu_block($code);
         $url = "http://hq.sinajs.cn/list=" . $stock_code;
         $content3=sina::curl_get_data($url);//封装为函数,
+        if (empty($content3))
+        {
+            throw new Exception('抓取的数据不能为空', 102);
+        }
         $data['date'] = $content3[30];
-        $data['code'] = $stock_code;
+        $data['code'] = $code;//股票代码此时去掉sh,sz
         $data['open_price'] = $content3[1];//开盘价
         $data['close_price'] = $content3[3];//3点之后的当前价格就是收盘价
         $data['hightest_price'] = $content3[4];//今日最高价

+ 2 - 1
lib/table/table_day_k_base.class.php

@@ -76,7 +76,8 @@ class Table_day_k_base extends Table {
              'day_k_date'    => array('number', strtotime($attr['date'])),
              'day_k_code'    => array('number', $attr['code']),
              'day_k_open_price'    => array('number', $attr['open_price']),
-             'day_k_hightest_price'    => array('number', $attr['hightest_price']),
+             'day_k_close_price'    => array('number', $attr['close_price']),
+            'day_k_hightest_price'    => array('number', $attr['hightest_price']),
              'day_k_lowest_price'    => array('number', $attr['lowest_price']),
              'day_k_amount'    => array('number', $attr['amount']),
              'day_k_value'    => array('number', $attr['value']),