why.xingtongworld.com项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

681 lines
29 KiB

<?php
// +----------------------------------------------------------------------
// | YFCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: rainfer <81818832@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use think\Db;
use think\Request;
use app\admin\model\Bigdata as Bigdatadb;
use think\Image;
class Bigdata extends Base{
public function __construct(){
parent::__construct();
}
//获取表格图片
protected function getImg($sheet){
/*取图片*/
$imgData = array();
$subpath=config('upload_path').'/bigdata/'.date('Y-m-d').'/';
$imageFilePath =ROOT_PATH.$subpath;//图片保存目录
if (!file_exists( $imageFilePath )) {
mkdir("$imageFilePath", 0777, true);
}
//遍历表格图片
try{
foreach ($sheet->getDrawingCollection() as $img) {
list($startColumn,$startRow)= \PHPExcel_Cell::coordinateFromString($img->getCoordinates());//获取图片所在行和列
$imageFileName =md5(uniqid());
$quality=80;
switch($img->getMimeType()) {
case 'image/jpg':
$imageFileName.='.jpg';
$imgtype='jpg';
imagejpeg($img->getImageResource(),$imageFilePath.$imageFileName,40);
break;
case 'image/gif':
$imageFileName.='.gif';
$imgtype='gif';
imagegif($img->getImageResource(),$imageFilePath.$imageFileName);
break;
case 'image/png':
$imageFileName.='.png';
$imgtype='png';
imagepng($img->getImageResource(),$imageFilePath.$imageFileName,4);
break;
default:
$imageFileName.='.jpg';
$imgtype='jpg';
imagejpeg($img->getImageResource(),$imageFilePath.$imageFileName,40);
}
$startColumn = $this->ABC2decimal($startColumn);//由于图片所在位置的列号为字母,转化为数字
$imgData[$startRow][$startColumn][] =$subpath.$imageFileName;//把图片插入到数组中
}
} catch(\Exception $e) {
}
return $imgData;
}
protected function ABC2decimal($abc){
$ten = 0;
$len = strlen($abc);
for($i=1;$i<=$len;$i++){
$char = substr($abc,0-$i,1);//反向获取单个字符
$int = ord($char);
$ten += ($int-65)*pow(26,$i-1);
}
return $ten;
}
public function importxls(){
$kind=input('post.ckind','','intval');
$file = request()->file('xlsfile');
if(empty($kind)){
$this->error("请选择产品类型");
}
if(!count($file)){
$this->error("请上传xls");
}
$uploadpath=config('upload_path');
$path=ROOT_PATH . config('upload_path').'/'.'excel';
$info = $file->move($path);
$inputFileName='';
if($info){
$inputFileName=$path.'/'.$info->getSaveName();
}else{
$this->error($file->getError());
}
include ROOT_PATH.'extend'.DS.'PHPExcel'.DS.'PHPExcel.php';
$imgs=array();
// 读取excel文件
try {
$inputFileType = \PHPExcel_IOFactory::identify($inputFileName);
if($inputFileType=='Excel2007'){
$objReader = new \PHPExcel_Reader_Excel2007();
}else{
$objReader = \PHPExcel_IOFactory::createReader($inputFileType);
}
$objPHPExcel = $objReader->load($inputFileName);
// 确定要读取的sheet,什么是sheet,看excel的右下角,真的不懂去百度吧
$sheet = $objPHPExcel->getSheet(0);
$imgs=$this->getImg($sheet);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
$cindex=3;
$cates=array(1=>'图片','音频','视频','电子文档','三维全景','其他');
// 获取一行的数据
for ($index =$cindex; $index <= $highestRow; $index++){
// Read a row of data into an array
$rowData = $sheet->rangeToArray('A'. $index .':'. $highestColumn . $index, NULL, TRUE, FALSE);
//这里得到的rowData都是一行的数据,得到数据后自行处理,我们这里只打出来看看效果
if(isset($rowData[0])){
switch ($kind){
case 2:
$row=$rowData[0];
if(count($row)){
if($row[1]){
$data=[];
$data['c_name']=$row[1];
$data['c_logo']='';
$data['c_kind']=2;
$data['c_infostime']=time();
$data['c_time']=time();
$query=Db::name('bigdata')->insert($data);
}
}
break;
case 1:
$row=$rowData[0];
if(count($row)){
if($row[1]){
$data=[];
$data['c_kind']=1;
$data['c_name']=$row[1];
$icode=$row[2];
$find=Db::name('bigdata')->where(['c_icode'=>$icode])->count();
if(!$find){
$data['c_icode']=$icode;
$data['c_logo']=isset($imgs[$index][3][0])?$imgs[$index][3][0]:'';
$data['c_price']=$row[6];
$data['c_seller']=$row[11];
$data['c_scode']=isset($row[12])?$row[12]:'';
$data['c_url']=$row[4];
$gptime=trim($row[5],'/');
if($gptime){
$gptime=\PHPExcel_Shared_Date::ExcelToPHP($gptime);
}
$data['c_gptime']=$gptime;
$data['c_pay']=$row[7]=='授权'?1:2;
$data['c_type']=$row[13]=='文化资源数据'?1:2;
$ccate=$row[9];
$data['c_cate']=in_array($ccate,$cates)?array_search($ccate,$cates):'';
$cdate=date("ymd");
$last=Db::name('bigdata')->count();
$prev='';
//一级代码:标的类型
$prev=$data['c_type']==1?'A':'B';
//二级代码:展示类别
$prev.=$data['c_cate'];
//四级代码:日期
$prev.=$cdate;
//五级代码:X13X14为标的数据包序号,从01起依次编码,如标的为单个数据文件,默认序号为00
$code=$prev.'00';
$code.=sprintf('%03s',($last+1));
$data['c_code']=$code;
$data['c_time']=time();
$query=Db::name('bigdata')->insert($data);
}
}
}
break;
}
}
}
} catch(\Exception $e) {
$this->error("加载文件发生错误:".pathinfo($inputFileName,PATHINFO_BASENAME).":".$e->getMessage());
}
$this->success('提交成功',url('bigdata/showlist'));
}
/**
* 首页数据展示
* @return mixed|string
*/
public function showlist(Request $request)
{
$search_name=input('search_name','');
$this->assign('search_name',$search_name);
$kind=$request->param('kind');
$ckind=$request->param('ckind');
$this->assign('ckind',$ckind);
$page=$request->param('page');
$this->assign('c_kind',$kind);
$db=Db::name('bigdata');
$where=array();
if($search_name){
$where['c_name|c_code|c_seller|c_icode'] = array('like', "%{$search_name}%", 'or');
}
$total=$db->where($where)->count();
$gp_list=$db->where($where)->order('c_order desc,c_id desc')->paginate(config('paginate.list_rows'),false,['query'=>get_query()]);
$show = $gp_list->render();
$this->assign('page',$page);
$this->assign('pageshow',$show);
$this->assign('fwhzc_list',$gp_list);
$this->assign('total',$total);
$where['c_status']=0;
$ftotal=Db::name('bigdata')->where($where)->count();
$this->assign('ftotal',$ftotal);
if(request()->isAjax()){
return $this->fetch('ajax_show_list');
}else{
return $this->fetch();
}
}
public function showexport(){
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('PRC');
$kind=input('kind');
if(in_array($kind,[17])){
$where=['n_status'=>1];
if($kind)$where['n_kind']=$kind;
$list=Db::name('news')->where($where)->order('n_id desc')->select();
}else{
$where=['c_status'=>1];
if($kind)$where['c_kind']=$kind;
$list=Db::name('bigdata')->where($where)->order('c_id desc')->select();
}
if(count($list)){
$title="";
switch ($kind){
case 1:
$title="招拍挂平台";
break;
}
$expTitle=$title."_".date("Y-m-d");
$expCellNames=[];
$expCellNames[1]=[['c_code','挂牌代码'],['c_name','企业名称'],['c_gptime','挂牌有效期']];
$expCellName=isset($expCellNames[$kind])?$expCellNames[$kind]:'';
if($expCellName){
$expTableData=[];
foreach ($list as $row){
array_push($expTableData,$row);
}
exportExcel($expTitle, $expCellName, $expTableData);
}
}
}
/**
* 非文化四版挂牌状态修改
*/
public function show_state()
{
$id=input('x');
$kind=input('kind');
$this->assign('c_kind',$kind);
$status=Db::name('bigdata')->where(array('c_id'=>$id))->value('c_status');
if($status==1){
$statedata = array('c_status'=>0);
Db::name('bigdata')->where(array('c_id'=>$id))->setField($statedata);
$this->success('状态禁止');
}else{
$statedata = array('c_status'=>1);
Db::name('bigdata')->where(array('c_id'=>$id))->setField($statedata);
$this->success('状态启用');
}
}
public function show_edit(Request $request)
{
$kind=input('kind');
$page=input('page');
$this->assign('page',$page);
$this->assign('c_kind',$kind);
$types=[];
if(!request()->isAjax()) {
$c_id = input('c_id', 0, 'intval');
if (!$c_id) $this->error('参数错误', url('admin/Bigdata/showlist',array('kind'=>$kind)));
$gp_list = Db::name('bigdata')->where('c_id', $c_id)->find();
try {
$childs=json_decode($gp_list['c_childs'],true);
if(is_string($childs)||empty($childs)){
$childs=json_decode(urldecode($gp_list['c_childs']),true);
}
$gp_list['c_childs']=$childs;
} catch (\Exception $e) {
$gp_list['c_childs']=array();
}
//多图字符串转换成数组
$tpl='show_edit1';
$this->assign('list', $gp_list);
$this->assign('kind',$kind);
$this->assign('types',$types);
return $this->fetch($tpl);
}else{
$jump=url('admin/Bigdata/showlist',array('kind'=>$kind,'page'=>$page));
$img_one='';
$file = request()->file('pic_one');
$ret=$this->dealFile($file);
if(isset($ret['error'])){
$this->error($ret['error'],$jump);
}else{
if(isset($ret['img_one'])&&$ret['img_one']){
$img_one=$ret['img_one'];
$quality=40;
$imgname=pathinfo($img_one,PATHINFO_FILENAME);
$imgtype=pathinfo($img_one,PATHINFO_EXTENSION);
$imgpath=pathinfo($img_one,PATHINFO_DIRNAME);
$imgname=str_replace($imgtype,'', $imgname);
$img=Image::open('.'.$img_one);
$newimg='.'.$imgpath.DIRECTORY_SEPARATOR.$imgname.'_new'.$imgtype;
$img->save($newimg,$imgtype,$quality);
$img_one=$newimg;
}
}
$sl_data=array();
$post=request()->post();
$c_id = input('c_id', 0, 'intval');
$code=input('c_code','');
if($code){
$check=$this->_checkCode($code,$c_id);
if($check){
$this->error('托管代码不能重复');
}
}
$cstype=isset($_POST["c_stype"])?$_POST["c_stype"]:array();
$ctype=input('c_type','');
$ccate=input('c_cate','');
$cdate=date("ymd");
$last=$prev='';
if(empty($code)){
$last=Db::name('bigdata')->where(array('c_id'=>array('neq',$c_id)))->count();
//一级代码:用户代码
$prev=$ctype==1?'A':'B';
//二级代码:展示类别
$prev.=$ccate;
//四级代码:日期
$prev.=$cdate;
//五级代码:X13X14为标的数据包序号,从01起依次编码,如标的为单个数据文件,默认序号为00
$code.=$prev.'00';
$code.=sprintf('%03s',($last+1));
}else{
$prev=substr($code, 0,8);
$last=substr($code,-3);
$last=intval($last)-1;
}
$cchilds=array();
$childs=htmlspecialchars_decode(input('c_childs'));
$childs=json_decode($childs,true);
if(count($childs)){
$index=1;
foreach ($childs as $key=>$child){
$child=json_decode($child,true);
if(count($child)){
$it=array();
$clen=count($child);
foreach ($child as $k=>$c){
$ch=explode("=", $c);
if($ch[0]=='ccode'&&empty($ch[1])){
$ch[1]=$prev.sprintf('%02s',$index).''.sprintf('%03s',($last+1));
}
if($ch[0]=='ccode'){
$index++;
}
$it[$k]=$ch[0].'='.$ch[1];
}
$childs[$key]=json_encode($it,JSON_UNESCAPED_UNICODE);
}
}
$row=array_filter($childs);
$row=array_values($row);
array_walk($row,"walkparse");
$cchilds=$row;
}
$sl_data['c_childs']=json_encode($cchilds,JSON_UNESCAPED_UNICODE);
//图片字段处理
if(!empty($img_one)){
$sl_data['c_logo']=$img_one;
}
$sl_data['c_infostime']=isset($post['c_infostime'])?strtotime($post['c_infostime']):time();
$sl_data['c_infoetime']=isset($post['c_infoetime'])?strtotime($post['c_infoetime']):time();
if(isset($post['c_gptime']))$sl_data['c_gptime']=strtotime($post['c_gptime']);
$sl_data['c_status']=input('c_status',0);
if(isset($post['c_pass']))$sl_data['c_pass']=input('c_pass',0);
if(isset($post['c_cate']))$sl_data['c_cate']=input('c_cate','');
if(isset($post['c_name']))$sl_data['c_name']=input('c_name');
if(isset($post['c_seller']))$sl_data['c_seller']=input('c_seller');
if(isset($post['c_scode']))$sl_data['c_scode']=input('c_scode');
if(isset($post['c_icode']))$sl_data['c_icode']=input('c_icode');
if(isset($post['c_sauth']))$sl_data['c_sauth']=input('c_sauth');
if(isset($post['c_code']))$sl_data['c_code']=input('c_code');
if(isset($post['c_ower']))$sl_data['c_ower']=input('c_ower');
if(isset($post['c_type']))$sl_data['c_type']=input('c_type');
if(isset($post['c_num']))$sl_data['c_num']=input('c_num');
if(isset($post['c_url']))$sl_data['c_url']=input('c_url');
if(isset($post['c_hot']))$sl_data['c_hot']=input('c_hot');
$sl_data['c_tag']=input('c_tag',0);
$sl_data['c_cate']=input('c_cate');
if($sl_data['c_cate']==6){
$sl_data['c_cother']=input('c_cother','');
}
if(isset($post['c_pay']))$sl_data['c_pay']=input('c_pay');
if(isset($post['c_ptype']))$sl_data['c_ptype']=input('c_ptype');
if(isset($post['c_pscope']))$sl_data['c_pscope']=input('c_pscope');
if(isset($post['c_price']))$sl_data['c_price']=input('c_price');
if(isset($post['c_proxy']))$sl_data['c_proxy']=input('c_proxy');
if(isset($post['c_year']))$sl_data['c_year']=input('c_year');
if(isset($post['c_source']))$sl_data['c_source']=input('c_source');
if(isset($post['c_charge']))$sl_data['c_charge']=input('c_charge');
$cright=isset($_POST["c_right"])?$_POST["c_right"]:[];
if(count($cright))$sl_data['c_right']=implode(',', $cright);
$cscene=isset($_POST["c_scene"])?$_POST["c_scene"]:[];
if(count($cscene))$sl_data['c_scene']=implode(',', $cscene);
if(isset($post['c_sother']))$sl_data['c_sother']=input('c_sother');
if(count($cstype))$sl_data['c_stype']=is_array($cstype)?implode(',', $cstype):'';
$sl_data['c_content']=htmlspecialchars_decode(input('c_content'));
$sl_data['c_code']=$code;
$sl_data['c_kind']=input('c_kind','');
$sl_data['c_infostime']=isset($post['c_infostime'])?strtotime($post['c_infostime']):time();
$sl_data['c_infoetime']=isset($post['c_infoetime'])?strtotime($post['c_infoetime']):time();
if(isset($sl_data['c_gptime']))$post['c_gptime']=strtotime($post['c_gptime']);
$sl_data['c_status']=input('c_status',0);
if(isset($sl_data['c_state']))$sl_data['c_state']=input('c_state',1);
$sl_data['c_uid']=session('admin_auth.aid');
$item=new Bigdatadb();
$sl_data['c_id']=$c_id;
$rst=$item->allowField(true)->update($sl_data);
if($rst!==false){
$this->success('修改成功',$jump);
}else{
$this->error('修改失败',$jump);
}
}
}
protected function _checkCode($code='',$id='',$kind=''){
$find=Db::name('bigdata')->where(['c_code'=>$code]);
if($id){
$find->where('c_id','neq',$id);
}
if($kind){
$find->where(['c_kind'=>$kind]);
}
$res=$find->count();
return $res;
}
/**
* 非文化资产挂牌增加
*/
public function show_add(Request $request)
{
$types=[];
if(!request()->isAjax()) {
$tpl='show_add1';
$this->assign('types',$types);
$kind=input('kind');
$this->assign('c_kind',$kind);
return $this->fetch($tpl);
}else{
$jump=url('admin/Bigdata/showlist');
$img_one='';
$img_one2='';
$picall_url='';
$file = request()->file('pic_one');
$ret=$this->dealFile($file);
if(isset($ret['error'])){
$this->error($ret['error'],$jump);
}else{
if(isset($ret['img_one'])&&$ret['img_one'])$img_one=$ret['img_one'];
}
$post=request()->post();
$item=new Bigdatadb();
$sl_data=array();
$curl=input('c_url');
$ckind=input('c_kind');
$cstype=isset($_POST["c_stype"])?$_POST["c_stype"]:array();
$ctype=input('c_type','');
$ccate=input('c_cate','');
$cdate=date("ymd");
$code=input('c_code','');
if($code){
$check=$this->_checkCode($code);
if($check){
$this->error('标的ISLI标志码不能重复');
}
}
$last=Db::name('bigdata')->count();
$prev='';
//一级代码:标的类型
$prev=$ctype==1?'A':'B';
//二级代码:展示类别
$prev.=$ccate;
//四级代码:日期
$prev.=$cdate;
//五级代码:X13X14为标的数据包序号,从01起依次编码,如标的为单个数据文件,默认序号为00
$code.=$prev.'00';
$code.=sprintf('%03s',($last+1));
$cchilds=array();
$childs=htmlspecialchars_decode(input('c_childs'));
$childs=json_decode($childs,true);
if(count($childs)){
$index=1;
foreach ($childs as $key=>$child){
$child=json_decode($child,true);
if(count($child)){
$it=array();
$clen=count($child);
foreach ($child as $k=>$c){
$ch=explode("=", $c);
if($ch[0]=='ccode'&&empty($ch[1])){
$ch[1]=$prev.sprintf('%02s',$index).''.sprintf('%03s',($last+1));
}
if($ch[0]=='ccode'){
$index++;
}
$it[$k]=$ch[0].'='.$ch[1];
}
$childs[$key]=json_encode($it,JSON_UNESCAPED_UNICODE);
}
}
$row=array_filter($childs);
$row=array_values($row);
array_walk($row,"walkparse");
$cchilds=$row;
}
$sl_data['c_code']=$code;
$sl_data['c_kind']=$ckind;
$sl_data['c_infostime']=isset($post['c_infostime'])?strtotime($post['c_infostime']):time();
$sl_data['c_infoetime']=isset($post['c_infoetime'])?strtotime($post['c_infoetime']):time();
if(isset($post['c_gptime']))$sl_data['c_gptime']=strtotime($post['c_gptime']);
$sl_data['c_status']=input('c_status',0);
if(isset($sl_data['c_cate']))$sl_data['c_cate']=input('c_cate','');
if(isset($sl_data['c_state']))$sl_data['c_state']=input('c_state',1);
$sl_data['c_content']=htmlspecialchars_decode(input('c_content'));
$sl_data['c_childs']=json_encode($cchilds,JSON_UNESCAPED_UNICODE);
//图片字段处理
if(!empty($img_one)){
$sl_data['c_logo']=$img_one;
}
$sl_data['c_time']=time();
$sl_data['c_name']=input('c_name','');
$sl_data['c_tag']=input('c_tag',0);
$sl_data['c_seller']=input('c_seller','');
$sl_data['c_icode']=input('c_icode','');
$sl_data['c_scode']=input('c_scode','');
$sl_data['c_sauth']=input('c_sauth','');
$sl_data['c_ower']=input('c_ower','');
$sl_data['c_hot']=input('c_hot');
$sl_data['c_type']=$ctype;
$sl_data['c_num']=input('c_num','');
$sl_data['c_url']=$curl;
$sl_data['c_cate']=$ccate;
if($sl_data['c_cate']==6){
$sl_data['c_cother']=input('c_cother','');
}
$cscene=isset($_POST["c_scene"])?$_POST["c_scene"]:array();
if(count($cscene))$sl_data['c_scene']=is_array($cscene)?implode(',', $cscene):'';
if(count($cstype))$sl_data['c_stype']=is_array($cstype)?implode(',', $cstype):'';
$sl_data['c_sother']=input('c_sother','');
$sl_data['c_pay']=input('c_pay','');
$sl_data['c_ptype']=input('c_ptype');
$sl_data['c_pscope']=input('c_pscope');
$sl_data['c_price']=input('c_price','');
$sl_data['c_proxy']=input('c_proxy','');
$sl_data['c_year']=input('c_year','');
$sl_data['c_source']=input('c_source','');
$sl_data['c_charge']=input('c_charge','');
$cright=isset($_POST["c_right"])?$_POST["c_right"]:array();
if(count($cright))$sl_data['c_right']=is_array($cright)?implode(',', $cright):'';
$sl_data['c_uid']=session('admin_auth.aid');
$rst=$item->allowField(true)->insert($sl_data);
if($rst){
$this->success('增加成功',$jump);
}else{
$this->error('增加失败',$jump);
}
}
}
/**
* 非文化资产挂牌排序
*/
public function show_order()
{
$kind=input('kind');
$this->assign('c_kind',$kind);
if (!request()->isAjax()){
$this->error('提交方式不正确',url('admin/Bigdata/showlist',array('kind'=>$kind)));
}else{
foreach (input('post.') as $c_id => $c_order){
Db::name('bigdata')->update(['c_id'=>$c_id,'c_order'=>$c_order]);
}
$this->success('排序更新成功',url('admin/Bigdata/showlist',array('kind'=>$kind)));
}
}
/**
* 非文化资产挂牌删除(单个)
*/
public function show_del()
{
$p=input('p');
$kind=input('kind');
$this->assign('c_kind',$kind);
$rst=Db::name('bigdata')->delete(input('c_id'));
if($rst!==false){
$this->success('删除成功',url('admin/Bigdata/showlist',array('p' => $p,'kind'=>$kind)));
}else{
$this -> error("删除失败!",url('admin/Bigdata/showlist',array('p'=>$p,'kind'=>$kind)));
}
}
/**
* 非文化资产删除挂牌(全选)
*/
public function show_alldel()
{
$p = input('p');
$kind=input('kind');
$this->assign('c_kind',$kind);
$ids = input('c_id/a');
if(empty($ids)){
$this -> error("请选择待删除的数据",url('admin/Bigdata/showlist',array('p'=>$p,'kind'=>$kind)));
}
if(is_array($ids)){
$where = 'c_id in('.implode(',',$ids).')';
}else{
$where = 'c_id='.$ids;
}
$rst=Db::name('bigdata')->where($where)->delete();
if($rst!==false){
$this->success("删除成功",url('admin/Bigdata/showlist',array('p'=>$p,'kind'=>$kind)));
}else{
$this -> error("删除失败!",url('admin/Bigdata/showlist',array('p'=>$p,'kind'=>$kind)));
}
}
}