table_stock.class.php 5.2 KB

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