diff --git a/application/admin/controller/Base.php b/application/admin/controller/Base.php index 304091e..19006e4 100644 --- a/application/admin/controller/Base.php +++ b/application/admin/controller/Base.php @@ -19,7 +19,7 @@ class Base extends Controller{ '10004'=>'未找到有效数据', '10005'=>'参数格式错误', '10006'=>'参数不能为空', - '10007'=>'', + '10007'=>'数据已存在', '10008'=>'', '10009'=>'', '10010'=>'', diff --git a/application/admin/controller/Estimate.php b/application/admin/controller/Estimate.php index 5ef2dbb..c80e8c6 100644 --- a/application/admin/controller/Estimate.php +++ b/application/admin/controller/Estimate.php @@ -4,6 +4,10 @@ namespace app\admin\controller; use think\Db; use think\Log; +use PHPExcel; +use PHPExcel_Cell_DataType; +use PHPExcel_IOFactory; +use PHPExcel_Style_NumberFormat; class Estimate extends Base{ @@ -58,22 +62,220 @@ class Estimate extends Base{ public function estimate_add(){ return $this->fetch(); } - - ################################################################业务接口################################################################ - ################################################################业务接口################################################################ - - ################################################device_data_list - public function device_data_list_action($data){ - $result = Db::table('app_device_data')->where(['is_del'=>0])->field('id,name,pic,content,page_measure,bluetooth_type,device_model')->select(); - foreach ($result as $key => $value) { - unset($result[$key]['ROW_NUMBER']); + public function estimate_content_observe(){ + $data = input(); + $result = Db::table('admin_estimate')->where(['id'=>$data['id']])->find(); + // dump($result); + $data = [ + 'province'=>$result['province'], + 'city'=>$result['city']=='无'?'':'-'.$result['city'], + 'list'=>[], + ]; + $temporary_array = json_decode($result['content'],true); + $temporary_array2 = []; + foreach ($temporary_array as $key => $value) { + $num = array_push($temporary_array2,[ + 'title'=>$key.'评定标准', + 'list'=>[], + ]); + foreach ($value as $k1 => $v1) { + $num2 = array_push($temporary_array2[$num-1]['list'],[ + 'title'=>$k1, + 'score'=>'', + 'gender'=>'', + 'choose_num'=>'', + 'list'=>[], + ]); + foreach ($v1 as $k2 => $v2) { + $temporary_array2[$num-1]['list'][$num2-1]['score'] = $v2['score']; + $temporary_array2[$num-1]['list'][$num2-1]['gender'] = $v2['gender']; + $temporary_array2[$num-1]['list'][$num2-1]['choose_num'] = $v2['choose_num']; + // $num3 = array_push($temporary_array2[$num-1]['list'][$num2-1]['list'],[ + // 'title'=>$k2, + // 'list'=>[], + // ]); + } + } } - if(empty($result)){ - return $this->msg(10004); + $data['list'] = $temporary_array2; + // foreach ($variable as $key => $value) { + // # code... + // } + // foreach ($temporary_array as $key => $value) { + // array_push($temporary_array2,[ + // 'province'=>$result['province'], + // 'city'=>$result['city']=='无'?'':'-'.$result['city'], + // 'title'=>$key.'评定标准', + // 'list'=>[], + // ]); + // } + + dump($data); + // dump($temporary_array2); + dump($temporary_array); + die; + // return $this->fetch(); + } + + ################################################################业务接口################################################################ + ################################################################业务接口################################################################ + + ################################################获取execl中数组 + public function submit_rule(){ + // $file = request()->file('file'); + $file = request()->file('execl'); + $name = request()->param(); + $address_data = explode(',',$name['address']); + // dump($name); + // die; + if($name['type'] == 'create'){ + $rule_is_true = Db::table('admin_estimate')->where(['province'=>$address_data[0],'city'=>$address_data[1]==''?'无':$address_data[1]])->count(); + if($rule_is_true > 0){ + return $this->msg(10007); + } + } + if($file){ + // 移动到框架应用根目录/public/uploads/ 目录下 + $file_name_new = time().'_ceshi.xlsx'; + $info = $file->validate(['size' => 2048000, 'ext' => 'xlsx'])->move(ROOT_PATH . 'public' . DS . 'estimate',$file_name_new); + if($info){ + $original_data = $this->excelToArray(ROOT_PATH . 'public' . DS . 'estimate' . DS . $info->getSaveName()); + $handle_data = $this->transformation_data($original_data,$address_data,$name['type']); + if($name['type'] == 'create'){ + $result = Db::table('admin_estimate')->insert($handle_data); + }else{ + $result = Db::table('admin_estimate')->where(['id'=>$name['id']])->update($handle_data); + } + + // return $this->msg(10002); + // 成功上传后 获取上传信息 + // 输出 jpg + // echo $info->getExtension(); + // // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg + // echo $info->getSaveName(); + // // 输出 42a79759f284b767dfcb2a0197904287.jpg + // echo $info->getFilename(); + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + + }else{ + // 上传失败获取错误信息 + return $this->msg(10001, $file->getError()); + // echo $file->getError(); + } }else{ - return $this->msg(['list'=>$result]); + return $this->msg(10001, '文件缺失'); } } + // 读取execl文件数据 + private function excelToArray($filename){ + vendor('PHPExcel.PHPExcel'); + $objPHPExcelReader = \PHPExcel_IOFactory::load($filename); + + $sheet = $objPHPExcelReader->getSheet(0); // 读取第一个工作表(编号从 0 开始) + $highestRow = $sheet->getHighestRow(); // 取得总行数 + $highestColumn = \PHPExcel_Cell::columnIndexFromString($sheet->getHighestColumn()); // 取得总列数 + + // 一次读取一列 + $res_arr = array(); + for ($row = 2; $row <= $highestRow; $row++) { + $row_arr = array(); + for ($column = 0; $column < $highestColumn; $column++) { + //判断单元格是否包含公式 + if ($sheet->getCellByColumnAndRow($column, $row)->isFormula()) { + $val = $sheet->getCellByColumnAndRow($column, $row)->getFormattedValue(); + } else { + $val = $sheet->getCellByColumnAndRow($column, $row)->getValue(); + } + $row_arr[] = $val; + } + + if (count($row_arr) > 0) { + $res_arr[] = $row_arr; + } + } + + return $res_arr; + } + + //处理估分数据格式 + private function transformation_data($data,$daaress,$type='create'){ + // dump($daaress); + $temporary_daaress = explode(',',$daaress); + // dump($temporary_daaress); + // die; + if($type == 'create'){ + $return_result = [ + 'province'=>$temporary_daaress[0] == ''?'无':$temporary_daaress[0], + 'city'=>$temporary_daaress[1] == ''?'无':$temporary_daaress[1], + 'area'=>'无', + 'create_time'=>date('Y-m-d H:i:s'), + 'update_time'=>date('Y-m-d H:i:s'), + 'content'=>[] + ]; + }else{ + $return_result = [ + 'update_time'=>date('Y-m-d H:i:s'), + 'content'=>[] + ]; + } + $temporary_array = []; + foreach ($data as $key => $value) { + if(!array_key_exists($value[0],$temporary_array)){ + // 如果第一分类不存在 + $temporary_array[$value[0]][$value[1]][$value[3]] = [ + 'score'=>$value[2], + 'unit_data'=>$value[4], + 'gender'=>$value[5], + 'choose_num'=>$value[9], + 'proportion'=>$value[10], + 'content'=>[ + [$value[6],$value[7],$value[8]] + ], + ]; + }else{ + // 第一分类存在 + if(!array_key_exists($value[1],$temporary_array[$value[0]])){ + // 如果第二分类不存在 + // array_push($temporary_array[$value[0]]); + $temporary_array[$value[0]][$value[1]][$value[3]] = [ + 'score'=>$value[2], + 'unit_data'=>$value[4], + 'gender'=>$value[5], + 'choose_num'=>$value[9], + 'proportion'=>$value[10], + 'content'=>[ + [$value[6],$value[7],$value[8]] + ], + ]; + }else{ + // 第二分类存在 + if(!array_key_exists($value[3],$temporary_array[$value[0]][$value[1]])){ + // 如果项目名不存在 + $temporary_array[$value[0]][$value[1]][$value[3]] = [ + 'score'=>$value[2], + 'unit_data'=>$value[4], + 'gender'=>$value[5], + 'choose_num'=>$value[9], + 'proportion'=>$value[10], + 'content'=>[ + [$value[6],$value[7],$value[8]] + ], + ]; + }else{ + array_push($temporary_array[$value[0]][$value[1]][$value[3]]['content'],[$value[6],$value[7],$value[8]]); + } + } + } + } + // return $temporary_array; + $temporary_array = json_encode($temporary_array); + $return_result['content'] = $temporary_array; + return $return_result; + } diff --git a/application/admin/view/estimate/estimate_add.html b/application/admin/view/estimate/estimate_add.html index aeacbcd..0c4a61e 100644 --- a/application/admin/view/estimate/estimate_add.html +++ b/application/admin/view/estimate/estimate_add.html @@ -55,14 +55,14 @@
+| ID | +区域 | +创建时间 | +修改时间 | +操作 | +
|---|---|---|---|---|
| {$vo.id} | +{$vo.province}/{$vo.city == '无'?'':$vo.city} | +{$vo.create_time} | +{$vo.update_time} | + ++ + + | +
diff --git a/application/admin/view/estimate/estimate_content_observe.html b/application/admin/view/estimate/estimate_content_observe.html new file mode 100644 index 0000000..4f849f6 --- /dev/null +++ b/application/admin/view/estimate/estimate_content_observe.html @@ -0,0 +1,359 @@ + + +
+ +
+ + + + + + + + + +
+ +