first commit

This commit is contained in:
2026-07-23 09:40:36 +08:00
commit 090abf48fa
989 changed files with 145728 additions and 0 deletions
+654
View File
@@ -0,0 +1,654 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\api\controller;
use app\api\BaseController;
use think\facade\Db;
class Check extends BaseController
{
//获取审核流程
public function get_flows($check_name='')
{
$cate_id = Db::name('FlowCate')->where(['name' => $check_name,'status'=>1])->value('id');
$flow = Db::name('Flow')->where(['cate_id' => $cate_id,'status'=>1,'delete_time'=>0])->select()->toArray();
return to_assign(0, '', $flow);
}
//获取审核步骤人员
public function get_flow_users($id=0)
{
$flow = Db::name('Flow')->where(['id' => $id])->find();
$flow_data = unserialize($flow['flow_list']);
if(!empty($flow_data)){
foreach ($flow_data as $key => &$val) {
$val['check_position'] = '';
if($val['check_role'] == 1){
$val['check_uids'] = get_department_leader($this->uid);
}
if($val['check_role'] == 2){
$val['check_uids'] = get_department_leader($this->uid,1);
}
if($val['check_role'] == 3){
$val['check_position'] = Db::name('Position')->where('id',$val['check_position_id'])->value('title');
$check_uids = Db::name('Admin')->where(['position_id'=>$val['check_position_id'],'status'=>1])->column('id');
$val['check_uids'] = implode(',',$check_uids);
}
$val['check_uids_info'] = Db::name('Admin')->field('id,name,thumb')->where('id','in',$val['check_uids'])->select()->toArray();
}
}
else{
$flow_data = [];
}
$data['copy_uids'] = $flow['copy_uids'];
$data['copy_unames'] ='';
if(!empty($flow['copy_uids'])){
$copy_unames = Db::name('Admin')->where('id', 'in', $flow['copy_uids'])->column('name');
$data['copy_unames'] = implode(',', $copy_unames);
}
$data['flow_data'] = $flow_data;
return to_assign(0, '', $data);
}
//提交审批申请
public function submit_check()
{
$param = get_params();
$flow_cate = Db::name('FlowCate')->where(['name' => $param['check_name']])->find();
$flow_list = Db::name('Flow')->where('id',$param['flow_id'])->value('flow_list');
$flow = unserialize($flow_list);
$subject = $flow_cate['title'];
$check_table = $flow_cate['check_table'];
//var_dump($flow);exit;
//删除原来的审核流程和审核记录
Db::name('FlowStep')->where(['action_id'=>$param['action_id'],'flow_id'=>$param['flow_id'],'delete_time'=>0])->update(['delete_time'=>time()]);
Db::name('FlowRecord')->where(['action_id'=>$param['action_id'],'check_table'=>$check_table,'delete_time'=>0])->update(['delete_time'=>time()]);
$recordData=array(
'action_id' => $param['action_id'],
'check_table' => $check_table,
'step_id' => 0,
'check_uid' => $this->uid,
'flow_id' => $param['flow_id'],
'check_time' => time(),
'check_status' => 0,
'content' => '提交申请',
'create_time' => time()
);
if (!isset($param['check_uids'])) {
//非自由审批模式
$step=[];
$sort=0;
foreach ($flow as $key => &$value){
if($value['check_role'] == 1){
$value['check_uids'] = get_department_leader($this->uid);
$value['flow_name'] = '当前部门负责人';
$value['check_position_id']=0;
}
if($value['check_role'] == 2){
$value['check_uids'] = get_department_leader($this->uid,1);
$value['flow_name'] = '上级部门负责人';
$value['check_position_id']=0;
}
if($value['check_role'] == 3){
$check_position = Db::name('Position')->where('id',$value['check_position_id'])->value('title');
$check_uids = Db::name('Admin')->where(['position_id'=>$value['check_position_id'],'status'=>1])->column('id');
$value['check_uids'] = implode(',',$check_uids);
$value['flow_name'] = $check_position;
}
if($value['check_role'] == 4){
$value['flow_name'] = '指定人员';
$value['check_position_id']=0;
}
if($value['check_role'] == 5){
$value['flow_name'] = '指定人员';
$value['check_position_id']=0;
$value['check_types']=1;
}
if(!empty($value['check_uids'])){
$step[]=[
'action_id' => $param['action_id'],
'flow_id' => $param['flow_id'],
'flow_name' => $value['flow_name'],
'check_position_id' => $value['check_position_id'],
'check_role' => $value['check_role'],
'check_types' => $value['check_types'],
'check_uids' => $value['check_uids'],
'create_time' => time(),
'sort'=>$sort
];
$sort++;
}
}
if(empty($step)){
return to_assign(1,'审批流程设置有问题,无法提交审批申请,请联系HR或者管理员重新设置审批流程');
}
$res = Db::name('FlowStep')->strict(false)->field(true)->insertAll($step);
if($res!=false){
Db::name('FlowRecord')->strict(false)->field(true)->insertGetId($recordData);
Db::name($check_table)->strict(false)->field(true)->update([
'id'=>$param['action_id'],
'check_flow_id'=>$param['flow_id'],
'check_status'=>1,
'check_step_sort'=>0,
'check_uids'=>$step[0]['check_uids'],
'check_copy_uids'=>isset($param['check_copy_uids'])?$param['check_copy_uids']:''
]);
//发送消息通知
if($flow_cate['template_id']>0){
$msg=[
'from_uid'=>$this->uid,//发送人
'to_uids'=>$step[0]['check_uids'],//接收人
'template_id'=>$flow_cate['template_id'],//消息模板ID
'template_field'=>'0',//消息模板字段
'content'=>[ //消息内容
'create_time'=>date('Y-m-d H:i:s'),
'action_id'=>$param['action_id'],
'title' => $subject
]
];
event('SendMessage',$msg);
}
return to_assign();
}
else{
return to_assign(1,'操作失败');
}
}
else{
//自由审批模式
$flow_step = array(
'action_id' => $param['action_id'],
'flow_id' => $param['flow_id'],
'flow_name' => '自由审批',
'check_uids' => $param['check_uids'],
'create_time' => time()
);
$res = Db::name('FlowStep')->strict(false)->field(true)->insertGetId($flow_step);
if($res!=false){
Db::name('FlowRecord')->strict(false)->field(true)->insertGetId($recordData);
Db::name($check_table)->strict(false)->field(true)->update([
'id'=>$param['action_id'],
'check_flow_id'=>$param['flow_id'],
'check_status'=>1,
'check_step_sort'=>0,
'check_uids'=>$param['check_uids'],
'check_copy_uids'=>isset($param['check_copy_uids'])?$param['check_copy_uids']:''
]);
//发送消息通知
if($flow_cate['template_id']>0){
$msg=[
'from_uid'=>$this->uid,//发送人
'to_uids'=>$param['check_uids'],//接收人
'template_id'=>$flow_cate['template_id'],//消息模板ID
'template_field'=>'0',//消息模板字段
'content'=>[ //消息内容
'create_time'=>date('Y-m-d H:i:s'),
'action_id'=>$param['action_id'],
'title' => $subject
]
];
event('SendMessage',$msg);
}
return to_assign();
}
else{
return to_assign(1,'操作失败');
}
}
}
//获取审核流程节点
public function get_flow_nodes($check_name='',$action_id=0,$flow_id=0)
{
$flow_cate = Db::name('FlowCate')->where(['name' => $check_name])->find();
$did = $this->did;
$map = [];
$map[] = ['cate_id','=',$flow_cate['id']];
$map[] = ['status','=',1];
$map[] = ['delete_time','=',0];
$map1=[
['department_ids','=','']
];
$map2=[
['', 'exp', Db::raw("FIND_IN_SET('{$did}',department_ids)")]
];
$whereOr =[$map1,$map2];
if($action_id==0){
$flow = Db::name('Flow')
->where($map)
->where(function ($query) use($whereOr) {
if (!empty($whereOr)){
$query->whereOr($whereOr);
}
})
->select()->toArray();
foreach ($flow as $k => &$v) {
$v['is_copy'] = $flow_cate['is_copy'];
}
return to_assign(0, '', $flow);
}
$check_table = $flow_cate['check_table'];
$detail = Db::name($check_table)->where('id',$action_id)->field('id,admin_id,check_status,check_flow_id,check_step_sort,check_uids,check_copy_uids')->find();
//创建人
$is_creater=0;
if($detail['admin_id'] == $this->uid){
$is_creater=1;
}
$detail['is_creater'] = $is_creater;
$detail['admin_name'] = Db::name('Admin')->where('id',$detail['admin_id'])->value('name');
//当前审批人
$is_checker=0;
if(in_array($this->uid,explode(',',$detail['check_uids']))){
$is_checker=1;
}
$detail['is_checker'] = $is_checker;
$detail['is_copy'] = $flow_cate['is_copy'];
$detail['is_file'] = $flow_cate['is_file'];
$detail['is_export'] = $flow_cate['is_export'];
$detail['is_back'] = $flow_cate['is_back'];
$detail['is_reversed'] = $flow_cate['is_reversed'];
//审批记录
$check_record = Db::name('FlowRecord')
->field('f.*,a.name')
->alias('f')
->join('Admin a', 'a.id = f.check_uid', 'left')
->where(['f.action_id' => $action_id,'f.check_table'=>$check_table])->select()->toArray();
foreach ($check_record as $kk => &$vv) {
$vv['check_time_str'] = date('Y-m-d H:i', $vv['check_time']);
$vv['status_str'] = '提交';
if($vv['check_status'] == 1){
$vv['status_str'] = '审核通过';
}
else if($vv['check_status'] == 2){
$vv['status_str'] = '审核拒绝';
}
if($vv['check_status'] == 3){
$vv['status_str'] = '撤销';
}
if($vv['check_status'] == 4){
$vv['status_str'] = '反确认';
}
if(!empty($vv['check_files'])){
$file_array = Db::name('File')->where('id','in',$vv['check_files'])->select()->toArray();
$vv['file_array'] = $file_array;
}
else{
$vv['file_array'] = [];
}
}
$detail['check_record'] = $check_record;
if($detail['check_status']==0 || $detail['check_status']==4){
//$flow = Db::name('Flow')->where(['cate_id' => $flow_cate['id'],'status'=>1,'delete_time'=>0])->select()->toArray();
$flow = Db::name('Flow')
->where($map)
->where(function ($query) use($whereOr) {
if (!empty($whereOr)){
$query->whereOr($whereOr);
}
})
->select()->toArray();
$detail['flow'] = $flow;
}
else{
//当前审批人
$detail['check_unames']='-';
if(!empty($detail['check_uids'])){
$check_unames = Db::name('Admin')->where('id','in',$detail['check_uids'])->column('name');
$detail['check_unames'] = implode(',',$check_unames);
}
//抄送人
$detail['copy_unames']='-';
if(!empty($detail['check_copy_uids'])){
$copy_uids = Db::name('Admin')->where('id','in',$detail['check_copy_uids'])->column('name');
$detail['copy_unames'] = implode(',',$copy_uids);
}
//审批节点步骤
$nodes = Db::name('FlowStep')->where(['action_id'=>$action_id,'flow_id'=>$flow_id,'delete_time'=>0])->order('sort asc')->select()->toArray();
foreach ($nodes as $key => &$val) {
$check_uids_info = Db::name('Admin')->field('id,name,thumb')->where('id','in',$val['check_uids'])->select()->toArray();
foreach ($check_uids_info as $k => &$v) {
$v['check_time'] = 0;
$v['content'] = '';
$v['check_status'] = 0;
$check_array = Db::name('FlowRecord')->where(['check_uid' => $v['id'],'step_id' => $val['id']])->order('check_time desc')->select()->toArray();
if(!empty($check_array)){
$checked = $check_array[0];
$v['check_time'] = date('Y-m-d H:i', $checked['check_time']);
$v['content'] = $checked['content'];
$v['check_status'] = $checked['check_status'];
}
}
$val['check_uids_info'] = $check_uids_info;
if(!empty($val['check_position_id'])){
$val['check_position'] = Db::name('Position')->where('id',$val['check_position_id'])->value('title');
}
else{
$val['check_position'] = '';
}
$check_list = [];
foreach ($check_record as $kkk => $vvv) {
if($vvv['step_id'] == $val['id'])
$check_list[] = $vvv;
}
$val['check_list'] = $check_list;
}
$detail['nodes'] = $nodes;
//当前审核节点
$step = Db::name('FlowStep')->where(['action_id'=>$action_id,'flow_id'=>$flow_id,'sort'=>$detail['check_step_sort'],'delete_time'=>0])->find();
$detail['step'] = $step;
}
return to_assign(0, '', $detail);
}
//流程审核
public function flow_check()
{
$param = get_params();
$param['check_files'] = isset($param['check_files']) ? $param['check_files'] : '';
$flow_cate = Db::name('FlowCate')->where(['name' => $param['check_name']])->find();
$subject = $flow_cate['title'];
$action_id = $param['action_id'];
$check_table = $flow_cate['check_table'];
$param['send_msg'] = 1;
//审核内容详情
$detail = Db::name($check_table)->where(['id' => $action_id])->find();
if (empty($detail)){
return to_assign(1,'审批数据错误');
}
//当前审核节点详情
$step = Db::name('FlowStep')->where(['action_id'=>$action_id,'flow_id'=>$detail['check_flow_id'],'sort'=>$detail['check_step_sort'],'delete_time'=>0])->find();
//审核通过时
if($param['check'] == 1){
$check_uids = explode(",",strval($detail['check_uids']));
if (!in_array($this->uid, $check_uids)){
return to_assign(1,'您没权限审核该审批');
}
//审批通过
if($step['check_role'] == 0){
//自由人审批
if($param['check_node'] == 2){
$next_step = $detail['check_step_sort']+1;
$flow_step = array(
'action_id' => $action_id,
'sort' => $next_step,
'flow_id' => $detail['check_flow_id'],
'check_uids' => $param['check_uids'],
'create_time' => time()
);
$fid = Db::name('FlowStep')->strict(false)->field(true)->insertGetId($flow_step);
//下一步审核步骤
$param['check_step_sort'] = $next_step;
$param['check_status'] = 1;
}
else{
//不存在下一步审核,审核结束
$param['check_status'] = 2;
$param['check_uids'] ='';
}
}
else{
//查询当前步骤审批记录数
$check_count = Db::name('FlowRecord')->where(['action_id'=>$action_id,'flow_id'=>$detail['check_flow_id'],'step_id'=>$step['id']])->count();
//当前当前步骤审批应有记录数
$flow_count = explode(',', $step['check_uids']);
$param['check_status'] = 1;
$uids_array = explode(',',$detail['check_uids']);
$new_uids= array_diff($uids_array, [$this->uid]);
$param['check_uids'] = implode(',',$new_uids);
if((($check_count+1) >= count($flow_count) && $step['check_types']==1) || $step['check_types']==2){
//会签
$next_step = Db::name('FlowStep')->where(['action_id'=>$action_id,'flow_id'=>$detail['check_flow_id'],'sort'=>($detail['check_step_sort']+1),'delete_time'=>0])->find();
if($next_step){
//存在下一步审核
if($next_step['check_role'] == 1){
$param['check_uids'] = get_department_leader($detail['admin_id']);
}
else if($next_step['check_role'] == 2){
$param['check_uids'] = get_department_leader($detail['admin_id'],1);
}
else if($next_step['check_role'] == 3){
$uids = Db::name('Admin')->where(['position_id'=>$next_step['check_position_id'],'status'=>1])->column('id');
$param['check_uids'] = implode(',' ,$uids);
}
else{
$param['check_uids'] = $next_step['check_uids'];
}
$param['check_step_sort'] = $detail['check_step_sort']+1;
$param['check_status'] = 1;
}
else{
//不存在下一步审核,审核结束
$param['check_status'] = 2;
$param['check_uids'] ='';
}
}
else{
$param['send_msg'] = 0;
}
}
if($param['check_status'] == 1 && empty($param['check_uids'])){
return to_assign(1,'找不到下一步的审批人,该审批流程设置有问题,请联系HR或者管理员');
}
//添加历史审核人
if(empty($detail['check_history_uids'])){
$param['check_history_uids'] = $this->uid;
}
else{
$param['check_history_uids'] = $detail['check_history_uids'].','.$this->uid;
}
$res = Db::name($check_table)->strict(false)->field('check_step_sort,check_status,check_history_uids,check_uids')->where(['id' => $action_id])->update($param);
if($res!==false){
$checkData=array(
'action_id' => $action_id,
'check_table' => $check_table,
'step_id' => $step['id'],
'check_uid' => $this->uid,
'flow_id' => $detail['check_flow_id'],
'check_time' => time(),
'check_files' => $param['check_files'],
'check_status' => $param['check'],
'content' => $param['content'],
'create_time' => time()
);
$aid = Db::name('FlowRecord')->strict(false)->field(true)->insertGetId($checkData);
add_log('check', $action_id, $param,$subject);
//发送消息通知
if($param['check_status'] == 1){
if($flow_cate['template_id']>0 && $param['send_msg']==1){
$msg=[
'from_uid'=>$detail['admin_id'],//发送人
'to_uids'=>$param['check_uids'],//接收人
'template_id'=>$flow_cate['template_id'],//消息模板ID
'template_field'=>'0',//消息模板字段,审批中
'content'=>[ //消息内容
'create_time'=>date('Y-m-d H:i:s',$detail['create_time']),
'action_id'=>$action_id,
'title' => $subject
]
];
event('SendMessage',$msg);
}
}
if($param['check_status'] == 2){
if($flow_cate['template_id']>0){
$msg=[
'from_uid'=>$this->uid,//发送人
'to_uids'=>$detail['admin_id'],//接收人
'template_id'=>$flow_cate['template_id'],//消息模板ID
'template_field'=>'1',//消息模板字段,审核通过
'content'=>[ //消息内容
'create_time'=>date('Y-m-d H:i:s',$detail['create_time']),
'action_id'=>$action_id,
'title' => $subject
]
];
event('SendMessage',$msg);
if(!empty($detail['check_copy_uids'])){
$msgs=[
'from_uid'=>$detail['admin_id'],//发送人
'to_uids'=>$detail['check_copy_uids'],//接收人
'template_id'=>$flow_cate['template_id'],//消息模板ID
'template_field'=>'3',//消息模板字段,审核通过抄送人接收
'content'=>[ //消息内容
'create_time'=>date('Y-m-d H:i:s',$detail['create_time']),
'action_id'=>$action_id,
'title' => $subject
]
];
event('SendMessage',$msgs);
}
}
}
return to_assign(0,'操作成功',['check_status'=>$param['check_status']]);
}
else{
return to_assign(1,'操作失败');
}
}
//审批拒绝
else if($param['check'] == 2){
$check_uids = explode(",",strval($detail['check_uids']));
if (!in_array($this->uid, $check_uids)){
return to_assign(1,'您没权限审核该审批');
}
//拒绝审核,数据操作
$param['check_status'] = 3;
//添加历史审核人
if(empty($detail['check_history_uids'])){
$param['check_history_uids'] = $this->uid;
}
else{
$param['check_history_uids'] = $detail['check_history_uids'].','.$this->uid;
}
$param['check_uids'] ='';
if($step['check_role'] == 5){
//获取上一步的审核信息
$prev_step = Db::name('FlowStep')->where(['action_id'=>$action_id,'flow_id'=>$detail['check_flow_id'],'sort'=>($detail['check_step_sort']-1),'delete_time'=>0])->find();
if($prev_step){
//存在上一步审核
$param['check_step_sort'] = $prev_step['sort'];
$param['check_uids'] = $prev_step['check_uids'];
$param['check_status'] = 1;
}
else{
//不存在上一步审核,审核初始化步骤
$param['check_step_sort'] = 0;
$param['check_uids'] = '';
$param['check_status'] = 0;
}
}
$res = Db::name($check_table)->strict(false)->field('check_step_sort,check_status,check_history_uids,check_uids')->where(['id' => $action_id])->update($param);
if($res!==false){
$checkData=array(
'action_id' => $action_id,
'check_table' => $check_table,
'step_id' => $step['id'],
'check_uid' => $this->uid,
'flow_id' => $detail['check_flow_id'],
'check_time' => time(),
'check_status' => $param['check'],
'check_files' => $param['check_files'],
'content' => $param['content'],
'create_time' => time()
);
$aid = Db::name('FlowRecord')->strict(false)->field(true)->insertGetId($checkData);
add_log('refue', $action_id, $param,$subject);
//发送消息通知
if($flow_cate['template_id']>0){
$msg=[
'from_uid'=>$this->uid,//发送人
'to_uids'=>$detail['admin_id'],//接收人
'template_id'=>$flow_cate['template_id'],//消息模板ID
'template_field'=>'2',//消息模板字段,审核拒绝
'content'=>[ //消息内容
'create_time'=>date('Y-m-d H:i:s',$detail['create_time']),
'action_id'=>$detail['id'],
'title' => $subject
]
];
event('SendMessage',$msg);
}
return to_assign(0,'操作成功',['check_status'=>$param['check_status']]);
}
else{
return to_assign(1,'操作失败');
}
}
else if($param['check'] == 3){
//审批撤回
if($detail['admin_id'] != $this->uid){
return to_assign(1,'你没权限操作');
}
//撤销审核,数据操作
$param['check_status'] = 4;
$param['check_uids'] ='';
$param['check_step_sort'] =0;
$res = Db::name($check_table)->strict(false)->field('check_step_sort,check_status,check_uids')->where(['id' => $action_id])->update($param);
if($res!==false){
$checkData=array(
'action_id' => $action_id,
'check_table' => $check_table,
'step_id' => $step['id'],
'check_uid' => $this->uid,
'flow_id' => $detail['check_flow_id'],
'check_time' => time(),
'check_status' => $param['check'],
'content' => $param['content'],
'create_time' => time()
);
$aid = Db::name('FlowRecord')->strict(false)->field(true)->insertGetId($checkData);
add_log('back', $action_id, $param,$subject);
return to_assign(0,'操作成功',['check_status'=>$param['check_status']]);
}else{
return to_assign(1,'操作失败');
}
}
else if($param['check'] == 4){
//审批反确认
//反确认审核,数据回到待提交审批
$param['check_status'] = 0;
$param['check_uids'] ='';
$param['check_step_sort'] =0;
$res = Db::name($check_table)->strict(false)->field('check_step_sort,check_status,check_uids')->where(['id' => $action_id])->update($param);
if($res!==false){
$checkData=array(
'action_id' => $action_id,
'check_table' => $check_table,
'step_id' => $step['id'],
'check_uid' => $this->uid,
'flow_id' => $detail['check_flow_id'],
'check_time' => time(),
'check_status' => 4,
'content' => $param['content'],
'create_time' => time()
);
$aid = Db::name('FlowRecord')->strict(false)->field(true)->insertGetId($checkData);
add_log('back', $action_id, $param,$subject);
return to_assign(0,'操作成功',['check_status'=>0]);
}else{
return to_assign(1,'操作失败');
}
}
}
}
+107
View File
@@ -0,0 +1,107 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\api\controller;
use app\api\BaseController;
use think\facade\Db;
use app\api\model\Comment as CommentModel;
class Comment extends BaseController
{
/**
* 构造函数
*/
protected $model;
public function __construct()
{
parent::__construct(); // 调用父类构造函数
$this->model = new CommentModel();
}
//获取评论列表
public function datalist()
{
$param = get_params();
$param['admin_id'] = $this->uid;
$where=[];
if (!empty($param['module'])) {
$where[] = ['module', '=', $param['module']];
}
if (!empty($param['topic_id'])) {
$where['topic_id'] = $param['topic_id'];
}
$where[] = ['delete_time', '=', 0];
$list = $this->model->datalist($param,$where);
$total = Db::name('Comment')->where($where)->count();
$totalRow['total'] = $total;
return table_assign(0, '', $list,$totalRow);
}
//添加修改评论内容
public function add()
{
$param = get_params();
if (!empty($param['id']) && $param['id'] > 0) {
$param['update_time'] = time();
unset($param['pid']);
unset($param['padmin_id']);
$res = CommentModel::where(['admin_id' => $this->uid,'id'=>$param['id']])->strict(false)->field(true)->update($param);
if ($res!==false) {
add_log('edit', $param['id'], $param,'评论');
return to_assign();
}
} else {
$param['create_time'] = time();
$param['admin_id'] = $this->uid;
$insertId = CommentModel::strict(false)->field(true)->insertGetId($param);
if ($insertId) {
add_log('add', $insertId, $param,'评论');
return to_assign();
}
}
}
//设为已读评论内容
public function view()
{
if (request()->isPost()) {
$id = get_params("id");
$res = Db::name('CommentRead')->strict(false)->field(true)->insertGetId(['comment_id'=>$id,'admin_id'=>$this->uid,'create_time'=>time()]);
if ($res!==false) {
add_log('view', $id,[],'评论');
return to_assign(0, "操作成功");
} else {
return to_assign(1, "操作失败");
}
}else{
return to_assign(1, "错误的请求");
}
}
//删除评论内容
public function del()
{
if (request()->isDelete()) {
$id = get_params("id");
$res = CommentModel::where('id',$id)->strict(false)->field(true)->update(['delete_time'=>time()]);
if ($res) {
add_log('delete', $id,[],'评论');
return to_assign(0, "删除成功");
} else {
return to_assign(1, "删除失败");
}
}else{
return to_assign(1, "错误的请求");
}
}
}
+138
View File
@@ -0,0 +1,138 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\api\controller;
use app\api\BaseController;
use app\api\middleware\Auth;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use think\facade\Db;
use think\facade\Request;
class Demo extends BaseController
{
/**
* 控制器中间件 [登录、注册 不需要鉴权]
* @var array
*/
protected $middleware = [
Auth::class => ['except' => ['index','login'] ]
];
/**
* @param $user_id
* @return string
*/
public function getToken($user_id){
$time = time(); //当前时间
$conf = $this->jwt_conf;
$token = [
'iss' => $conf['iss'], //签发者 可选
'aud' => $conf['aud'], //接收该JWT的一方,可选
'iat' => $time, //签发时间
'nbf' => $time-1 , //(Not Before):某个时间点后才能访问,比如设置time+30,表示当前时间30秒后才能使用
'exp' => $time+$conf['exptime'], //过期时间,这里设置2个小时
'data' => [
//自定义信息,不要定义敏感信息
'userid' =>$user_id,
]
];
return JWT::encode($token, $conf['secrect'], 'HS256'); //输出Token 默认'HS256'
}
/**
* @param $token
*/
public static function checkToken($token){
try {
JWT::$leeway = 60;//当前时间减去60,把时间留点余地
$decoded = JWT::decode($token, self::$config['secrect'], ['HS256']); //HS256方式,这里要和签发的时候对应
return (array)$decoded;
} catch(\Firebase\JWT\SignatureInvalidException $e) { //签名不正确
return json(['code'=>403,'msg'=>'签名错误']);
}catch(\Firebase\JWT\BeforeValidException $e) { // 签名在某个时间点之后才能用
return json(['code'=>401,'msg'=>'token失效']);
}catch(\Firebase\JWT\ExpiredException $e) { // token过期
return json(['code'=>401,'msg'=>'token已过期']);
}catch(Exception $e) { //其他错误
return json(['code'=>404,'msg'=>'非法请求']);
}catch(\UnexpectedValueException $e) { //其他错误
return json(['code'=>404,'msg'=>'非法请求']);
} catch(\DomainException $e) { //其他错误
return json(['code'=>404,'msg'=>'非法请求']);
}
}
/**
* @api {post} /demo/login 会员登录
* @apiDescription 系统登录接口,返回 token 用于操作需验证身份的接口
* @apiParam (请求参数:) {string} username 登录用户名
* @apiParam (请求参数:) {string} password 登录密码
* @apiParam (响应字段:) {string} token Token
* @apiSuccessExample {json} 成功示例
* {"code":0,"msg":"登录成功","time":1627374739,"data":{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhcGkuZ291Z3VjbXMuY29tIiwiYXVkIjoiZ291Z3VjbXMiLCJpYXQiOjE2MjczNzQ3MzksImV4cCI6MTYyNzM3ODMzOSwidWlkIjoxfQ.gjYMtCIwKKY7AalFTlwB2ZVWULxiQpsGvrz5I5t2qTs"}}
* @apiErrorExample {json} 失败示例
* {"code":1,"msg":"帐号或密码错误","time":1627374820,"data":[]}
*/
public function login()
{
$param = get_params();
if (empty($param['username']) || empty($param['password'])) {
$this->apiError('参数错误');
}
// 校验用户名密码
$user = Db::name('Admin')->where(['username' => $param['username']])->find();
if (empty($user)) {
$this->apiError('帐号或密码错误');
}
$param['pwd'] = set_password($param['password'], $user['salt']);
if ($param['pwd'] !== $user['pwd']) {
$this->apiError('帐号或密码错误');
}
if ($user['status'] == -1) {
$this->apiError('该用户禁止登录,请于平台联系');
}
$data = [
'last_login_time' => time(),
'last_login_ip' => request()->ip(),
'login_num' => $user['login_num'] + 1,
];
$res = Db::name('Admin')->where(['id' => $user['id']])->update($data);
if ($res) {
$token = self::getToken($user['id']);
$this->apiSuccess('登录成功', ['token' => $token]);
}
}
/**
* @api {post} /index/demo 测试页面
* @apiDescription 返回文章列表信息
* @apiParam (请求参数:) {string} token Token
* @apiSuccessExample {json} 响应数据样例
* {"code":1,"msg":"","time":1563517637,"data":{"id":13,"email":"test110@qq.com","password":"e10adc3949ba59abbe56e057f20f883e","sex":1,"last_login_time":1563517503,"last_login_ip":"127.0.0.1","qq":"123455","mobile":"","mobile_validated":0,"email_validated":0,"type_id":1,"status":1,"create_ip":"127.0.0.1","update_time":1563507130,"create_time":1563503991,"type_name":"注册会员"}}
*/
public function test(Request $request)
{
$uid = JWT_UID;
$userInfo = Db::name('Admin')->where(['id' => $uid])->find();
$this->apiSuccess('请求成功', ['user' => $userInfo]);
}
}
+317
View File
@@ -0,0 +1,317 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2025 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\api\controller;
use app\api\BaseController;
use think\facade\Db;
use think\facade\View;
use Mpdf\Mpdf;
use PhpOffice\PhpWord\TemplateProcessor;
use app\adm\model\MeetingRecords;
use app\adm\model\MeetingOrder;
use app\home\model\Leaves;
use app\home\model\Trips;
use app\home\model\Outs;
use app\adm\model\Seal;
use app\user\model\PersonalQuit;
use app\user\model\DepartmentChange;
use app\user\model\Talent;
use app\adm\model\OfficialDocs;
use app\finance\model\Loan;
use app\finance\model\Expense;
use app\finance\model\Invoice;
use app\finance\model\Ticket;
use app\contract\model\Contract;
use app\contract\model\Purchase;
class Export extends BaseController
{
public function pdf($types='',$id=0)
{
$name='PDF文件';
$is_header=true;
$check_record=true;
$is_page=false;
$logo = CMS_ROOT.'public/static/home/images/logo.png';
//请假审批
if($types=='leaves'){
$model = new Leaves();
$detail= $model->getById($id);
$detail['types_name'] = leaves_types_name($detail['types']);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的请假审批单';
}
//出差审批
if($types=='trips'){
$model = new Trips();
$detail= $model->getById($id);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的出差审批单';
}
//外出审批
if($types=='outs'){
$model = new Outs();
$detail= $model->getById($id);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的外出审批单';
}
//加班审批
if($types=='overtimes'){
$model = new Outs();
$detail= $model->getById($id);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的加班审批单';
}
//用印审批
if($types=='seal'){
$model = new Seal();
$detail= $model->getById($id);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的用章审批单';
}
//离职审批
if($types=='personal_quit'){
$model = new PersonalQuit();
$detail= $model->getById($id);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的离职审批单';
}
//人事调动审批单
if($types=='department_change'){
$model = new DepartmentChange();
$detail= $model->getById($id);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的人事调动审批单';
}
//入职审批单
if($types=='talent'){
$model = new Talent();
$detail= $model->getById($id);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的入职审批单';
}
//公文审批
if($types=='official_docs'){
$model = new OfficialDocs();
$detail= $model->getById($id);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的公文审批单';
}
//借支审批
if($types=='loan'){
$model = new Loan();
$detail= $model->getById($id);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的借支审批单';
}
//报销审批
if($types=='expense'){
$model = new Expense();
$detail= $model->getById($id);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的报销审批单';
}
//开票回款
if($types=='invoice'){
$model = new Invoice();
$detail= $model->getById($id);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的发票开票审批单';
}
//无票回款
if($types=='invoicea'){
$model = new Invoice();
$detail= $model->getById($id);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的无发票回款审批单';
}
//收票付款
if($types=='ticket'){
$model = new Ticket();
$detail= $model->getById($id);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的收票审批单';
}
//无发票付款单
if($types=='ticketa'){
$model = new Ticket();
$detail= $model->getById($id);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的无发票付款审批单';
}
//销售合同
if($types=='contract'){
$model = new Contract();
$detail= $model->getById($id);
$detail['cate_title'] = Db::name('ContractCate')->where(['id' => $detail['cate_id']])->value('title');
$detail['subject_title'] = Db::name('Enterprise')->where(['id' => $detail['subject_id']])->value('title');
$detail['department'] = $detail['sign_department'];
$detail['content_array'] = unserialize($detail['content']);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的销售合同审批单';
}
//采购合同
if($types=='purchase'){
$model = new Purchase();
$detail= $model->getById($id);
$detail['cate_title'] = Db::name('ContractCate')->where(['id' => $detail['cate_id']])->value('title');
$detail['subject_title'] = Db::name('Enterprise')->where(['id' => $detail['subject_id']])->value('title');
$detail['department'] = $detail['sign_department'];
$detail['content_array'] = unserialize($detail['content']);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的采购合同审批单';
}
//会议记录
if($types=='meeting'){
$model = new MeetingRecords();
$detail= $model->getById($id);
$name = date('Ymd',$detail['meeting_date']).$detail['did_name'].'_会议纪要';
$check_record=false;
}
//会议室预定
if($types=='meeting_order'){
$model = new MeetingOrder();
$detail= $model->getById($id);
$name = to_date($detail['create_time'],'Ymd').$detail['admin_name'].'提交的会议室预定';
}
//员工档案
if($types=='files'){
$detail = get_admin($id);
$detail['pname'] = Db::name('Admin')->where('id',$detail['pid'])->value('name');
$detail['position'] = Db::name('Position')->where('id',$detail['position_id'])->value('title');
$detail['department'] = Db::name('Department')->where('id',$detail['did'])->value('title');
$department_ids = Db::name('DepartmentAdmin')->where('admin_id',$id)->column('department_id');
$department_names = Db::name('Department')->whereIn('id',$department_ids)->column('title');
$detail['department_names'] = implode(',',$department_names);
if($detail['file_ids'] !=''){
$file_array = Db::name('File')->where('id','in',$detail['file_ids'])->select();
$detail['file_array'] = $file_array;
}
$edu = Db::name('AdminProfiles')->where(['types'=>1,'admin_id'=>$id,'delete_time'=>0])->select()->toArray();
$work = Db::name('AdminProfiles')->where(['types'=>2,'admin_id'=>$id,'delete_time'=>0])->select()->toArray();
$certificate = Db::name('AdminProfiles')->where(['types'=>3,'admin_id'=>$id,'delete_time'=>0])->select()->toArray();
$skills = Db::name('AdminProfiles')->where(['types'=>4,'admin_id'=>$id,'delete_time'=>0])->select()->toArray();
$language = Db::name('AdminProfiles')->where(['types'=>5,'admin_id'=>$id,'delete_time'=>0])->select()->toArray();
View::assign('edu', $edu);
View::assign('work', $work);
View::assign('skills', $skills);
View::assign('certificate', $certificate);
View::assign('language', $language);
View::assign('detail', $detail);
$name = $detail['name'].'_档案信息';
$check_record=false;
$is_page=true;
}
if($check_record){
if(!empty($detail['check_copy_uids'])){
$check_copy_names = Db::name('Admin')->where([['id','in',$detail['check_copy_uids']],['status','=',1]])->column('name');
$detail['check_copy_names'] = implode(',',$check_copy_names);
}
$detail['check_status_str'] = check_status_name($detail['check_status']);
//审批记录
$check_table = $types;
if($types=='invoicea'){
$check_table = 'invoice';
}
if($types=='ticketa'){
$check_table = 'ticket';
}
$check_record_array = Db::name('FlowRecord')
->field('f.*,a.name')
->alias('f')
->join('Admin a', 'a.id = f.check_uid', 'left')
->where([['f.action_id','=',$id],['f.check_table','=',$check_table],['f.delete_time','=',0],['f.step_id','>',0]])->select()->toArray();
foreach ($check_record_array as $kk => &$vv) {
$vv['check_time_str'] = date('Y-m-d H:i', $vv['check_time']);
$vv['status_str'] = '提交';
if($vv['check_status'] == 1){
$vv['status_str'] = '审核通过';
}
else if($vv['check_status'] == 2){
$vv['status_str'] = '审核拒绝';
}
if($vv['check_status'] == 3){
$vv['status_str'] = '撤销';
}
if($vv['check_status'] == 4){
$vv['status_str'] = '反确认';
}
}
$detail['check_record_array'] = $check_record_array;
}
$detail['pdf_admin'] = Db::name('Admin')->where([['id','=',$this->uid]])->value('name');
$detail['pdf_time'] = date('Y-m-d H:i:s');
//var_dump($detail);exit;
View::assign('detail', $detail);
View::assign('logo', $logo);
$html = View::fetch($types);
$time = time();
//tempDir指定临时文件目录,需要有可写入的权限,否则会报错
$mpdf = new Mpdf([
'mode'=>'zh',//或者utf-8
'format' => 'A4',
'margin_top'=>23,
'margin_bottom'=>19,
//重新定义字体路径
'fontDir' => [
CMS_ROOT . "public/static/font/"
],
//重新定义默认字体
'fontdata' => [
"sun-exta" => [
'R' => 'MiSans-Regular.ttf', // regular font
'B' => 'MiSans-Bold.ttf', // optional: bold font
'I' => 'MiSans-Regular.ttf', // optional: italic font
'BI' => 'MiSans-Bold.ttf', // optional: bold-italic font
'useKashida' => 75,
'sip-ext' => 'MiSans-Regular.ttf', /* SIP=Plane2 Unicode (extension B) */
]
],
'tempDir' => CMS_ROOT . "public/storage/pdf/"
]);
$mpdf->SetDisplayMode('fullpage');
//自动分析录入内容字体
$mpdf->autoScriptToLang = true;
$mpdf->autoLangToFont = true;
//文件名称
$filename = $name."_".$time.".pdf";
//文章pdf文件存储路径
$path = CMS_ROOT . "public" . "/storage/pdf/".$filename;
$pageNumber = count($mpdf->pages);
$header= '<table width="100%" style="margin:0;padding:0"><tr>
<td width="50%" style="text-align:left;font-size:12px; color:#999999;margin:0;padding:0"><img src="'.$logo.'" height="36" /></td>
<td width="50%" style="text-align:right;font-size:12px; color:#999999;margin:0;padding:0">勾股OA办公系统</td>
</tr></table><hr style="border-color:#f1f1f1;margin:0">';
$page= '<p style="text-align:center;font-size:12px; color:#999999">第 {PAGENO}/{nbpg} 页</p>';
if($is_header){
$mpdf->SetHTMLHeader($header);
}
if($is_page){
$mpdf->SetHTMLFooter($page);
}
//以html为标准分析写入内容
$mpdf->WriteHTML($html);
//直接下载文件
$mpdf->Output('tmp.pdf',true);
$mpdf->Output($filename,"d");
exit;
/*
//生成磁盘文件
$mpdf->Output($path);
if($type==0){
//下载文件
if (is_file($path)){
//return to_assign(0,"文件生成成功");
$file = fopen($path, "rb");
Header( "Content-type: application/octet-stream ");
Header( "Accept-Ranges: bytes ");
Header( "Content-Disposition: attachment; filename= $filename");
while (!feof($file)) {
echo fread($file, 8192);
ob_flush();
flush();
}
fclose($file);
} else {
return to_assign(1,"文件生成失败");
}
}
*/
}
}
+379
View File
@@ -0,0 +1,379 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\api\controller;
use app\api\BaseController;
use think\facade\Db;
use app\user\model\Admin;
use app\customer\model\Customer;
use avatars\MDAvatars;
use Overtrue\Pinyin\Pinyin;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Shared\Date as Shared;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
class Import extends BaseController
{
//生成头像
public function to_avatars($char)
{
$defaultData = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'S', 'Y', 'Z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖', '拾',
'一', '二', '三', '四', '五', '六', '七', '八', '九', '十');
if (isset($char)) {
$Char = $char;
} else {
$Char = $defaultData[mt_rand(0, count($defaultData) - 1)];
}
$OutputSize = min(512, empty($_GET['size']) ? 36 : intval($_GET['size']));
$Avatar = new MDAvatars($Char, 256, 1);
$avatar_name = '/avatars/avatar_256_' . set_salt(10) . time() . '.png';
$path = get_config('filesystem.disks.public.url') . $avatar_name;
$res = $Avatar->Save('.' . $path, 256);
$Avatar->Free();
return $path;
}
//登录名校验
public function check_name($name,$arr)
{
if(in_array($name,$arr)){
$name = $this->check_name($name.'1',$arr);
}
return $name;
}
//导入员工
public function import_admin(){
// 获取表单上传文件
$file[]= request()->file('file');
if($this->uid>1){
return to_assign(1,'该操作只能是超级管理员有权限操作');
}
try {
// 验证文件大小,名称等是否正确
validate(['file' => 'filesize:51200|fileExt:xls,xlsx'])->check($file);
// 日期前綴
$dataPath = date('Ym');
$md5 = $file[0]->hash('md5');
$savename = \think\facade\Filesystem::disk('public')->putFile($dataPath, $file[0], function () use ($md5) {
return $md5;
});
$fileExtendName = substr(strrchr($savename, '.'), 1);
// 有Xls和Xlsx格式两种
if ($fileExtendName == 'xlsx') {
$objReader = IOFactory::createReader('Xlsx');
} else {
$objReader = IOFactory::createReader('Xls');
}
$objReader->setReadDataOnly(TRUE);
$path = get_config('filesystem.disks.public.url');
// 读取文件,tp6默认上传的文件,在runtime的相应目录下,可根据实际情况自己更改
$objPHPExcel = $objReader->load('.'.$path . '/' .$savename);
$sheet = $objPHPExcel->getSheet(0); //excel中的第一张sheet
$highestRow = $sheet->getHighestRow(); // 取得总行数
$highestColumn = $sheet->getHighestColumn(); // 取得总列数
Coordinate::columnIndexFromString($highestColumn);
$lines = $highestRow - 1;
if ($lines <= 0) {
return to_assign(1, '数据不能为空');
exit();
}
$sex_array=['未知','男','女'];
$type_array=['未知','正式','试用','实习'];
$mobile_array = Db::name('Admin')->where([['status','>=',0],['delete_time','=',0]])->column('mobile');
$email_array = Db::name('Admin')->where([['status','>=',0],['delete_time','=',0]])->column('email');
$username_array = Db::name('Admin')->where([['status','>=',0],['delete_time','=',0]])->column('username');
$department_array = Db::name('Department')->where(['status' => 1])->column('title', 'id');
$position_array = Db::name('Position')->where(['status' => 1])->column('title', 'id');
//循环读取excel表格,整合成数组。如果是不指定key的二维,就用$data[i][j]表示。
for ($j = 3; $j <= $highestRow; $j++) {
$salt = set_salt(20);
$reg_pwd = '123456';
$name = $objPHPExcel->getActiveSheet()->getCell("A" . $j)->getValue();
if(empty($name)){
continue;
}
$char = mb_substr($name, 0, 1, 'utf-8');
$sex = array_search_plus($sex_array,$objPHPExcel->getActiveSheet()->getCell("D" . $j)->getValue());
$department = array_search_plus($department_array,$objPHPExcel->getActiveSheet()->getCell("E" . $j)->getValue());
$position = array_search_plus($position_array,$objPHPExcel->getActiveSheet()->getCell("f" . $j)->getValue());
$type = array_search_plus($type_array,$objPHPExcel->getActiveSheet()->getCell("G" . $j)->getValue());
$username = Pinyin::name($name,'none')->join('');
//$username = implode('-', $pinyinname);
$mobile = $objPHPExcel->getActiveSheet()->getCell("B" . $j)->getValue();
$email = $objPHPExcel->getActiveSheet()->getCell("C" . $j)->getValue();
$file_check['mobile'] = $mobile;
$file_check['email'] = $email;
$validate_mobile = \think\facade\Validate::rule([
'mobile' => 'require|mobile',
]);
$validate_email = \think\facade\Validate::rule([
'email' => 'email',
]);
if (!$validate_mobile->check($file_check)) {
return to_assign(1, '第'.($j - 2).'行的手机号码的格式错误');
}
else{
if(in_array($mobile,$mobile_array)){
return to_assign(1, '第'.($j - 2).'行的手机号码已存在或者重复');
}
else{
array_push($mobile_array,$mobile);
}
}
if(!empty($email)){
if (!$validate_email->check($file_check)) {
return to_assign(1, '第'.($j - 2).'行的电子邮箱的格式错误');
}
else{
if(in_array($email,$email_array)){
return to_assign(1, '第'.($j - 2).'行的电子邮箱已存在或者重复');
}
else{
array_push($email_array,$email);
}
}
}
else{
$email='';
}
if(empty($department)){
return to_assign(1, '第'.($j - 2).'行的所在部门错误');
}
if(empty($position)){
return to_assign(1, '第'.($j - 2).'行的所属职位错误');
}
$newusername = $this->check_name($username,$username_array);
array_push($username_array,$newusername);
$data[$j - 3] = [
'name' => $name,
'nickname' => $name,
'mobile' => $mobile,
'email' => $email,
'sex' => $sex,
'did' => $department,
'position_id' => $position,
'type' => $type,
'entry_time' => Shared::excelToTimestamp($objPHPExcel->getActiveSheet()->getCell("H" . $j)->getValue(),'Asia/Shanghai'),
'username' => $newusername,
'salt' => $salt,
'pwd' => set_password($reg_pwd, $salt),
'reg_pwd' => $reg_pwd,
'thumb' => $this->to_avatars($char)
];
}
//dd($data);exit;
$count=0;
foreach ($data as $a => $aa) {
$aid = Admin::strict(false)->field(true)->insertGetId($aa);
if($aid>0){
//Db::name('DepartmentAdmin')->insert(['admin_id'=>$aid,'department_id'=>$aa['did'],'create_time' => time()]);
$count++;
}
}
return to_assign(0, '共成功导入了'.$count.'条员工数据');
} catch (\think\exception\ValidateException $e) {
return to_assign(1, $e->getMessage());
}
}
//导入客户
public function import_customer(){
// 获取表单上传文件
$file[]= request()->file('file');
$param = get_params();
$type = 'sea';
if(isset($param['type'])){
$type = $param['type'];
}
try {
// 验证文件大小,名称等是否正确
validate(['file' => 'filesize:51200|fileExt:xls,xlsx'])->check($file);
// 日期前綴
$dataPath = date('Ym');
$md5 = $file[0]->hash('md5');
$savename = \think\facade\Filesystem::disk('public')->putFile($dataPath, $file[0], function () use ($md5) {
return $md5;
});
$fileExtendName = substr(strrchr($savename, '.'), 1);
// 有Xls和Xlsx格式两种
if ($fileExtendName == 'xlsx') {
$objReader = IOFactory::createReader('Xlsx');
} else {
$objReader = IOFactory::createReader('Xls');
}
$objReader->setReadDataOnly(TRUE);
$path = get_config('filesystem.disks.public.url');
// 读取文件,tp6默认上传的文件,在runtime的相应目录下,可根据实际情况自己更改
$objPHPExcel = $objReader->load('.'.$path . '/' .$savename);
//$objPHPExcel = $objReader->load('./storage/202209/d11544d20b3ca1c1a5f8ce799c3b2433.xlsx');
$sheet = $objPHPExcel->getSheet(0); //excel中的第一张sheet
$highestRow = $sheet->getHighestRow(); // 取得总行数
$highestColumn = $sheet->getHighestColumn(); // 取得总列数
Coordinate::columnIndexFromString($highestColumn);
$lines = $highestRow - 1;
if ($lines <= 0) {
return to_assign(1, '数据不能为空');
exit();
}
$name_array = [];
$source_array = Db::name('CustomerSource')->where(['status' => 1])->column('title', 'id');
$grade_array = Db::name('CustomerGrade')->where(['status' => 1])->column('title', 'id');
$industry_array = Db::name('Industry')->where(['status' => 1])->column('title', 'id');
//循环读取excel表格,整合成数组。如果是不指定key的二维,就用$data[i][j]表示。
for ($j = 3; $j <= $highestRow; $j++) {
$file_check = [];
$name = $objPHPExcel->getActiveSheet()->getCell("A" . $j)->getValue();
if(empty($name)){
continue;
}
$count_name = Db::name('Customer')->where(['name'=>$name,'delete_time'=>0])->count();
if($count_name>0){
return to_assign(1, '第'.($j - 2).'行的客户名称已经存在');
}
if(in_array($name,$name_array)){
return to_assign(1, '上传的文件存在相同的客户名称,请删除再操作');
}
array_push($name_array,$name);
$source_id = array_search_plus($source_array,$objPHPExcel->getActiveSheet()->getCell("B" . $j)->getValue());
$grade_id = array_search_plus($grade_array,$objPHPExcel->getActiveSheet()->getCell("C" . $j)->getValue());
$industry_id = array_search_plus($industry_array,$objPHPExcel->getActiveSheet()->getCell("D" . $j)->getValue());
$c_name = $objPHPExcel->getActiveSheet()->getCell("E" . $j)->getValue();
$c_mobile = $objPHPExcel->getActiveSheet()->getCell("F" . $j)->getValue();
$file_check['c_mobile'] = $c_mobile;
$tax_num = $objPHPExcel->getActiveSheet()->getCell("G" . $j)->getValue();
$bank = $objPHPExcel->getActiveSheet()->getCell("H" . $j)->getValue();
$bank_sn = $objPHPExcel->getActiveSheet()->getCell("I" . $j)->getValue();
$file_check['bank_sn'] = $bank_sn;
$bank_no = $objPHPExcel->getActiveSheet()->getCell("K" . $j)->getValue();
$cperson_mobile = $objPHPExcel->getActiveSheet()->getCell("K" . $j)->getValue();
$address = $objPHPExcel->getActiveSheet()->getCell("L" . $j)->getValue();
$content = $objPHPExcel->getActiveSheet()->getCell("M" . $j)->getValue();
$market = $objPHPExcel->getActiveSheet()->getCell("N" . $j)->getValue();
if(empty($c_name)){
return to_assign(1, '第'.($j - 2).'行的客户联系人姓名没完善');
}
if(empty($c_mobile)){
return to_assign(1, '第'.($j - 2).'行的客户联系人手机号码没完善');
}
$validate_mobile = \think\facade\Validate::rule([
'c_mobile' => 'mobile',
]);
if (!$validate_mobile->check($file_check)) {
return to_assign(1, '第'.($j - 2).'行的客户联系人手机号码格式错误');
}
if(empty($source_id)){
return to_assign(1, '第'.($j - 2).'行的客户来源错误');
}
if(empty($grade_id)){
return to_assign(1, '第'.($j - 2).'行的客户等级错误');
}
if(empty($industry_id)){
return to_assign(1, '第'.($j - 2).'行的所属行业错误');
}
if(empty($tax_num)){
$tax_num='';
}
if(empty($bank)){
$bank='';
}
$validate_bank = \think\facade\Validate::rule([
'bank_sn' => 'number',
]);
if(!empty($bank_sn)){
if (!$validate_bank->check($file_check)) {
return to_assign(1, '第'.($j - 2).'行的银行卡账号格式错误');
}
}
else{
$bank_sn='';
}
if(empty($bank_no)){
$bank_no='';
}
if(empty($cperson_mobile)){
$cperson_mobile='';
}
if(empty($address)){
$address='';
}
if(empty($content)){
$content='';
}
if(empty($market)){
$market='';
}
$belong_uid = 0;
$belong_did = 0;
if($type != 'sea'){
$belong_uid = $this->uid;
$belong_did = $this->did;
}
$data[$j - 3] = [
'name' => $name,
'source_id' => $source_id,
'grade_id' => $grade_id,
'industry_id' => $industry_id,
'tax_num' => $tax_num,
'bank' => $bank,
'bank_sn' => $bank_sn,
'bank_no' => $bank_no,
'cperson_mobile' => $cperson_mobile,
'address' => $address,
'content' => $content,
'market' => $market,
'admin_id' => $this->uid,
'belong_uid' => $belong_uid,
'belong_did' => $belong_did,
'c_mobile' => $c_mobile,
'c_name' => $c_name,
'create_time' => time(),
'update_time' => time()
];
}
//dd($data);exit;
// 批量添加数据
$count=0;
foreach ($data as $a => $aa) {
$cid = Customer::strict(false)->field(true)->insertGetId($aa);
if($cid>0){
$contact = [
'name' => $aa['c_name'],
'mobile' => $aa['c_mobile'],
'sex' => 1,
'cid' => $cid,
'is_default' => 1,
'create_time' => time(),
'admin_id' => $this->uid
];
Db::name('CustomerContact')->strict(false)->field(true)->insert($contact);
$count++;
}
}
return to_assign(0, '共成功导入了'.$count.'条客户数据');
} catch (\think\exception\ValidateException $e) {
return to_assign(1, $e->getMessage());
}
}
}
+637
View File
@@ -0,0 +1,637 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\api\controller;
use app\api\BaseController;
use app\api\model\EditLog;
use smsservice\Smsservice;
use think\Image; // 引入Image类
use think\facade\Db;
class Index extends BaseController
{
//上传文件
public function upload()
{
if (request()->isPost()) {
$param = get_params();
$sourse = 'file';
if(isset($param['sourse'])){
$sourse = $param['sourse'];
}
if($sourse == 'file' || $sourse == 'tinymce'){
if(request()->file('file')){
$file = request()->file('file');
}
else{
return to_assign(1, '没有选择上传文件');
}
}
else{
if (request()->file('editormd-image-file')) {
$file = request()->file('editormd-image-file');
} else {
return to_assign(1, '没有选择上传文件');
}
}
// 获取上传文件的hash散列值
$sha1 = $file->hash('sha1');
$md5 = $file->hash('md5');
$rule = [
'image' => 'jpg,png,jpeg,gif',
'doc' => 'txt,doc,docx,ppt,pptx,xls,xlsx,pdf',
'file' => 'zip,gz,7z,rar,tar',
'video' => 'mpg,mp4,mpeg,avi,wmv,mov,flv,m4v',
'audio' => 'mp3,wav,wma,flac,midi',
];
$fileExt = $rule['image'] . ',' . $rule['doc'] . ',' . $rule['file'] . ',' . $rule['video'] . ',' . $rule['audio'];
//1M=1024*1024=1048576字节
$file_size = get_system_config('system','upload_max_filesize');
if(!isset($file_size)){
$file_size=50;
}
$fileSize = $file_size * 1024 * 1024;
if (isset($param['type']) && $param['type']) {
$fileExt = $rule[$param['type']];
}
if (isset($param['size']) && $param['size']) {
$fileSize = $param['size'];
}
$validate = \think\facade\Validate::rule([
'image' => 'require|fileSize:' . $fileSize . '|fileExt:' . $fileExt,
]);
$file_check['image'] = $file;
if (!$validate->check($file_check)) {
return to_assign(1, $validate->getError());
}
// 日期前綴
$dataPath = date('Ym');
$use = 'thumb';
$filename = \think\facade\Filesystem::disk('public')->putFile($dataPath, $file, function () use ($md5) {
return set_salt(5).'_'.$md5;
});
if ($filename) {
//写入到附件表
$imagePath = get_config('filesystem.disks.public.url'). '/' . $filename;
$thumbPath = '';
if(in_array($file->extension(),['jpg','png','jpeg','gif'])){
// 生成等比缩略图
$image = Image::open(request()->file('file'));
$thumbPath = dirname($imagePath) . '/thumb_' . basename($imagePath);
// 生成等比缩略图保存到指定位置,这里设置最大宽度为360px, 高度自适应
$image->thumb(360,360,Image::THUMB_CENTER)->save('./'.$thumbPath);
}
$data = [];
$data['filepath'] = $imagePath;
$data['thumbpath'] = $thumbPath;
$data['name'] = $file->getOriginalName();
$data['mimetype'] = $file->getOriginalMime();
$data['fileext'] = $file->extension();
$data['filesize'] = $file->getSize();
$data['filename'] = $filename;
$data['sha1'] = $sha1;
$data['md5'] = $md5;
$data['module'] = \think\facade\App::initialize()->http->getName();
$data['action'] = app('request')->action();
$data['uploadip'] = app('request')->ip();
$data['create_time'] = time();
$data['user_id'] = $this->uid;
if ($data['module'] = 'admin') {
//通过后台上传的文件直接审核通过
$data['status'] = 1;
$data['admin_id'] = $data['user_id'];
$data['audit_time'] = time();
}
$data['use'] = request()->has('use') ? request()->param('use') : $use; //附件用处
$res['id'] = Db::name('file')->insertGetId($data);
$res['filepath'] = $data['filepath'];
$res['name'] = $data['name'];
$res['uid'] = $this->uid;
$res['filename'] = $data['filename'];
$res['filesize'] = $data['filesize'];
$res['fileext'] = $data['fileext'];
add_log('upload', $data['user_id'], $data,'文件');
if($sourse == 'editormd'){
//editormd编辑器上传返回
return json(['success'=>1,'message'=>'上传成功','url'=>$data['filepath']]);
}
else if($sourse == 'tinymce'){
//tinymce编辑器上传返回
return json(['success'=>1,'message'=>'上传成功','location'=>$data['filepath']]);
}
else{
//普通上传返回
return to_assign(0, '上传成功', $res);
}
}
else {
return to_assign(1, '上传失败,请重试');
}
}
else{
return to_assign(1, '非法请求');
}
}
//执行分块上传的控制器方法
public function chunkUpload() {
if ($this->request->isPost()) {
//执行分块上传流程
$data = $this->request->post();
//判断是否是分块上传
if ($data['type'] === 'chunk') {
$file = request()->file('file');
$rule = [
'image' => 'jpg,png,jpeg,gif',
'doc' => 'txt,doc,docx,ppt,pptx,xls,xlsx,pdf',
'file' => 'zip,gz,7z,rar,tar',
'video' => 'mpg,mp4,mpeg,avi,wmv,mov,flv,m4v',
'audio' => 'mp3,wav,wma,flac,midi',
];
$fileExt = $rule['image'] . ',' . $rule['doc'] . ',' . $rule['file'] . ',' . $rule['video'] . ',' . $rule['audio'];
//1M=1024*1024=1048576字节
$file_size = get_system_config('system','upload_max_filesize');
if(!isset($file_size)){
$file_size=50;
}
$fileSize = $file_size * 1024 * 1024;
$validate = \think\facade\Validate::rule([
'image' => 'require|fileSize:' . $fileSize . '|fileExt:' . $fileExt,
]);
$file_check['image'] = $file;
if (!$validate->check($file_check)) {
return to_assign(1, $validate->getError());
}
//获取对应的上传配置
$fs = \think\facade\Filesystem::disk('public');
$ext = $file->extension();
$chunkPath = $data['file_id'].'/'.$file->md5().($ext ? '.'.$ext : '');
//存储分片文件到指定路径
$savename = $fs->putFileAs( 'chunk', $file,$chunkPath);
if (!$savename) {
return json([
'code' => 1,
'msg' => '上传失败',
'data' => [],
]);
}
if (!$data['is_end']) {
$filepath = '';
} else {
//合并块文件
$fileUrl = '';
$chunkSaveDir = \think\facade\Filesystem::getDiskConfig('public');
$smallChunkDir = $chunkSaveDir['root'].'/chunk/'.$data['file_id'];
//获取已存储的属于源文件的所有分块文件 进行合并
if ($handle = opendir($smallChunkDir)) {
$chunkList = [];
$modifyTime = [];
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$temp['path'] = $smallChunkDir.'/'.$file;
$temp['modify'] = filemtime($smallChunkDir.'/'.$file);
$chunkList[] = $temp;
$modifyTime[] = $temp['modify'];
}
}
//对分块文件进行排序
array_multisort($modifyTime,SORT_ASC,$chunkList);
$saveDir = \think\facade\Filesystem::getDiskConfig('public');
$saveName = md5($data['file_id'].$data['file_name']).'.'.$data['file_extension'];
$newPath = $saveDir['root'].'/'.date('Ym').'/'.$saveName;
if (!file_exists($saveDir['root'].'/'.date('Ym'))) {
mkdir($saveDir['root'].'/'.date('Ym'),0777,true);
}
$newFileHandle = fopen($newPath,'a+b');
foreach ($chunkList as $item) {
fwrite($newFileHandle,file_get_contents($item['path']));
unlink($item['path']);
}
rmdir($smallChunkDir);
//将合并后的文件存储到指定路径
$fileUrl = $saveDir['url'].'/'.date('Ym').'/'.$saveName;
fclose($newFileHandle);
closedir($handle);
} else {
return json([
'code' => 1,
'msg' => '目录:'.$chunkSaveDir['root'].'/chunk/'.$data['file_id'].'不存在',
'data' => [],
]);
}
$filepath = $fileUrl;
}
$res=[];
//合并流程结束
if ($filepath!='') {
$fileinfo = [];
$fileinfo['filepath'] = $filepath;
$fileinfo['name'] = $data['file_name'];
$fileinfo['fileext'] = $data['file_extension'];
$fileinfo['filesize'] = $data['file_size'];
$fileinfo['filename'] = date('Ym').'/'.$saveName;
$fileinfo['sha1'] = $data['file_id'];
$fileinfo['md5'] = $data['file_id'];
$fileinfo['module'] = \think\facade\App::initialize()->http->getName();
$fileinfo['action'] = app('request')->action();
$fileinfo['uploadip'] = app('request')->ip();
$fileinfo['create_time'] = time();
$fileinfo['user_id'] = get_login_admin('id') ? get_login_admin('id') : 0;
if ($fileinfo['module'] = 'admin') {
//通过后台上传的文件直接审核通过
$fileinfo['status'] = 1;
$fileinfo['admin_id'] = $fileinfo['user_id'];
$fileinfo['audit_time'] = time();
}
$fileinfo['use'] = 'big';
$res['id'] = Db::name('file')->insertGetId($fileinfo);
$res['filepath'] = $fileinfo['filepath'];
$res['name'] = $fileinfo['name'];
$res['filename'] = $fileinfo['filename'];
$res['filesize'] = $fileinfo['filesize'];
$res['fileext'] = $fileinfo['fileext'];
add_log('upload', $fileinfo['user_id'], $fileinfo);
}
return to_assign(0, '上传成功', $res);
}
}
else{
return to_assign(1, '非法请求', $res);
}
}
//取消上传,删除临时文件
public function clearChunk() {
if ($this->request->isPost()) {
$param = get_params();
$saveDir = \think\facade\Filesystem::getDiskConfig('public');
$smallChunkDir = $saveDir['root'].'/chunk/'.$param['file_id'];
if(!is_dir($smallChunkDir)){
return to_assign(0, '上传的临时文件已删除');
}
//获取已存储的属于源文件的所有分块文件
if ($handle = opendir($smallChunkDir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$temp['path'] = $smallChunkDir.'/'.$file;
unlink($temp['path']);
}
}
rmdir($smallChunkDir);
closedir($handle);
return to_assign(0, '已取消上传');
}
}
}
//附件重命名
public function file_edit()
{
$param = get_params();
if (Db::name('File')->where('id',$param['id'])->update(['name'=>$param['title']]) !== false) {
add_log('edit', $param['id'], $param,'文件名称');
return to_assign(0, "操作成功");
} else {
return to_assign(1, "操作失败");
}
}
//获取编辑记录
public function load_log()
{
$param = get_params();
$log = new EditLog();
$list = $log->datalist($param);
$total = Db::name('EditLog')->where(['name'=>$param['name'],'action_id'=>$param['action_id']])->count();
$totalRow['total'] = $total;
return to_assign(0, '', $list,$totalRow);
}
//清空缓存
public function cache_clear()
{
\think\facade\Cache::clear();
return to_assign(0, '系统缓存已清空');
}
// 测试邮件发送
public function email_test()
{
$sender = get_params('email');
//检查是否邮箱格式
if (!is_email($sender)) {
return to_assign(1, '测试邮箱码格式有误');
}
$email_config = \think\facade\Db::name('config')->where('name', 'email')->find();
$config = unserialize($email_config['content']);
$content = $config['template'];
//所有项目必须填写
if (empty($config['smtp']) || empty($config['smtp_port']) || empty($config['smtp_user']) || empty($config['smtp_pwd'])) {
return to_assign(1, '请完善邮件配置信息');
}
$send = send_email($sender, '测试邮件', $content);
if ($send) {
return to_assign(0, '邮件发送成功');
} else {
return to_assign(1, '邮件发送失败');
}
}
//测试发送阿里云短信
public function sms_test()
{
$phoneNumbers = '136xxxxxxxx';
// $code = rand(1000, 9999); // 示例验证码
$sms = new Smsservice();
$result = $sms->sendSms($phoneNumbers, 'SMS_xxxxxx', ['name' => '勾股OA','title'=>'《测试阿里云短信发送成功》']);
if ($result['code'] === 'OK') {
return to_assign(0, '发送成功');
} else {
return to_assign(1, '发送失败:'.$result['message']);
}
}
//获取未读消息
public function get_msg()
{
$msg_map[] = ['to_uid', '=', $this->uid];
$msg_map[] = ['read_time', '=', 0];
$msg_map[] = ['delete_time', '=', 0];
$msg_count = Db::name('Msg')->where($msg_map)->count();
return to_assign(0, 'ok', $msg_count);
}
//获取部门
public function get_department()
{
$department = get_department();
return to_assign(0, '', $department);
}
//获取部门树形节点列表,用于tree前端组件
public function get_department_tree()
{
$department = get_department();
$list = get_tree($department);
$data['trees'] = $list;
return json($data);
}
//获取下属部门树形节点列表,用于tree前端组件
public function get_department_tree_sub()
{
if($this->uid==1){
$department = get_department();
}
else{
$dids = get_leader_departments($this->uid);
$department = Db::name('Department')->order('sort desc,id asc')->where([['status','=',1],['id','in',$dids]])->select()->toArray();
}
$list = get_tree($department,$department[0]['pid']);
$data['trees'] = $list;
return json($data);
}
//获取部门树形节点列表,用于X-select前端组件
public function get_department_select()
{
$keyword = get_params('keyword');
$selected = [];
if(!empty($keyword)){
$selected = explode(",",$keyword);
}
$department = get_department();
$list = get_select_tree($department, 0,0,$selected);
return to_assign(0, '',$list);
}
//获取所有员工,did>0时时获取部门员工,用于picker签单组件
public function get_employee($did = 0)
{
$where=[];
$whereOr=[];
if (!empty($did)) {
$admin_array = Db::name('DepartmentAdmin')->where('department_id',$did)->column('admin_id');
$map1=[
['a.id','in',$admin_array],
];
$map2=[
['a.did', '=', $did],
];
$whereOr =[$map1,$map2];
}
$where[] = ['a.id', '>', 1];
$where[] = ['a.status', '=', 1];
$where[] = ['a.delete_time', '=', 0];
$employee = Db::name('admin')
->field('a.id,a.did,a.position_id,a.mobile,a.name,a.nickname,a.sex,a.status,a.thumb,a.username,d.title as department')
->alias('a')
->join('Position p', 'p.id = a.position_id','left')
->join('Department d', 'a.did = d.id','left')
->where($where)
->where(function ($query) use($whereOr) {
if (!empty($whereOr)){
$query->whereOr($whereOr);
}
})
->group('a.id')
->order('a.id desc')
->select();
return to_assign(0, '', $employee);
}
//获取所有下属员工,did>0时时获取部门员工,用于picker签单组件
public function get_employee_sub($did = 0)
{
$where=[];
$whereOr=[];
if (!empty($did)) {
$admin_array = Db::name('DepartmentAdmin')->where('department_id',$did)->column('admin_id');
$map1=[
['a.id','in',$admin_array],
];
$map2=[
['a.did', '=', $did],
];
$whereOr =[$map1,$map2];
}
else{
if($this->uid>1){
$dids = get_leader_departments($this->uid);
$where[] = ['a.did', 'in', $dids];
}
}
$where[] = ['a.id', '>', 1];
$where[] = ['a.status', '=', 1];
$where[] = ['a.delete_time', '=', 0];
$employee = Db::name('admin')
->field('a.id,a.did,a.position_id,a.mobile,a.name,a.nickname,a.sex,a.status,a.thumb,a.username,d.title as department')
->alias('a')
->join('Position p', 'p.id = a.position_id','left')
->join('Department d', 'a.did = d.id','left')
->where($where)
->where(function ($query) use($whereOr) {
if (!empty($whereOr)){
$query->whereOr($whereOr);
}
})
->group('a.id')
->order('a.id desc')
->select();
return to_assign(0, '', $employee);
}
//获取所有员工
public function get_personnel()
{
$param = get_params();
$where[] = ['a.status', '=', 1];
$where[] = ['a.id', '>', 1];
$where[] = ['a.delete_time', '=', 0];
if (!empty($param['keywords'])) {
$where[] = ['a.name', 'like', '%' . $param['keywords'] . '%'];
}
if(!empty($param['ids'])){
//排除某些员工
$where[] = ['a.id', 'notin', $param['ids']];
}
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
$list = Db::name('admin')
->field('a.id,a.did,a.position_id,a.mobile,a.name,a.nickname,a.sex,a.status,a.thumb,a.username,d.title as department')
->alias('a')
->join('Department d', 'a.did = d.id')
->where($where)
->order('a.id desc')
->paginate(['list_rows'=> $rows]);
return table_assign(0, '', $list);
}
//获取所有员工,用于X-select前端组件,did>0时时获取部门员工
public function get_employee_select($did=0)
{
$keyword = get_params('keyword');
$selected = [];
if(!empty($keyword)){
$selected = explode(",",$keyword);
}
if($did == 0){
$employee = Db::name('admin')->field('id as value,name')->where(['status' => 1,'delete_time'=>0])->select()->toArray();
}
else{
$employee = get_department_employee($did);
}
$list=[];
foreach($employee as $k => $v){
$select = '';
if(in_array($v['id'],$selected)){
$select = 'selected';
}
$list[]=[
'value'=>$v['id'],
'name'=>$v['name'],
'selected'=>$select
];
}
return to_assign(0, '', $list);
}
//获取某部门的负责人
public function get_department_leader($uid=0,$pid=0)
{
$leaders = get_department_leader($uid,$pid);
return to_assign(0, '', $leaders);
}
//获取职位
public function get_position()
{
$position = Db::name('Position')->field('id,title')->where([['status', '=', 1], ['id', '>', 1]])->select();
return to_assign(0, '', $position);
}
//获取消息模板
public function get_template()
{
$param = get_params();
if (!empty($param['keywords'])) {
$where[] = ['title', 'like', '%' . $param['keywords'] . '%'];
}
$where[] = ['status', '=', 1];
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
$list = Db::name('Template')->field('id,title')->where($where)->paginate(['list_rows'=> $rows]);;
return table_assign(0, '', $list);
}
//读取报销类型
function get_expense_cate()
{
$cate = get_base_data('ExpenseCate');
return to_assign(0, '', $cate);
}
//读取费用类型
function get_cost_cate()
{
$cate = get_base_data('CostCate');
return to_assign(0, '', $cate);
}
//读取印章类型
function get_seal_cate()
{
$cate = get_base_data('SealCate');
return to_assign(0, '', $cate);
}
//读取车辆类型
function get_car_cate()
{
$cate = get_base_data('CarCate');
return to_assign(0, '', $cate);
}
//读取企业主体
function get_subject()
{
$subject = get_base_data('Subject');
return to_assign(0, '', $subject);
}
//读取行业类型
function get_industry()
{
$industry = get_base_data('Industry');
return to_assign(0, '', $industry);
}
//读取服务类型
function get_services()
{
$services = get_base_data('Services');
return to_assign(0, '', $services);
}
//获取工作类型列表
public function get_work_cate()
{
$cate = get_base_data('WorkCate');
return to_assign(0, '', $cate);
}
}
+94
View File
@@ -0,0 +1,94 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\api\controller;
use app\api\BaseController;
use think\facade\Db;
use Firebase\JWT\JWT;
class Office extends BaseController
{
public function view($id=0,$mode='edit')
{
$file = Db::name('File')->where('id',$id)->find();
if(empty($file)){
return view('../../base/view/common/filetemplate');
}
$path = $file['filepath'];
$title = $file['name'];
$extension = pathinfo($path, PATHINFO_EXTENSION);
$filename = pathinfo($path, PATHINFO_FILENAME);
$office_config = get_system_config('other');
$office_config['token'] = 'secret_8JFhzy';
//$directory = substr($path, 0, 16);
//$key = set_salt(10).str_replace("/", "T", $directory).$filename.'.'.$extension;
$key = "key".$file['audit_time']."T".$id;
$domain = $_SERVER['HTTP_HOST'];
$url = "http://".$domain.$path;
$callbackUrl = "http://".$domain."/office.php";
$admin = Db::name('Admin')->where('id',$this->uid)->find();
$config = [
"document" => [
"url" => $url,
"key" => $key,
"permissions" => [
"chat"=> true,
"comment"=> true,
"copy"=> true,
"deleteCommentAuthorOnly"=> false,
"download"=> true,
"edit"=> true,
"editCommentAuthorOnly"=> false,
"fillForms"=> true,
"modifyContentControl"=> true,
"modifyFilter"=> true,
"print"=>true,
"protect"=> true,
"review"=> true
]
],
"editorConfig"=>[
"mode" => $mode,//view,edit
"forcesave"=>true,
"lang"=>"zh-CN",
"createUrl" => '',
"customization"=>[
"autosave"=>true,//是否自动保存
"comments"=>false,
"help"=>false
],
"user" => [
"id" => $admin['id'],
"name" => $admin['name']
],
"callbackUrl"=>$callbackUrl
]
];
$token = JWT::encode($config, $office_config['token'], 'HS256'); //输出Token 默认'HS256'
return View('',['token'=>$token,'key'=>$key,'office'=>$office_config,'mode'=>$mode,'domain'=>$domain,'url'=>$url,'title'=>$title,'callbackUrl'=>$callbackUrl,'admin'=>$admin]);
}
public function officeapps($id=0,$mode='edit')
{
$file = Db::name('File')->where('id',$id)->find();
if(empty($file)){
return view('../../base/view/common/filetemplate');
}
$path = $file['filepath'];
$domain = $_SERVER['HTTP_HOST'];
$url = "//".$domain.$path;
return View('',['url'=>$url]);
}
}