table_stock.class.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. public function getStockList($filter = array(), $count = 0, $page = 0, $pagesize = 0){
  34. $where=" ";
  35. if(!empty($filter["sector"])){
  36. $where = $this->filterToWhere($filter);
  37. }
  38. if($count == 0){//列表
  39. if($page==0 ||$page==-1 ){//表示不分页
  40. $sql = "select * from ". $this->table_fullname ." $where order by ".$this->table_id." desc";
  41. }else{//表示不分页
  42. $sql = "select * from ". $this->table_fullname ." $where order by ".$this->table_id." desc";
  43. if($page > 0){//分页
  44. $startrow = ($page - 1) * $pagesize;
  45. $sql_limit = " limit $startrow, $pagesize";
  46. $sql .= $sql_limit;
  47. }
  48. }
  49. $rs = $this->pdo->sqlQuery($sql);
  50. $r = array();
  51. if($rs){
  52. foreach($rs as $key => $val){
  53. $r[$key] = $this->dataToAttr($val);
  54. }
  55. return $r;
  56. }else{
  57. return $r;
  58. }
  59. }else{//统计
  60. $sql = "select count(*) as c from ". $this->table_fullname . " $where ";
  61. $rs = $this->pdo->sqlQuery($sql);
  62. if($rs){
  63. return $rs[0]['c'];
  64. }else{
  65. return 0;
  66. }
  67. }
  68. }
  69. }
  70. ?>