table_index_day_k.class.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 index_recent_days($code,$start_date,$traceback_days,$order)
  30. {
  31. //查询语句必须用sql_check_input检查参数
  32. $stock_code = $this->pdo->sql_check_input(array('string', $code));//类型是字符串,那一定要在条件中将数据使用引号引用起来,否则不使用索引
  33. $sql = "select * from ". $this->table_fullname ." where 1=1 ";
  34. $where =" and index_day_k_code=".$stock_code." and index_day_k_date <=".$start_date ;
  35. $sql.=$where;
  36. $orderInfo=" ORDER BY index_day_k_date desc";
  37. $sql.=$orderInfo;
  38. $limit=" limit ".$traceback_days;
  39. $sql.=$limit;
  40. if($order==1){
  41. $sql= " SELECT a.* FROM "."($sql) a ORDER BY a.index_day_k_date desc ";
  42. }else{
  43. $sql= " SELECT a.* FROM "."($sql) a ORDER BY a.index_day_k_date asc";
  44. }
  45. $rs = $this->pdo->sqlQuery($sql);
  46. $r = array();
  47. if($rs){
  48. foreach($rs as $key => $val){
  49. $r[$key] = $this->dataToAttr($val);
  50. }
  51. return $r;
  52. }else{
  53. return $r;
  54. }
  55. }
  56. /***
  57. * @param $code
  58. * @param $date
  59. * @return array
  60. * wanggangtao
  61. * 获取某天的指数代码
  62. */
  63. public function get_current_day_index($code,$date)
  64. {
  65. //查询语句必须用sql_check_input检查参数
  66. $stock_code = $this->pdo->sql_check_input(array('string', $code));//类型是字符串,那一定要在条件中将数据使用引号引用起来,否则不使用索引
  67. $sql = "select * from ". $this->table_fullname ;
  68. $where=" where 1=1 ";
  69. $where.=" and index_day_k_code=".$stock_code ;
  70. if($date==0){//获取的是当天的数据,最近一天的交易日的数据
  71. $date = date("Ymd",time());
  72. $where.=" and index_day_k_date <= ".$date;
  73. }else{//获取某一天的数据,不是交易日则返回空
  74. $date = $this->pdo->sql_check_input(array('number', $date));
  75. $where.=" and index_day_k_date =".$date;
  76. }
  77. $sql.=$where;
  78. $order=" order by index_day_k_date desc limit 1 ";
  79. $sql.=$order;
  80. $rs = $this->pdo->sqlQuery($sql);
  81. $r = array();
  82. if($rs){
  83. foreach($rs as $key => $val){
  84. $r[$key] = $this->dataToAttr($val);
  85. }
  86. return $r[0];
  87. }else{
  88. return $r;
  89. }
  90. }
  91. /****
  92. * @param $start_date
  93. * @param $end_date
  94. * @param $index_type
  95. * @param $num
  96. * @param $order_info
  97. * @return array
  98. * wanggangtao
  99. */
  100. public function getIndexListHistroy($code,$start_date,$end_date,$order_info)
  101. {
  102. //查询语句必须用sql_check_input检查参数
  103. $stock_code= $this->pdo->sql_check_input(array('string', $code));
  104. $start_date= $this->pdo->sql_check_input(array('number', $start_date));
  105. $end_date = $this->pdo->sql_check_input(array('number', $end_date));
  106. $sql = "select * from ". $this->table_fullname ." where 1=1 ";
  107. $sql.=" and index_day_k_code=".$stock_code ;
  108. $where =" and index_day_k_date >= ".$start_date." and index_day_k_date<=".$end_date ;
  109. $sql.=$where;
  110. if($order_info==1){
  111. $order=" order by index_day_k_date desc ";
  112. }else{
  113. $order=" order by index_day_k_date asc ";
  114. }
  115. $sql.=$order;
  116. $rs = $this->pdo->sqlQuery($sql);
  117. $r = array();
  118. if($rs){
  119. foreach($rs as $key => $val){
  120. $r[$key] = $this->dataToAttr($val);
  121. }
  122. return $r;
  123. }else{
  124. return $r;
  125. }
  126. }
  127. public function add($attr){
  128. $param = array (
  129. 'index_day_k_timestamp' => array('number', $attr['timestamp']),
  130. 'index_day_k_date' => array('number', $attr['date']),
  131. 'index_day_k_code' => array('string', $attr['code']),
  132. 'index_day_k_name' => array('string', $attr['name']),
  133. 'index_day_k_open_price' => array('number', $attr['open_price']),
  134. 'index_day_k_close_price' => array('number', $attr['close_price']),
  135. 'index_day_k_highest_price' => array('number', $attr['highest_price']),
  136. 'index_day_k_lowest_price' => array('number', $attr['lowest_price']),
  137. 'index_day_k_increase_price' => array('number', $attr['increase_price']),
  138. 'index_day_k_increase_ratio' => array('number', $attr['increase_ratio']),
  139. 'index_day_k_amount' => array('number', $attr['amount']),
  140. 'index_day_k_value' => array('number', $attr['value']), );
  141. return $this->pdo->sqlinsert($this->table_fullname, $param);
  142. }
  143. /***
  144. * @param $attr
  145. * @return mixed
  146. * 历史指数数据
  147. */
  148. public function insert($attr){
  149. $param = array (
  150. 'index_day_k_timestamp' => array('number', $attr['timestamp']),
  151. 'index_day_k_date' => array('number', $attr['date']),
  152. 'index_day_k_code' => array('string', $attr['code']),
  153. 'index_day_k_name' => array('string', $attr['name']),
  154. 'index_day_k_open_price' => array('number', $attr['open_price']),
  155. 'index_day_k_close_price' => array('number', $attr['close_price']),
  156. 'index_day_k_highest_price' => array('number', $attr['highest_price']),
  157. 'index_day_k_lowest_price' => array('number', $attr['lowest_price']),
  158. 'index_day_k_increase_price' => array('number', $attr['increase_price']),
  159. 'index_day_k_increase_ratio' => array('number', $attr['increase_ratio']),
  160. 'index_day_k_amount' => array('number', $attr['amount']),
  161. 'index_day_k_value' => array('number', $attr['value']), );
  162. return $this->pdo->sqlinsert($this->table_fullname, $param);
  163. }
  164. }
  165. ?>