table_index_day_k.class.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 王刚涛
  5. * Date: 2020/11/24
  6. * Time: 14:51
  7. */
  8. class Table_index_day_k extends Table {
  9. protected $table_name = "index_day_k";//表名,不带前缀,前缀在config中定义
  10. protected $table_id = "index_day_k_id";//指定ID字段名称,必须
  11. //数据库结构
  12. protected function struct(){
  13. $attr = array();
  14. $attr['id'] = 'index_day_k_id';
  15. $attr['timestamp'] = 'index_day_k_timestamp';
  16. $attr['date'] = 'index_day_k_date';
  17. $attr['code'] = 'index_day_k_code';
  18. $attr['name'] = 'index_day_k_name';
  19. $attr['open_price'] = 'index_day_k_open_price';
  20. $attr['close_price'] = 'index_day_k_close_price';
  21. $attr['highest_price'] = 'index_day_k_highest_price';
  22. $attr['lowest_price'] = 'index_day_k_lowest_price';
  23. $attr['increase_price'] = 'index_day_k_increase_price';
  24. $attr['increase_ratio'] = 'index_day_k_increase_ratio';
  25. $attr['amount'] = 'index_day_k_amount';
  26. $attr['value'] = 'index_day_k_value';
  27. return $attr;
  28. }
  29. public function getIndexListHistroy($start_date,$end_date,$index_type)
  30. {
  31. //查询语句必须用sql_check_input检查参数
  32. $start_date= $this->pdo->sql_check_input(array('number', $start_date));
  33. $end_date = $this->pdo->sql_check_input(array('number', $end_date));
  34. $sql = "select * from ". $this->table_fullname ." where 1=1 ";
  35. if($index_type==1){
  36. $stock_code="000001";
  37. $sql.=" and index_day_k_code=".$stock_code ;
  38. }else if($index_type==2){
  39. $stock_code="399001";
  40. $sql.=" and index_day_k_code=".$stock_code ;
  41. }else if($index_type==3){
  42. $stock_code="000016";
  43. $sql.=" and index_day_k_code=".$stock_code ;
  44. }else if($index_type==4){
  45. $stock_code="399300";
  46. $sql.=" and index_day_k_code=".$stock_code ;
  47. }else if($index_type==5){
  48. $stock_code="399006";
  49. $sql.=" and index_day_k_code=".$stock_code ;
  50. }else if($index_type==6){
  51. $stock_code="000688";
  52. $sql.=" and index_day_k_code=".$stock_code ;
  53. }
  54. $where =" and index_day_k_timestamp between ".$start_date." and ".$end_date ;
  55. $sql.=$where;
  56. $order=" order by index_day_k_timestamp desc";
  57. $sql.=$order;
  58. var_dump($sql);
  59. $rs = $this->pdo->sqlQuery($sql);
  60. $r = array();
  61. if($rs){
  62. foreach($rs as $key => $val){
  63. $r[$key] = $this->dataToAttr($val);
  64. }
  65. return $r;
  66. }else{
  67. return $r;
  68. }
  69. }
  70. public function add($attr){
  71. $param = array (
  72. 'index_day_k_timestamp' => array('number', $attr['timestamp']),
  73. 'index_day_k_date' => array('number', $attr['date']),
  74. 'index_day_k_code' => array('string', $attr['code']),
  75. 'index_day_k_name' => array('string', $attr['name']),
  76. 'index_day_k_open_price' => array('number', $attr['open_price']),
  77. 'index_day_k_close_price' => array('number', $attr['close_price']),
  78. 'index_day_k_highest_price' => array('number', $attr['highest_price']),
  79. 'index_day_k_lowest_price' => array('number', $attr['lowest_price']),
  80. 'index_day_k_increase_price' => array('number', $attr['increase_price']),
  81. 'index_day_k_increase_ratio' => array('number', $attr['increase_ratio']),
  82. 'index_day_k_amount' => array('number', $attr['amount']),
  83. 'index_day_k_value' => array('number', $attr['value']), );
  84. return $this->pdo->sqlinsert($this->table_fullname, $param);
  85. }
  86. /***
  87. * @param $attr
  88. * @return mixed
  89. * 历史指数数据
  90. */
  91. public function insert($attr){
  92. $param = array (
  93. 'index_day_k_timestamp' => array('number', $attr['timestamp']),
  94. 'index_day_k_date' => array('number', $attr['date']),
  95. 'index_day_k_code' => array('string', $attr['code']),
  96. 'index_day_k_name' => array('string', $attr['name']),
  97. 'index_day_k_open_price' => array('number', $attr['open_price']),
  98. 'index_day_k_close_price' => array('number', $attr['close_price']),
  99. 'index_day_k_highest_price' => array('number', $attr['highest_price']),
  100. 'index_day_k_lowest_price' => array('number', $attr['lowest_price']),
  101. 'index_day_k_increase_price' => array('number', $attr['increase_price']),
  102. 'index_day_k_increase_ratio' => array('number', $attr['increase_ratio']),
  103. 'index_day_k_amount' => array('number', $attr['amount']),
  104. 'index_day_k_value' => array('number', $attr['value']), );
  105. return $this->pdo->sqlinsert($this->table_fullname, $param);
  106. }
  107. }
  108. ?>