table_stock.class.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * 数据库表:管理员组
  4. *
  5. * @createtime 2018/03/01
  6. * @author 空竹
  7. * @copyright 芝麻开发(http://www.zhimawork.com)
  8. */
  9. class Table_stock extends Table {
  10. protected $table_name = 'stock';//表名,不带前缀,前缀在config中定义
  11. protected $table_id = 'stock_id';//指定ID字段名称,必须
  12. protected $table_status = '';//指定状态字段名称,如果有
  13. protected $table_order = '';//指定排序字段名称,如果有
  14. //数据库结构
  15. protected function struct(){
  16. $attr = array();
  17. $attr['id'] = 'stock_id';
  18. $attr['code'] = 'stock_code';
  19. $attr['name'] = 'stock_name';
  20. $attr['exchange'] = 'stock_exchange';
  21. $attr['sector'] = 'stock_sector';
  22. return $attr;
  23. }
  24. public function add($attr){
  25. $param = array (
  26. 'stock_code' => array('string', $attr['code']),
  27. 'stock_name' => array('string', $attr['name']),
  28. 'stock_exchange' => array('string', $attr['exchange']),
  29. 'stock_sector' => array('number', $attr['sector']),
  30. );
  31. return $this->pdo->sqlinsert($this->table_fullname, $param);
  32. }
  33. /***
  34. * @param array $filter
  35. * @param int $count
  36. * @param int $page
  37. * @param int $pagesize
  38. * @return array
  39. * 获取代码列表
  40. * 王刚涛
  41. */
  42. public function getStockCodeList(){
  43. $where="where 1=1";
  44. $sql = "select "."`*`". "from ". $this->table_fullname ." $where order by ".$this->table_id." asc";
  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. public function getStockList($filter = array(), $count = 0, $page = 0, $pagesize = 0){
  57. $where=" ";
  58. if(!empty($filter["sector"])){
  59. $where = $this->filterToWhere($filter);
  60. }
  61. if($count == 0){//列表
  62. if($page==0 ||$page==-1 ){//表示不分页
  63. $sql = "select * from ". $this->table_fullname ." $where order by ".$this->table_id." desc";
  64. }else{//表示不分页
  65. $sql = "select * from ". $this->table_fullname ." $where order by ".$this->table_id." desc";
  66. if($page > 0){//分页
  67. $startrow = ($page - 1) * $pagesize;
  68. $sql_limit = " limit $startrow, $pagesize";
  69. $sql .= $sql_limit;
  70. }
  71. }
  72. $rs = $this->pdo->sqlQuery($sql);
  73. $r = array();
  74. if($rs){
  75. foreach($rs as $key => $val){
  76. $r[$key] = $this->dataToAttr($val);
  77. }
  78. return $r;
  79. }else{
  80. return $r;
  81. }
  82. }else{//统计
  83. $sql = "select count(*) as c from ". $this->table_fullname . " $where ";
  84. $rs = $this->pdo->sqlQuery($sql);
  85. if($rs){
  86. return $rs[0]['c'];
  87. }else{
  88. return 0;
  89. }
  90. }
  91. }
  92. /***
  93. * @param $code
  94. * @return array|mixed
  95. * wanggangtao
  96. */
  97. public function getInfoByCode($code){
  98. //查询语句必须用sql_check_input检查参数
  99. $code = trim($code);
  100. $code = $this->pdo->sql_check_input(array('string', $code));
  101. $sql = "select * from ". $this->table_fullname ." where stock_code = $code limit 1";
  102. $rs = $this->pdo->sqlQuery($sql);
  103. $r = array();
  104. if($rs){
  105. foreach($rs as $key => $val){
  106. $r[$key] = $this->dataToAttr($val);
  107. }
  108. return $r[0];
  109. }else{
  110. return $r;
  111. }
  112. }
  113. }
  114. ?>