123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- <?php
- // +----------------------------------------------------------------------
- // | ThinkAdmin
- // +----------------------------------------------------------------------
- // | 版权所有 2014~2019 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
- // +----------------------------------------------------------------------
- // | 官方网站: http://demo.thinkadmin.top
- // +----------------------------------------------------------------------
- // | 开源协议 ( https://mit-license.org )
- // +----------------------------------------------------------------------
- // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
- // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
- // +----------------------------------------------------------------------
- namespace app\user\controller;
- use app\common\constant\CommonConstant;
- use app\common\service\DingtalkService;
- use app\common\service\UserService;
- use app\common\model\User as model;
- use library\Controller;
- /**
- * 员工
- */
- class Member extends Controller
- {
- /**
- * 绑定数据表
- * @var string
- */
- protected $table = 'StoreMember';
- /**
- * 控制器初始化
- */
- protected function initialize()
- {
- $this->get_status_list = CommonConstant::get_status_list();
- $this->get_signature_status_list = CommonConstant::get_signature_status_list();
- }
- /**
- * 列表
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function index()
- {
- $status = input('status');
- $signature_status = input('signature_status');
- $this->title = '员工列表';
- $query = $this->_query($this->table)
- ->field('is_deleted',true)
- ->where('is_deleted', CommonConstant::IS_DELETED_0)
- ->when(array_key_exists($status, $this->get_status_list), function ($query) use ($status) {
- $query->where('status', $status);
- })
- ->when(array_key_exists($signature_status, $this->get_signature_status_list), function ($query) use ($signature_status) {
- $query->where('signature_status', $signature_status);
- })
- ->like('name,mobile,title');
- $query->page();
- }
- /**
- * 列表数据处理
- * @param array $data
- * @throws \Exception
- */
- protected function _index_page_filter(&$data)
- {
- if($data){
- $department_list = UserService::get_department_column();
- $this->user_list = UserService::get_list(1);
- $user_object = array_column($this->user_list->toArray(),null,'userid');
- foreach ($data as &$value) {
- // 所属部门
- $department_ids = explode(',',$value['department']);
- $department_text = '';
- foreach ($department_ids as $val){
- if(array_key_exists($val,$department_list)){
- $department_text .= $department_list[$val].',';
- }
- }
- $value['department_text'] = $department_text;
- // 员工的直属主管
- $manager_text = !empty($value['manager_userid']) && array_key_exists($value['manager_userid'],$user_object) ? $user_object[$value['manager_userid']]['name'] : '';
- $value['manager_text'] = $manager_text;
- }
- }
- }
- /**
- * 编辑
- * @auth true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function edit()
- {
- $this->title = '编辑';
- $this->_form($this->table, 'form');
- }
- /**
- * 表单处理
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- protected function _form_filter(&$data)
- {
- if($this->request->isGet()) {
- if($data){
- // 编辑获取数据时
- $department_list = UserService::get_department_column();
- $this->user_list = UserService::get_list(1);
- // 所属部门
- $department_ids = explode(',', $data['department']);
- $department_text = '';
- foreach ($department_ids as $val) {
- if (array_key_exists($val, $department_list)) {
- $department_text .= $department_list[$val] . ',';
- }
- }
- $data['department_text'] = $department_text;
- }
- }
- if($this->request->isPost()){
- if($data) {
- // 编辑提交数据时
- if (isset_full($data, 'signature_status')) {
- if (!in_array($data['signature_status'], [CommonConstant::SIGNATURE_STATUS_3, CommonConstant::SIGNATURE_STATUS_4])) {
- unset($data['signature_status']);
- }
- }
- }
- }
- }
- /**
- * 启用
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function resume()
- {
- $this->applyCsrfToken();
- $this->_save($this->table, ['status' => CommonConstant::STATUS_NORMAL]);
- }
- /**
- * 禁用
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function forbid()
- {
- $this->applyCsrfToken();
- $this->_save($this->table, ['status' => CommonConstant::STATUS_FROZEN]);
- }
- /**
- * 审核签名
- * @auth true
- * @throws \think\Exception
- * @throws \think\exception\PDOException
- */
- public function signature_status()
- {
- $signature_status = input('signature_status');
- if(!array_key_exists($signature_status,CommonConstant::get_signature_status_list())){
- $this->controller->error('审核状态参数错误');
- }
- $this->applyCsrfToken();
- $this->_save($this->table, ['signature_status' => $signature_status]);
- }
- /**
- * 导出
- **/
- public function export(){
- $data = model::field('name,mobile,title')
- ->where('is_deleted', CommonConstant::IS_DELETED_0)
- ->select()
- ->toArray();
- if(!$data) $this->error('暂无可以导出的数据');
- $field=array(
- 'A' => array('name', '用户姓名'),
- 'B' => array('mobile', '手机号码'),
- 'C' => array('title', '职位'),
- );
- $this->phpExcelList($field,$data,'会员列表');
- }
- public function phpExcelList($field=[],$list=[],$title='文件'){
- $PHPExcel=new \PHPExcel();
- $PHPSheet=$PHPExcel->getActiveSheet();
- $PHPSheet->setTitle('demo'); //给当前活动sheet设置名称
- foreach($list as $key=>$value)
- {
- foreach($field as $k=>$v){
- if($key == 0){
- $PHPSheet= $PHPExcel->getActiveSheet()->setCellValue($k.'1',$v[1]);
- }
- $i=$key+2;
- $PHPExcel->getActiveSheet()->setCellValue($k . $i, $value[$v[0]]);
- }
- }
- $PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,'Excel2007'); //按照指定格式生成Excel文件,
- header('Content-Type: application/vnd.ms-excel'); // 告诉浏览器生成一个excel05版的表格
- header("Content-Disposition: attachment;filename={$title}.xls"); //告诉浏览器输出文件的名称
- header('Cache-Control: max-age=0'); //禁止缓存
- $PHPWriter->save("php://output"); //输出到浏览器
- }
- /**
- * 更新员工和部门
- **/
- public function renew(){
- DingtalkService::renew();
- $this->success('更新员工和部门成功');
- }
- }
|