Quellcode durchsuchen

Merge branch 'master' of http://121.40.40.223:3000/wiipu/boniu

chenbo vor 5 Jahren
Ursprung
Commit
d2241c0099

+ 1 - 2
data/get_boniu_index_csi300.php

@@ -14,5 +14,4 @@ require('../init.php');
  * 2.遍历股票代码,住区数据,插入到数据库中
  */
 
-
-sina::get_boniu_index_csi300();//默认是今天
+var_dump(Sina::get_boniu_index_csi300());

+ 1 - 1
data/get_boniu_index_gem.php

@@ -9,4 +9,4 @@
 require('../init.php');
 
 
-sina::get_boniu_index_gem();//默认是今天
+Sina::get_boniu_index_gem();//默认是今天

+ 1 - 1
data/get_boniu_index_kc50.php

@@ -15,4 +15,4 @@ require('../init.php');
  */
 
 
-sina::get_boniu_index_kc50();//默认是今天
+Sina::get_boniu_index_kc50();//默认是今天

+ 1 - 1
data/get_boniu_index_scz.php

@@ -12,4 +12,4 @@ require('../init.php');
 
 
 
-sina::get_boniu_index_scz();//默认是今天
+Sina::get_boniu_index_scz();//默认是今天

+ 1 - 1
data/get_boniu_index_sh.php

@@ -15,4 +15,4 @@ require('../init.php');
  */
 
 
-sina::get_boniu_index_sh();//默认是今天
+Sina::get_boniu_index_sh();//默认是今天

+ 1 - 1
data/get_boniu_index_sh50.php

@@ -15,4 +15,4 @@ require('../init.php');
  */
 
 
-sina::get_boniu_index_sh50();//默认是今天
+Sina::get_boniu_index_sh50();//默认是今天

+ 1 - 1
data/get_day_k_base.php

@@ -16,4 +16,4 @@ require('../init.php');
 
 $date=date('Ym');
 $code=601006;
-sina::get_day_k_base($code,$date);//默认是今天
+Sina::get_day_k_base($code,$date);//默认是今天

+ 18 - 0
data/get_history_trade_data.php

@@ -0,0 +1,18 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 王刚涛
+ * Date: 2020/11/24
+ * Time: 19:16
+ * 获取某天的某个股票的数据
+ */
+require('../init.php');
+
+//$end_date = date("Ymd", time());
+//$start_date = date("Ymd", time() - 86400 * 10);
+//var_dump($end_date);
+//die;
+$end_date = "20201030";
+$start_date = "20201001";;
+
+$meg=Finance163::get_history_trade_data(601006,$start_date,$end_date);

+ 22 - 3
lib/day_k_base.class.php

@@ -13,7 +13,7 @@ class Day_k_base {
      * @param $attrs
      * @return mixed
      * @throws Exception
-     * 添加信息
+     * 添加股票的某一天数据信息
      */
     static public function add($attrs,$date=0)
     {
@@ -27,8 +27,27 @@ class Day_k_base {
         return $id;
     }
 
-    
-	/** 
+    /***
+     * @param $attrs
+     * @param int $date
+     * @return mixed
+     * @throws Exception
+     * 添加某一直股票的历史数据
+     */
+    static public function insert($attrs,$date=0)
+    {
+        if (empty($attrs)) throw new Exception('参数不能为空', 102);
+        if($date===0)
+        {
+            $date=strtotime(date('Ym'));
+        }
+        $Table_day_k_base = new Table_day_k_base($date);
+        $id = $Table_day_k_base->insert($attrs);
+        return $id;
+    }
+
+
+    /**
 	 * 管理员日志记录列表
 	 * 
 	 * @param $page        当前页

+ 87 - 0
lib/finance163.class.php

@@ -0,0 +1,87 @@
+<?php
+
+/**
+ * Created by PhpStorm.
+ * User: 王刚涛
+ * Date: 2020/11/26
+ * Time: 11:38
+ */
+class Finance163
+{
+    /****
+     * @param $code
+     * @return string
+     * 返回股票所属的板块,在股票代码前拼接0或者1
+     */
+    static public function stock_block($code)
+    {
+        $f = substr($code, 0, 1);
+        if ($f == "6") {
+            $stock_code = "0" . $code;
+        } else {
+            $stock_code = "1" . $code;
+        }
+        return $stock_code;
+    }
+
+    /***
+     * @param $code
+     * @return int
+     * 获取历史交易数据
+     */
+    static public function get_history_trade_data($stock_code,$start_date,$end_date)
+    {
+        $code = self::stock_block($stock_code);
+        $url = "http://quotes.money.163.com/service/chddata.html?code=" . $code . "&start=" . $start_date . "&end=" . $end_date . "&fields=TOPEN;HIGH;LOW;TCLOSE;VATURNOVER;VOTURNOVER;LCLOSE;CHG;PCHG;TURNOVER";
+        //构建所要发送的url
+        $curlHandle = curl_init();
+        curl_setopt($curlHandle, CURLOPT_URL, $url);
+        curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($curlHandle, CURLOPT_SSL_VERIFYHOST, false);
+        curl_setopt($curlHandle, CURLOPT_TIMEOUT, 10);
+        $content = curl_exec($curlHandle);
+        curl_close($curlHandle);
+        $content1 = explode("\n", $content);//以换行符进行分割字符串
+        if (!empty($content1[1])) {
+            for ($i = count($content1) - 1; $i >0; $i--) {//排除日期,代码等标题栏
+                if (!empty($content1[$i])) {
+                    $content3 = explode(",", iconv("gbk", "utf-8", $content1[$i]));
+                }
+                else{
+                    continue;
+                }
+//                解析返回的历史数据
+                $t = explode("-",$content3[0]);
+                $date = trim($t[0].$t[1]);
+                $time = trim($t[0].$t[1].$t[2]);
+
+                $data['date'] = $date;//用于创建表
+                $data['time'] = $time;//用于获取时间戳
+                $data['code'] = intval(explode("'",$content3[1])[1]);
+                $data['open_price'] = floatval($content3[3]);
+                $data['hightest_price'] = floatval($content3[4]);
+                $data['lowest_price'] = floatval($content3[5]);
+                $data['close_price'] = floatval($content3[6]);
+                $data['value'] = floatval($content3[7]);
+                $data['amount'] = floatval($content3[8]);
+                $data['close_price_qfq'] = floatval($content3[9]);
+                $data['increase_price'] = floatval($content3[10]);
+                $data['increase_value'] = floatval($content3[11]);
+                $data['turnover'] = floatval($content3[12]);//换手率
+                //将所要存储的数据放入一个数组中
+                $stock_name = $content3[1];
+                if ($data['close_price'] == 0) {//当收盘价为0的时候,表示此时的基于9-3点,所以不存储
+                    continue;
+                }
+                if (!empty($data)) {
+//                    Index::add($stock_name, $content3[0]);//将这支股票的股票名称和股票代码存入
+                    $msg= Day_k_base::insert($data,$date);//将这支股票的历史数据存入数据库
+                }
+            }
+        }
+        return $msg;
+    }
+}
+
+?>

+ 11 - 14
lib/index_csi300.class.php

@@ -8,26 +8,23 @@
 
 class Index_csi300 {
 
-	/**
-	 * 记录管理员日志
-	 * 
-	 * @param $log       日志内容
-	 * 
-	 */
+    /****
+     * @param $attrs
+     * @return mixed
+     * @throws Exception
+     *
+     */
 	static public function add($attrs){
         if (empty($attrs)) throw new Exception('参数不能为空', 102);
         $Table_index_csi300 = new Table_index_csi300();
         $id = $Table_index_csi300->add($attrs);
         return $id;
 	}
-    
-	/** 
-	 * 管理员日志记录列表
-	 * 
-	 * @param $page        当前页
-	 * @param $pagesize    每页大小
-	 * 
-	 */
+
+    /****
+     * @param $page
+     * @param $pagesize
+     */
 	static public function getListByPage($page, $pagesize){
 		$filter = array();
 

+ 34 - 8
lib/sina.class.php

@@ -26,7 +26,6 @@ class Sina
         $content3 = substr($content2, stripos($content2, "=\"") + 2); //获取 var hq_str_sz000002="万 科A,30.780,30.800,30.510,  ="之后部分
         $content4 = substr($content3, 0, strripos($content3, "\";")); //获取     万 科A,30.94,0.14,0.45,584039,178827";         ";之前部分
         $content5 = explode(",", $content4);//分割
-
         return $content5;
     }
 
@@ -106,6 +105,29 @@ class Sina
     }
 
     /****
+     * @param $code
+     * @return string
+     * 判断股票的类型,属于创业板,科创板,主板,$code
+     */
+    static public function get_boniu_block($code)
+    {
+        if (strncmp($code, "30", 2) == 0) {
+            //创业板
+            $code .= "sz";
+        } else if (strncmp($code, "68", 2) == 0) {
+            //科创板
+            $code .= "sh";
+        } else if (strncmp($code, "60", 2) == 0) {
+            //主板
+            $code .= "sh";
+        } else if (strncmp($code, "00", 2) == 0) {
+            //中小板
+            $code .= "sz";
+        }
+        return $code;
+
+    }
+    /****
      * @param string $code
      * @return mixed
     //上证指数表(boniu_index_sh)
@@ -255,13 +277,14 @@ 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 = $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获取结果并解析
         return $content3;
@@ -298,6 +321,9 @@ class Sina
 
 //除权除息表(boniu_xrxd_log)
 //st记录表(boniu_st_log)
+
+
+//获取历史数据的表
 }
 
 ?>

+ 28 - 0
lib/table/table_day_k_base.class.php

@@ -86,6 +86,34 @@ class Table_day_k_base extends Table {
         return $msg;
     }
 
+
+    /****
+     * @param $attr
+     * @return mixed
+     *
+     */
+    public function insert($attr){
+        $param = array (
+            '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_lowest_price'    => array('number', $attr['lowest_price']),
+            'day_k_value'    => array('number', $attr['value']),
+            'day_k_amount'    => array('number', $attr['amount']),
+            'day_k_close_price'    => array('number', $attr['close_price']),
+            'day_k_close_price_qfq'    => array('number', $attr['close_price_qfq']),
+            'day_k_increase_price'    => array('number', $attr['increase_price']),
+            'day_k_increase_value'    => array('number', $attr['increase_value']),
+            'day_k_turnover'    => array('number', $attr['turnover']),
+
+        );
+
+        $msg=$this->pdo->sqlinsert($this->table_fullname, $param);
+        return $msg;
+    }
+
+
     //获取列表(分页)
     //$count、$page和$pagesize都为0时,返回全部结果(适用于无需分页的情况)
     //