| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 | 
							- <?php
 
- namespace app\admin\controller;
 
- use think\facade\Session;
 
- use think\facade\Request;
 
- use think\facade\Filesystem;
 
- use app\common\model\Attachment as AttachmentModel;
 
- class Attachment
 
- {
 
- 	
 
- 	// 文件上传
 
- 	public function tplFieldFile()
 
- 	{
 
- 		$file = request()->file("file");
 
- 		$savename = \think\facade\Filesystem::disk('public')->putFile('files',$file);
 
- 		if($file){
 
- 			$filename = str_replace(strrchr($_FILES['file']['name'], "."),"",$_FILES['file']['name']);
 
- 			$attachment = AttachmentModel::create([
 
- 				'filename'  	=> $filename,
 
- 				'atype'     	=> 4,
 
- 				'attachment'    => request()->domain() ."/attachment/". str_replace("\\","/",$savename),
 
- 				'createtime'	=> time() 
 
- 			]);
 
- 			exit(json_encode(array(
 
- 				'code' 	=> 0,
 
- 				'msg'   => "",
 
- 				'data'  => array(
 
- 					'src'	=> request()->domain() ."/attachment/". str_replace("\\","/",$savename),
 
- 					'path'	=> "./attachment/". str_replace("\\","/",$savename),
 
- 					'title'	=> $filename
 
- 				)
 
- 			)));
 
- 		}else{
 
- 			exit(json_encode(array(
 
- 				'code' 	=> 1,
 
- 				'msg'   => "上传失败,请稍后重试"
 
- 			)));
 
- 		}
 
- 	}
 
- 	
 
- 	// 图片上传
 
- 	public function tplFieldImage()
 
- 	{
 
- 		$file = request()->file("file");
 
- 		$savename = \think\facade\Filesystem::disk('public')->putFile('images',$file);
 
- 		if($file){
 
- 			$filename = str_replace(strrchr($_FILES['file']['name'], "."),"",$_FILES['file']['name']);
 
- 			$attachment = AttachmentModel::create([
 
- 				'filename'  	=> $filename,
 
- 				'atype'     	=> 1,
 
- 				'attachment'    => request()->domain() ."/attachment/". str_replace("\\","/",$savename),
 
- 				'createtime'	=> time() 
 
- 			]);
 
- 			exit(json_encode(array(
 
- 				'code' 	=> 0,
 
- 				'msg'   => "",
 
- 				'data'  => array(
 
- 					'src'	=> request()->domain() ."/attachment/". str_replace("\\","/",$savename),
 
- 					'title'	=> $filename
 
- 				)
 
- 			)));
 
- 		}else{
 
- 			exit(json_encode(array(
 
- 				'code' 	=> 1,
 
- 				'msg'   => "上传失败,请稍后重试"
 
- 			)));
 
- 		}
 
- 	}
 
- 	
 
- 	
 
- 	
 
- 	
 
- 	// 图片
 
- 	public function image()
 
- 	{
 
- 		$years = range( date('Y'), date('Y')-9 );
 
- 		$months = array(
 
- 			array('key'=>1, 'val'=>1),
 
- 			array('key'=>2, 'val'=>2),
 
- 			array('key'=>3, 'val'=>3),
 
- 			array('key'=>4, 'val'=>4),
 
- 			array('key'=>5, 'val'=>5),
 
- 			array('key'=>6, 'val'=>6),
 
- 			array('key'=>7, 'val'=>7),
 
- 			array('key'=>8, 'val'=>8),
 
- 			array('key'=>9, 'val'=>9),
 
- 			array('key'=>10, 'val'=>10),
 
- 			array('key'=>11, 'val'=>11),
 
- 			array('key'=>12, 'val'=>12)
 
- 		);
 
- 		$yearmonth = array();
 
- 		foreach ( $years as $key=>$value ){
 
- 			$yearmonth[$key]['key'] = $value;
 
- 			$yearmonth[$key]['val'] = $value;
 
- 			$yearmonth[$key]['month'] = $months;
 
- 		}
 
- 		return view('attachment/image',[
 
- 			'yearmonth' => json_encode($yearmonth)
 
- 		]);
 
- 	}
 
- 	
 
- 	public function listImage()
 
- 	{
 
- 		$limit = input('limit');
 
- 		$page = input('page');
 
- 		$map = array();
 
- 		$map[] = ['atype', '=', 1];
 
- 		$keywords = input('keywords/s');
 
- 		if (!empty($keywords)){
 
- 			$map[] =['filename', 'like', '%'.$keywords.'%'];
 
- 		}
 
- 		$yearmonth = input('yearmonth/s');
 
- 		if (!empty($yearmonth)){
 
- 			$yearmontharr = explode(",", $yearmonth);
 
- 			if (!empty($yearmontharr[1])) {
 
- 				$year = $yearmontharr[0];
 
- 				$month = $yearmontharr[1];
 
- 				$monthday = date("t",strtotime($year."-".$month));
 
- 				$stime = mktime(0,0,0,$month,1,$year);
 
- 				$etime = mktime(23,59,59,$month,$monthday,$year);
 
- 				$map[] = ['createtime', 'between', [$stime,$etime]];
 
- 			}else{
 
- 				$year = $yearmontharr[0];
 
- 				$stime = mktime(0,0,0,1,1,$year);
 
- 				$etime = mktime(23,59,59,12,31,$year);
 
- 				$map[] = ['createtime', 'between', [$stime,$etime]];
 
- 			}
 
- 		}
 
- 		$list = AttachmentModel::where($map)->order(['id'=>'desc'])->limit($limit)->page($page)->select();
 
- 		$count = AttachmentModel::where($map)->count();
 
- 		if ($count==0){
 
- 			exit(json_encode(array(
 
- 				'code' 	=> 1,
 
- 				'msg'	=> "未查询到数据"
 
- 			)));
 
- 		}
 
- 		exit(json_encode(array(
 
- 			'code' 	=> 0,
 
- 			'msg'	=> "",
 
- 			'count' => $count,
 
- 			'data'  => $list
 
- 		)));
 
- 	}
 
- 	
 
- 	
 
- 	// 附件公共操作
 
- 	public function fieldAttachment()
 
- 	{
 
- 		$id = input('id/d');
 
- 		$attachment = AttachmentModel::findOrEmpty($id);
 
- 		if ($attachment->isEmpty()){
 
- 			exit(json_encode(array(
 
- 				'code' 	=> 1,
 
- 				'msg'	=> "附件信息不存在"
 
- 			)));
 
- 		}else{
 
- 			$attachment->save([
 
- 				input('field/s')  => input('value')
 
- 			]);
 
- 		}
 
- 		exit(json_encode(array(
 
- 			'code' 	=> 0
 
- 		)));
 
- 	}
 
- 	
 
- 	public function delAttachment()
 
- 	{
 
- 		$idarr = input('idarr/a');
 
- 		$attachment = AttachmentModel::whereIn('id',$idarr)->select();
 
- 		foreach($attachment as $v){
 
- 			$attachmenturl = str_replace( request()->domain(), ".", $v['attachment']);
 
- 			@unlink( $attachmenturl );
 
- 		}
 
- 		$result = $attachment->delete();
 
- 		if ($result){
 
- 			exit(json_encode(array(
 
- 				'code' 	=> 0,
 
- 				'msg'	=> ""
 
- 			)));
 
- 		}
 
- 		exit(json_encode(array(
 
- 			'code' 	=> 1,
 
- 			'msg'	=> "删除失败,请稍后重试"
 
- 		)));
 
- 	}
 
- 	
 
- 	
 
- }
 
 
  |