table_index_day_k.class.php 7.2 KB

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