table_index_day_k.class.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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,$num,$order_info)
  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. if($order_info==1){
  57. $order=" order by index_day_k_timestamp desc ";
  58. }else{
  59. $order=" order by index_day_k_timestamp asc ";
  60. }
  61. $sql.=$order;
  62. $limit=" limit ".$num;
  63. $sql.=$limit;
  64. $rs = $this->pdo->sqlQuery($sql);
  65. $r = array();
  66. if($rs){
  67. foreach($rs as $key => $val){
  68. $r[$key] = $this->dataToAttr($val);
  69. }
  70. return $r;
  71. }else{
  72. return $r;
  73. }
  74. }
  75. public function add($attr){
  76. $param = array (
  77. 'index_day_k_timestamp' => array('number', $attr['timestamp']),
  78. 'index_day_k_date' => array('number', $attr['date']),
  79. 'index_day_k_code' => array('string', $attr['code']),
  80. 'index_day_k_name' => array('string', $attr['name']),
  81. 'index_day_k_open_price' => array('number', $attr['open_price']),
  82. 'index_day_k_close_price' => array('number', $attr['close_price']),
  83. 'index_day_k_highest_price' => array('number', $attr['highest_price']),
  84. 'index_day_k_lowest_price' => array('number', $attr['lowest_price']),
  85. 'index_day_k_increase_price' => array('number', $attr['increase_price']),
  86. 'index_day_k_increase_ratio' => array('number', $attr['increase_ratio']),
  87. 'index_day_k_amount' => array('number', $attr['amount']),
  88. 'index_day_k_value' => array('number', $attr['value']), );
  89. return $this->pdo->sqlinsert($this->table_fullname, $param);
  90. }
  91. /***
  92. * @param $attr
  93. * @return mixed
  94. * 历史指数数据
  95. */
  96. public function insert($attr){
  97. $param = array (
  98. 'index_day_k_timestamp' => array('number', $attr['timestamp']),
  99. 'index_day_k_date' => array('number', $attr['date']),
  100. 'index_day_k_code' => array('string', $attr['code']),
  101. 'index_day_k_name' => array('string', $attr['name']),
  102. 'index_day_k_open_price' => array('number', $attr['open_price']),
  103. 'index_day_k_close_price' => array('number', $attr['close_price']),
  104. 'index_day_k_highest_price' => array('number', $attr['highest_price']),
  105. 'index_day_k_lowest_price' => array('number', $attr['lowest_price']),
  106. 'index_day_k_increase_price' => array('number', $attr['increase_price']),
  107. 'index_day_k_increase_ratio' => array('number', $attr['increase_ratio']),
  108. 'index_day_k_amount' => array('number', $attr['amount']),
  109. 'index_day_k_value' => array('number', $attr['value']), );
  110. return $this->pdo->sqlinsert($this->table_fullname, $param);
  111. }
  112. }
  113. ?>