=',$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(); 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_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'=>[], // ]); } } } $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(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; } ################################################################其他接口################################################################ ################################################################其他接口################################################################ }