【php】excel导出分sheet

Continue Read..
    /**
     * 导出export 生成多个sheet
     * $data = [
     *      'sheet1'=>[
     *          'header'=>['k'=>v],
     *          'date'=>['k'=>v],
     *      ]
     *      'sheet2'=>[
     *          'header'=>['k'=>v]
     *          'data'=>['k'=>v]
     *      ]
     * ]
     * header和data 用k 关联
     * @param unknown $data
     * @param string $user
     * @param string $format
     * @param string $title
     * @return multitype:mixed
     */  
    public function multiExportSheet($data, $user = 'admin', $format = false, $title = ''){
        require_once __DIR__.'/PHPExcel.php';
        $objPHPExcel = new \PHPExcel();
        $j = 0;
        foreach ($data as $dk=>$dv){
            if($j==0){
                $objPHPExcel->setActiveSheetIndex($j); //设置第一个工作表为活动工作表
                $objPHPExcel->getActiveSheet()->setTitle($dk); //设置工作表名称
            }else{
                $msgWorkSheet = new \PHPExcel_Worksheet($objPHPExcel, $dk); //创建一个工作表
                $objPHPExcel->addSheet($msgWorkSheet); //插入工作表
                $objPHPExcel->setActiveSheetIndex($j); //切换到新创建的工作表
            }
            
            $arrHeader = $dv['header'];
            $arrBody = $dv['data'];
            $newdata = [];
            
            $i = 0;
            foreach ($arrBody as $k=>$v){
                foreach ($arrHeader as $kk=>$vv){
                    if(!empty($v[$kk])){
                        if($kk == 'idcard' || $kk == 'bank_card'){
                            $newdata[$i][$kk] = $v[$kk]."\t";
                        }else{
                            $newdata[$i][$kk] = $v[$kk];
                        }
                    }else{
                        $newdata[$i][$kk] = "";
                    }
                }
                $i++;
            }
            $hd[0] = $arrHeader;
            $arrExcelInfo = array_merge($hd, $newdata);
            $objPHPExcel->getActiveSheet()->fromArray(
                $arrExcelInfo, // 赋值的数组
                NULL, // 忽略的值,不会在excel中显示
                'A1' // 赋值的起始位置
            );
            
            unset($arrExcelInfo);
            unset($hd);
            unset($arrHeader);
            unset($arrBody);
            unset($newdata);
            $j++;
        }
        
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    
        $result=[];
        $path = 'down/'.md5($user.'down').'/';
        $rootPath = $this->mkdirPath($path);
        $date = date('YmdHis');
    
        $title = $date.rand(10000,99999);
        $outputFileName = $rootPath.$title.".xlsx";
        $objWriter->save($outputFileName);
        $result[]= str_replace(APP_PATH, '', $outputFileName);
        return $result;
    }


声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【linux】gitlab和nginx冲突的解决方案

Continue Read..

vim /etc/gitlab/gitlab.rb

external_url = 'http://IP或域名'

unicorn['listen'] = '127.0.0.1'

unicorn['port'] = 3002

nginx['listen_addresses'] = ['*']

nginx['listen_port'] = 3001


如果修改了 external_url 

需修改/opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml中 host 和 port

 

vim /var/opt/gitlab/gitlab-rails/etc/unicorn.rb
listen "127.0.0.1:3002", :tcp_nopush => true



vim /var/opt/gitlab/nginx/conf/gitlab-http.conf
listen *:3001;




改完之后
先关闭gitlab的ngxin服务
gitlab-ctl stop nginx

然后开启自己的nginx服务
service nginx start

然后启动gitlab的nginx服务
gitlab-ctl start nginx


gitlab的访问地址就是 http://127.0.0.1:3001/users/sign_in

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

vue.js 组件中filter后的数据,实时更新

Continue Read..

组件中的数据在模板显示后,变动数据发现不能更新的情况,可以做下面的检查

1、组件标签属性需要动态绑定v-bind:key="val"

2、VUE中加一个动态改变的变量time,动态绑定到组件标签对,props到组件中,在其他地方更新time就可以了

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【PHP】七牛,php<=5.3版本

Continue Read..
<?php
class SDK implements ArrayAccess {

	const QINIU_UP_HOST	= 'http://up.qiniu.com';
	const QINIU_RS_HOST	= 'http://rs.qbox.me';
	const QINIU_RSF_HOST= 'http://rsf.qbox.me';
	//查看 
	//删除 
	//复制 x
	//移动 x
	//上传 
	protected $access_token ;
	protected $secret_token ;
	protected $bucket;
	protected $cache = array();
	protected $aliases = array(); //文件别名, 针对文件名比较长的文件
	//curl 
	protected $ch;
	protected $headers;
	protected $options = array();
	protected $response;
	protected $info;
	protected $errno; 
	protected $error;

	public function __construct($access_token, $secret_token, $bucket = null)
	{
		$this->access_token = $access_token;
		$this->secret_token = $secret_token;
		$this->bucket = $bucket;
	}

	//获取空间名称
	public function getBucket()
	{
		return $this->bucket;
	}

	//设置空间
	public function setBucket($bucket)
	{
		$this->bucket = $bucket;
	}

	/**
	 * 查看指定文件信息。
	 * @param  string $key  	文件名或者目录+文件名
	 * @return Array|boolean 	成功返回文件内容,否会返回false.
	 */
	public function stat($key)
	{
		list($bucket, $key) = $this->parseKey($key);
		if ( is_null($bucket) ) 
		{
			die('error');
		}
		$url = self::QINIU_RS_HOST .'/stat/' . $this->encode("$bucket:$key");
		$token = $this->accessToken($url);
		$options[CURLOPT_HTTPHEADER] = array('Authorization: QBox '. $token);
		return $this->get($url, $options);
	}

	/**
	 * 删除指定文件信息。
	 * @param  string $key  	文件名或者目录+文件名
	 * @return NULL
	 */
	public function delete($key)
	{
		list($bucket, $key) = $this->parseKey($key);
		if ( is_null($bucket) ) 
		{
			die('error');
		}
		$url = self::QINIU_RS_HOST .'/delete/' . $this->encode("$bucket:$key");

		$token = $this->accessToken($url);
		$options[CURLOPT_HTTPHEADER] = array('Authorization: QBox '. $token);
		return $this->get($url, $options);
	}

	public function upload($file, $name=null, $token = null)
	{
		if ( NULL === $token ) 
		{
			$token = $this->uploadToken($this->bucket);
		}

		if ( !file_exists($file) ) 
		{
			die('文件不存在,构建一个临时文件');
		}
		$hash = hash_file('crc32b', $file);
		$array = unpack('N', pack('H*', $hash));
		$postFields = array(
			'token' => $token,
			'file'  => '@'.$file,
			'key'   => $name,
// 			'crc32' => sprintf('%u', $array[1]),
		);

		//未指定文件名,使用七牛默认的随机文件名
		if ( NULL === $name ) 
		{
			unset($postFields['key']);
		}
		else
		{
			//设置文件名后缀。
		}
		$options = array(
			CURLOPT_POSTFIELDS => $postFields,
		);
		return $this->get(self::QINIU_UP_HOST, $options);
	}

	protected function parseKey($key)
	{
		$key = $this->getAlias($key);
		if ( isset($this->cache[$key]) ) 
		{
			return $this->cache[$key];
		}
		$segments = explode("|", $key);
		if ( count($segments) === 1 ) 
		{
			$this->cache[$key] = array($this->bucket, $segments[0]);
		}
		else
		{
			$temp = implode('|', array_slice($segments, 1));
			$this->cache[$key] = array($segments[0], $temp);
		}
		return $this->cache[$key];
	}

	public function getAlias($key)
	{
		return isset($this->aliases[$key]) ? $this->aliases[$key] : $key;
	}

	public function uploadToken($config = array())
	{
		if ( is_string($config) ) 
		{
			$scope = $config;
			$config = array();
		}
		else
		{
			$scope = $config['scope'];
		}
		$config['scope'] = $scope;
		//硬编码,需修改。
		$config['deadline'] = time() + 3600;
		foreach ( $this->activeUploadSettings($config) as $key => $value ) 
		{
			if ( $value ) 
			{
				$config[$key] = $value;
			}
		}

		//build token
		$body = json_encode($config);
		$body = $this->encode($body);
		$sign = hash_hmac('sha1', $body, $this->secret_token, true);
		return $this->access_token . ':' . $this->encode($sign) . ':' .$body;
	}

	public function uploadSettings()
	{
		return array(
			'scope','deadline','callbackUrl', 'callbackBody', 'returnUrl',
			'returnBody', 'asyncOps', 'endUser', 'exclusive', 'detectMime',
			'fsizeLimit', 'saveKey', 'persistentOps', 'persistentNotifyUrl'
		);
	}

	protected function activeUploadSettings($array)
	{
		return array_intersect_key($array, array_flip($this->uploadSettings()));
	}

	public function accessToken($url, $body = false)
	{
		$url = parse_url($url);
		$result = '';
		if (isset($url['path'])) {
			$result = $url['path'];
		}
		if (isset($url['query'])) {
			$result .= '?' . $url['query'];
		}
		$result .= "\n";
		if ($body) {
			$result .= $body;
		}
		$sign = hash_hmac('sha1', $result, $this->secret_token, true);
		return $this->access_token . ':' . $this->encode($sign);
	}

	public function get($url, $options = array())
	{
		$this->ch = curl_init();
		$this->options[CURLOPT_URL] = $url;
		$this->options = $options + $this->options;
		//临时处理逻辑
		
		return $this->execute();
	}

	protected function execute() 
	{
		if ( !$this->option(CURLOPT_RETURNTRANSFER) ) 
		{
			$this->option(CURLOPT_RETURNTRANSFER, true);
		}
		if ( !$this->option(CURLOPT_SSL_VERIFYPEER) ) 
		{
			$this->option(CURLOPT_SSL_VERIFYPEER, false);
		}
		if ( !$this->option(CURLOPT_SSL_VERIFYHOST) ) 
		{
			$this->option(CURLOPT_SSL_VERIFYHOST, false);
		}
		if ( !$this->option(CURLOPT_CUSTOMREQUEST) ) 
		{
			$this->option(CURLOPT_CUSTOMREQUEST, 'POST');
		}
		if ( $this->headers ) 
		{
			$this->option(CURLOPT_HTTPHEADER, $this->headers);
		}
		$this->setupCurlOptions();

		$this->response = curl_exec($this->ch);
		$this->info = curl_getinfo($this->ch);

		if ( $this->response === false ) 
		{
			$this->error = curl_error($this->ch);
			$this->errno = curl_errno($this->ch);
			curl_close($this->ch);
			return false;
		}
		else
		{
			curl_close($this->ch);
			//未处理http_code。
			if ( $this->info['content_type'] == 'application/json' ) 
			{
				$this->response = json_decode($this->response, true);
			}
			return $this->response;
		}
	}
	public function setupCurlOptions()
	{
		curl_setopt_array($this->ch, $this->options);
	}

	public function option($key, $value = NULL)
	{
		if ( is_null($value) ) 
		{
			return !isset($this->options[$key]) ? null: $this->options[$key];
		}
		else
		{
			$this->options[$key] = $value;
			return $this;
		}
	}

	public function alias($key, $value)
	{
		$this->alias[$key] = $value;
	}

	protected function encode($str)
	{
        $trans = array("+" => "-", "/" => "_");
        return strtr(base64_encode($str), $trans);
	}

	public function __get($key)
	{
		return $this->$key;
	}

	public function offsetExists($key)
	{
		//check response;
	}

	public function offsetGet($key)
	{
		return $this->stat($key);
	}

	public function offsetSet($key, $value) 
	{
		//move or copy
	}

	public function offsetUnset($key)
	{
		return $this->delete();
	}
}


upload($filePath,$key);
var_dump($update);die;










声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

vue.js filter处理后返回显示html

Continue Read..
类似这样的代码
{{ description | filterfunction }}


filterfunction 返回一段html,
显示代码类似
<div v-html="description|filterfunction"


这样是不行的,应该这样

<div v-html="$options.filters.filterfunction(description)">


声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【PHP】无限极函数

Continue Read..

数据库

CREATE TABLE `position` (
   `position_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '岗位id',
   `position_ids` text COMMENT '所属父级ids',
   `position_name` varchar(50) NOT NULL COMMENT '岗位名称',
   `position_addtime` int(11) DEFAULT NULL COMMENT '添加时间',
   `position_uptime` int(11) DEFAULT NULL COMMENT '修改时间',
   `parent_id` int(11) DEFAULT NULL COMMENT '父级id',
   `is_delete` int(11) NOT NULL DEFAULT '0' COMMENT '是否删除',
   `role_id` int(10) DEFAULT NULL COMMENT '角色id',
   PRIMARY KEY (`position_id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8 COMMENT='岗位表'

点击查看原图

 

 

$data = select * from position

 

$newData = [];

foreach ($data as $k=>$v){

    $newData[$v['position_id']] = $v;

}

 

foreach ($data as $k=>$v){

    if($v['parent_id'] && isset($newData[$v['parent_id']])){

        $newData[$v['parent_id']]['son'][] = &$newData[$v['position_id']];

    }

}

 

var_dump($newData);die;

 

 

 

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

php crontab唯一实例运行

Continue Read..
#检测是否是唯一运行
if(!checkSingleRun($_SERVER['SCRIPT_FILENAME']))
{
	echo "{$_SERVER['SCRIPT_FILENAME']} is runnging....\n";
	exit;
}

#检测是否存在相同的进程正在运行,仅支持在linux下运行,windows下无法检测
function checkSingleRun($cronName,$limit=1,$isDebug=false)
{
	$flagIsRunning = true;
	$osIsLinux = strtoupper(substr(PHP_OS, 0, 3)) != 'WIN';
	if($osIsLinux)
	{
		$arrayOutput = array();
		exec('ps -fea | grep ' . $cronName . ' | grep -v grep', $arrayOutput);
		$counter = 0;
		#调试模式时打印出匹配的进程信息
		if($isDebug)
			print_r($arrayOutput);

		$cronName_preg = str_replace('/','\/',$cronName);
		foreach ($arrayOutput as $value) 
		{
			if (preg_match('/^.*\s' . $cronName_preg . '.*$/', $value) 
					|| preg_match('/^.*\s.+(?:\x2F|\x5C)' . $cronName_preg . '.*$/', $value) ) 
			{
				$counter++;
			}
		}
		if ($counter > $limit) {
			$flagIsRunning = false;
		}
	}
	return $flagIsRunning;
}


声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【PHP】php 操作LDAP

Continue Read..

1.首先安装php ldap的扩展

      参考网站http://blog.csdn.net/secondjanuary/article/details/8979686

  • 安装PHP的LDAP扩展
    • Windows下
      1. 如果你的php已经有php_ldap.dll文件,你可以打开php.ini文件, 找到 “;extension=php_ldap.dll” 去掉分号后保存
      2. 如果你没有php_ldap.dll文件,你可以从网上找的符合自己php版本的php_ldap.dll 文件,将文件放在相应的目录,重复上过程
      3. 重启Apache服务
    • Linux下
      1. 如果你的php是编译安装的,那么你需要加“--with-ldap”参数,重新编译安装
      2. 如果你的php是通过Linux的包管理器安装的,你可以通过包管理器安装php_ldap。 以Debian为例,执行apt-get install php5_ldap
      3. 重启Apache服务
  • 查看LDAP扩展是否安装成功
    • 打开phpinfo()测试画面,查看如下画面即php的ldap扩展方法启用成功:



        linux下扩展LDAP  

        参考网站 :http://www.sijitao.net/1851.html    https://my.oschina.net/kisshua/blog/199020




2. 编写代码测试

<?php

//phpinfo();  
$hostname="10.69.40.200";  
// $username = "cn=root,dc=www,dc=wulinlw,dc=org"; // Linux下管理员用户名的格式  
$username = "账号"; // Windows下管理员用户名的格式  
$password = "密码";  
$basedn = "dc=wulinlw,dc=org";  
$ds=ldap_connect($hostname,9999);  
if( $ds )  
{  
        ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION,3);  
        ldap_set_option($ds, LDAP_OPT_REFERRALS,0);  
          
        $r=ldap_bind($ds,$username,$password);  
        if($r){
    //         var_dump(ldap_error($ds));
            $filter   = "(|(objectClass=u*)(name=TONGXING))";
    //         $filter   = "(name=TONGXING)";
    //         $attr     =  array("displayName","description","cn","givenName","sn","mail","co","mobile","company","displayName");
            $attr     = array();
            $sr=ldap_search($ds, $basedn,$filter,$attr)or die ("Error in search query: ".ldap_error($ds));;  
    //         echo "Number of entries returned is " . ldap_count_entries($ds, $sr) . "
";
            
            $info = ldap_get_entries($ds, $sr);    
            echo json_encode($info);  
            //file_put_contents("D:\\json.json",json_encode($info));  
            var_dump($info['count']);  
            var_dump($info);  
            
        }
        ldap_close($ds);  
}   
else   
{  
    echo "

Unable to connect to LDAP server

"; } 


参考网站     

http://php.net/manual/zh/book.ldap.php     

http://jingyan.baidu.com/article/c85b7a642b2ee9003bac95b1.html

http://blog.itpub.net/750220/viewspace-878964/

http://www.cnblogs.com/qiuxiangmuyu/p/6437937.html

http://xuqq999.blog.51cto.com/3357083/786708

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

时间比较,判断:当天/昨天/昨天以前/隔年

Continue Read..
<script type="text/javascript">
var vd = new Date('2016/05/01 08:26:23');
var vy= vd.getFullYear();
var vm=vd.getMonth()+1;
var vda=vd.getDate();
var vh= vd.getHours();
var vmi= vd.getMinutes()

var d = new Date();
var cy=d.getFullYear();
var cm=d.getMonth() +1;
var cd=d.getDate();

if(vy==cy){
   var monthFlag = cm== vm? 1 : 0;
   var dateFlag = cd- vda;
   document.write(monthFlag+'--'+dateFlag+'>');
   if (monthFlag == 1 && dateFlag == 0) {
        document.write('今天');
   } else if (monthFlag == 1 && dateFlag == 1) {
        document.write('昨天');
   } else {
        document.write('昨天以前');
   }
}else{
   document.write('隔年');
}

</script>

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

CentOS 安装/升级Git 1.9.4

Continue Read..

因为yum源的最新版本是1.7.x,所以无法通过yum进行更新,下面描述如何通过编译源码进行安装

1.安装需要的依赖

第一步我们需要做的就是确认系统已经安装了编译git时需要的依赖。使用下面的安装命令即可(已经安装过的不会重新再安装)

yum install curl
yum install curl-devel
yum install zlib-devel
yum install openssl-devel
yum install perl
yum install cpio
yum install expat-devel
yum install gettext-devel
yum install gcc
yum install perl-ExtUtils-MakeMaker

当然,为了快速安装,你可以把上面命令写在一行中,一次执行

yum install crul curl-devel zlib-devel openssl-devel perl cpio expat-devel gettext-devel gcc perl-ExtUtils-MakeMaker

2.下载Git

 cd /usr/src
 wget https://www.kernel.org/pub/software/scm/git/git-1.9.4.tar.gz
 tar xzf git-1.9.4.tar.gz

3.编译

cd git-1.9.4 autoconf
./configure
make
make install

运行autoconf命令时,如果终端提示no command的话就执行yum install autoconf命令后再试

4.重新指定git命令对应的版本

echo "export PATH=$PATH:/usr/local/git/bin" >> /etc/bashrcsource /etc/bashrc

不执行这一步将出现git版本仍然是升级前的

5.检查安装/升级后的版本是否正确

git --version

执行以上命令后应该显示

git version 1.9.4 

6.安装过程中可能遇到的问题

usr/bin/perl Makefile.PL PREFIX='/usr/local/git' INSTALL_BASE='' --localedir='/usr/local/git/share/locale' Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) <span class="goog_qs-tidbit goog_qs-tidbit-0">at Makefile.PL line 3.
BEGIN failed--compilation aborted at Makefile.PL line 3.

出现这个错误的原因是perl-ExtUtils-MakeMaker依赖没有安装成功,执行以下命令重新进行安装

yum install perl-ExtUtils-MakeMaker