table_index_day_k.class.php 7.2 KB

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