398 lines
18 KiB
PHP
398 lines
18 KiB
PHP
<?php
|
|
|
|
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{
|
|
|
|
protected $page_num = 10;
|
|
protected $file_max = 1024*1024*5;//xxxMB
|
|
################################################################接口################################################################
|
|
################################################################接口################################################################
|
|
################################################################接口################################################################
|
|
// 获取系统设备列表
|
|
public function index($page = 1){
|
|
$data = input();
|
|
$pd = true;
|
|
// $parameter = [];
|
|
$parameter['type'] = 1;
|
|
// $parameter['is_del'] = 0;
|
|
if(array_key_exists('tt', $data)){
|
|
$page = $data['page_num'];
|
|
unset($data['page_num']);
|
|
unset($data['tt']);
|
|
$pd = false;
|
|
// $parameter['type'] = 1;
|
|
// if($data['status_num'] === "0" || $data['status_num'] === "1"){
|
|
// $parameter['is_del'] = $data['status_num'];
|
|
// }
|
|
|
|
// if($data['tel']){
|
|
// $parameter['tel'] = $data['tel'];
|
|
// }
|
|
// if($data['email']){
|
|
// $parameter['email'] = $data['email'];
|
|
// }
|
|
// if($data['s_time']){
|
|
// $parameter['create_time'] = ['>=',$data['s_time']];
|
|
// }
|
|
// if($data['e_time']){
|
|
// $parameter['create_time'] = ['<=',$data['e_time']];
|
|
// }
|
|
}
|
|
$num = Db::table('admin_estimate')->where($parameter)->count();
|
|
$result = Db::table('admin_estimate')->where($parameter)->order('is_del,id desc')->page($page,$this->page_num)->select();
|
|
// dump($num);
|
|
// dump($result);
|
|
// die;
|
|
if(!$pd){
|
|
$result['num'] = $num;
|
|
$result['data'] = $result;
|
|
return $this->msg(0,'success',$result);
|
|
}
|
|
$this->assign([
|
|
'result' => $result,
|
|
'num' => $num,
|
|
]);
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function estimate_add(){
|
|
return $this->fetch();
|
|
}
|
|
public function estimate_edit(){
|
|
$data = input();
|
|
$this->assign([
|
|
'id' => $data['id'],
|
|
]);
|
|
return $this->fetch();
|
|
}
|
|
// 规则详情页面
|
|
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);
|
|
|
|
// return $this->msg($temporary_array);
|
|
|
|
$temporary_array2 = [];
|
|
|
|
foreach ($temporary_array as $key => $value) {
|
|
// 男女
|
|
foreach ($value as $dlk1 => $dlv1) {
|
|
// 大类
|
|
$num = array_push($temporary_array2,[
|
|
'title'=> $key==1?'男生'.$dlk1.'评定标准':'女生'.$dlk1.'评定标准',
|
|
'list'=>[],
|
|
]);
|
|
foreach ($dlv1 as $dlk2 => $dlv2) {
|
|
// 第二类
|
|
$num2 = array_push($temporary_array2[$num-1]['list'],[
|
|
'title'=>$dlk2,
|
|
'choose_num'=>$dlv2['choose_num'],
|
|
'choose_all'=>count($dlv2['list']),
|
|
'list'=>[],
|
|
]);
|
|
foreach ($dlv2['list'] as $xmk1 => $xmv1) {
|
|
$num3 = array_push($temporary_array2[$num-1]['list'][$num2-1]['list'],[
|
|
'title'=>$xmk1,
|
|
'unit_data'=>$xmv1['unit_data'],
|
|
'proportion'=>$xmv1['proportion'],
|
|
'score'=>$xmv1['score'],
|
|
// 'list'=>count($v2['content'])==0?[['成绩','无'],['数据','无']]:[['成绩'],['数据']],
|
|
'list'=>[['成绩'],['数据']],
|
|
]);
|
|
foreach ($xmv1['content'] as $gzk1 => $gzv1) {
|
|
array_push($temporary_array2[$num-1]['list'][$num2-1]['list'][$num3-1]['list'][0],$gzv1[2]);
|
|
array_push($temporary_array2[$num-1]['list'][$num2-1]['list'][$num3-1]['list'][1],$gzv1[1].$gzv1[0]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// return $this->msg($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'=>'',
|
|
// 'choose_num'=>'',
|
|
// 'choose_all'=>count($v1),
|
|
// 'list'=>[],
|
|
// ]);
|
|
// foreach ($v1 as $k2 => $v2) {
|
|
// $temporary_array2[$num-1]['list'][$num2-1]['score'] = $v2['score'];
|
|
|
|
|
|
// $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,
|
|
// 'gender'=>'',
|
|
// 'unit_data'=>$v2['unit_data'],
|
|
// 'proportion'=>$v2['proportion'],
|
|
// 'list'=>count($v2['content'])==0?[['成绩','无'],['数据','无']]:[['成绩'],['数据']],
|
|
// ]);
|
|
// if($v2['gender'] == '1'){
|
|
// $temporary_array2[$num-1]['list'][$num2-1]['list'][$num3-1]['gender'] = '男生';
|
|
// }else if($v2['gender'] == '2'){
|
|
// $temporary_array2[$num-1]['list'][$num2-1]['list'][$num3-1]['gender'] = '女生';
|
|
// }else{
|
|
// $temporary_array2[$num-1]['list'][$num2-1]['list'][$num3-1]['gender'] = '男生&女生';
|
|
// }
|
|
// foreach ($v2['content'] as $k3 => $v3) {
|
|
// array_push($temporary_array2[$num-1]['list'][$num2-1]['list'][$num3-1]['list'][0],$v3[2]);
|
|
// array_push($temporary_array2[$num-1]['list'][$num2-1]['list'][$num3-1]['list'][1],$v3[1].$v3[0]);
|
|
// }
|
|
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
$data['list'] = $temporary_array2;
|
|
// return $this->msg($data);
|
|
$this->assign([
|
|
'result' => $data,
|
|
'num' => 1,
|
|
]);
|
|
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 = date('YmdHis').'_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']);
|
|
// die;
|
|
if($name['type'] == 'create'){
|
|
$result = Db::table('admin_estimate')->insert($handle_data);
|
|
}else{
|
|
$result = Db::table('admin_estimate')->where(['id'=>$name['update_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(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 = $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 = [];
|
|
|
|
|
|
$gender = [];
|
|
foreach ($data as $key => $value) {
|
|
$gender = explode(',',$value[5]);
|
|
foreach ($gender as $gk => $gv) {
|
|
if(!array_key_exists($gv,$temporary_array)){
|
|
// $temporary_array[$gv][$value[0]][$value[1]]['score'] = $value[2];
|
|
$temporary_array[$gv][$value[0]][$value[1]]['choose_num'] = $value[9];
|
|
$temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]] = [
|
|
'unit_data'=>$value[4],
|
|
'proportion'=>$value[10],
|
|
'value'=>$value[11],
|
|
'type'=>$value[12],
|
|
'score'=>$value[2],
|
|
];
|
|
$temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]]['content'] = [[$value[6],$value[7],$value[8]]];
|
|
// if($value[6] == null){
|
|
// $temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]]['content'] = [];
|
|
// }else{
|
|
// $temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]]['content'] = [[$value[6],$value[7],$value[8]]];
|
|
// }
|
|
}else{
|
|
// 如果性别已经存在
|
|
if(!array_key_exists($value[0],$temporary_array[$gv])){
|
|
// 如果第一分类不存在
|
|
// $temporary_array[$gv][$value[0]][$value[1]]['score'] = $value[2];
|
|
$temporary_array[$gv][$value[0]][$value[1]]['choose_num'] = $value[9];
|
|
$temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]] = [
|
|
'unit_data'=>$value[4],
|
|
'proportion'=>$value[10],
|
|
'value'=>$value[11],
|
|
'type'=>$value[12],
|
|
'score'=>$value[2],
|
|
];
|
|
$temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]]['content'] = [[$value[6],$value[7],$value[8]]];
|
|
// if($value[6] == null){
|
|
// $temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]]['content'] = [];
|
|
// }else{
|
|
// $temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]]['content'] = [[$value[6],$value[7],$value[8]]];
|
|
// }
|
|
}else{
|
|
// 第一分类存在
|
|
if(!array_key_exists($value[1],$temporary_array[$gv][$value[0]])){
|
|
// 如果第二分类不存在
|
|
// array_push($temporary_array[$value[0]]);
|
|
// $temporary_array[$gv][$value[0]][$value[1]]['score'] = $value[2];
|
|
$temporary_array[$gv][$value[0]][$value[1]]['choose_num'] = $value[9];
|
|
$temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]] = [
|
|
'unit_data'=>$value[4],
|
|
'proportion'=>$value[10],
|
|
'value'=>$value[11],
|
|
'type'=>$value[12],
|
|
'score'=>$value[2],
|
|
];
|
|
$temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]]['content'] = [[$value[6],$value[7],$value[8]]];
|
|
// if($value[6] == null){
|
|
// $temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]]['content'] = [];
|
|
// }else{
|
|
// $temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]]['content'] = [[$value[6],$value[7],$value[8]]];
|
|
// }
|
|
}else{
|
|
// 第二分类存在
|
|
|
|
if(!array_key_exists($value[3],$temporary_array[$gv][$value[0]][$value[1]]['list'])){
|
|
// 如果项目名不存在
|
|
// $temporary_array[$gv][$value[0]][$value[1]]['score'] = $value[2];
|
|
$temporary_array[$gv][$value[0]][$value[1]]['choose_num'] = $value[9];
|
|
$temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]] = [
|
|
'unit_data'=>$value[4],
|
|
'proportion'=>$value[10],
|
|
'value'=>$value[11],
|
|
'type'=>$value[12],
|
|
'score'=>$value[2],
|
|
];
|
|
$temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]]['content'] = [[$value[6],$value[7],$value[8]]];
|
|
// if($value[6] == null){
|
|
// $temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]]['content'] = [];
|
|
// }else{
|
|
// $temporary_array[$gv][$value[0]][$value[1]]['list'][$value[3]]['content'] = [[$value[6],$value[7],$value[8]]];
|
|
// }
|
|
}else{
|
|
array_push($temporary_array[$gv][$value[0]][$value[1]]['list'][$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;
|
|
}
|
|
|
|
|
|
|
|
|
|
################################################################其他接口################################################################
|
|
################################################################其他接口################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |