table_index_day_k.class.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. protected $table_status = '';//指定状态字段名称,如果有
  12. protected $table_order = '';//指定排序字段名称,如果有
  13. //数据库结构
  14. protected function struct(){
  15. $attr = array();
  16. $attr['id'] = 'index_day_k_id';
  17. $attr['timestamp'] = 'index_day_k_timestamp';
  18. $attr['date'] = 'index_day_k_date';
  19. $attr['code'] = 'index_day_k_code';
  20. $attr['name'] = 'index_day_k_name';
  21. $attr['open_price'] = 'index_day_k_open_price';
  22. $attr['close_price'] = 'index_day_k_close_price';
  23. $attr['highest_price'] = 'index_day_k_highest_price';
  24. $attr['lowest_price'] = 'index_day_k_lowest_price';
  25. $attr['increase_price'] = 'index_day_k_increase_price';
  26. $attr['increase_ratio'] = 'index_day_k_increase_ratio';
  27. $attr['amount'] = 'index_day_k_amount';
  28. $attr['value'] = 'index_day_k_value';
  29. return $attr;
  30. }
  31. public function add($attr){
  32. $param = array (
  33. 'index_day_k_timestamp' => array('number', $attr['timestamp']),
  34. 'index_day_k_date' => array('number', $attr['date']),
  35. 'index_day_k_code' => array('string', $attr['code']),
  36. 'index_day_k_name' => array('string', $attr['name']),
  37. 'index_day_k_open_price' => array('number', $attr['open_price']),
  38. 'index_day_k_close_price' => array('number', $attr['close_price']),
  39. 'index_day_k_highest_price' => array('number', $attr['highest_price']),
  40. 'index_day_k_lowest_price' => array('number', $attr['lowest_price']),
  41. 'index_day_k_increase_price' => array('number', $attr['increase_price']),
  42. 'index_day_k_increase_ratio' => array('number', $attr['increase_ratio']),
  43. 'index_day_k_amount' => array('number', $attr['amount']),
  44. 'index_day_k_value' => array('number', $attr['value']),
  45. );
  46. return $this->pdo->sqlinsert($this->table_fullname, $param);
  47. }
  48. //-------------------------------
  49. /***
  50. * @param $code
  51. * @param $date
  52. * @return array
  53. * wanggangtao
  54. * 获取某天的指数代码
  55. */
  56. public function get_current_day_index($code,$date)
  57. {
  58. //查询语句必须用sql_check_input检查参数
  59. $stock_code = $this->pdo->sql_check_input(array('string', $code));//类型是字符串,那一定要在条件中将数据使用引号引用起来,否则不使用索引
  60. $sql = "select * from ". $this->table_fullname ;
  61. $where=" where 1=1 ";
  62. $where.=" and index_day_k_code=".$stock_code ;
  63. if($date==0){//获取的是当天的数据,最近一天的交易日的数据
  64. $date = date("Ymd",time());
  65. $where.=" and index_day_k_date <= ".$date;
  66. }else{//获取某一天的数据,不是交易日则返回空
  67. $date = $this->pdo->sql_check_input(array('number', $date));
  68. $where.=" and index_day_k_date =".$date;
  69. }
  70. $sql.=$where;
  71. $order=" order by index_day_k_date desc limit 1 ";
  72. $sql.=$order;
  73. $rs = $this->pdo->sqlQuery($sql);
  74. $r = array();
  75. if($rs){
  76. foreach($rs as $key => $val){
  77. $r[$key] = $this->dataToAttr($val);
  78. }
  79. return $r[0];
  80. }else{
  81. return $r;
  82. }
  83. }
  84. /****
  85. * @param $start_date
  86. * @param $end_date
  87. * @param $index_type
  88. * @param $num
  89. * @param $order_info
  90. * @return array
  91. * wanggangtao
  92. */
  93. public function getIndexListHistroy($code,$start_date,$end_date,$order_info)
  94. {
  95. //查询语句必须用sql_check_input检查参数
  96. $stock_code= $this->pdo->sql_check_input(array('string', $code));
  97. $start_date= $this->pdo->sql_check_input(array('number', $start_date));
  98. $end_date = $this->pdo->sql_check_input(array('number', $end_date));
  99. $sql = "select * from ". $this->table_fullname ." where 1=1 ";
  100. $sql.=" and index_day_k_code=".$stock_code ;
  101. $where =" and index_day_k_date >= ".$start_date." and index_day_k_date<=".$end_date ;
  102. $sql.=$where;
  103. if($order_info==1){
  104. $order=" order by index_day_k_date desc ";
  105. }else{
  106. $order=" order by index_day_k_date asc ";
  107. }
  108. $sql.=$order;
  109. $rs = $this->pdo->sqlQuery($sql);
  110. $r = array();
  111. if($rs){
  112. foreach($rs as $key => $val){
  113. $r[$key] = $this->dataToAttr($val);
  114. }
  115. return $r;
  116. }else{
  117. return $r;
  118. }
  119. }
  120. /***
  121. * @param $attr
  122. * @return mixed
  123. * 历史指数数据
  124. */
  125. public function insert($attr){
  126. $param = array (
  127. 'index_day_k_timestamp' => array('number', $attr['timestamp']),
  128. 'index_day_k_date' => array('number', $attr['date']),
  129. 'index_day_k_code' => array('string', $attr['code']),
  130. 'index_day_k_name' => array('string', $attr['name']),
  131. 'index_day_k_open_price' => array('number', $attr['open_price']),
  132. 'index_day_k_close_price' => array('number', $attr['close_price']),
  133. 'index_day_k_highest_price' => array('number', $attr['highest_price']),
  134. 'index_day_k_lowest_price' => array('number', $attr['lowest_price']),
  135. 'index_day_k_increase_price' => array('number', $attr['increase_price']),
  136. 'index_day_k_increase_ratio' => array('number', $attr['increase_ratio']),
  137. 'index_day_k_amount' => array('number', $attr['amount']),
  138. 'index_day_k_value' => array('number', $attr['value']), );
  139. return $this->pdo->sqlinsert($this->table_fullname, $param);
  140. }
  141. }
  142. ?>