diff --git a/Application/Admin/Controller/SocietyInfoController.class.php b/Application/Admin/Controller/SocietyInfoController.class.php
index f2182a0b0..85a72bd25 100644
--- a/Application/Admin/Controller/SocietyInfoController.class.php
+++ b/Application/Admin/Controller/SocietyInfoController.class.php
@@ -114,7 +114,9 @@ class SocietyInfoController extends ThinkController
$v['num'] = $k+1+intval((I('get.p', 0)?I('get.p', 0):1)-1)*$row;
$v['sociaty_level_str'] = $this->level[$v['sociaty_level']];
- if (time() - $v['communication_time'] > $gap * 86400)
+ if (time() - $v['communication_time'] > $gap * 86400
+ && $v['is_potential'] == 1
+ )
$v['is_gap_time'] = 1;
}
@@ -299,9 +301,24 @@ class SocietyInfoController extends ThinkController
if ($_POST) {
$save = I("post.");
+ if (empty($save['province'])) {
+ $this->error("省份为必填项");
+ }
+ if (empty($save['city'])) {
+ $this->error("城市为必填项");
+ }
if (empty($save['company_name'])) {
$this->error("公司为必填项");
}
+ if (empty($save['game_types'])) {
+ $this->error("游戏类型为必填项");
+ }
+ foreach ($save['game_types'] as $v) {
+ $save['game_type'] .= $v . "/";
+ }
+
+ $save['game_type'] = trim($save['game_type'], '/');
+// dump($save['game_type']);die();
if ($save['province'] == "请选择省份") $save['province'] = '';
if ($save['city'] == "请选择城市") $save['city'] = '';
$save['create_time'] = time();
@@ -331,6 +348,15 @@ class SocietyInfoController extends ThinkController
$save['province'] = '';
$save['city'] = '';
}
+ if (empty($save['city'])) {
+ $this->error("城市为必填项");
+ }
+ if (empty($save['company_name'])) {
+ $this->error("公司为必填项");
+ }
+ if (empty($save['game_type'])) {
+ $this->error("游戏类型为必填项");
+ }
$save['game_type'] = trim($save['game_type'], '/');
$save['communication_time'] = time();
@@ -463,6 +489,7 @@ class SocietyInfoController extends ThinkController
// 导入
public function excelImport() {
+
header("Content-Type:text/html;charset=utf-8");
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
@@ -473,8 +500,10 @@ class SocietyInfoController extends ThinkController
$info = $upload->uploadOne($_FILES['excelData']);
$filename = './Uploads/'.$info['savepath'].$info['savename'];
$exts = $info['ext'];
+
if(!$info) {// 上传错误提示错误信息
- $this->error($upload->getError());
+ $this->ajaxReturn(['msg'=>$upload->getError(),"status"=>0]);
+// $this->error($upload->getError());
}
// 上传成功
$datas = $this->parseExcelIn($filename, $exts);
@@ -489,68 +518,83 @@ class SocietyInfoController extends ThinkController
if ($flag == 0) continue;
if ($k == 1) continue;
$inserts[$k-2]['province'] = $v['A'] ?? '';
+ if (!$v['A']) {
+ $this->ajaxReturn(['msg'=>"省份不能为空".$k,"status"=>0]);
+ }
+
$inserts[$k-2]['city'] = $v['B'] ?? '';
+ if (!$v['B']) {
+ $this->ajaxReturn(['msg'=>"城市不能为空".$k,"status"=>0]);
+ }
+
$inserts[$k-2]['company_name'] = $v['C'] ?? '';
if (mb_strlen($inserts[$k-2]['company_name'], "utf-8") > 100) {
- $this->error("公司名太长".$k);
+ $this->ajaxReturn(['msg'=>"公司名太长".$k,"status"=>0]);
}
if (!$inserts[$k-2]['company_name']) {
- $this->error("公司不能为空".$k);
+ $this->ajaxReturn(['msg'=>"公司不能为空".$k,"status"=>0]);
}
$inserts[$k-2]['register_capital'] = $v['D'] ?? '';
if (strlen($inserts[$k-2]['register_capital']) > 50) {
- $this->error("推荐人太长".$k);
+ $this->ajaxReturn(['msg'=>"推荐人太长".$k,"status"=>0]);
}
$inserts[$k-2]['functionary'] = $v['E'] ?? '';
if (strlen($inserts[$k-2]['functionary']) > 50) {
- $this->error("负责人太长".$k);
+ $this->ajaxReturn(['msg'=>"负责人太长".$k,"status"=>0]);
}
$inserts[$k-2]['phone'] = $v['F'] ?? '';
if (strlen($inserts[$k-2]['phone']) > 50) {
- $this->error("手机号太长".$k);
+ $this->ajaxReturn(['msg'=>"手机号太长".$k,"status"=>0]);
}
$inserts[$k-2]['wechat'] = $v['G'] ?? '';
if (strlen($inserts[$k-2]['wechat']) > 50) {
- $this->error("微信号太长".$k);
+ $this->ajaxReturn(['msg'=>"微信号太长".$k,"status"=>0]);
}
$inserts[$k-2]['qq'] = $v['H'] ?? '';
if (strlen($inserts[$k-2]['qq']) > 50) {
- $this->error("qq号太长".$k);
+ $this->ajaxReturn(['msg'=>"qq号太长".$k,"status"=>0]);
}
$inserts[$k-2]['game_type'] = $v['I'] ?? '';
$inserts[$k-2]['game_name'] = $v['J'] ?? '';
if (strlen($inserts[$k-2]['game_name']) > 50) {
- $this->error("游戏名太长".$k);
+ $this->ajaxReturn(['msg'=>"游戏名太长".$k,"status"=>0]);
}
$inserts[$k-2]['join_platform'] = $v['K'] ?? '';
if (strlen($inserts[$k-2]['join_platform']) > 50) {
- $this->error("合作平台太长".$k);
+ $this->ajaxReturn(['msg'=>"合作平台太长".$k,"status"=>0]);
}
$inserts[$k-2]['promote_scale'] = $v['L'] ?? '';
if (strlen($inserts[$k-2]['promote_scale']) > 50) {
- $this->error("推广规模太长".$k);
+ $this->ajaxReturn(['msg'=>"推广规模太长".$k,"status"=>0]);
}
+
$inserts[$k-2]['turnover'] = $v['M'] ?? '';
if (strlen($inserts[$k-2]['turnover']) > 50) {
- $this->error("流水太长".$k);
+ $this->ajaxReturn(['msg'=>"公会等级".$k,"status"=>0]);
+ }
+
+ $inserts[$k-2]['turnover'] = $v['N'] ?? '';
+ if (strlen($inserts[$k-2]['turnover']) > 50) {
+ $this->ajaxReturn(['msg'=>"流水太长".$k,"status"=>0]);
}
- $inserts[$k-2]['address'] = $v['N'] ?? '';
+ $inserts[$k-2]['address'] = $v['O'] ?? '';
if (mb_strlen($inserts[$k-2]['address'], 'utf-8') > 100) {
- $this->error("地址太长".$k);
+ $this->ajaxReturn(['msg'=>"地址太长".$k,"status"=>0]);
}
- $inserts[$k-2]['league_info'] = $v['O'] ?? '';
+ $inserts[$k-2]['league_info'] = $v['P'] ?? '';
if (strlen($inserts[$k-2]['league_info']) > 100) {
- $this->error("联盟信息太长".$k);
+ $this->ajaxReturn(['msg'=>"联盟信息太长".$k,"status"=>0]);
}
- $inserts[$k-2]['is_potential'] = $v['P']=="是" ? 1 : 0;
- $inserts[$k-2]['remark'] = $v['Q'] ?? '';
+ $inserts[$k-2]['is_potential'] = $v['Q']=="是" ? 1 : 0;
+ $inserts[$k-2]['remark'] = $v['R'] ?? '';
if (strlen($inserts[$k-2]['remark']) > 100) {
- $this->error("备注太长".$k);
+ $this->ajaxReturn(['msg'=>"备注太长".$k,"status"=>0]);
}
- $inserts[$k-2]['interface_person'] = $v['R'] ?? '';
+ $inserts[$k-2]['interface_person'] = $v['S'] ?? '';
if (strlen($inserts[$k-2]['interface_person']) > 50) {
- $this->error("对接人太长".$k);
+ $this->ajaxReturn(['msg'=>"对接人太长".$k,"status"=>0]);
}
+
$inserts[$k-2]['create_time'] = time();
$inserts[$k-2]['update_time'] = time();
$inserts[$k-2]['communication_time'] = time();
@@ -559,13 +603,14 @@ class SocietyInfoController extends ThinkController
$gameTypes = explode('/', $v['I']);
foreach ($gameTypes as $gameType) {
if (!M('game_type', 'tab_')->where(["type_name" => $gameType])->find()) {
- $this->error("游戏类型有误:{$gameType}");
+ $this->ajaxReturn(['msg'=>"游戏类型有误:{$gameType}","status"=>0]);
return;
}
}
}
M('society_info', 'tab_')->addAll($inserts);
- $this->success("导入成功");
+ $this->ajaxReturn(['msg'=>"导入成功","status"=>1]);
+// $this->success("导入成功");
}
private function parseExcelIn($filename, $exts) {
@@ -575,13 +620,13 @@ class SocietyInfoController extends ThinkController
//创建PHPExcel对象,注意,不能少了\
$PHPExcel=new \PHPExcel();
//如果excel文件后缀名为.xls,导入这个类
- if($exts == 'xls'){
+// if($exts == 'xls'){
//import("Org.Util.PHPExcel.Reader.Excel5");
$PHPReader=new \PHPExcel_Reader_Excel5();
- }else if($exts == 'xlsx'){
- //import("Org.Util.PHPExcel.Reader.Excel2007");
- $PHPReader=new \PHPExcel_Reader_Excel2007();
- }
+// }else if($exts == 'xlsx'){
+// //import("Org.Util.PHPExcel.Reader.Excel2007");
+// $PHPReader=new \PHPExcel_Reader_Excel2007();
+// }
//载入文件
$PHPExcel=$PHPReader->load($filename);
//获取表中的第一个工作表,如果要获取第二个,把0改为1,依次类推
@@ -606,4 +651,32 @@ class SocietyInfoController extends ThinkController
return $data;
}
+ //模板导出
+ public function downloadSocial()
+ {
+ header("Content-type: text/html; charset=utf-8");
+ error_reporting(E_ALL);
+ ini_set('display_errors', TRUE);
+ ini_set('display_startup_errors', TRUE);
+
+ define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '
');
+
+ Vendor("PHPExcel.PHPExcel");
+ $objPHPExcel = new \PHPExcel();
+ $objReader = \PHPExcel_IOFactory::createReader('Excel2007');
+
+ //设置模板文件
+ $objPHPExcel = $objReader->load("Public/Admin/excel/social_template.xls");
+
+ $fileName = "公会信息模板";
+
+ ob_end_clean();//清除缓冲区,避免乱码
+ header('pragma:public');
+ header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $fileName .'".xls');
+ header("Content-Disposition:attachment;filename={$fileName}.xls");//attachment新窗口打印inline本窗口打印
+ $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+ $objWriter->save('php://output');
+ exit;
+ }
+
}
diff --git a/Application/Admin/View/SocietyInfo/add.html b/Application/Admin/View/SocietyInfo/add.html
index d6257700f..b6fc92202 100644
--- a/Application/Admin/View/SocietyInfo/add.html
+++ b/Application/Admin/View/SocietyInfo/add.html
@@ -32,7 +32,7 @@
省份: | +*省份: | @@ -40,7 +40,7 @@ | ||||||||||||
城市: | +*城市: | @@ -84,8 +84,8 @@ | ||||||||||||
游戏类型: | - +*游戏类型: | +
{$_page|default=''}
@@ -375,6 +376,12 @@
//导航高亮
highlight_subnav("{:U('lists')}");
$(function(){
+ $("#downloads").on("click",function(){
+ var url = $(this).attr("url");
+ window.location.href = url;
+ return false;;
+
+ });
$("#excel_in").click(function () {
$(".search_list").hide();
$(".excel_list").show();
@@ -382,6 +389,46 @@
$(".model").show();
return false;
});
+
+ $("#submit").click(function () {
+ var fileObj = document.getElementById("excelData").files[0]; // js 获取文件对象
+ var url = $(this).attr('url');
+ var oReq = new XMLHttpRequest();
+
+ var formFile = new FormData();
+ formFile.append("excelData", fileObj,"excelData.xlsx"); //加入文件对象
+
+ layer.confirm('【提示】是否确认财务部编辑保存', {
+ btn: ['确认','取消'],
+ title:false
+ }, function(index){
+ $.ajax({
+ url:url,
+ type:"post",
+ data:formFile,
+ dataType:'json',
+ cache: false,
+ processData: false,
+ contentType: false,
+ success:function(data){
+ if (data.status == 1) {
+ layer.msg(data.msg);
+ setTimeout(function(){
+ // window.parent.reload()
+ window.location.href = "{:U('lists')}";
+ },2000)
+
+ } else {
+ layer.msg(data.msg);
+ }
+
+ }
+ })
+ });
+
+ return false;
+ });
+
$("#excel_back").click(function () {
$(".search_list").show();
$(".excel_list").hide();
diff --git a/Public/Admin/excel/social_template.xls b/Public/Admin/excel/social_template.xls
new file mode 100644
index 000000000..0c9502a78
Binary files /dev/null and b/Public/Admin/excel/social_template.xls differ
|