<?php


class CommonClassModel extends Model
{
    //客户列表接口
    public function getcustomer()
    {
        $uid = $this->getuid();
        $data = $this->db->getall('select `contract_number` as value,name from 
                                    oa_customer 
                                    where (uid = ' . $uid . '
                                        or department_id=(select deptname from oa_userinfo where id=' . $uid . ') 
                                    or department_id like concat((select deptname from oa_userinfo where id=' . $uid . '),",%") 
                                    or department_id like concat("%,",(select deptname from oa_userinfo where id=' . $uid . ')) 
                                    or department_id like concat("%,",(select deptname from oa_userinfo where id=' . $uid . '),",%"))
                                    and status = 1 
                                    order by id desc');
        return $data;
    }

    //获取客户公海池列表接口
    public function getgongcustomer()
    {
        $data = $this->db->getall('select id as value,name from [Q]customer where isgh = 1 order by id desc');
        return $data;
    }

    public function getbusilist()
    {
        $data = m('option')->getall('pid = 484','id as value,name');

        return $data;
    }

    //合同列表接口
    public function getcontractList($param)
    {
        $data = m('c_contract')->getall('status = ' . $param, 'id as value,  CONCAT(title, "（",numb,"）") as name');
        return $data;
    }

    //合同列表接口
    public function getcontractlistfk()
    {
        $uid = $this->getuid();
        $sql = '';
        if ($uid != 1)
            $sql .= ' and (c.uid = ' . $uid . ' or c.staff_id = ' . $uid . ')';
            $where='select c.id as value, CONCAT(c.title, "(",c.numb,")") as name from [Q]c_contract as c inner join  [Q]flow_bill as f  on c.id=f.mid where (f.nowcourseid =752  or c.status=1) '.$sql;
        
            $data = $this->db->getall($where);
        return $data;
    }

    //客户列表接口
    public function getsupplier()
    {
        $uid = $this->getuid();

        $data = $this->db->getall('select `number` as value,name from 
                                    oa_supplier 
                                    where (uid = ' . $uid . ' 
                                    or department_id=(select deptname from oa_userinfo where id=' . $uid . ') 
                                    or department_id like concat((select deptname from oa_userinfo where id=' . $uid . '),",%") 
                                    or department_id like concat("%,",(select deptname from oa_userinfo where id=' . $uid . ')) 
                                    or department_id like concat("%,",(select deptname from oa_userinfo where id=' . $uid . '),",%"))
                                    and status = 1 
                                    order by id desc');
        return $data;
    }
   //账户列表接口
    public function getaccountlist()
    {
        $uid = $this->getuid();
        $data = $this->db->getall('select `id` as value,name from 
        oa_c_fund_account 
        where (uid = ' . $uid . '  or uid=' . $uid . '   or uid like concat(' . $uid . ',",%")   or uid like concat("%,",' . $uid . ')        or uid like concat("%,",' . $uid . ',",%"))
        and status = 1 ');
        return $data;
    }
    //成本中心列表接口
    public function getcbzx()
    {
        $data = m('c_cbzx')->getall('status = 1', 'id as value,CONCAT(code, "（",name,"）") as name');
        return $data;
    }

    //成本中心列表接口
    public function getcbzxnoxmbm()
    {
        $data = m('c_cbzx')->getall('status = 1 and iscbzx = 1', 'id as value,CONCAT(code, "（",name,"）") as name');
        return $data;
    }

    //付款类型-科目列表接口
    public function getbxlx()
    {
        $data = m('c_bxlx')->getall('status = 1', 'id as value,name');
        return $data;
    }

    //获取部门列表接口
    public function getdept()
    {
        $data = m('c_department')->getall('status = 1', 'id as value,name');
        return $data;
    }

    public function getuid()
    {
        return (new Action())->adminid;
    }


      //获取合同供应商列表
    public function getcontract_supplier()
    {
        $uid = $this->getuid();

        $data = $this->db->getall('select `number` as value,CONCAT(name, "（","供应商","）") as name from 
                                    oa_supplier 
                                    where (uid = ' . $uid . ' 
                                    or department_id=(select deptname from oa_userinfo where id=' . $uid . ') 
                                    or department_id like concat((select deptname from oa_userinfo where id=' . $uid . '),",%") 
                                    or department_id like concat("%,",(select deptname from oa_userinfo where id=' . $uid . ')) 
                                    or department_id like concat("%,",(select deptname from oa_userinfo where id=' . $uid . '),",%"))
                                    and status = 1 
                                    order by id desc');
        return $data;
    }

        //获取合同客户列表
    public function getcontract_customer()
    {
        $uid = $this->getuid();
        $data = $this->db->getall('select `contract_number` as value,CONCAT(name, "（","客户","）") as name from 
                                    oa_customer 
                                    where (uid = ' . $uid . '
                                        or department_id=(select deptname from oa_userinfo where id=' . $uid . ') 
                                    or department_id like concat((select deptname from oa_userinfo where id=' . $uid . '),",%") 
                                    or department_id like concat("%,",(select deptname from oa_userinfo where id=' . $uid . ')) 
                                    or department_id like concat("%,",(select deptname from oa_userinfo where id=' . $uid . '),",%"))
                                    and status = 1 
                                    order by id desc');
        return $data;
    }

         //固定资产申领
    public function getassetmuse()
    {
        $data = m('assetm')->getall('state = 0', 'id as value,  CONCAT(num, "（",title,"）") as name');
        return $data;
    }
}
