table_index_day_k.class.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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;
  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($start_date,$end_date,$index_type,$num,$order_info)
  101. {
  102. //查询语句必须用sql_check_input检查参数
  103. $start_date= $this->pdo->sql_check_input(array('number', $start_date));
  104. $end_date = $this->pdo->sql_check_input(array('number', $end_date));
  105. $sql = "select * from ". $this->table_fullname ." where 1=1 ";
  106. if($index_type==1){
  107. $stock_code="000001";
  108. $sql.=" and index_day_k_code=".$stock_code ;
  109. }else if($index_type==2){
  110. $stock_code="399001";
  111. $sql.=" and index_day_k_code=".$stock_code ;
  112. }else if($index_type==3){
  113. $stock_code="000016";
  114. $sql.=" and index_day_k_code=".$stock_code ;
  115. }else if($index_type==4){
  116. $stock_code="399300";
  117. $sql.=" and index_day_k_code=".$stock_code ;
  118. }else if($index_type==5){
  119. $stock_code="399006";
  120. $sql.=" and index_day_k_code=".$stock_code ;
  121. }else if($index_type==6){
  122. $stock_code="000688";
  123. $sql.=" and index_day_k_code=".$stock_code ;
  124. }
  125. $where =" and index_day_k_timestamp between ".$start_date." and ".$end_date ;
  126. $sql.=$where;
  127. if($order_info==1){
  128. $order=" order by index_day_k_timestamp desc ";
  129. }else{
  130. $order=" order by index_day_k_timestamp asc ";
  131. }
  132. $sql.=$order;
  133. $limit=" limit ".$num;
  134. $sql.=$limit;
  135. $rs = $this->pdo->sqlQuery($sql);
  136. $r = array();
  137. if($rs){
  138. foreach($rs as $key => $val){
  139. $r[$key] = $this->dataToAttr($val);
  140. }
  141. return $r;
  142. }else{
  143. return $r;
  144. }
  145. }
  146. public function add($attr){
  147. $param = array (
  148. 'index_day_k_timestamp' => array('number', $attr['timestamp']),
  149. 'index_day_k_date' => array('number', $attr['date']),
  150. 'index_day_k_code' => array('string', $attr['code']),
  151. 'index_day_k_name' => array('string', $attr['name']),
  152. 'index_day_k_open_price' => array('number', $attr['open_price']),
  153. 'index_day_k_close_price' => array('number', $attr['close_price']),
  154. 'index_day_k_highest_price' => array('number', $attr['highest_price']),
  155. 'index_day_k_lowest_price' => array('number', $attr['lowest_price']),
  156. 'index_day_k_increase_price' => array('number', $attr['increase_price']),
  157. 'index_day_k_increase_ratio' => array('number', $attr['increase_ratio']),
  158. 'index_day_k_amount' => array('number', $attr['amount']),
  159. 'index_day_k_value' => array('number', $attr['value']), );
  160. return $this->pdo->sqlinsert($this->table_fullname, $param);
  161. }
  162. /***
  163. * @param $attr
  164. * @return mixed
  165. * 历史指数数据
  166. */
  167. public function insert($attr){
  168. $param = array (
  169. 'index_day_k_timestamp' => array('number', $attr['timestamp']),
  170. 'index_day_k_date' => array('number', $attr['date']),
  171. 'index_day_k_code' => array('string', $attr['code']),
  172. 'index_day_k_name' => array('string', $attr['name']),
  173. 'index_day_k_open_price' => array('number', $attr['open_price']),
  174. 'index_day_k_close_price' => array('number', $attr['close_price']),
  175. 'index_day_k_highest_price' => array('number', $attr['highest_price']),
  176. 'index_day_k_lowest_price' => array('number', $attr['lowest_price']),
  177. 'index_day_k_increase_price' => array('number', $attr['increase_price']),
  178. 'index_day_k_increase_ratio' => array('number', $attr['increase_ratio']),
  179. 'index_day_k_amount' => array('number', $attr['amount']),
  180. 'index_day_k_value' => array('number', $attr['value']), );
  181. return $this->pdo->sqlinsert($this->table_fullname, $param);
  182. }
  183. }
  184. ?>