<?php
/**
 * Copyright (C) LJCMS All rights reserved.
 * <E-Mail：aspcms@qq.com>
 * Url http://www.liangjing.org
 *     http://www.8CMS.com
 * Update 2016.03.19
 */

class userOModel extends X {

        
        public function getList($items){
                    $where      = " WHERE 1=1".$items['searchsql'];
                    $start      = ($items['page']-1)*$items['pagesize'];
                    $countsql   = "SELECT COUNT(*) AS my_count FROM ".DB_PREFIXOA."user ".$where;
                    $total      = parent::$obj->fetch_count($countsql);
                    $sql        = "SELECT * FROM ".DB_PREFIXOA."user ".$where." ORDER BY id asc LIMIT ".$start.", ".$items['pagesize']."";
                    $array = parent::$obj->getall($sql);
                    return array($total, $array);
        }
         public function get_List($searchsql){
                    $sql="SELECT * FROM `oa_user` WHERE ".$searchsql." ORDER BY id asc";
                    return parent::$obj->getall($sql);
        }
        public function get_user_view($searchsql){
            $sql="SELECT User.id AS id,User.emp_no AS emp_no,User.name AS name,User.letter AS letter,User.dept_id AS dept_id,User.position_id AS position_id,User.email AS email,User.duty AS duty,User.office_tel AS office_tel,User.mobile_tel AS mobile_tel,User.pic AS pic,User.birthday AS birthday,User.sex AS sex,User.password AS password,User.is_del AS is_del,Position.name AS position_name,Dept.name AS dept_name FROM oa_user User JOIN oa_position Position ON Position.id=User.position_id JOIN oa_dept Dept ON Dept.id=User.dept_id WHERE ".$searchsql." ORDER BY User.emp_no asc";
        return parent::$obj->getall($sql);
        }

        public function getposition_list(){
            $sql="SELECT `id`,`name` FROM `oa_position` WHERE ( is_del=0 ) ORDER BY sort asc";
            return parent::$obj->getall($sql);
        }
         public function getdept_list(){
            $sql="SELECT `id`,`name` FROM `oa_dept` WHERE ( is_del=0 ) ORDER BY sort asc";
            return parent::$obj->getall($sql);
        }

        public function get_top_menu_data($id){
	        $sql = "SELECT * FROM ".DB_PREFIXOA."user WHERE id='".$id."'";
                return parent::$obj->fetch_first($sql);
	}
        public function get_info($id){
               $sql="SELECT User.id AS id,User.emp_no AS emp_no,User.name AS name,User.letter AS letter,User.dept_id AS dept_id,User.position_id AS position_id,User.email AS email,User.duty AS duty,User.office_tel AS office_tel,User.mobile_tel AS mobile_tel,User.pic AS pic,User.birthday AS birthday,User.sex AS sex,User.password AS password,User.is_del AS is_del,Position.name AS position_name,Dept.name AS dept_name FROM oa_user User JOIN oa_position Position ON Position.id=User.position_id JOIN oa_dept Dept ON Dept.id=User.dept_id WHERE User.id='".$id."'";
               return parent::$obj->fetch_first($sql);
        }

        public function doEdit($id,$arr){
                unset($arr['id']);
                unset($arr['save_name']);
                unset($arr['signature']);
                unset($arr['opmode']);
                unset($arr['dept_name']);
                unset($arr['ajax']);
                $result = parent::$obj->update(DB_PREFIXOA.'user', $arr, 'id='.$id.'');
                return $result;
        }  
        public function doAdd($array) {
           // print_r($array);die;
             unset($array['ajax']);
             unset($array['opmode']);
             unset($array['dept_name']);
             $pwd="123456";
             $array['password']=md5($pwd);
             $array['westatus']=1;
             $array['openid']=$array['emp_no'];
             $array['create_time']= time();
           return parent::$obj->insert(DB_PREFIXOA.'user', $array); 
      }
      public function del($id){
    
        $sql = "DELETE FROM ".DB_PREFIXOA."user WHERE id='".intval($id)."'";
        return parent::$obj->query($sql);
      }
}
?>
