table_stock.class.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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['desc'] = 'stock_desc';
  21. $attr['tradable_amount'] = 'stock_tradable_amount';
  22. $attr['tradable_value'] = 'stock_tradable_value';
  23. $attr['total_amount'] = 'stock_total_amount';
  24. $attr['total_value'] = 'stock_total_value';
  25. $attr['profitable'] = 'stock_profitable';
  26. $attr['pb'] = 'stock_pb';
  27. $attr['pe_static'] = 'stock_pe_static';
  28. $attr['pe_dynamic'] = 'stock_pe_dynamic';
  29. $attr['pe_ttm'] = 'stock_pe_ttm';
  30. $attr['exchange'] = 'stock_exchange';
  31. $attr['sector'] = 'stock_sector';
  32. return $attr;
  33. }
  34. public function add($attr){
  35. $param = array (
  36. 'stock_code' => array('string', $attr['code']),
  37. 'stock_name' => array('string', $attr['name']),
  38. 'stock_desc' => array('string', $attr['desc']),
  39. 'stock_tradable_amount' => array('number', $attr['tradable_amount']),
  40. 'stock_tradable_value' => array('number', $attr['tradable_value']),
  41. 'stock_total_amount' => array('number', $attr['total_amount']),
  42. 'stock_total_value' => array('number', $attr['total_value']),
  43. 'stock_profitable' => array('number', $attr['profitable']),
  44. 'stock_pb' => array('number', $attr['pb']),
  45. 'stock_pe_static' => array('number', $attr['pe_static']),
  46. 'stock_pe_dynamic' => array('number', $attr['pe_dynamic']),
  47. 'stock_pe_ttm' => array('number', $attr['pe_ttm']),
  48. 'stock_exchange' => array('string', $attr['exchange']),
  49. 'stock_sector' => array('number', $attr['sector']),
  50. );
  51. return $this->pdo->sqlinsert($this->table_fullname, $param);
  52. }
  53. /***
  54. * @param array $filter
  55. * @param int $count
  56. * @param int $page
  57. * @param int $pagesize
  58. * @return array
  59. * 获取代码列表
  60. */
  61. public function getStockCodeList($filter = array(), $count = 0, $page = 0, $pagesize = 0){
  62. $where="where 1=1";
  63. $sql = "select "."`stock_code`". "from ". $this->table_fullname ." $where order by ".$this->table_id." desc";
  64. $rs = $this->pdo->sqlQuery($sql);
  65. $r = array();
  66. if($rs){
  67. foreach($rs as $key => $val){
  68. $r[$key] =$val["stock_code"];
  69. }
  70. return $r;
  71. }else{
  72. return $r;
  73. }
  74. }
  75. public function addCodeAndName($attr){
  76. $param = array (
  77. 'stock_code' => array('string', $attr['code']),
  78. 'stock_name' => array('string', $attr['name']),
  79. 'stock_desc' => array('string', ''),
  80. 'stock_tradable_amount' => array('number', 0),
  81. 'stock_tradable_value' => array('number', 0),
  82. 'stock_total_amount' => array('number', 0),
  83. 'stock_total_value' => array('number', 0),
  84. 'stock_profitable' => array('number', 0),
  85. 'stock_pb' => array('number', 0),
  86. 'stock_pe_static' => array('number', 0),
  87. 'stock_pe_dynamic' => array('number', 0),
  88. 'stock_pe_ttm' => array('number', 0),
  89. 'stock_exchange' => array('string', $attr['exchange']),
  90. 'stock_sector' => array('number', $attr['sector']),
  91. );
  92. return $this->pdo->sqlinsert($this->table_fullname, $param);
  93. }
  94. public function getInfoByCode($code){
  95. //查询语句必须用sql_check_input检查参数
  96. $code = trim($code);
  97. $code = $this->pdo->sql_check_input(array('string', $code));
  98. $sql = "select * from ". $this->table_fullname ." where stock_code = $code limit 1";
  99. $rs = $this->pdo->sqlQuery($sql);
  100. $r = array();
  101. if($rs){
  102. foreach($rs as $key => $val){
  103. $r[$key] = $this->dataToAttr($val);
  104. }
  105. return $r[0];
  106. }else{
  107. return $r;
  108. }
  109. }
  110. }
  111. ?>