<?php
class Soft_version_model extends SDF_Model
{
public $title = 'soft_version';
public $_table = 'soft_version';
public function __construct(){
$this->db = $this->load->database('default',true);
parent::__construct();
}
public function get_soft_version_by_soft_id($soft_id){
$arr = $this->db->order_by('id DESC')->get_where('soft_version',array('soft_id'=>$soft_id))->result_array();
$soft_arr = array();
foreach ($arr as $v){
if(empty($v['file_list'])){
$v['file_list'] = array();
}else{
$v['file_list'] = json_decode($v['file_list'],true);
}
$soft_arr[$v['id']] = $v;
}
unset($arr);
return $soft_arr;
}
public function get_all_version($soft_id){
$arr = $this->db->select('id,version')->get_where('soft_version',array('soft_id'=>$soft_id))->result_array();
foreach ($arr as $k=>$v){
$version_list[$v['id']] = $v['version'];
}
return $version_list;
}
public function result($where){
$arr = $this->db->order_by('id')->get_where('soft_version',$where)->result_array();
foreach ($arr as $k=>$v){
$soft_arr[$v['id']] = $v;
}
unset($arr);
return $soft_arr;
}
public function isapp_web($id){
$arr = $this->db->select('app_to_web')->get_where('soft_version',array('id'=>$id))->result_array();
$info = $arr[0]['app_to_web'];
return $info;
}
public function app_to_web($soft_id,$id)
{
$table = 'bg_soft_version';
$this->db->where('soft_id',$soft_id);
$this->db->update($table,array('app_to_web'=>0));
$this->db->where('id',$id);
if($this->db->update($table,array('app_to_web'=>1))){
return true;
}else {
return false;
}
}
public function get_remark($id){
$arr = $this->db->select('remark')->get_where('soft_version',array('id'=>$id))->result_array();
$remark = $arr[0]['remark'];
return $remark;
}
public function get_remark_result($where = null){
$arr = $this->db->order_by('id')->get_where('soft_version',$where)->result_array();
foreach ($arr as $k=>$v){
$soft_arr[$v['version']] = $v['remark'];
}
unset($arr);
return $soft_arr;
}
public function get_version_id($soft_id,$version)
{
$where = array('soft_id'=>$soft_id,'version'=>$version);
$query = $this->db->select('id')->order_by('id','desc')->limit(1)->get_where('soft_version',$where);
if($query->num_rows() <= 0){
return null;
}
$row = $query->row_array();
return $row['id'];
}
public function get_latest_version($softid)
{
$list = $this->db->select('version')->order_by('id','desc')->limit(1)->get_where('soft_version',array('soft_id'=>$softid))->result_array();
$version = $list[0]['version'];
return $version;
}
}