table_stock.class.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 "."`stock_code`". "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] =$val["stock_code"];
  50. }
  51. return $r;
  52. }else{
  53. return $r;
  54. }
  55. }
  56. public function getInfoByCode($code){
  57. //查询语句必须用sql_check_input检查参数
  58. $code = trim($code);
  59. $code = $this->pdo->sql_check_input(array('string', $code));
  60. $sql = "select * from ". $this->table_fullname ." where stock_code = $code limit 1";
  61. $rs = $this->pdo->sqlQuery($sql);
  62. $r = array();
  63. if($rs){
  64. foreach($rs as $key => $val){
  65. $r[$key] = $this->dataToAttr($val);
  66. }
  67. return $r[0];
  68. }else{
  69. return $r;
  70. }
  71. }
  72. }
  73. ?>