Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/HyFrame.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/scopes/scope_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

607 changes: 607 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

30 changes: 19 additions & 11 deletions Application/Common/Model/HyAccountModel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@
class HyAccountModel extends HyBaseModel{

protected $tableName = 'user';

/**
* 登录
* @param string $account
* @return kvArr
*/
public function login($account){
$arr=$this->where(array('user_no'=>$account,'status'=>1))->field(true)->find();
if($arr)$arr['password']=$this->pwdDecrypt($arr['password'],C('CRYPT_KEY_PWD'));
return $arr;
}

/**
* 登录
* @param string $account array $forbid_roles
* @return array
*/
public function login($account,$forbid_roles){
$arr=$this->where(array('user_no'=>$account,'status'=>1))->field(true)->find();
if($arr && $forbid_roles){
$role_arr = explode(',',$arr['roles']);
foreach($forbid_roles as $k => $v ){
if(in_array($v,$role_arr)){
return false;
}
}
}
if($arr) $arr['password'] = $this->pwdDecrypt($arr['password']);
return $arr;
}
/**
* 密码加密
* @param string $pwd
Expand Down
36 changes: 36 additions & 0 deletions Application/Excel/Conf/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
return array(
'LOAD_ASSETS' =>array(
'GLOBAL' => array(
'CSS' => array(

),
'JS' => array(

)
),
'PLUGINS' => array(
'CSS' => array(

),
'JS' => array(
'Excel/excel' => array(
'jquery-fileapi/FileAPI/FileAPI.min.js',
'jquery-fileapi/FileAPI/FileAPI.exif.js',
'jquery-fileapi/jquery.fileapi.custom.js'
),

)
),

'PAGES' => array(
'CSS' => array(

),
'JS' => array(
'Excel/excel' => 'excel-import.js',
'SqlExport/export' => 'sql-export.js'
)
)
),
);
11 changes: 11 additions & 0 deletions Application/Excel/Controller/EmptyController.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
namespace Excel\Controller;
use Common\Controller\HyAllController;

/**
* 空控制器
* 未定义的控制器,自动转为HyAllController,并解析HyAllModel
* @author Homkai
*
*/
class EmptyController extends HyAllController {}
9 changes: 9 additions & 0 deletions Application/Excel/Controller/ExcelController.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
// 本类由系统自动生成,仅供测试用途
namespace Excel\Controller;
use Common\Controller\HyAllController;
use Excel\Model\ExcelModel;

class ExcelController extends HyAllController {

}
10 changes: 10 additions & 0 deletions Application/Excel/Controller/SqlExportController.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Excel\Controller;
use Common\Controller\HyAllController;
class SqlExportController extends HyAllController {
public function export(){
$this->grade=M('class')->where(array('status'=>1))->group('grade')->getField('grade',true);
$this->display();
}

}
136 changes: 136 additions & 0 deletions Application/Excel/Model/ExcelModel.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php

namespace Excel\Model;
use Common\Model\HyAllModel;

/**
*
*
* @author
*/
class ExcelModel extends HyAllModel {
protected $tableName = 'user';
protected function initTableName(){
}

protected function _initialize(){
}

/**
* @overrides
*/
protected function initInfoOptions() {
}
/**
* @overrides
*/
protected function initSqlOptions() {
return array(
'decrypt'=>true
);
}
/**
* @overrides
*/
protected function initListsOptions() {
}
/**
* @overrides
*/
protected function initFieldsOptions() {
}
protected function initPageOptions(){
}

public function ajax_excel_import(&$json){

//导入PHPExcel类库,因为PHPExcel没有用命名空间,只能inport导入
import("Org.Util.PHPExcel");
//要导入的xls文件,位于根目录下的Public文件夹
$filename='.'.I('path');
//创建PHPExcel对象,注意,不能少了
$PHPExcel=new \PHPExcel();
//如果excel文件后缀名为.xls,导入这个类
import("Org.Util.PHPExcel.Reader.Excel5");
//如果excel文件后缀名为.xlsx,导入这下类
// import("Org.Util.PHPExcel.Reader.Excel2007");
// $PHPReader=new \PHPExcel_Reader_Excel2007();

$PHPReader=new \PHPExcel_Reader_Excel5();
//载入文件
$PHPExcel=$PHPReader->load($filename);
//获取表中的第一个工作表,如果要获取第二个,把0改为1,依次类推
$currentSheet=$PHPExcel->getSheet(0);
//获取总列数
$allColumn=$currentSheet->getHighestColumn();
//获取总行数
$allRow=$currentSheet->getHighestRow();
//循环获取表中的数据,$currentRow表示当前行,从哪行开始读取数据,索引值从0开始
for($currentRow=1;$currentRow<=$allRow;$currentRow++){
//从哪列开始,A表示第一列
for($currentColumn='A';$currentColumn<=$allColumn;$currentColumn++){
//数据坐标
$address=$currentColumn.$currentRow;
//读取到的数据,保存到数组$arr中
$arr[$currentRow][$currentColumn]=$currentSheet->getCell($address)->getValue();
}
}
// dump($this->model);
// dump($arr);
// return $json['data'] = $arr;
$data_for_user = array();
$data_for_student = array();
$error_write = array();
$error_equal = array();
foreach($arr as $k=>$v){
$data_for_user['user_no'] = $v['C'];
$data_for_user['name'] = $v['D'];
$data_for_user['roles'] = '21';
$data_for_user['password'] = 'tHHPF4VYX4V7S7CAryffPdAFtpHlcSZVIL7aUKqVAIEuoQedpaPeSU62_ARBH4fa-6H7qT-vCApYp6CpHSqJn1aUi3XGBsAer2IzMIET7f4TxeJscQxCKd2aNiQe2fyW';
$data_for_user['sex'] = $v['G'];
$data_for_user['birth'] = $v['I'];
$data_for_user['phone'] = val_encrypt($v['E']);
$data_for_user['qq'] = $v['F'];
$data_for_user['email'] = $v['H'];
$data_for_user['country'] = $v['J'];
$class_name = $v['B'];
if(!$class_name){
continue;
}
$class_id = M('class')->where(array(
'name'=>$class_name,
'status'=>array('eq',1)
))->getField('id');
if(!$class_id) {
$json['status'] = false;
$json['info'] = '请先添加班级!';
return $json;
}
$equal_user_id = M('user')->where(array(
'user_no' => $v['C']
))->find();
if($equal_user_id){
$error_equal[] = $v['C'];
continue;
}
$user_id = M('user')->data($data_for_user)->add();
$data_for_student['user_id'] = $user_id;
$data_for_student['class_id'] = $class_id;
$student_id = M('student')->data($data_for_student)->add();
if($user_id && $class_id && $student_id){
continue;
}else{
$error_write[] = $v['C'];
break;
}
}
// dump($error_equal);
// dump($error_write);
$json['status'] = true;
$json['info'] = '导入成功!';
$json['data'] = array($error_equal,$error_write);
return $json;
}


}
Loading