<?php

/**
 * 修改接口
 * Class opencatClassAction
 */
class openupdClassAction extends openapiAction
{
    public function __call($name, $arguments)
    {
        $msg = $name.' action not found';
        return $this->showreturn([],$msg,'201');
    }

 

    
    public function listAction(){
        
        $sql  = "select id,department_id from [Q]supplier";  
        $data = $this->db->getall($sql);

        foreach ($data as $key => $value) {
         
         $deptarr=explode(',',$value['department_id']);

         array_walk($deptarr,
            function (&$s, $k, $prefix = "''") {
            $s = str_pad($s, strlen($prefix) + strlen($s), $prefix, STR_PAD_BOTH);
            }
           );

            $department_id=implode(',', $deptarr);

            $sqll  = "select new_name from [Q]tmp_department  where name  in "."(".$department_id.")";
            $data_list = $this->db->getall($sqll);

            $new=array();
            foreach ($data_list as $key => $vo) {
                $new[]=$vo['new_name'];
             } 
             $zfarr = array(
                'department_id'        =>implode(',', $new),
              
                );
                var_dump(m('supplier')->update($zfarr,'id='.$value['id'].''));
      

        }
     

        // return $this->showreturn($data);
    }

  public function custAction(){
        
        $sql  = "select id,department_id from [Q]customer";  
        $data = $this->db->getall($sql);
       
        foreach ($data as $key => $value) {
         
         $deptarr=explode(',',$value['department_id']);

         array_walk($deptarr,
            function (&$s, $k, $prefix = "''") {
            $s = str_pad($s, strlen($prefix) + strlen($s), $prefix, STR_PAD_BOTH);
            }
           );

            $department_id=implode(',', $deptarr);

            $sqll  = "select new_name from [Q]tmp_department  where name  in "."(".$department_id.")";
            $data_list = $this->db->getall($sqll);
            $new=array();
            foreach ($data_list as $key => $vo) {
                $new[]=$vo['new_name'];
             } 
             $zfarr = array(
                'department_id'        =>implode(',', $new),
              
                );
                if(m('customer')->update($zfarr,'id='.$value['id'].'')){
                    echo 1;
                }else{
                    echo 2;
                }
      

        }
     

        // return $this->showreturn($data);
    }


    public function catAction(){
        
        $sql  = "select id,departmentname from [Q]c_contract";  
        $data = $this->db->getall($sql);
 
        foreach ($data as $key => $value) {
         
    

            $sqll  = "select new_name from [Q]tmp_department  where name ="."'".$value['departmentname']."'";
            $data_list = $this->db->getall($sqll);

           

             $zfarr = array(
                'departmentname'        =>$data_list[0]['new_name'],
              
                );
                if(m('c_contract')->update($zfarr,'id='.$value['id'].'')){
                    echo 1;
                }else{
                    echo 2;
                }

      

        }
     

        // return $this->showreturn($data);
    }

   
}
