table_stock.class.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. public function updateByCode($stock_code, $attrs)
  54. {
  55. $params = array();
  56. foreach ($attrs as $key => $value) {
  57. $params[$this->table_name.'_'.$key] = array('string', $value);
  58. }
  59. //where条件
  60. $where = array( "stock_code" => array("number", $stock_code));
  61. //返回结果
  62. $r = $this->pdo->sqlupdate($this->table_fullname, $params, $where);
  63. return $r;
  64. }
  65. /***
  66. * @param array $filter
  67. * @param int $count
  68. * @param int $page
  69. * @param int $pagesize
  70. * @return array
  71. * 获取代码列表
  72. */
  73. public function getStockCodeList(){
  74. $where="where 1=1";
  75. $sql = "select "."`stock_code`". "from ". $this->table_fullname ." $where order by ".$this->table_id." asc";
  76. $rs = $this->pdo->sqlQuery($sql);
  77. $r = array();
  78. if($rs){
  79. foreach($rs as $key => $val){
  80. $r[$key] =$val["stock_code"];
  81. }
  82. return $r;
  83. }else{
  84. return $r;
  85. }
  86. }
  87. public function addCodeAndName($attr){
  88. $param = array (
  89. 'stock_code' => array('string', $attr['code']),
  90. 'stock_name' => array('string', $attr['name']),
  91. 'stock_desc' => array('string', ''),
  92. 'stock_tradable_amount' => array('number', 0),
  93. 'stock_tradable_value' => array('number', 0),
  94. 'stock_total_amount' => array('number', 0),
  95. 'stock_total_value' => array('number', 0),
  96. 'stock_profitable' => array('number', 0),
  97. 'stock_pb' => array('number', 0),
  98. 'stock_pe_static' => array('number', 0),
  99. 'stock_pe_dynamic' => array('number', 0),
  100. 'stock_pe_ttm' => array('number', 0),
  101. 'stock_exchange' => array('string', $attr['exchange']),
  102. 'stock_sector' => array('number', $attr['sector']),
  103. );
  104. return $this->pdo->sqlinsert($this->table_fullname, $param);
  105. }
  106. public function getInfoByCode($code){
  107. //查询语句必须用sql_check_input检查参数
  108. $code = trim($code);
  109. $code = $this->pdo->sql_check_input(array('string', $code));
  110. $sql = "select * from ". $this->table_fullname ." where stock_code = $code limit 1";
  111. $rs = $this->pdo->sqlQuery($sql);
  112. $r = array();
  113. if($rs){
  114. foreach($rs as $key => $val){
  115. $r[$key] = $this->dataToAttr($val);
  116. }
  117. return $r[0];
  118. }else{
  119. return $r;
  120. }
  121. }
  122. }
  123. ?>