| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- /**
- * 数据库表:管理员组
- *
- * @createtime 2018/03/01
- * @author 空竹
- * @copyright 芝麻开发(http://www.zhimawork.com)
- */
- class Table_stock extends Table {
- protected $table_name = 'stock';//表名,不带前缀,前缀在config中定义
- protected $table_id = 'stock_id';//指定ID字段名称,必须
- protected $table_status = '';//指定状态字段名称,如果有
- protected $table_order = '';//指定排序字段名称,如果有
- //数据库结构
- protected function struct(){
- $attr = array();
- $attr['id'] = 'stock_id';
- $attr['code'] = 'stock_code';
- $attr['name'] = 'stock_name';
- $attr['desc'] = 'stock_desc';
- $attr['tradable_amount'] = 'stock_tradable_amount';
- $attr['tradable_value'] = 'stock_tradable_value';
- $attr['total_amount'] = 'stock_total_amount';
- $attr['total_value'] = 'stock_total_value';
- $attr['profitable'] = 'stock_profitable';
- $attr['pb'] = 'stock_pb';
- $attr['pe_static'] = 'stock_pe_static';
- $attr['pe_dynamic'] = 'stock_pe_dynamic';
- $attr['pe_ttm'] = 'stock_pe_ttm';
- $attr['exchange'] = 'stock_exchange';
- $attr['sector'] = 'stock_sector';
- return $attr;
- }
- public function add($attr){
- $param = array (
- 'stock_code' => array('string', $attr['code']),
- 'stock_name' => array('string', $attr['name']),
- 'stock_desc' => array('string', $attr['desc']),
- 'stock_tradable_amount' => array('number', $attr['tradable_amount']),
- 'stock_tradable_value' => array('number', $attr['tradable_value']),
- 'stock_total_amount' => array('number', $attr['total_amount']),
- 'stock_total_value' => array('number', $attr['total_value']),
- 'stock_profitable' => array('number', $attr['profitable']),
- 'stock_pb' => array('number', $attr['pb']),
- 'stock_pe_static' => array('number', $attr['pe_static']),
- 'stock_pe_dynamic' => array('number', $attr['pe_dynamic']),
- 'stock_pe_ttm' => array('number', $attr['pe_ttm']),
- 'stock_exchange' => array('string', $attr['exchange']),
- 'stock_sector' => array('number', $attr['sector']),
- );
- return $this->pdo->sqlinsert($this->table_fullname, $param);
- }
- public function updateByCode($stock_code, $attrs)
- {
- $params = array();
- foreach ($attrs as $key => $value) {
- //$type = self::getTypeByAttr($key);
- $params[$this->table_name.'_'.$key] = array('string', $value);
- }
- //where条件
- $where = array( "stock_code" => array("number", $stock_code));
- //返回结果
- $r = $this->pdo->sqlupdate($this->table_fullname, $params, $where);
- return $r;
- }
- /***
- * @param array $filter
- * @param int $count
- * @param int $page
- * @param int $pagesize
- * @return array
- * 获取代码列表
- */
- public function getStockCodeList($filter = array(), $count = 0, $page = 0, $pagesize = 0){
- $where="where 1=1";
- $sql = "select "."`stock_code`". "from ". $this->table_fullname ." $where order by ".$this->table_id." desc";
- $rs = $this->pdo->sqlQuery($sql);
- $r = array();
- if($rs){
- foreach($rs as $key => $val){
- $r[$key] =$val["stock_code"];
- }
- return $r;
- }else{
- return $r;
- }
- }
- public function addCodeAndName($attr){
- $param = array (
- 'stock_code' => array('string', $attr['code']),
- 'stock_name' => array('string', $attr['name']),
- 'stock_desc' => array('string', ''),
- 'stock_tradable_amount' => array('number', 0),
- 'stock_tradable_value' => array('number', 0),
- 'stock_total_amount' => array('number', 0),
- 'stock_total_value' => array('number', 0),
- 'stock_profitable' => array('number', 0),
- 'stock_pb' => array('number', 0),
- 'stock_pe_static' => array('number', 0),
- 'stock_pe_dynamic' => array('number', 0),
- 'stock_pe_ttm' => array('number', 0),
- 'stock_exchange' => array('string', $attr['exchange']),
- 'stock_sector' => array('number', $attr['sector']),
- );
- return $this->pdo->sqlinsert($this->table_fullname, $param);
- }
- public function getInfoByCode($code){
- //查询语句必须用sql_check_input检查参数
- $code = trim($code);
- $code = $this->pdo->sql_check_input(array('string', $code));
- $sql = "select * from ". $this->table_fullname ." where stock_code = $code limit 1";
- $rs = $this->pdo->sqlQuery($sql);
- $r = array();
- if($rs){
- foreach($rs as $key => $val){
- $r[$key] = $this->dataToAttr($val);
- }
- return $r[0];
- }else{
- return $r;
- }
- }
- }
- ?>
|