parent
e36dc45de4
commit
a20e5ab784
@ -0,0 +1,8 @@
|
|||||||
|
<IfModule mod_rewrite.c>
|
||||||
|
Options +FollowSymlinks -Multiviews
|
||||||
|
RewriteEngine on
|
||||||
|
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-d
|
||||||
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
|
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
|
||||||
|
</IfModule>
|
@ -0,0 +1 @@
|
|||||||
|
deny from all
|
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
// 基础模块配置文件
|
||||||
|
|
||||||
|
return [
|
||||||
|
//'配置项'=>'配置值'
|
||||||
|
'LANG_SWITCH_ON' => true, //开启语言包功能
|
||||||
|
'LANG_AUTO_DETECT' => true, // 自动侦测语言
|
||||||
|
'DEFAULT_LANG' => 'zh-cn', // 默认语言
|
||||||
|
'LANG_LIST' => 'en-us,zh-cn,zh-tw', //必须写可允许的语言列表
|
||||||
|
'VAR_LANGUAGE' => 'l', // 默认语言切换变量
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 基础类,无需验证权限。
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author:
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use com\verify\HonrayVerify;
|
||||||
|
use app\common\controller\Common;
|
||||||
|
use think\Request;
|
||||||
|
use think\Session;
|
||||||
|
|
||||||
|
class Base extends Common
|
||||||
|
{
|
||||||
|
public function login()
|
||||||
|
{
|
||||||
|
$request = Request::instance();
|
||||||
|
$paramArr = $request->param();
|
||||||
|
$userModel = model('User');
|
||||||
|
$param = $this->param;
|
||||||
|
$username = $param['username'];
|
||||||
|
$password = $param['password'];
|
||||||
|
$verifyCode = !empty($param['verifyCode']) ? $param['verifyCode']: '';
|
||||||
|
$isRemember = !empty($param['isRemember']) ? $param['isRemember']: '';
|
||||||
|
$data = $userModel->login($username, $password, $verifyCode, $isRemember, $type, $authKey, $paramArr);
|
||||||
|
|
||||||
|
Session::set('user_id', $data['userInfo']['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $userModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//退出登录
|
||||||
|
public function logout()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
$header = Request::instance()->header();
|
||||||
|
$request = Request::instance();
|
||||||
|
$paramArr = $request->param();
|
||||||
|
$platform = $paramArr['platform'] ? '_'.$paramArr['platform'] : ''; //请求平台(mobile,ding)
|
||||||
|
$cache = cache('Auth_'.$authKey.$platform,null);
|
||||||
|
cookie(null, '72crm_');
|
||||||
|
cookie(null, '5kcrm_');
|
||||||
|
session('user_id','null');
|
||||||
|
return resultArray(['data'=>'退出成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取图片验证码
|
||||||
|
public function getVerify()
|
||||||
|
{
|
||||||
|
$captcha = new HonrayVerify(config('captcha'));
|
||||||
|
return $captcha->entry();
|
||||||
|
}
|
||||||
|
|
||||||
|
//网站信息
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$systemModel = model('System');
|
||||||
|
$data = $systemModel->getDataList();
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// miss 路由:处理没有匹配到的路由规则
|
||||||
|
public function miss()
|
||||||
|
{
|
||||||
|
if (Request::instance()->isOptions()) {
|
||||||
|
return ;
|
||||||
|
} else {
|
||||||
|
echo '悟空软件';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 评论
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: yykun
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use think\Request;
|
||||||
|
use think\Session;
|
||||||
|
use think\Hook;
|
||||||
|
use app\common\controller\Common;
|
||||||
|
|
||||||
|
class Comment extends Common
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission'=>[''], //不登录可访问
|
||||||
|
'allow'=>['save','delete'] //需要登录才能访问
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
$c = strtolower($request->controller());
|
||||||
|
$m = strtolower($request->module());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加评论
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
$model = model('Comment');
|
||||||
|
if ($param['task_id']) {
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$param['create_user_id'] = $userInfo['id'];
|
||||||
|
$flag = $model->createData($param);
|
||||||
|
if ($flag) {
|
||||||
|
return resultArray(['data'=>$flag]);
|
||||||
|
} else {
|
||||||
|
return resultArray(['error'=>$workModel->getError()]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return resultArray(['error'=>'参数错误']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除评论
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
$commentModel = model('Comment');
|
||||||
|
if ($param['comment_id']) {
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$param['create_user_id'] = $userInfo['id'];
|
||||||
|
$flag = $commentModel->delDataById($param);
|
||||||
|
if ($flag) {
|
||||||
|
return resultArray(['data'=>'删除成功']);
|
||||||
|
} else {
|
||||||
|
return resultArray(['error'=>$commentModel->getError()]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return resultArray(['error'=>'参数错误']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 应用状态
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class ConfigSet extends ApiCommon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission'=>[''],
|
||||||
|
'allow'=>['']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用状态列表
|
||||||
|
* @author Michael_xu
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$configModel = model('Config');
|
||||||
|
$data = $configModel->getDataList();
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态编辑
|
||||||
|
* @author Michael_xu
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function update()
|
||||||
|
{
|
||||||
|
$configModel = model('Config');
|
||||||
|
$param = $this->param;
|
||||||
|
if (!$param['id']) {
|
||||||
|
return resultArray(['error' => '参数错误']);
|
||||||
|
}
|
||||||
|
if ($configModel->updateDataById($param, $param['id'])) {
|
||||||
|
return resultArray(['data' => '编辑成功']);
|
||||||
|
}
|
||||||
|
return resultArray(['error' => $configModel->getError()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,152 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 日志规则控制器
|
||||||
|
*
|
||||||
|
* @author qifan
|
||||||
|
* @date 2020-12-03
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use app\admin\logic\DailyRuleLogic;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class DailyRule extends ApiCommon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission'=>[''],
|
||||||
|
'allow'=>['welcome', 'setwelcome', 'worklogrule', 'setworklogrule','scheduleList','addschedule','setschedule','delschedule']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取欢迎语
|
||||||
|
*
|
||||||
|
* @param DailyRuleLogic $dailyRuleLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
|
public function welcome(DailyRuleLogic $dailyRuleLogic)
|
||||||
|
{
|
||||||
|
$data = $dailyRuleLogic->welcome();
|
||||||
|
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加欢迎语
|
||||||
|
*
|
||||||
|
* @param DailyRuleLogic $dailyRuleLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function setWelcome(DailyRuleLogic $dailyRuleLogic)
|
||||||
|
{
|
||||||
|
$mark = $this->param['welcome'];
|
||||||
|
|
||||||
|
if (empty($mark)) return resultArray(['error' => '缺少日志欢迎语!']);
|
||||||
|
|
||||||
|
if (!$dailyRuleLogic->setWelcome($mark)) return resultArray(['error' => '添加失败!']);
|
||||||
|
|
||||||
|
return resultArray(['data' => '添加成功!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取日志规则
|
||||||
|
*
|
||||||
|
* @param DailyRuleLogic $dailyRuleLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function workLogRule(DailyRuleLogic $dailyRuleLogic)
|
||||||
|
{
|
||||||
|
$data = $dailyRuleLogic->workLogRule();
|
||||||
|
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置日志规则
|
||||||
|
*
|
||||||
|
* @param DailyRuleLogic $dailyRuleLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function setWorkLogRule(DailyRuleLogic $dailyRuleLogic)
|
||||||
|
{
|
||||||
|
if (empty($this->param['rule'])) return resultArray(['error' => '缺少规则参数!']);
|
||||||
|
|
||||||
|
$dailyRuleLogic->setWorkLogRule($this->param['rule']);
|
||||||
|
|
||||||
|
return resultArray(['data' => '设置成功!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取日程规则
|
||||||
|
* @param DailyRuleLogic $dailyRuleLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function scheduleList(DailyRuleLogic $dailyRuleLogic){
|
||||||
|
$data = $dailyRuleLogic->schedule();
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置日程自定义规则
|
||||||
|
* @param DailyRuleLogic $dailyRuleLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function setSchedule(DailyRuleLogic $dailyRuleLogic){
|
||||||
|
if(empty($this->param['id'])) return resultArray(['error'=>'缺少参数']);
|
||||||
|
$dailyRuleLogic->setSchedule($this->param);
|
||||||
|
return resultArray(['data' => '设置成功!']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加日程自定义规则
|
||||||
|
* @param DailyRuleLogic $dailyRuleLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
|
public function addSchedule(DailyRuleLogic $dailyRuleLogic){
|
||||||
|
if(empty($this->param['name'])) return resultArray(['error'=>'缺少参数']);
|
||||||
|
$dailyRuleLogic->addSchedule($this->param);
|
||||||
|
return resultArray(['data' => '添加成功!']);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除日程自定义规则
|
||||||
|
* @param DailyRuleLogic $dailyRuleLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
|
public function delSchedule(DailyRuleLogic $dailyRuleLogic){
|
||||||
|
if(empty($this->param['id'])) return resultArray(['error'=>'缺少参数']);
|
||||||
|
$dailyRuleLogic->delSchedule($this->param['id']);
|
||||||
|
return resultArray(['data' => '删除成功!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,230 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 附件
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use app\work\traits\WorkAuthTrait;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class File extends ApiCommon
|
||||||
|
{
|
||||||
|
use WorkAuthTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission'=>[''],
|
||||||
|
'allow'=>['index', 'save', 'delete', 'update', 'read', 'download', 'deleteall', 'downloadimage']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 附件列表
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$fileModel = model('File');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $fileModel->getDataList($param, $param['by']);
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 附件上传
|
||||||
|
* @author Michael_xu
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
header('Access-Control-Allow-Origin: *');
|
||||||
|
header('Access-Control-Allow-Methods: POST');
|
||||||
|
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
|
||||||
|
$type = $this->param['type'];
|
||||||
|
$files = request()->file('file');
|
||||||
|
$imgs = request()->file('img');
|
||||||
|
$i = 0;
|
||||||
|
$newFiles = [];
|
||||||
|
|
||||||
|
# 项目上传附件权限
|
||||||
|
if (!empty($this->param['module']) && $this->param['module'] == 'work_task' && !empty($this->param['work_id'])) {
|
||||||
|
if (!$this->checkWorkOperationAuth('uploadTaskFile', $this->param['work_id'], $this->userInfo['id'])) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code' => 102, 'error' => '无权操作!']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($type) && in_array($type, ['img', 'file'])) {
|
||||||
|
# todo 兼容11.0前端
|
||||||
|
if ($type == 'img') {
|
||||||
|
$newFiles[0]['obj'] = $files;
|
||||||
|
$newFiles[0]['types'] = 'img';
|
||||||
|
}
|
||||||
|
if ($type == 'file') {
|
||||||
|
$newFiles[0]['obj'] = $files;
|
||||||
|
$newFiles[0]['types'] = 'file';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
# todo 兼容9.0前端
|
||||||
|
if (!empty($files)) {
|
||||||
|
foreach ($files as $v) {
|
||||||
|
$newFiles[$i]['obj'] = $v;
|
||||||
|
$newFiles[$i]['types'] = 'file';
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!empty($imgs)) {
|
||||||
|
foreach ($imgs as $v) {
|
||||||
|
$newFiles[$i]['obj'] = $v;
|
||||||
|
$newFiles[$i]['types'] = 'img';
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$fileModel = model('File');
|
||||||
|
$param = $this->param;
|
||||||
|
$param['create_user_id'] = $this->userInfo['id'];
|
||||||
|
$res = $fileModel->createData($newFiles, $param);
|
||||||
|
if($res){
|
||||||
|
return resultArray(['data' => $res]);
|
||||||
|
} else {
|
||||||
|
return resultArray(['error' => $fileModel->getError()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 附件删除
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param 通过 save_name 作为条件 来删除附件
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
$fileModel = model('File');
|
||||||
|
$param = $this->param;
|
||||||
|
|
||||||
|
# 项目删除附件权限
|
||||||
|
if (!empty($this->param['module']) && $this->param['module'] == 'work_task' && !empty($this->param['work_id'])) {
|
||||||
|
if (!$this->checkWorkOperationAuth('deleteTaskFile', $this->param['work_id'], $this->userInfo['id'])) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code' => 102, 'error' => '无权操作!']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$res = $fileModel->delFileBySaveName($param['save_name'], $param);
|
||||||
|
if (!$res) {
|
||||||
|
return resultArray(['error' => $fileModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '删除成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全部删除(活动、产品)
|
||||||
|
*
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function deleteAll()
|
||||||
|
{
|
||||||
|
if ((empty($this->param['module']) && empty($this->param['module_id'])) || empty($this->param['file_id'])) {
|
||||||
|
return resultArray(['error' => '参数错误!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$fileModel = new \app\admin\model\File();
|
||||||
|
|
||||||
|
if (!$fileModel->deleteAll($this->param)) return resultArray(['error' => '操作失败!']);
|
||||||
|
|
||||||
|
return resultArray(['data' => '操作成功!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 附件编辑
|
||||||
|
*/
|
||||||
|
public function update()
|
||||||
|
{
|
||||||
|
$fileModel = model('File');
|
||||||
|
$param = $this->param;
|
||||||
|
if ( $param['save_name'] && $param['name'] ) {
|
||||||
|
$ret = $fileModel->updateNameBySaveName($param['save_name'],$param['name']);
|
||||||
|
if ($ret) {
|
||||||
|
return resultArray(['data'=>'操作成功']);
|
||||||
|
} else {
|
||||||
|
return resultArray(['error'=>'操作失败']);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return resultArray(['error'=>'参数错误']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 附件查看(下载)
|
||||||
|
* @author Michael_xu
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function read()
|
||||||
|
{
|
||||||
|
$fileModel = model('File');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $fileModel->getDataBySaveName($param['save_name']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $this->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 静态资源文件下载
|
||||||
|
*/
|
||||||
|
public function download()
|
||||||
|
{
|
||||||
|
if(isset($this->param['path'])){
|
||||||
|
$path = $this->param['path'];
|
||||||
|
$name = $this->param['name'] ?: '';
|
||||||
|
if (empty($path)) return resultArray(['error' => '参数错误!']);
|
||||||
|
return download(realpath('./public/' . $path), $name);
|
||||||
|
}else{
|
||||||
|
$path = $this->param['save_name'];
|
||||||
|
$name = $this->param['name'] ?: '';
|
||||||
|
if (empty($path)) return resultArray(['error' => '参数错误!']);
|
||||||
|
if (!strstr($path, 'uploads')) $path = 'uploads/' . $path;
|
||||||
|
return download(realpath('./public/' . $path), $name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下载图片(头像),前端要求重写一个。
|
||||||
|
*
|
||||||
|
* @return \think\response\Json|void
|
||||||
|
*/
|
||||||
|
public function downloadImage()
|
||||||
|
{
|
||||||
|
$path = $this->param['path'];
|
||||||
|
$file = explode('public/', $path);
|
||||||
|
|
||||||
|
if (empty($path) || empty($file[1])) return resultArray(['error' => '参数错误!']);
|
||||||
|
|
||||||
|
return download(realpath('./public/'.$file[1]));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,217 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 用户组
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use app\admin\logic\FieldGrantLogic;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class Groups extends ApiCommon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission'=>[''],
|
||||||
|
'allow'=>['index','enables','copy','typelist','save','update','delete']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
//权限判断
|
||||||
|
$unAction = ['index','typelist'];
|
||||||
|
if (!in_array($a, $unAction) && !checkPerByAction('admin', 'groups', 'update')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色列表
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$groupModel = model('Group');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $groupModel->getDataList($param);
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色详情
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function read()
|
||||||
|
{
|
||||||
|
$groupModel = model('Group');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $groupModel->getDataById($param['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $groupModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色添加
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function save(FieldGrantLogic $fieldGrantLogic)
|
||||||
|
{
|
||||||
|
$groupModel = model('Group');
|
||||||
|
$param = $this->param;
|
||||||
|
$param['rules'] = arrayToString($param['rules']);
|
||||||
|
$lastInsId = $groupModel->createData($param);
|
||||||
|
if (!$lastInsId) {
|
||||||
|
return resultArray(['error' => $groupModel->getError()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
# 新增客户管理角色的字段授权数据
|
||||||
|
if (isset($param['pid']) && $param['pid'] == 2) {
|
||||||
|
$fieldGrantLogic->createCrmFieldGrant($lastInsId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultArray(['data' => 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色编辑
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function update()
|
||||||
|
{
|
||||||
|
$groupModel = model('Group');
|
||||||
|
$param = $this->param;
|
||||||
|
$dataInfo = $groupModel->getDataById($param['id']);
|
||||||
|
if (!$dataInfo) {
|
||||||
|
return resultArray(['error' => '参数错误']);
|
||||||
|
}
|
||||||
|
|
||||||
|
# 处理前端传来的type是work的错误
|
||||||
|
if (!empty($param['type']) && $param['type'] == 'work') $param['type'] = 1;
|
||||||
|
|
||||||
|
$param['rules'] = arrayToString($param['rules']);
|
||||||
|
$data = $groupModel->updateDataById($param, $param['id']);
|
||||||
|
return resultArray(['data' => '编辑成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色删除
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function delete(FieldGrantLogic $fieldGrantLogic)
|
||||||
|
{
|
||||||
|
$groupModel = model('Group');
|
||||||
|
$param = $this->param;
|
||||||
|
$dataInfo = $groupModel->getDataById($param['id']);
|
||||||
|
if (!$dataInfo) {
|
||||||
|
return resultArray(['error' => '参数错误']);
|
||||||
|
}
|
||||||
|
if ($dataInfo['types']) {
|
||||||
|
return resultArray(['error' => '系统角色,不能删除']);
|
||||||
|
}
|
||||||
|
$data = $groupModel->delGroupById($param['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $groupModel->getError()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
# 删除字段授权数据
|
||||||
|
$fieldGrantLogic->deleteCrmFieldGrant($param['id']);
|
||||||
|
|
||||||
|
return resultArray(['data' => '删除成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色启用、禁用
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function enables()
|
||||||
|
{
|
||||||
|
$groupModel = model('Group');
|
||||||
|
$param = $this->param;
|
||||||
|
$dataInfo = $groupModel->getDataById($param['id']);
|
||||||
|
if (!$dataInfo) {
|
||||||
|
return resultArray(['error' => '参数错误']);
|
||||||
|
}
|
||||||
|
if ($dataInfo['types']) {
|
||||||
|
return resultArray(['error' => '系统角色,不能删除']);
|
||||||
|
}
|
||||||
|
$data = $groupModel->enableDatas($param['id'], $param['status'], true);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $groupModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '操作成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色复制
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function copy(FieldGrantLogic $fieldGrantLogic)
|
||||||
|
{
|
||||||
|
$groupModel = model('Group');
|
||||||
|
$param = $this->param;
|
||||||
|
$dataInfo = $groupModel->getDataById($param['id']);
|
||||||
|
if (!$dataInfo) {
|
||||||
|
return resultArray(['error' => '参数错误']);
|
||||||
|
}
|
||||||
|
$dataInfo = json_decode($dataInfo, true);
|
||||||
|
unset($dataInfo['id']);
|
||||||
|
$titleCount = db('admin_group')->where(['title' => $dataInfo['title']])->count();
|
||||||
|
$dataInfo['title'] = $dataInfo['title'].'('.$titleCount.')';
|
||||||
|
$data = $groupModel->createData($dataInfo);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $groupModel->getError()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
# 复制客户管理角色的字段授权数据
|
||||||
|
if (!empty($dataInfo['pid']) && $dataInfo['pid'] == 2) {
|
||||||
|
$fieldGrantLogic->copyCrmFieldGrant($param['id'], $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultArray(['data' => '操作成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色分类列表
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function typeList()
|
||||||
|
{
|
||||||
|
$groupModel = model('Group');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $groupModel->getTypeList($param);
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 初始化控制器
|
||||||
|
*
|
||||||
|
* @author qifan
|
||||||
|
* @date 2020-01-05
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use app\admin\logic\InitializeLogic;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class Initialize extends ApiCommon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission' => [],
|
||||||
|
'allow' => ['verification']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表
|
||||||
|
*
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
['type' => 1, 'name' => '全部应用'],
|
||||||
|
['type' => 2, 'name' => '客户管理'],
|
||||||
|
['type' => 3, 'name' => '任务/审批'],
|
||||||
|
['type' => 4, 'name' => '日志'],
|
||||||
|
['type' => 5, 'name' => '项目管理'],
|
||||||
|
['type' => 6, 'name' => '日历'],
|
||||||
|
// ['type' => 7, 'name' => '知识库'],
|
||||||
|
];
|
||||||
|
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化数据
|
||||||
|
*
|
||||||
|
* @param InitializeLogic $initializeLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function update(InitializeLogic $initializeLogic)
|
||||||
|
{
|
||||||
|
if (empty($this->param['type']) || !is_array($this->param['type'])) return resultArray(['error' => '模块类型错误!']);
|
||||||
|
|
||||||
|
if (!empty($this->param['password']) && !$initializeLogic->verification($this->userInfo['id'], $this->param['password'])) {
|
||||||
|
return resultArray(['error' => '密码错误!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$initializeLogic->update($this->param['type']);
|
||||||
|
|
||||||
|
return resultArray(['data' => $initializeLogic->log]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证密码
|
||||||
|
*
|
||||||
|
* @param InitializeLogic $initializeLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function verification(InitializeLogic $initializeLogic)
|
||||||
|
{
|
||||||
|
if (empty($this->param['password'])) return resultArray(['error' => '参数错误!']);
|
||||||
|
|
||||||
|
if (!$initializeLogic->verification($this->userInfo['id'], $this->param['password'])) return resultArray(['error' => '密码错误!']);
|
||||||
|
|
||||||
|
return resultArray(['data' => '密码正确!']);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 日志控制器
|
||||||
|
*
|
||||||
|
* @author qifan
|
||||||
|
* @date 2020-11-30
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use app\admin\logic\LogLogic;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class Log extends ApiCommon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission' => [''],
|
||||||
|
'allow' => ['dataRecord', 'systemRecord', 'loginRecord']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据操作日志
|
||||||
|
*
|
||||||
|
* @param LogLogic $logLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function dataRecord(LogLogic $logLogic)
|
||||||
|
{
|
||||||
|
$data['list'] = $logLogic->getRecordLogs($this->param);
|
||||||
|
$data['count'] = $logLogic->getRecordLogCount($this->param);
|
||||||
|
$data['modules'] = $logLogic->recordModules;
|
||||||
|
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统操作日志
|
||||||
|
*
|
||||||
|
* @param LogLogic $logLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function systemRecord(LogLogic $logLogic)
|
||||||
|
{
|
||||||
|
$data['list'] = $logLogic->getSystemLogs($this->param);
|
||||||
|
$data['count'] = $logLogic->getSystemLogCount($this->param);
|
||||||
|
$data['modules'] = $logLogic->systemModules;
|
||||||
|
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录日志
|
||||||
|
*
|
||||||
|
* @param LogLogic $logLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function loginRecord(LogLogic $logLogic)
|
||||||
|
{
|
||||||
|
$data = $logLogic->getLoginRecord($this->param);
|
||||||
|
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 菜单
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
class Menus extends ApiCommon
|
||||||
|
{
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$menuModel = model('Menu');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $menuModel->getDataList();
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function read()
|
||||||
|
{
|
||||||
|
$menuModel = model('Menu');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $menuModel->getDataById($param['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $menuModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
$menuModel = model('Menu');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $menuModel->createData($param);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $menuModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '添加成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update()
|
||||||
|
{
|
||||||
|
$menuModel = model('Menu');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $menuModel->updateDataById($param, $param['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $menuModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '编辑成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
$menuModel = model('Menu');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $menuModel->delDataById($param['id'], true);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $menuModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '删除成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deletes()
|
||||||
|
{
|
||||||
|
$menuModel = model('Menu');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $menuModel->delDatas($param['ids'], true);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $menuModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '删除成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enables()
|
||||||
|
{
|
||||||
|
$menuModel = model('Menu');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $menuModel->enableDatas($param['ids'], $param['status'], true);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $menuModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '操作成功']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,205 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 工作台及基础
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use app\admin\logic\MessageLogic;
|
||||||
|
use think\Db;
|
||||||
|
use think\Hook;
|
||||||
|
use app\admin\model\Message as MessageModel;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class Message extends ApiCommon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
parent::_initialize();
|
||||||
|
$action = [
|
||||||
|
'permission' => [],
|
||||||
|
'allow' => ['index', 'markedRead', 'messagelist', 'updatemessage','delete','readallmessage','clear','unreadcount'],
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth', $action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统信息
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$type = $param['type'] ?: 'all';
|
||||||
|
|
||||||
|
if ($type != 'all' && !isset(MessageModel::$typeGroup[$type])) {
|
||||||
|
return resultArray(['error' => '参数错误']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$where = ['to_user_id' => $userInfo['id']];
|
||||||
|
|
||||||
|
if ($type != 'all') {
|
||||||
|
$where['type'] = ['IN', MessageModel::$typeGroup[$type]];
|
||||||
|
}
|
||||||
|
|
||||||
|
$order = [
|
||||||
|
'read_time' => 'ASC',
|
||||||
|
'send_time' => 'DESC',
|
||||||
|
];
|
||||||
|
|
||||||
|
$page = $param['page'] ?: 1;
|
||||||
|
$limit = $param['limit'] ?: 15;
|
||||||
|
|
||||||
|
$data = MessageModel::where($where)
|
||||||
|
->order($order)
|
||||||
|
->paginate($limit)
|
||||||
|
->each(function ($val) {
|
||||||
|
$val['relation_title'] = $val->relation_title;
|
||||||
|
$val['from_user_id_info'] = $val->from_user_id_info;
|
||||||
|
})
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
return resultArray([
|
||||||
|
'data' => [
|
||||||
|
'list' => $data['data'],
|
||||||
|
'dataCount' => $data['total']
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阅读系统通知,修改状态为已读
|
||||||
|
*/
|
||||||
|
public function markedRead()
|
||||||
|
{
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$param = $this->param;
|
||||||
|
|
||||||
|
$where = [
|
||||||
|
'to_user_id' => $userInfo['id'],
|
||||||
|
'message_id' => ['IN', (array)$param['message_id']],
|
||||||
|
'read_time' => 0,
|
||||||
|
];
|
||||||
|
|
||||||
|
$res = MessageModel::where($where)->update(['read_time' => time()]);
|
||||||
|
return resultArray(['data' => $res > 0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 未读数
|
||||||
|
*/
|
||||||
|
// public function unReadCount()
|
||||||
|
// {
|
||||||
|
// $data = [];
|
||||||
|
// foreach (MessageModel::$typeGroup as $key => $val) {
|
||||||
|
// $data[$key] = MessageModel::where(['type' => ['IN', $val]])->count();
|
||||||
|
// }
|
||||||
|
// $data['all'] = array_sum($data);
|
||||||
|
// return resultArray(['data' => $data]);
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 未读消息列表
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
|
public function messageList()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$param['user_id'] = $userInfo['id'];
|
||||||
|
$messageLogic = new MessageLogic();
|
||||||
|
$data = $messageLogic->getDataList($param);
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*更新消息类型 已读未读
|
||||||
|
*/
|
||||||
|
public function updateMessage()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$param['id']=$userInfo['id'];
|
||||||
|
$messageLogic = new MessageLogic();
|
||||||
|
$data = $messageLogic->endMessage($param);
|
||||||
|
if(!$data){
|
||||||
|
return resultArray(['data' => "操作失败!"]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => "操作成功!"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除消息
|
||||||
|
*
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
if (empty($this->param['message_id'])) return resultArray(['error' => '参数错误!']);
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$param = $this->param;
|
||||||
|
$data['message_id'] = $param['message_id'];
|
||||||
|
$data['user_id'] = $userInfo['id'];
|
||||||
|
$messageLogic = new MessageLogic();
|
||||||
|
if (!$messageLogic->delete($data)) return resultArray(['error' => '操作失败!']);
|
||||||
|
|
||||||
|
return resultArray(['data' => '操作成功!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量更新
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function readAllMessage(){
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$param['user_id'] = $userInfo['id'];
|
||||||
|
$messageLogic = new MessageLogic();
|
||||||
|
$data = $messageLogic->readAllMessage($param);
|
||||||
|
return resultArray(['data' => "操作成功!"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function clear(){
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$param['user_id'] = $userInfo['id'];
|
||||||
|
$messageLogic = new MessageLogic();
|
||||||
|
$data = $messageLogic->clear($param);
|
||||||
|
return resultArray(['data' => "操作成功!"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总数
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function unreadCount(){
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$param['user_id'] = $userInfo['id'];
|
||||||
|
$messageLogic = new MessageLogic();
|
||||||
|
$data = $messageLogic->unreadCount($param);
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 岗位控制器
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
class Posts extends ApiCommon
|
||||||
|
{
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$postModel = model('Post');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $postModel->getDataList($param);
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function read()
|
||||||
|
{
|
||||||
|
$postModel = model('Post');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $postModel->getDataById($param['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $postModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
$postModel = model('Post');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $postModel->createData($param);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $postModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '添加成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update()
|
||||||
|
{
|
||||||
|
$postModel = model('Post');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $postModel->updateDataById($param, $param['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $postModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '编辑成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
$postModel = model('Post');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $postModel->delDataById($param['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $postModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '删除成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deletes()
|
||||||
|
{
|
||||||
|
$postModel = model('Post');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $postModel->delDatas($param['ids']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $postModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '删除成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enables()
|
||||||
|
{
|
||||||
|
$postModel = model('Post');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $postModel->enableDatas($param['ids'], $param['status']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $postModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '操作成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 规则
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class Rules extends ApiCommon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission'=>[''],
|
||||||
|
'allow'=>['index']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
$m = $this->m;
|
||||||
|
$c = $this->c;
|
||||||
|
$a = $this->a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$ruleModel = model('Rule');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $ruleModel->getDataList($param);
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新建规则
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
$ruleModel = model('Rule');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $ruleModel->createData($param);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $ruleModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '添加成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑规则
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function update()
|
||||||
|
{
|
||||||
|
$ruleModel = model('Rule');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $ruleModel->updateDataById($param, $param['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $ruleModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '编辑成功']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,169 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 场景
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use think\Hook;
|
||||||
|
use think\Session;
|
||||||
|
use think\Request;
|
||||||
|
use think\Db;
|
||||||
|
|
||||||
|
class Scene extends ApiCommon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission'=>[''],
|
||||||
|
'allow'=>['index','save','read','update','delete','sort','defaults']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 场景列表
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$sceneModel = model('Scene');
|
||||||
|
$data = $sceneModel->getDataList($param['types'], $userInfo['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $sceneModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 场景创建
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
$sceneModel = model('Scene');
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$param['user_id'] = $userInfo['id'];
|
||||||
|
$data = $sceneModel->createData($param, $param['types']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $sceneModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '添加成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 场景详情
|
||||||
|
* @param int $id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function read()
|
||||||
|
{
|
||||||
|
$sceneModel = model('Scene');
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$data = $sceneModel->getDataById($param['id'], $userInfo['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $sceneModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑场景
|
||||||
|
* @param int $id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function update()
|
||||||
|
{
|
||||||
|
$sceneModel = model('Scene');
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$param['user_id'] = $userInfo['id'];
|
||||||
|
$data = $sceneModel->updateDataById($param, $param['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $sceneModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '编辑成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除场景
|
||||||
|
* @param int $id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function delete($id)
|
||||||
|
{
|
||||||
|
$sceneModel = model('Scene');
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
//权限判断
|
||||||
|
if (!$sceneModel->getDataById($param['id'], $userInfo['id'])) {
|
||||||
|
return resultArray(['error' => '数据不存在或已删除']);
|
||||||
|
}
|
||||||
|
$dataInfo = db('admin_scene')->where(['scene_id' => $param['id']])->find();
|
||||||
|
$resData = $sceneModel->delDataById($param['id']);
|
||||||
|
if ($resData) {
|
||||||
|
//重新设置默认
|
||||||
|
$default = db('admin_scene')->where(['types' => $dataInfo['types'],'bydata' => 'all'])->find();
|
||||||
|
$sceneModel->defaultDataById(['types' => $dataInfo['types'],'user_id' => $userInfo['id']], $default['scene_id']);
|
||||||
|
return resultArray(['data' => '删除成功']);
|
||||||
|
} else {
|
||||||
|
return resultArray(['error' => $sceneModel->getError()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 场景排序
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function sort()
|
||||||
|
{
|
||||||
|
$sceneModel = model('Scene');
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$param['ids'] = $param['ids'] ? : [];
|
||||||
|
$param['hide_ids'] = $param['hide_ids'] ? : [];
|
||||||
|
$resData = $sceneModel->listOrder($param, $userInfo['id']);
|
||||||
|
if (!$resData) {
|
||||||
|
return resultArray(['error' => $sceneModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '设置成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 场景默认
|
||||||
|
* @param scene_id 场景ID
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function defaults()
|
||||||
|
{
|
||||||
|
$sceneModel = model('Scene');
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$scene_id = $param['id'];
|
||||||
|
$param['user_id'] = $userInfo['id'];
|
||||||
|
$resData = $sceneModel->defaultDataById($param, $scene_id);
|
||||||
|
if (!$resData) {
|
||||||
|
return resultArray(['error' => $sceneModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '设置成功']);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 系统设置
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use app\admin\controller\ApiCommon;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class Setting extends ApiCommon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission'=>[''],
|
||||||
|
'allow'=>['']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
//权限判断
|
||||||
|
$unAction = [''];
|
||||||
|
$adminTypes = adminGroupTypes($userInfo['id']);
|
||||||
|
if (!in_array(2,$adminTypes) && !in_array(1,$adminTypes) && !in_array($a, $unAction)) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,243 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 组织架构
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
use think\Db;
|
||||||
|
|
||||||
|
class Structures extends ApiCommon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission'=>[''],
|
||||||
|
'allow'=>['index','read','save','update','delete','deletes','enables','listdialog','subindex','getsubuserbystructrue']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取权限范围内的部门
|
||||||
|
public function subIndex()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$userModel = model('User');
|
||||||
|
$m = $param['m'] ? : '';
|
||||||
|
$c = $param['c'] ? : '';
|
||||||
|
$a = $param['a'] ? : '';
|
||||||
|
$ret = $userModel->getUserByPer($m, $c, $a);
|
||||||
|
$where['au.id'] = ['in',$ret];
|
||||||
|
$structure_ids = Db::name('AdminUser')
|
||||||
|
->alias('au')
|
||||||
|
->join('AdminStructure ast','ast.id = au.structure_id','LEFT')
|
||||||
|
->where($where)
|
||||||
|
->group('structure_id')
|
||||||
|
->order('structure_id asc')
|
||||||
|
->column('ast.id');
|
||||||
|
$list = Db::name('AdminStructure')
|
||||||
|
->group('id')
|
||||||
|
->order('id asc')
|
||||||
|
->select();
|
||||||
|
$result = getSubObj(0, $list, '', 1);
|
||||||
|
$adminTypes = adminGroupTypes($userInfo['id']);
|
||||||
|
if(!in_array(1,$adminTypes)){
|
||||||
|
foreach ($result as $key => $value) {
|
||||||
|
if(!in_array($value['id'],$structure_ids)){
|
||||||
|
unset($result[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultArray(['data'=>$result]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取部门下权限范围内员工
|
||||||
|
public function getSubUserByStructrue()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
$userModel = model('User');
|
||||||
|
$structureList = $userModel->getSubUserByStr($param['structure_id'],2);
|
||||||
|
if($param['structure_id']){
|
||||||
|
$where['id'] = ['in',$structureList];
|
||||||
|
}
|
||||||
|
$list =Db::name('AdminUser')->field('id,realname')->where($where)->select();
|
||||||
|
$list = $list?:array();
|
||||||
|
return resultArray(['data'=>$list]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门列表
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
//权限判断
|
||||||
|
// if (!checkPerByAction('admin', 'users', 'index')) {
|
||||||
|
// header('Content-Type:application/json; charset=utf-8');
|
||||||
|
// exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
// }
|
||||||
|
$structureModel = model('Structure');
|
||||||
|
$param = $this->param;
|
||||||
|
$type = $param['type'] ? 'tree' : '';
|
||||||
|
$data = $structureModel->getDataList($type);
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门详情
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function read()
|
||||||
|
{
|
||||||
|
$structureModel = model('Structure');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $structureModel->getDataById($param['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $structureModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门添加
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
//权限判断
|
||||||
|
if (!checkPerByAction('admin', 'users', 'structures_save')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
$structureModel = model('Structure');
|
||||||
|
$param = $this->param;
|
||||||
|
if(!$param['pid']){
|
||||||
|
resultArray(['error' => '请选择上级部门']);
|
||||||
|
}
|
||||||
|
$data = $structureModel->createData($param);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $structureModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '添加成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门编辑
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function update()
|
||||||
|
{
|
||||||
|
//权限判断
|
||||||
|
if (!checkPerByAction('admin', 'users', 'structures_update')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
$structureModel = model('Structure');
|
||||||
|
$param = $this->param;
|
||||||
|
$dataInfo = $structureModel->getDataByID($param['id']);
|
||||||
|
if (empty($dataInfo['pid']) || $param['id'] == '1') {
|
||||||
|
unset($param['pid']);
|
||||||
|
}
|
||||||
|
$data = $structureModel->updateDataById($param, $param['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $structureModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '编辑成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门删除
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
//权限判断
|
||||||
|
if (!checkPerByAction('admin', 'users', 'structures_delete')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
$structureModel = model('Structure');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $structureModel->delStrById($param['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $structureModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '删除成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门启用、停用
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function enables()
|
||||||
|
{
|
||||||
|
//权限判断
|
||||||
|
if (!checkPerByAction('admin', 'users', 'structures_update')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
$structureModel = model('Structure');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $structureModel->enableDatas($param['ids'], $param['status'], true);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $structureModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '操作成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门list
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function listDialog()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
$structure_id = $param['id'];
|
||||||
|
$type = $param['type'];
|
||||||
|
if (!$structure_id) {
|
||||||
|
return resultArray(['error' => '参数错误']);
|
||||||
|
}
|
||||||
|
$structureList = db('admin_structure')->select();
|
||||||
|
if ($type == 'update') {
|
||||||
|
//去除自身及下属部门
|
||||||
|
foreach ($structureList as $k => $v) {
|
||||||
|
if (($v['id'] == $structure_id) || ($v['pid'] == $structure_id)) {
|
||||||
|
unset($structureList[$k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$structureList = getSubObj(0, $structureList, '', 1);
|
||||||
|
return resultArray(['data' => $structureList]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 系统配置
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: yykun
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class System extends ApiCommon
|
||||||
|
{
|
||||||
|
//用于判断权限
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission'=>['index'],
|
||||||
|
'allow'=>['']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//信息列表
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$systemModel = model('System');
|
||||||
|
$data = $systemModel->getDataList();
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//编辑保存
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
|
||||||
|
if (isset($param['logo'])) {
|
||||||
|
$logo = !empty($param['logo']) ? './public/uploads/'.$param['logo'] : '';
|
||||||
|
db('admin_system')->where('name', 'logo')->update(['value' => $logo]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($param['name'])) {
|
||||||
|
db('admin_system')->where('name', 'name')->update(['value' => $param['name']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultArray(['data' => '操作成功!']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,723 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 系统员工
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use app\admin\model\User;
|
||||||
|
use think\Request;
|
||||||
|
use think\Session;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Cache;
|
||||||
|
use think\Db;
|
||||||
|
use app\admin\model\LoginRecord;
|
||||||
|
use app\admin\model\User as UserModel;
|
||||||
|
use app\admin\logic\UserLogic;
|
||||||
|
use app\admin\model\Admin as AdminModel;
|
||||||
|
use app\crm\traits\StarTrait;
|
||||||
|
class Users extends ApiCommon
|
||||||
|
{
|
||||||
|
use StarTrait;
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录员工可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission' => ['exceldownload'],
|
||||||
|
'allow' => [
|
||||||
|
'index',
|
||||||
|
'update',
|
||||||
|
'updatepwd',
|
||||||
|
'read',
|
||||||
|
'updateimg',
|
||||||
|
'resetpassword',
|
||||||
|
'userlistbystructid',
|
||||||
|
'groups',
|
||||||
|
'groupsdel',
|
||||||
|
'tobeusers',
|
||||||
|
'structureuserlist',
|
||||||
|
'getuserlist',
|
||||||
|
'usernameedit',
|
||||||
|
'import',
|
||||||
|
'setparent',
|
||||||
|
'loginRecord',
|
||||||
|
'userstar',
|
||||||
|
'querylist',
|
||||||
|
'starlist',
|
||||||
|
'copyrole',
|
||||||
|
'subordinate'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工列表
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$userModel = model('User');
|
||||||
|
$param = $this->param;
|
||||||
|
$data = $userModel->getDataList($param);
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工详情
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function read()
|
||||||
|
{
|
||||||
|
$userModel = model('User');
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
if (!$param['id']) $param['id'] = $userInfo['id'];
|
||||||
|
$data = $userModel->getDataById($param['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $userModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工创建
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
$userModel = model('User');
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$data = $userModel->createData($param);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $userModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '添加成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工编辑
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function update()
|
||||||
|
{
|
||||||
|
$userModel = model('User');
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$userData = db('admin_user')->where(['id' => $param['id']])->find();
|
||||||
|
if (!$param['id']) {
|
||||||
|
//修改个人信息
|
||||||
|
$param['user_id'] = $userInfo['id'];
|
||||||
|
} else {
|
||||||
|
//权限判断
|
||||||
|
if (!checkPerByAction('admin', 'users', 'update')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unset($param['username']);
|
||||||
|
$data = $userModel->updateDataById($param, $param['id']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $userModel->getError()]);
|
||||||
|
}
|
||||||
|
$param['userInfo'] = $userData;
|
||||||
|
$resSync = model('Sync')->syncData($param);
|
||||||
|
return resultArray(['data' => '编辑成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//批量设置密码
|
||||||
|
public function updatePwd()
|
||||||
|
{
|
||||||
|
//权限判断
|
||||||
|
if (!checkPerByAction('admin', 'users', 'update')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
$param = $this->param;
|
||||||
|
if ($param['password'] && is_array($param['id'])) {
|
||||||
|
$userModel = model('User');
|
||||||
|
$ret = $userModel->updatePwdById($param);
|
||||||
|
if ($ret) {
|
||||||
|
return resultArray(['data'=>true]);
|
||||||
|
} else {
|
||||||
|
return resultArray(['error'=>$userModel->getError()]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return resultArray(['error'=>'参数错误']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工状态
|
||||||
|
* @param status 0禁用,1启用,2禁止登陆,3未激活
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function enables()
|
||||||
|
{
|
||||||
|
$userModel = model('User');
|
||||||
|
$param = $this->param;
|
||||||
|
if (!is_array($param['id'])) {
|
||||||
|
$ids[] = $param['id'];
|
||||||
|
} else {
|
||||||
|
$ids = $param['id'];
|
||||||
|
}
|
||||||
|
//顶级管理员不能修改
|
||||||
|
foreach ($ids as $k=>$v) {
|
||||||
|
if ((int)$v == 1 && $param['status'] == '0') {
|
||||||
|
unset($ids[$k]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data = $userModel->enableDatas($ids, $param['status']);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $userModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '操作成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取权限范围内的员工数组
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function getUserList()
|
||||||
|
{
|
||||||
|
$userModel = model('User');
|
||||||
|
$param = $this->param;
|
||||||
|
$by = $param['by'] ? : '';
|
||||||
|
$user_id = $param['user_id'] ? : '';
|
||||||
|
$where = [];
|
||||||
|
$belowIds = [];
|
||||||
|
if ($param['m'] && $param['c'] && $param['a']) {
|
||||||
|
if ($param['m'] == 'oa' && $param['c'] == 'task') {
|
||||||
|
$belowIds = getSubUserId(true, 1);
|
||||||
|
} else {
|
||||||
|
$belowIds = $userModel->getUserByPer($param['m'], $param['c'], $param['a']);
|
||||||
|
}
|
||||||
|
$where['user.id'] = ['in',$belowIds];
|
||||||
|
} else {
|
||||||
|
if ($by == 'sub') {
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$adminIds = $userModel->getAdminId();
|
||||||
|
if (in_array($userInfo['id'],$adminIds)) {
|
||||||
|
$belowIds = getSubUserId(true, 1);
|
||||||
|
} else {
|
||||||
|
//下属id
|
||||||
|
$belowIds = getSubUserId();
|
||||||
|
}
|
||||||
|
$where['user.id'] = ['in',$belowIds];
|
||||||
|
} elseif ($by == 'parent') {
|
||||||
|
if ($user_id == 1) {
|
||||||
|
$where['user.id'] = 0;
|
||||||
|
} else {
|
||||||
|
$unUserId[] = $user_id;
|
||||||
|
$subUserId = getSubUser($user_id);
|
||||||
|
$unUserId = $subUserId ? array_merge($subUserId,$unUserId) : $unUserId;
|
||||||
|
}
|
||||||
|
$where['user.id'] = ['not in',$unUserId];
|
||||||
|
} else {
|
||||||
|
$belowIds = getSubUserId(true, 1);
|
||||||
|
$where['user.id'] = ['in',$belowIds];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$userList = db('admin_user')
|
||||||
|
->alias('user')
|
||||||
|
->where($where)
|
||||||
|
->where('user.status>0 and user.type=1')
|
||||||
|
->join('__ADMIN_STRUCTURE__ structure', 'structure.id = user.structure_id', 'LEFT')
|
||||||
|
->field('user.id,user.realname,user.thumb_img,structure.name as s_name')
|
||||||
|
->select();
|
||||||
|
|
||||||
|
# 角色数据
|
||||||
|
$groupList = db('admin_access')->alias('access')
|
||||||
|
->join('__ADMIN_GROUP__ group', 'group.id = access.group_id', 'LEFT')
|
||||||
|
->field('group.id, group.title, access.user_id')->select();
|
||||||
|
$groupArray = [];
|
||||||
|
foreach ($groupList AS $key => $value) {
|
||||||
|
$groupArray[$value['user_id']]['roleId'][] = $value['id'];
|
||||||
|
$groupArray[$value['user_id']]['roleName'][] = $value['title'];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($userList as $k=>$v) {
|
||||||
|
$userList[$k]['username'] = $v['realname'];
|
||||||
|
$userList[$k]['thumb_img'] = $v['thumb_img'] ? getFullPath($v['thumb_img']) : '';
|
||||||
|
|
||||||
|
# 员工新增角色ID和角色名称字段
|
||||||
|
$userList[$k]['roleId'] = !empty($groupArray[$v['id']]['roleId']) ? implode(',', $groupArray[$v['id']]['roleId']) : '';
|
||||||
|
$userList[$k]['roleName'] = !empty($groupArray[$v['id']]['roleName']) ? implode(',', $groupArray[$v['id']]['roleName']) : '';
|
||||||
|
# 单独处理admin管理员的角色ID和角色名称字段
|
||||||
|
if ($v['id'] == 1 && (empty($groupArray[$v['id']]['roleId']) || empty($groupArray[$v['id']]['roleName']))) {
|
||||||
|
$userList[$k]['roleId'] = '1';
|
||||||
|
$userList[$k]['roleName'] = '超级管理员角色';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultArray(['data' => $userList ? : []]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改头像
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function updateImg()
|
||||||
|
{
|
||||||
|
$fileModel = model('File');
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
//处理图片
|
||||||
|
header('Access-Control-Allow-Origin: *');
|
||||||
|
header('Access-Control-Allow-Methods: POST');
|
||||||
|
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
|
||||||
|
$param['file'] = request()->file('file');
|
||||||
|
|
||||||
|
$resImg = $fileModel->updateByField($param['file'], 'User', $param['id'], 'img', 'thumb_img', 150, 150);
|
||||||
|
if (!$resImg) {
|
||||||
|
return resultArray(['error' => $fileModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '上传成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置密码
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function resetPassword()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$userModel = model('User');
|
||||||
|
if ($param['id'] && (int)$param['id'] !== $userInfo['id']) {
|
||||||
|
//权限判断
|
||||||
|
if (!checkPerByAction('admin', 'users', 'update')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
$user_id = $param['id'];
|
||||||
|
if (!$param['new_pwd']) {
|
||||||
|
$this->error = '请输入重置密码';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$userInfo = $userModel->getDataById($user_id);
|
||||||
|
if (user_md5($param['new_pwd'], $userInfo['salt'], $userInfo['username']) == $userInfo['password']) {
|
||||||
|
$this->error = '密码没改变';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (db('admin_user')->where('id', $user_id)->setField('password', user_md5($param['new_pwd'], $userInfo['salt'], $userInfo['username']))) {
|
||||||
|
$syncData = [];
|
||||||
|
$syncModel = new \app\admin\model\Sync();
|
||||||
|
$syncData['user_id'] = $userInfo['id'];
|
||||||
|
$syncData['salt'] = $userInfo['salt'];
|
||||||
|
$syncData['password'] = user_md5($param['new_pwd'], $userInfo['salt'], $userInfo['username']);
|
||||||
|
$resSync = $syncModel->syncData($syncData);
|
||||||
|
return resultArray(['data' => '密码重置成功']);
|
||||||
|
} else {
|
||||||
|
return resultArray(['error' => '密码重置失败,请重试']);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$userModel = model('User');
|
||||||
|
$old_pwd = $param['old_pwd'];
|
||||||
|
$new_pwd = $param['new_pwd'];
|
||||||
|
$data = $userModel->updatePaw($userInfo, $old_pwd, $new_pwd);
|
||||||
|
if (!$data) {
|
||||||
|
return resultArray(['error' => $userModel->getError()]);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工角色关系
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function groups()
|
||||||
|
{
|
||||||
|
//权限判断
|
||||||
|
if (!checkPerByAction('admin', 'groups', 'update')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
$param = $this->param;
|
||||||
|
if (!$param['users'] && !$param['structures']) {
|
||||||
|
return resultArray(['error' => '请选择员工']);
|
||||||
|
}
|
||||||
|
if (!$param['groups']) {
|
||||||
|
return resultArray(['error' => '请选择角色']);
|
||||||
|
}
|
||||||
|
$userModel = model('User');
|
||||||
|
//部门下所有员工
|
||||||
|
$userArr = [];
|
||||||
|
if (is_array($param['structures'])) {
|
||||||
|
foreach ($param['structures'] as $v) {
|
||||||
|
$userArr[] = $userModel->getSubUserByStr($v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($userArr) $userArr = call_user_func_array('array_merge', $userArr); //数组合并
|
||||||
|
if ($userArr && $param['users']) {
|
||||||
|
$userIds = array_merge($userArr, $param['users']);
|
||||||
|
} elseif ($userArr) {
|
||||||
|
$userIds = $userArr;
|
||||||
|
} else {
|
||||||
|
$userIds = $param['users'];
|
||||||
|
}
|
||||||
|
$userIds = array_unique($userIds);
|
||||||
|
$groups = $param['groups'];
|
||||||
|
$accessModel = model('Access');
|
||||||
|
$resData = true;
|
||||||
|
foreach ($userIds as $k=>$v) {
|
||||||
|
//角色员工关系处理
|
||||||
|
$res = $accessModel->userGroup($v, $param['groups']);
|
||||||
|
if (!$res) {
|
||||||
|
$resData = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// if ($resData == false) {
|
||||||
|
// return resultArray(['error' => '操作失败,请重试']);
|
||||||
|
// }
|
||||||
|
return resultArray(['data' => '创建成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工角色关系(删除)
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function groupsDel()
|
||||||
|
{
|
||||||
|
//权限判断
|
||||||
|
if (!checkPerByAction('admin', 'groups', 'update')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
$param = $this->param;
|
||||||
|
if (!$param['user_id']) {
|
||||||
|
return resultArray(['error' => '请选择员工']);
|
||||||
|
}
|
||||||
|
if (!$param['group_id']) {
|
||||||
|
return resultArray(['error' => '参数错误']);
|
||||||
|
}
|
||||||
|
|
||||||
|
# 员工至少保留一个角色
|
||||||
|
$count = db('admin_access')->where(['user_id' => $param['user_id']])->count();
|
||||||
|
if ($count == 1) return resultArray(['error' => '员工至少保留一个角色!']);
|
||||||
|
|
||||||
|
$res = db('admin_access')->where(['user_id' => $param['user_id'],'group_id' => $param['group_id']])->delete();
|
||||||
|
if (!$res) {
|
||||||
|
return resultArray(['error' => '操作失败,请重试']);
|
||||||
|
}
|
||||||
|
return resultArray(['data' => '删除成功']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [structureUserList 部门员工混合数据]
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function structureUserList()
|
||||||
|
{
|
||||||
|
$structure_list = db('admin_structure')->select();
|
||||||
|
$structureList = getSubObj(0, $structure_list, '', 1);
|
||||||
|
foreach ($structureList as $k=>$v) {
|
||||||
|
$userList = [];
|
||||||
|
$userList = db('admin_user')->where(['structure_id' => $v['id'],'status' => array('in',['1','3'])])->field('id,realname')->select();
|
||||||
|
$structureList[$k]['userList'] = $userList;
|
||||||
|
}
|
||||||
|
return $structureList;
|
||||||
|
}
|
||||||
|
|
||||||
|
//人资员工导入
|
||||||
|
public function tobeusers(){
|
||||||
|
$userModel = model('User');
|
||||||
|
$param = $this->param;
|
||||||
|
$flag = $userModel->beusers($param);
|
||||||
|
if ($flag) {
|
||||||
|
return resultArray(['data'=>$flag]);
|
||||||
|
} else {
|
||||||
|
return resultArray(['error'=>$userModel->getError()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//根据部门ID获取员工列表
|
||||||
|
public function userListByStructId()
|
||||||
|
{
|
||||||
|
$usermodel = model('User');
|
||||||
|
$param = $this->param;
|
||||||
|
$structure_id = $param['structure_id']?:'';
|
||||||
|
$ret = $usermodel->getUserListByStructureId($structure_id) ? : [];
|
||||||
|
return resultArray(['data'=>$ret]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工账号修改
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function usernameEdit()
|
||||||
|
{
|
||||||
|
//权限判断
|
||||||
|
if (!checkPerByAction('admin', 'users', 'update')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
//权限判断
|
||||||
|
if ($param['id'] == 1) {
|
||||||
|
return resultArray(['error' => '管理员账号暂不能修改']);
|
||||||
|
}
|
||||||
|
$adminTypes = adminGroupTypes($userInfo['id']);
|
||||||
|
if (!in_array(3,$adminTypes) && !in_array(1,$adminTypes) && !in_array(2,$adminTypes)) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
if (!$param['id'] || !$param['username'] || !$param['password']) {
|
||||||
|
return resultArray(['error' => '参数错误!']);
|
||||||
|
}
|
||||||
|
if (db('admin_user')->where(['id' => ['neq',$param['id']],'username' => $param['username']])->find()) {
|
||||||
|
return resultArray(['error' => '手机号码已存在!']);
|
||||||
|
}
|
||||||
|
$userData = db('admin_user')->where(['id' => $param['id']])->field('username,salt,password')->find();
|
||||||
|
$data = [];
|
||||||
|
$data['username'] = $param['username'];
|
||||||
|
$data['password'] = user_md5($param['password'], $userData['salt'], $param['username']);
|
||||||
|
$data['userInfo'] = $userData;
|
||||||
|
$resSync = model('Sync')->syncData($data);
|
||||||
|
if ($resSync) {
|
||||||
|
unset($data['userInfo']);
|
||||||
|
$res = db('admin_user')->where(['id' => $param['id']])->update($data);
|
||||||
|
return resultArray(['data' => '修改成功!']);
|
||||||
|
} else {
|
||||||
|
return resultArray(['error' => '修改失败,请重试!']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录记录
|
||||||
|
*/
|
||||||
|
public function loginRecord()
|
||||||
|
{
|
||||||
|
if (!checkPerByAction('admin', 'loginRecord', 'index')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code' => 102, 'error' => '无权操作']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$loginRecordModel = new LoginRecord();
|
||||||
|
$where = [];
|
||||||
|
getWhereUserByParam($where, 'create_user_id');
|
||||||
|
getWhereTimeByParam($where, 'create_time');
|
||||||
|
|
||||||
|
$limit = $this->param['limit'] ?: 15;
|
||||||
|
$data = $loginRecordModel
|
||||||
|
->where($where)
|
||||||
|
->order(['create_time' => 'DESC'])
|
||||||
|
->paginate($limit)
|
||||||
|
->each(function ($val) {
|
||||||
|
$val['username'] = $val->create_user_info['realname'];
|
||||||
|
$val['type_name'] = $val->type_name;
|
||||||
|
})
|
||||||
|
->toArray();
|
||||||
|
return resultArray([
|
||||||
|
'data' => [
|
||||||
|
'list' => $data['data'],
|
||||||
|
'dataCount' => $data['total']
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工导入模板下载
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param string $save_path 本地保存路径 用于错误数据导出,在 Admin\Model\Excel::batchImportData()调用
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function excelDownload($save_path = '')
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$excelModel = new \app\admin\model\Excel();
|
||||||
|
|
||||||
|
// 导出的字段列表
|
||||||
|
$field_list = UserModel::$import_field_list;
|
||||||
|
$excelModel->excelImportDownload($field_list, 'admin_user', $save_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工导入
|
||||||
|
*/
|
||||||
|
public function import()
|
||||||
|
{
|
||||||
|
// 仅允许超管,系统管理员,部门与员工管理员 导入
|
||||||
|
if (false === UserModel::checkUserGroup([1, 2, 3])) {
|
||||||
|
return resultArray(['error' => '没有该权限']);
|
||||||
|
}
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$excelModel = new \app\admin\model\Excel();
|
||||||
|
$param['types'] = 'admin_user';
|
||||||
|
$file = request()->file('file');
|
||||||
|
$res = $excelModel->batchImportData($file, $param, $this);
|
||||||
|
$list=[];
|
||||||
|
$list[]=$excelModel->getError();
|
||||||
|
$item=$list[0];
|
||||||
|
if (!$res) {
|
||||||
|
return resultArray(['data' => $item]);
|
||||||
|
}
|
||||||
|
Cache::clear('user_info');
|
||||||
|
return resultArray(['data' => $item]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量设置直属上级
|
||||||
|
*
|
||||||
|
* @author Ymob
|
||||||
|
* @datetime 2019-10-28 13:37:57
|
||||||
|
*/
|
||||||
|
public function setParent()
|
||||||
|
{
|
||||||
|
// 仅允许超管,系统管理员,部门与员工管理员 批量设置
|
||||||
|
if (false === UserModel::checkUserGroup([1, 2, 3])) {
|
||||||
|
return resultArray(['error' => '没有该权限']);
|
||||||
|
}
|
||||||
|
$parent_id = (int) $this->param['parent_id'];
|
||||||
|
$parent_user = UserModel::find($parent_id);
|
||||||
|
if (!$parent_user) {
|
||||||
|
return resultArray(['error' => '请选择直属上级']);
|
||||||
|
}
|
||||||
|
$user_id_list = (array) $this->param['id_list'];
|
||||||
|
if (empty($user_id_list)) {
|
||||||
|
return resultArray(['error' => '请选择员工']);
|
||||||
|
}
|
||||||
|
if (in_array(1, $user_id_list)) {
|
||||||
|
return resultArray(['error' => '超级管理员不能设置上级']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($parent_id, $user_id_list)) {
|
||||||
|
return resultArray(['error' => '直属上级不能为员工自己']);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($user_id_list as $val) {
|
||||||
|
if (in_array($parent_id, getSubUserId(true, 0, (int) $val))) {
|
||||||
|
return resultArray(['error' => '直属上级不能是自己下属(包含下属的下属)']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$a = new UserModel;
|
||||||
|
if ($a->where(['id' => ['IN', $user_id_list]])->update(['parent_id' => $parent_id])) {
|
||||||
|
Cache::clear('user_info');
|
||||||
|
return resultArray(['data' => '员工直属上级设置成功']);
|
||||||
|
} else {
|
||||||
|
return resultArray(['error' => '员工直属上级设置失败' . $a->getError()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通讯录列表
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function queryList(){
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$param['user_id']=$userInfo['id'];
|
||||||
|
$userLogic=new UserLogic();
|
||||||
|
$data=$userLogic->getDataList($param);
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关注的通讯录列表
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function starList(){
|
||||||
|
$param = $this->param;
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$param['user_id']=$userInfo['id'];
|
||||||
|
$userLogic=new UserLogic();
|
||||||
|
$data=$userLogic->queryList($param);
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 设置关注
|
||||||
|
*
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function userStar()
|
||||||
|
{
|
||||||
|
$userInfo = $this->userInfo;
|
||||||
|
$userId = $userInfo['id'];
|
||||||
|
$targetId = $this->param['target_id'];
|
||||||
|
$type = $this->param['type'];
|
||||||
|
|
||||||
|
if (empty($userId) || empty($targetId) || empty($type)) return resultArray(['error' => '缺少必要参数!']);
|
||||||
|
|
||||||
|
if (!$this->setStar($type, $userId, $targetId)) {
|
||||||
|
return resultArray(['error' => '设置关注失败!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultArray(['data' => '设置关注成功!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复制员工角色
|
||||||
|
*
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
|
public function copyRole()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
|
||||||
|
if (empty($param['user_id']) && empty($param['structure_id'])) return resultArray(['error' => '请选择员工或部门!']);
|
||||||
|
if (empty($param['group_id'])) return resultArray(['error' => '请选择角色!']);
|
||||||
|
|
||||||
|
$userModel = new User();
|
||||||
|
|
||||||
|
if (!$userModel->copyRole($param)) return resultArray(['error' => '操作失败!']);
|
||||||
|
|
||||||
|
return resultArray(['data' => '操作成功!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取下属(全部层级)
|
||||||
|
*
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function subordinate()
|
||||||
|
{
|
||||||
|
$userId = $this->userInfo['id'];
|
||||||
|
|
||||||
|
# 获取下属的ID
|
||||||
|
$subIds = getSubUserId(false, 0, $userId);
|
||||||
|
|
||||||
|
$data = Db::name('admin_user')->field(['id', 'realname', 'thumb_img as img'])->whereIn('id', $subIds)->select();
|
||||||
|
|
||||||
|
foreach ($data AS $key => $value) {
|
||||||
|
$data[$key]['img'] = !empty($data[$key]['img']) ? getFullPath($data[$key]['img']) : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 项目管理控制器
|
||||||
|
*
|
||||||
|
* @author qifan
|
||||||
|
* @date 2020-12-17
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\admin\controller;
|
||||||
|
|
||||||
|
use app\admin\logic\WorkLogic;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class Work extends ApiCommon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission' => [''],
|
||||||
|
'allow' => ['rules', 'roles', 'saverole', 'readrole', 'updaterole', 'deleterole']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 规则列表
|
||||||
|
*
|
||||||
|
* @param WorkLogic $workLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function rules(WorkLogic $workLogic)
|
||||||
|
{
|
||||||
|
$data = $workLogic->getRules();
|
||||||
|
|
||||||
|
$result = [
|
||||||
|
'menu_id' => 0,
|
||||||
|
'menu_name' => "项目管理",
|
||||||
|
'menu_type' => 1,
|
||||||
|
'parent_id' => 0,
|
||||||
|
'realm' => 'work',
|
||||||
|
'children' => []
|
||||||
|
];
|
||||||
|
|
||||||
|
$result['children'][] = ['id' => 0, 'title' => '项目', 'name' => 'work', 'children' => $data];
|
||||||
|
|
||||||
|
return resultArray(['data' => $result]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色
|
||||||
|
*
|
||||||
|
* @param WorkLogic $workLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function roles(WorkLogic $workLogic)
|
||||||
|
{
|
||||||
|
$data = $workLogic->getRoles();
|
||||||
|
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建角色
|
||||||
|
*
|
||||||
|
* @param WorkLogic $workLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
*/
|
||||||
|
public function saveRole(WorkLogic $workLogic)
|
||||||
|
{
|
||||||
|
if (empty($this->param['title'])) return resultArray(['error' => '请填写权限名称!']);
|
||||||
|
|
||||||
|
if (!$workLogic->saveRole($this->param)) return resultArray(['操作失败!']);
|
||||||
|
|
||||||
|
return resultArray(['data' => '操作成功!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限角色详情
|
||||||
|
*
|
||||||
|
* @param WorkLogic $workLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function readRole(WorkLogic $workLogic)
|
||||||
|
{
|
||||||
|
if (empty($this->param['id'])) return resultArray(['error' => '请选择权限角色!']);
|
||||||
|
|
||||||
|
$data = $workLogic->readRole($this->param['id']);
|
||||||
|
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑权限角色
|
||||||
|
*
|
||||||
|
* @param WorkLogic $workLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function updateRole(WorkLogic $workLogic)
|
||||||
|
{
|
||||||
|
if (empty($this->param['id'])) return resultArray(['error' => '请选择要编辑的权限角色!']);
|
||||||
|
if (empty($this->param['title'])) return resultArray(['error' => '请填写权限名称!']);
|
||||||
|
|
||||||
|
if ($workLogic->updateRole($this->param) === false) return resultArray(['error' => '操作失败!']);
|
||||||
|
|
||||||
|
return resultArray(['data' => '操作成功!']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除权限角色
|
||||||
|
*
|
||||||
|
* @param WorkLogic $workLogic
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function deleteRole(WorkLogic $workLogic)
|
||||||
|
{
|
||||||
|
if (empty($this->param['id'])) return resultArray(['error' => '请选择要删除的权限角色!']);
|
||||||
|
|
||||||
|
$result = $workLogic->deleteRole($this->param['id']);
|
||||||
|
|
||||||
|
if (empty($result['status'])) return resultArray(['error' => $result['error']]);
|
||||||
|
|
||||||
|
return resultArray(['data' => '操作成功!']);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
|
||||||
|
];
|
@ -0,0 +1,309 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 日志规则逻辑类
|
||||||
|
*
|
||||||
|
* @author qifan
|
||||||
|
* @date 2020-12-03
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\admin\logic;
|
||||||
|
|
||||||
|
use think\Db;
|
||||||
|
|
||||||
|
class DailyRuleLogic
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 获取日志欢迎语
|
||||||
|
*
|
||||||
|
* @return array|mixed
|
||||||
|
*/
|
||||||
|
public function welcome()
|
||||||
|
{
|
||||||
|
$mark = Db::name('admin_oalog_rule')->where('type', 4)->value('mark');
|
||||||
|
|
||||||
|
return !empty($mark) ? unserialize($mark) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存欢迎语
|
||||||
|
*
|
||||||
|
* @param $data
|
||||||
|
* @return int|string
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function setWelcome($data)
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach ($data as $key => $value) {
|
||||||
|
if (!empty($value)) $result[] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = serialize($result);
|
||||||
|
|
||||||
|
if (Db::name('admin_oalog_rule')->where('type', 4)->value('id')) {
|
||||||
|
return Db::name('admin_oalog_rule')->where('type', 4)->update(['mark' => $result]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Db::name('admin_oalog_rule')->insert([
|
||||||
|
'type' => 4,
|
||||||
|
'status' => 1,
|
||||||
|
'mark' => $result
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取日志规则
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function workLogRule()
|
||||||
|
{
|
||||||
|
$result[] = $this->getDayLogRule();
|
||||||
|
$result[] = $this->getWeekLogRule();
|
||||||
|
$result[] = $this->getMonthLogRule();
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置日志规则
|
||||||
|
*
|
||||||
|
* @param $param
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function setWorkLogRule($param)
|
||||||
|
{
|
||||||
|
if (!empty($param[0])) $this->setDayLogRule($param[0]);
|
||||||
|
if (!empty($param[1])) $this->setWeekLogRule($param[1]);
|
||||||
|
if (!empty($param[2])) $this->setMonthLogRule($param[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置日规则
|
||||||
|
*
|
||||||
|
* @param $param
|
||||||
|
* @return int|string
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
private function setDayLogRule($param)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'type' => 1,
|
||||||
|
'userIds' => $param['userIds'],
|
||||||
|
'effective_day' => $param['effective_day'],
|
||||||
|
'start_time' => $param['start_time'],
|
||||||
|
'end_time' => $param['end_time'],
|
||||||
|
'status' => $param['status']
|
||||||
|
];
|
||||||
|
|
||||||
|
if (Db::name('admin_oalog_rule')->where('type', 1)->value('id')) {
|
||||||
|
return Db::name('admin_oalog_rule')->where('type', 1)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Db::name('admin_oalog_rule')->insert($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置周规则
|
||||||
|
*
|
||||||
|
* @param $param
|
||||||
|
* @return int|string
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
private function setWeekLogRule($param)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'type' => 2,
|
||||||
|
'userIds' => $param['userIds'],
|
||||||
|
'start_time' => $param['start_time'],
|
||||||
|
'end_time' => $param['end_time'],
|
||||||
|
'status' => $param['status']
|
||||||
|
];
|
||||||
|
|
||||||
|
if (Db::name('admin_oalog_rule')->where('type', 2)->value('id')) {
|
||||||
|
return Db::name('admin_oalog_rule')->where('type', 2)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Db::name('admin_oalog_rule')->insert($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置月规则
|
||||||
|
*
|
||||||
|
* @param $param
|
||||||
|
* @return int|string
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
private function setMonthLogRule($param)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'type' => 3,
|
||||||
|
'userIds' => $param['userIds'],
|
||||||
|
'start_time' => $param['start_time'],
|
||||||
|
'end_time' => $param['end_time'],
|
||||||
|
'status' => $param['status']
|
||||||
|
];
|
||||||
|
|
||||||
|
if (Db::name('admin_oalog_rule')->where('type', 3)->value('id')) {
|
||||||
|
return Db::name('admin_oalog_rule')->where('type', 3)->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Db::name('admin_oalog_rule')->insert($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取日规则
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
private function getDayLogRule()
|
||||||
|
{
|
||||||
|
$day = Db::name('admin_oalog_rule')->where('type', 1)->find();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'type' => $day['type'],
|
||||||
|
'status' => $day['status'],
|
||||||
|
'userIds' => $day['userIds'],
|
||||||
|
'user' => $this->getUsers($day['userIds']),
|
||||||
|
'effective_day' => $day['effective_day'],
|
||||||
|
'start_time' => $day['start_time'],
|
||||||
|
'end_time' => $day['end_time']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取周规则
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
private function getWeekLogRule()
|
||||||
|
{
|
||||||
|
$week = Db::name('admin_oalog_rule')->where('type', 2)->find();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'type' => $week['type'],
|
||||||
|
'status' => $week['status'],
|
||||||
|
'userIds' => $week['userIds'],
|
||||||
|
'user' => $this->getUsers($week['userIds']),
|
||||||
|
'effective_day' => $week['effective_day'],
|
||||||
|
'start_time' => $week['start_time'],
|
||||||
|
'end_time' => $week['end_time']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取月规则
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
private function getMonthLogRule()
|
||||||
|
{
|
||||||
|
$month = Db::name('admin_oalog_rule')->where('type', 3)->find();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'type' => $month['type'],
|
||||||
|
'status' => $month['status'],
|
||||||
|
'userIds' => $month['userIds'],
|
||||||
|
'user' => $this->getUsers($month['userIds']),
|
||||||
|
'effective_day' => $month['effective_day'],
|
||||||
|
'start_time' => $month['start_time'],
|
||||||
|
'end_time' => $month['end_time']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户列表
|
||||||
|
*
|
||||||
|
* @param $ids
|
||||||
|
* @return bool|\PDOStatement|string|\think\Collection
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
private function getUsers($ids)
|
||||||
|
{
|
||||||
|
return Db::name('admin_user')->field(['id', 'realname'])->whereIn('id', $ids)->select();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义日程类型列表
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function schedule()
|
||||||
|
{
|
||||||
|
$list = Db::name('admin_oa_schedule')->where('type', 2)->field(['name,color,schedule_id as id'])->select();
|
||||||
|
$data = [];
|
||||||
|
$data['list'] = $list;
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置日程自定义规则
|
||||||
|
* @param $param
|
||||||
|
* @return int|string
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function setSchedule($param)
|
||||||
|
{
|
||||||
|
if (Db::name('admin_oa_schedule')->where('schedule_id', $param['id'])->value('schedule_id')) {
|
||||||
|
$data = [
|
||||||
|
'name' => $param['name'],
|
||||||
|
'update_time' => time(),
|
||||||
|
'color' => $param['color'],
|
||||||
|
];
|
||||||
|
return Db::name('admin_oa_schedule')->where( 'schedule_id', $param['id'])->update($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加自定义日程规则
|
||||||
|
* @param $param
|
||||||
|
* @return int|string
|
||||||
|
*/
|
||||||
|
public function addSchedule($param)
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'name' => $param['name'],
|
||||||
|
'create_time' => time(),
|
||||||
|
'color' => $param['color'],
|
||||||
|
];
|
||||||
|
return Db::name('admin_oa_schedule')->insert($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除日程自定义规则
|
||||||
|
* @param $param
|
||||||
|
* @return int
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function delSchedule($param)
|
||||||
|
{
|
||||||
|
if (Db::name('admin_oa_schedule')->where('schedule_id', $param)->value('schedule_id')) {
|
||||||
|
return Db::name('AdminOaSchedule')->where('schedule_id', $param)->delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,218 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 日志逻辑类
|
||||||
|
*
|
||||||
|
* @author qifan
|
||||||
|
* @date 2020-11-30
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\admin\logic;
|
||||||
|
|
||||||
|
use app\admin\model\LoginRecord;
|
||||||
|
use app\admin\model\OperationLog;
|
||||||
|
use app\admin\model\SystemLog;
|
||||||
|
|
||||||
|
class LogLogic
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 数据操作日志中的模块对应的中文名称
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
public $recordModules = [
|
||||||
|
'crm_leads' => '线索',
|
||||||
|
'crm_customer' => '客户',
|
||||||
|
'crm_pool' => '客户公海',
|
||||||
|
'crm_contacts' => '联系人',
|
||||||
|
'crm_product' => '产品',
|
||||||
|
'crm_business' => '商机',
|
||||||
|
'crm_contract' => '合同',
|
||||||
|
'crm_receivables' => '回款',
|
||||||
|
'crm_visit' => '回访',
|
||||||
|
'crm_invoice' => '回款',
|
||||||
|
'oa_log' => '办公日志',
|
||||||
|
'oa_examine' => '办公审批',
|
||||||
|
'work_task' => '任务',
|
||||||
|
'work' => '项目',
|
||||||
|
'label' => '标签',
|
||||||
|
'calendar' => '日历'
|
||||||
|
];
|
||||||
|
|
||||||
|
public $systemModules = [
|
||||||
|
'company' => '企业首页',
|
||||||
|
'application' => '应用管理',
|
||||||
|
'structures' => '部门管理',
|
||||||
|
'employee' => '员工管理',
|
||||||
|
'role' => '角色管理',
|
||||||
|
'approval' => '审批流程管理',
|
||||||
|
'workbench' => '工作台',
|
||||||
|
'project' => '项目管理',
|
||||||
|
'customer' => '客户管理'
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志记录中的行为所对应的中文名称
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
private $action = [
|
||||||
|
'index' => '查看数据',
|
||||||
|
'save' => '添加数据',
|
||||||
|
'update' => '编辑数据',
|
||||||
|
'delete' => '删除数据'
|
||||||
|
];
|
||||||
|
private $loginType = [
|
||||||
|
'成功', '密码错误', '账号禁用'
|
||||||
|
];
|
||||||
|
/**
|
||||||
|
* 登录日志
|
||||||
|
*
|
||||||
|
* @param $param
|
||||||
|
* @return array
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function getLoginRecord($param)
|
||||||
|
{
|
||||||
|
$loginRecordModel = new LoginRecord();
|
||||||
|
|
||||||
|
$limit = !empty($param['limit']) ? $param['limit'] : 15;
|
||||||
|
|
||||||
|
$data = $loginRecordModel->where(function ($query) use ($param) {
|
||||||
|
if (!empty($param['startTime'])) $query->where('create_time', '>=', strtotime($param['startTime']));
|
||||||
|
if (!empty($param['endTime'])) $query->where('create_time', '<=', strtotime($param['endTime']));
|
||||||
|
if (!empty($param['userIds'])) $query->whereIn('create_user_id', $param['userIds']);
|
||||||
|
})->order('id', 'desc')->paginate($limit)->each(function ($value) {
|
||||||
|
$value['username'] = $value->create_user_info['realname'];
|
||||||
|
$value['type'] = $this->loginType[$value['type']];
|
||||||
|
})->toArray();
|
||||||
|
|
||||||
|
return ['list' => $data['data'], 'count' => $data['total']];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统操作日志列表
|
||||||
|
*
|
||||||
|
* @param $param 查询条件、分页参数
|
||||||
|
* @return bool|\PDOStatement|string|\think\Collection
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function getSystemLogs($param)
|
||||||
|
{
|
||||||
|
$data = SystemLog::with(['toAdminUser'])
|
||||||
|
->where(function ($query) use ($param) {
|
||||||
|
if (!empty($param['startTime'])) $query->where('create_time', '>=', strtotime($param['startTime']));
|
||||||
|
if (!empty($param['endTime'])) $query->where('create_time', '<=', strtotime($param['endTime']));
|
||||||
|
if (!empty($param['modules'])) $query->whereIn('modules', $param['modules']);
|
||||||
|
if (!empty($param['userIds'])) $query->whereIn('user_id', $param['userIds']);
|
||||||
|
})->limit(($param['page'] - 1) * $param['limit'])->order('log_id', 'desc')->select();
|
||||||
|
|
||||||
|
return $this->setSystemData($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取系统操作日志总数
|
||||||
|
*
|
||||||
|
* @param $param 查询条件、分页参数
|
||||||
|
* @return int|string|null
|
||||||
|
*/
|
||||||
|
public function getSystemLogCount($param)
|
||||||
|
{
|
||||||
|
return SystemLog::where(function ($query) use ($param) {
|
||||||
|
if (!empty($param['startTime'])) $query->where('create_time', '>=', strtotime($param['startTime']));
|
||||||
|
if (!empty($param['endTime'])) $query->where('create_time', '<=', strtotime($param['endTime']));
|
||||||
|
if (!empty($param['modules'])) $query->whereIn('controller_name', $param['modules']);
|
||||||
|
if (!empty($param['userIds'])) $query->whereIn('user_id', $param['userIds']);
|
||||||
|
})->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据操作日志列表
|
||||||
|
*
|
||||||
|
* @param $param 查询条件、分页参数
|
||||||
|
* @return bool|\PDOStatement|string|\think\Collection
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function getRecordLogs($param)
|
||||||
|
{
|
||||||
|
$data = OperationLog::with(['toAdminUser'])
|
||||||
|
->where(function ($query) use ($param) {
|
||||||
|
if (!empty($param['startTime'])) $query->where('create_time', '>=', strtotime($param['startTime']));
|
||||||
|
if (!empty($param['endTime'])) $query->where('create_time', '<=', strtotime($param['endTime']));
|
||||||
|
if (!empty($param['modules'])) $query->whereIn('module', $param['modules']);
|
||||||
|
if (!empty($param['userIds'])) $query->whereIn('user_id', $param['userIds']);
|
||||||
|
})
|
||||||
|
->limit(($param['page'] - 1) * $param['limit'])->order('log_id', 'desc')->select();
|
||||||
|
|
||||||
|
return $this->setRecordData($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据操作日志总数
|
||||||
|
*
|
||||||
|
* @param $param 查询条件、分页参数
|
||||||
|
* @return int|string|null
|
||||||
|
*/
|
||||||
|
public function getRecordLogCount($param)
|
||||||
|
{
|
||||||
|
return OperationLog::where(function ($query) use ($param) {
|
||||||
|
if (!empty($param['startTime'])) $query->where('create_time', '>=', strtotime($param['startTime']));
|
||||||
|
if (!empty($param['endTime'])) $query->where('create_time', '<=', strtotime($param['endTime']));
|
||||||
|
if (!empty($param['modules'])) $query->whereIn('module', $param['module']);
|
||||||
|
if (!empty($param['userIds'])) $query->whereIn('user_id', $param['userIds']);
|
||||||
|
})->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组装数据操作日志数据
|
||||||
|
*
|
||||||
|
* @param $data
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function setRecordData($data)
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach ($data AS $key => $value) {
|
||||||
|
$result[] = [
|
||||||
|
'log_id' => $value['log_id'],
|
||||||
|
'source_name' => $value['source_name'],
|
||||||
|
'create_time' => date('Y-m-d H:i:s', $value['create_time']),
|
||||||
|
'ip' => $value['client_ip'],
|
||||||
|
'module' => $this->recordModules[$value['module']],
|
||||||
|
'content' => $value['content']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 组装数据操作日志数据
|
||||||
|
*
|
||||||
|
* @param $data
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function setSystemData($data)
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach ($data AS $key => $value) {
|
||||||
|
$result[] = [
|
||||||
|
'log_id' => $value['log_id'],
|
||||||
|
'source_name' => $value['source_name'],
|
||||||
|
'create_time' => date('Y-m-d H:i:s', $value['create_time']),
|
||||||
|
'ip' => $value['client_ip'],
|
||||||
|
'module' => $this->systemModules[$value['module']],
|
||||||
|
'content' => $value['content']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,282 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\logic;
|
||||||
|
|
||||||
|
use think\Db;
|
||||||
|
|
||||||
|
class MessageLogic
|
||||||
|
{
|
||||||
|
private function label($label)
|
||||||
|
{
|
||||||
|
$where = '';
|
||||||
|
switch ($label) {
|
||||||
|
|
||||||
|
case '1': //任务
|
||||||
|
$where = array('in', [1, 2, 3]);//
|
||||||
|
break;
|
||||||
|
case '2': //日志
|
||||||
|
$where = array('in', [4, 5]);//27项目导入
|
||||||
|
break;
|
||||||
|
case '3': //办公审批
|
||||||
|
$where = array('in', [6, 7, 8]);
|
||||||
|
break;
|
||||||
|
case '4': //公告
|
||||||
|
$where = array('eq', 9);
|
||||||
|
break;
|
||||||
|
case '5' : //日程
|
||||||
|
$where = 10;
|
||||||
|
break;
|
||||||
|
case '6' : //客户管理
|
||||||
|
$where = array('in', [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 16, 27, 28, 29, 30]);
|
||||||
|
break;
|
||||||
|
case '4' :
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$where = array('in', [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 16, 27, 28, 29, 30]);//17181920
|
||||||
|
}
|
||||||
|
return $where;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDataList($param)
|
||||||
|
{
|
||||||
|
$userId = $param['user_id'];
|
||||||
|
unset($param['user_id']);
|
||||||
|
//types 1表示已读 0表示未读
|
||||||
|
if (isset($param['is_read'])) {
|
||||||
|
$where['m.read_time'] = ['=', 0];
|
||||||
|
}
|
||||||
|
$where['m.to_user_id'] = $userId;
|
||||||
|
$where['m.is_delete'] = ['eq', 1];
|
||||||
|
$order = [
|
||||||
|
'm.send_time' => 'DESC',
|
||||||
|
];
|
||||||
|
$where['m.type'] = $this->label($param['label']);
|
||||||
|
if ($param['label'] == 4) {
|
||||||
|
$where['m.type'] = 9;
|
||||||
|
$list = db('admin_message')
|
||||||
|
->alias('m')
|
||||||
|
->join('__ADMIN_USER__ user', 'user.id=m.from_user_id', 'LEFT')
|
||||||
|
->where($where)
|
||||||
|
->field('m.*,user.realname as user_name')
|
||||||
|
->page($param['page'], $param['limit'])
|
||||||
|
->order($order)
|
||||||
|
->select();
|
||||||
|
$dataCount = db('admin_message')
|
||||||
|
->alias('m')
|
||||||
|
->join('__ADMIN_USER__ user', 'user.id=m.from_user_id', 'LEFT')
|
||||||
|
->where($where)->count();
|
||||||
|
} else {
|
||||||
|
$list = db('admin_message')
|
||||||
|
->alias('m')
|
||||||
|
->join('__ADMIN_USER__ user', 'user.id=m.from_user_id', 'LEFT')
|
||||||
|
->where($where)
|
||||||
|
->field('m.*,user.realname as user_name')
|
||||||
|
->page($param['page'], $param['limit'])
|
||||||
|
->order($order)
|
||||||
|
->select();
|
||||||
|
}
|
||||||
|
$dataCount = db('admin_message')
|
||||||
|
->alias('m')
|
||||||
|
->join('__ADMIN_USER__ user', 'user.id=m.from_user_id', 'LEFT')
|
||||||
|
->where($where)->count();
|
||||||
|
//1表示已读 0表示未读
|
||||||
|
foreach ($list as $k => $v) {
|
||||||
|
if ($v['read_time'] == 0) {
|
||||||
|
$list[$k]['is_read'] = 0;
|
||||||
|
} else {
|
||||||
|
$list[$k]['is_read'] = 1;
|
||||||
|
}
|
||||||
|
$list[$k]['create_time'] = date('Y-m-d H:i:s', $v['send_time']);
|
||||||
|
if ($v['type'] == 4) {
|
||||||
|
$content = db('admin_comment')
|
||||||
|
->where(
|
||||||
|
[ 'status' => 1,
|
||||||
|
'comment_id' => $v['action_id'],
|
||||||
|
'type' => ['like', '%' . $v['controller_name' . '%']],
|
||||||
|
'user_id' => $v['from_user_id']
|
||||||
|
])
|
||||||
|
->find();
|
||||||
|
if (!empty($content)) {
|
||||||
|
$list[$k]['content'] = $content['content'];
|
||||||
|
}
|
||||||
|
} elseif (in_array($v['type'], ['12', '15'])) {
|
||||||
|
$content = db('admin_examine_record')->where(['types_id' => $v['action_id'], 'types' => ['like', '%' . $v['controller_name' . '%']], 'check_user_id' => $v['from_user_id']])->field('content')->find();
|
||||||
|
if ($content['content']) {
|
||||||
|
$list[$k]['content'] = $content['content'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($v['type'] == 10) {
|
||||||
|
$item = db('oa_event_notice')->where('id', $v['action_id'])->find();
|
||||||
|
|
||||||
|
if ($item) {
|
||||||
|
$noticetype = $item['noticetype'];
|
||||||
|
if($item['noticetype'] == 1){
|
||||||
|
$advance_time =$v['advance_time'] - ($item['number'] * 60);
|
||||||
|
}elseif ($item['noticetype'] == 2){
|
||||||
|
$advance_time =$v['advance_time'] - ($item['number'] * 60 * 60);
|
||||||
|
}else{
|
||||||
|
$advance_time = $v['advance_time'] - ($item['number'] * 60 * 60 * 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
$time = time();
|
||||||
|
if ($time == $advance_time ||$time>$advance_time) {
|
||||||
|
$type['value']=$item['number'];
|
||||||
|
$type['type']=$item['noticetype'];
|
||||||
|
$list[$k]['content']= $type;
|
||||||
|
$list[$k]['action_id'] = $item['event_id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// p(222);
|
||||||
|
}
|
||||||
|
if (in_array($v['type'], ['17', '18', '19', '20', '27'])) {
|
||||||
|
$error_file_path = db('admin_import_record')->where('id', $v['action_id'])->find();
|
||||||
|
if($error_file_path['error_data_file_path']==''){
|
||||||
|
$list[$k]['title'] = '';
|
||||||
|
}
|
||||||
|
$list[$k]['error_file_path'] = $error_file_path['error_data_file_path'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data = [];
|
||||||
|
$data['page']['list'] = $list;
|
||||||
|
$data['page']['dataCount'] = $dataCount ?: 0;
|
||||||
|
if ($param['page'] != 1 && ($param['page'] * $param['limit']) >= $dataCount) {
|
||||||
|
$data['page']['firstPage'] = false;
|
||||||
|
$data['page']['lastPage'] = true;
|
||||||
|
} else if ($param['page'] != 1 && (int)($param['page'] * $param['limit']) < $dataCount) {
|
||||||
|
$data['page']['firstPage'] = false;
|
||||||
|
$data['page']['lastPage'] = false;
|
||||||
|
} else if ($param['page'] == 1) {
|
||||||
|
$data['page']['firstPage'] = true;
|
||||||
|
$data['page']['lastPage'] = false;
|
||||||
|
}
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改状态变为已读
|
||||||
|
* @param $param
|
||||||
|
* @return array
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function endMessage($param)
|
||||||
|
{
|
||||||
|
$where = [
|
||||||
|
'to_user_id' => $param['id'],
|
||||||
|
'message_id' => ['IN', (array)$param['message_id']],
|
||||||
|
'read_time' => 0,
|
||||||
|
];
|
||||||
|
$list = db('admin_message')
|
||||||
|
->where($where)
|
||||||
|
->update(['read_time' => time()]);
|
||||||
|
$data = [];
|
||||||
|
$data['list'] = $list;
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*
|
||||||
|
* @param $messageId
|
||||||
|
* @return array|int|string
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function delete($param)
|
||||||
|
{
|
||||||
|
$res = db('admin_message')->where(['message_id' => $param['message_id']])->find();
|
||||||
|
if ($res['to_user_id'] != $param['user_id']) {
|
||||||
|
return resultArray(['error' => '没有权限!']);
|
||||||
|
}
|
||||||
|
return db('admin_message')->where(['message_id' => $param['message_id']])->update(['is_delete' => 2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量更新
|
||||||
|
* @param $param
|
||||||
|
* @return array
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function readAllMessage($param)
|
||||||
|
{
|
||||||
|
|
||||||
|
$where = [
|
||||||
|
'to_user_id' => $param['user_id'],
|
||||||
|
'read_time' => 0
|
||||||
|
];
|
||||||
|
if ($param['label'] == 4) {
|
||||||
|
$list = db('admin_message')
|
||||||
|
->where('type', 9)
|
||||||
|
->where($where)
|
||||||
|
->update(['read_time' => time()]);
|
||||||
|
} else {
|
||||||
|
$where['type'] = $this->label($param['label']);
|
||||||
|
$list = db('admin_message')
|
||||||
|
->where($where)
|
||||||
|
->update(['read_time' => time()]);
|
||||||
|
}
|
||||||
|
$data = [];
|
||||||
|
$data['list'] = $list;
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除已读
|
||||||
|
* @param $param
|
||||||
|
* @return array
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function clear($param)
|
||||||
|
{
|
||||||
|
$where = [];
|
||||||
|
$where = [
|
||||||
|
'to_user_id' => $param['user_id'],
|
||||||
|
'is_delete' => 1,
|
||||||
|
'read_time' => ['neq', 0],
|
||||||
|
];
|
||||||
|
$where['type'] = $this->label($param['label']);
|
||||||
|
$list = db('admin_message')
|
||||||
|
->where($where)
|
||||||
|
->update(['is_delete' => 2]);
|
||||||
|
$data = [];
|
||||||
|
$data['list'] = $list;
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function unreadCount($param)
|
||||||
|
{
|
||||||
|
$userId = $param['user_id'];
|
||||||
|
//types 1表示已读 0表示未读
|
||||||
|
$where['read_time'] = ['=', 0];
|
||||||
|
$label = '';
|
||||||
|
$where['to_user_id'] = ['eq', $userId];
|
||||||
|
$where['is_delete'] = ['eq', 1];
|
||||||
|
|
||||||
|
$where['type'] = $this->label('');
|
||||||
|
$allCount = db('admin_message')->where($where)->count();
|
||||||
|
$where['type'] = $this->label(1);
|
||||||
|
$taskCount = db('admin_message')->where($where)->count();
|
||||||
|
$where['type'] = $this->label(2);
|
||||||
|
$logCount = db('admin_message')->where($where)->count();
|
||||||
|
$where['type'] = $this->label(3);
|
||||||
|
$jxcCount = db('admin_message')->where($where)->count();
|
||||||
|
$where['type'] = 9;
|
||||||
|
$announceCount = db('admin_message')->where($where)->count();
|
||||||
|
$where['type'] = $this->label(5);
|
||||||
|
$eventCount = db('admin_message')->where($where)->where('advance_time', '>=', time())->count();
|
||||||
|
$where['type'] = $this->label(6);
|
||||||
|
$crmCount = db('admin_message')->where($where)->count();
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
$data['allCount'] = $allCount ?: 0;
|
||||||
|
$data['taskCount'] = $taskCount ?: 0;
|
||||||
|
$data['logCount'] = $logCount ?: 0;
|
||||||
|
$data['examineCount'] = $jxcCount ?: 0;
|
||||||
|
$data['announceCount'] = $announceCount ?: 0;
|
||||||
|
$data['eventCount'] = $eventCount ?: 0;
|
||||||
|
$data['crmCount'] = $crmCount ?: 0;
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 项目管理逻辑类
|
||||||
|
*
|
||||||
|
* @author qifan
|
||||||
|
* @date 2020-12-17
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\admin\logic;
|
||||||
|
|
||||||
|
use think\Db;
|
||||||
|
|
||||||
|
class WorkLogic
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 规则列表
|
||||||
|
*
|
||||||
|
* @return bool|\PDOStatement|string|\think\Collection
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function getRules()
|
||||||
|
{
|
||||||
|
return Db::name('admin_rule')->field(['id', 'title', 'name'])->where(['types' => 3, 'level' => 4, 'status' => 0])->select();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色
|
||||||
|
*
|
||||||
|
* @return bool|\PDOStatement|string|\think\Collection
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function getRoles()
|
||||||
|
{
|
||||||
|
$data = Db::name('admin_group')->field(['id', 'title', 'rules', 'remark', 'system'])->where(['pid' => 5, 'types' => 7, 'status' => 1])->select();
|
||||||
|
|
||||||
|
foreach ($data AS $key => $value) {
|
||||||
|
$data[$key]['rules'] = explode(',', trim($value['rules'], ','));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建角色
|
||||||
|
*
|
||||||
|
* @param $param
|
||||||
|
* @return int|string
|
||||||
|
*/
|
||||||
|
public function saveRole($param)
|
||||||
|
{
|
||||||
|
# 设置参数
|
||||||
|
$param['pid'] = 5;
|
||||||
|
$param['status'] = 1;
|
||||||
|
$param['type'] = 0;
|
||||||
|
$param['types'] = 7;
|
||||||
|
$param['system'] = 0;
|
||||||
|
|
||||||
|
return Db::name('admin_group')->insert($param);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权限角色详情
|
||||||
|
*
|
||||||
|
* @param $id
|
||||||
|
* @return array|bool|\PDOStatement|string|\think\Model|null
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function readRole($id)
|
||||||
|
{
|
||||||
|
$data = Db::name('admin_group')->field(['id', 'title', 'rules', 'remark'])->where('id', $id)->find();
|
||||||
|
|
||||||
|
$data['rules'] = trim($data['rules'], ',');
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑权限角色
|
||||||
|
*
|
||||||
|
* @param $param
|
||||||
|
* @return int|string
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function updateRole($param)
|
||||||
|
{
|
||||||
|
return Db::name('admin_group')->update($param);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除权限角色
|
||||||
|
*
|
||||||
|
* @param $id
|
||||||
|
* @return array|bool[]
|
||||||
|
* @throws \think\Exception
|
||||||
|
* @throws \think\exception\PDOException
|
||||||
|
*/
|
||||||
|
public function deleteRole($id)
|
||||||
|
{
|
||||||
|
$system = Db::name('admin_group')->where('id', $id)->value('system');
|
||||||
|
|
||||||
|
if (!empty($system)) return ['status' => false, 'error' => '不允许删除系统默认角色!'];
|
||||||
|
|
||||||
|
if (!Db::name('admin_group')->where('id', $id)->delete()) return ['status' => false, 'error' => '操作失败!'];
|
||||||
|
|
||||||
|
return ['status' => true];
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 导入记录
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: ymob
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
class ImportRecord extends Common
|
||||||
|
{
|
||||||
|
protected $name = 'admin_import_record';
|
||||||
|
|
||||||
|
protected $autoWriteTimestamp = true;
|
||||||
|
protected $createTime = 'create_time';
|
||||||
|
protected $updateTime = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存记录
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @return void
|
||||||
|
* @author Ymob
|
||||||
|
* @datetime 2019-10-22 11:46:41
|
||||||
|
*/
|
||||||
|
public function createData($data)
|
||||||
|
{
|
||||||
|
$res = $this->save($data);
|
||||||
|
|
||||||
|
$message_type_list = [
|
||||||
|
'crm_customer' => Message::IMPORT_CUSTOMER,
|
||||||
|
'crm_contacts' => Message::IMPORT_CONTACTS,
|
||||||
|
'crm_leads' => Message::IMPORT_LEADS,
|
||||||
|
'crm_product' => Message::IMPORT_PRODUCT,
|
||||||
|
'task' => Message::IMPORT_TASK,
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($res) {
|
||||||
|
(new Message())->send(
|
||||||
|
$message_type_list[$data['type']],
|
||||||
|
[
|
||||||
|
'total' => $data['total'],
|
||||||
|
'error' => $data['error'],
|
||||||
|
'done' => $data['done'],
|
||||||
|
'success' => $data['done'] - $data['error'],
|
||||||
|
'cover' => $data['cover'],
|
||||||
|
'title' => $data['error'] > 0 ? '点击下载错误数据' : '',
|
||||||
|
'action_id' => $this->id,
|
||||||
|
],
|
||||||
|
User::userInfo('id'),
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 数据操作日志
|
||||||
|
*
|
||||||
|
* @author qifna
|
||||||
|
* @date 2020-12-29
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use think\Model;
|
||||||
|
|
||||||
|
class OperationLog extends Model
|
||||||
|
{
|
||||||
|
protected $name = 'admin_operation_log';
|
||||||
|
|
||||||
|
protected $pk = 'log_id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关联后台员工表姓名
|
||||||
|
*
|
||||||
|
* @return \think\model\relation\HasOne
|
||||||
|
*/
|
||||||
|
public function toAdminUser()
|
||||||
|
{
|
||||||
|
return $this->hasOne('User', 'id', 'user_id')->bind(['source_name' => 'realname']);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description:
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use app\admin\model\Common;
|
||||||
|
|
||||||
|
class Sync extends Common
|
||||||
|
{
|
||||||
|
public function syncData($param)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 系统基础
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use app\admin\model\Common;
|
||||||
|
use think\Db;
|
||||||
|
|
||||||
|
class System extends Common
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $name = 'admin_system';
|
||||||
|
|
||||||
|
//列表
|
||||||
|
public function getDataList()
|
||||||
|
{
|
||||||
|
$list = Db::name('AdminSystem')->select();
|
||||||
|
$temp = array();
|
||||||
|
foreach ($list as $key => $value) {
|
||||||
|
$temp[$value['name']] = $value['value'];
|
||||||
|
}
|
||||||
|
$temp['logo'] = !empty($temp['logo']) ? getFullPath($temp['logo']) : '';
|
||||||
|
return $temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
//新建
|
||||||
|
public function createData($param)
|
||||||
|
{
|
||||||
|
if( isset($param['name'])){
|
||||||
|
$data['name'] = 'name';
|
||||||
|
$data['value'] = $param['name'];
|
||||||
|
$data['description'] = '网站名称';
|
||||||
|
$this->where('id=1')->update($data);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 系统日志模型
|
||||||
|
*
|
||||||
|
* @author qifan
|
||||||
|
* @date 2020-11-30
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use think\Model;
|
||||||
|
|
||||||
|
class SystemLog extends Model
|
||||||
|
{
|
||||||
|
protected $name = 'admin_system_log';
|
||||||
|
|
||||||
|
protected $pk = 'log_id';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关联后台员工表姓名
|
||||||
|
*
|
||||||
|
* @return \think\model\relation\HasOne
|
||||||
|
*/
|
||||||
|
public function toAdminUser()
|
||||||
|
{
|
||||||
|
return $this->hasOne('User', 'id', 'user_id')->bind(['source_name' => 'realname']);
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,198 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 字段列表配置
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
namespace app\admin\model;
|
||||||
|
|
||||||
|
use think\Config;
|
||||||
|
use think\Db;
|
||||||
|
use think\Model;
|
||||||
|
|
||||||
|
class UserField extends Model
|
||||||
|
{
|
||||||
|
protected $name = 'admin_user_field';
|
||||||
|
protected $createTime = 'create_time';
|
||||||
|
protected $updateTime = 'update_time';
|
||||||
|
protected $autoWriteTimestamp = true;
|
||||||
|
|
||||||
|
protected $type = [
|
||||||
|
'datas' => 'array',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置配置信息
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param types 分类
|
||||||
|
* @param param 参数
|
||||||
|
* @param id 主键ID
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function updateConfig($types, $param, $id = '')
|
||||||
|
{
|
||||||
|
if (!is_array($param['value']) || ($param['hide_value'] && !is_array($param['hide_value']))) {
|
||||||
|
$this->error = '参数错误';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$data = [];
|
||||||
|
if ($id) {
|
||||||
|
$resInfo = $this->where(['id' => $id])->find();
|
||||||
|
} else {
|
||||||
|
$resInfo = $this->where(['types' => $types,'user_id' => $param['user_id']])->find();
|
||||||
|
}
|
||||||
|
if (!$resInfo) {
|
||||||
|
$data['types'] = $types;
|
||||||
|
$data['user_id'] = $param['user_id'];
|
||||||
|
}
|
||||||
|
//处理value
|
||||||
|
$valueData = [];
|
||||||
|
//展示列
|
||||||
|
if ($param['value']) {
|
||||||
|
foreach ($param['value'] as $k=>$v) {
|
||||||
|
$valueData[$v['field']]['width'] = $v['width'];
|
||||||
|
$valueData[$v['field']]['is_hide'] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//隐藏列
|
||||||
|
if ($param['hide_value']) {
|
||||||
|
foreach ($param['hide_value'] as $k=>$v) {
|
||||||
|
$valueData[$v['field']]['width'] = $v['width'];
|
||||||
|
$valueData[$v['field']]['is_hide'] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['datas'] = $valueData;
|
||||||
|
if ($resInfo) {
|
||||||
|
$data['id'] = $resInfo['id'];
|
||||||
|
$res = $this->update($data);
|
||||||
|
} else {
|
||||||
|
$res = $this->save($data);
|
||||||
|
}
|
||||||
|
if ($res == false) {
|
||||||
|
$this->error = '设置出错';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置信息详情
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param types 分类
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function getConfig($types, $user_id)
|
||||||
|
{
|
||||||
|
$data = $this->where(['types' => $types,'user_id' => $user_id])->value('datas');
|
||||||
|
return $data ? : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置列宽度
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param types 分类
|
||||||
|
* @param field 字段
|
||||||
|
* @param width 宽度
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function setColumnWidth($types, $field, $width, $user_id)
|
||||||
|
{
|
||||||
|
$info = db('admin_user_field')->where(['types' => $types,'user_id' => $user_id])->find();
|
||||||
|
if ($info) {
|
||||||
|
$datas = json_decode($info['datas'], true);
|
||||||
|
$datas[$field]['width'] = $width;
|
||||||
|
$datas = json_encode($datas);
|
||||||
|
$res = $this->where(['id' => $info['id']])->update(['datas' => $datas]);
|
||||||
|
} else {
|
||||||
|
$newTypes = $types;
|
||||||
|
if ($types == 'crm_customer_pool') $newTypes = 'crm_customer';
|
||||||
|
$fieldArr = db('admin_field')->where(['types' => ['in',['',$newTypes]]])->field('field,name')->order('types desc,order_id asc')->select();
|
||||||
|
$value = [];
|
||||||
|
foreach ($fieldArr as $k=>$v) {
|
||||||
|
$field_width = '';
|
||||||
|
if ($field == $v['field']) {
|
||||||
|
$field_width = $width;
|
||||||
|
}
|
||||||
|
$value[$v['field']]['width'] = $field_width;
|
||||||
|
$value[$v['field']]['is_hide'] = 0;
|
||||||
|
$value[$v['field']]['field'] = $v['field'];
|
||||||
|
}
|
||||||
|
$param['value'] = $value;
|
||||||
|
$param['hide_value'] = [];
|
||||||
|
$param['user_id'] = $user_id;
|
||||||
|
$res = $this->updateConfig($types, $param);
|
||||||
|
}
|
||||||
|
if (!$res) {
|
||||||
|
$this->error = '设置出错,请重试!';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 列表数据
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param types 分类
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function getDataList($types, $user_id)
|
||||||
|
{
|
||||||
|
$fieldArr = (new Field)->getFieldList($types);
|
||||||
|
$fieldList = [];
|
||||||
|
$field_list = [];
|
||||||
|
foreach ($fieldArr as $k=>$v) {
|
||||||
|
$fieldList[] = $v['field'];
|
||||||
|
$field_list[$v['field']]['name'] = $v['name'];
|
||||||
|
$fieldArr[$k]['width'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
//已设置字段
|
||||||
|
$value = $this->where(['types' => $types,'user_id' => $user_id])->value('datas');
|
||||||
|
$value = $value ? json_decode($value, true) : [];
|
||||||
|
|
||||||
|
$valueList = [];
|
||||||
|
$value_list = []; //显示列
|
||||||
|
|
||||||
|
$hideList = [];
|
||||||
|
$hide_list = []; //隐藏列
|
||||||
|
|
||||||
|
if ($value) {
|
||||||
|
$a = 0;
|
||||||
|
$b = 0;
|
||||||
|
foreach ($value as $k=>$v) {
|
||||||
|
if (empty($v['is_hide'])) {
|
||||||
|
$valueList[] = $k;
|
||||||
|
$value_list[$a]['field'] = $k;
|
||||||
|
$value_list[$a]['width'] = $v['width'];
|
||||||
|
$value_list[$a]['name'] = $field_list[$k]['name'];
|
||||||
|
$a++;
|
||||||
|
} else {
|
||||||
|
$hideList[] = $k;
|
||||||
|
$hide_list[$b]['field'] = $k;
|
||||||
|
$hide_list[$b]['width'] = $v['width'];
|
||||||
|
$hide_list[$b]['name'] = $field_list[$k]['name'];
|
||||||
|
$b++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$diffList = $valueList ? array_diff($fieldList, $valueList) : $fieldList;
|
||||||
|
//隐藏的列(新增的字段数据)
|
||||||
|
$hideList = $hideList ? array_diff($diffList,$hideList) : $diffList;
|
||||||
|
foreach ($hideList as $k=>$v) {
|
||||||
|
$hide_list[$b]['field'] = $v;
|
||||||
|
$hide_list[$b]['width'] = '';
|
||||||
|
$hide_list[$b]['name'] = $field_list[$v]['name'];
|
||||||
|
$b++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$value_list = array_values($fieldArr);
|
||||||
|
$hide_list = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
$data['value_list'] = $value_list ? : []; //展示列
|
||||||
|
$data['hide_list'] = $hide_list ? : []; //隐藏列
|
||||||
|
return $data ? : [];
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\validate;
|
||||||
|
use think\Validate;
|
||||||
|
/**
|
||||||
|
* 设置模型
|
||||||
|
*/
|
||||||
|
class AdminField extends Validate{
|
||||||
|
|
||||||
|
protected $rule = [
|
||||||
|
'field' => ['regex'=>'/^[a-z]([a-z]|_)+[a-z]$/i'],
|
||||||
|
'name' => 'require',
|
||||||
|
'types' => 'require',
|
||||||
|
'form_type' => 'require',
|
||||||
|
];
|
||||||
|
protected $message = [
|
||||||
|
'field.regex' => '字段名称格式不正确!',
|
||||||
|
'name.require' => '字段标识必须填写',
|
||||||
|
'types.require' => '分类必须填写',
|
||||||
|
'form_type.require' => '字段类型必须填写',
|
||||||
|
];
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\validate;
|
||||||
|
use think\Validate;
|
||||||
|
/**
|
||||||
|
* 设置模型
|
||||||
|
*/
|
||||||
|
class AdminGroup extends Validate{
|
||||||
|
|
||||||
|
protected $rule = [
|
||||||
|
'title' => 'require',
|
||||||
|
'types' => 'require',
|
||||||
|
];
|
||||||
|
protected $message = [
|
||||||
|
'title.require' => '角色名称必须填写',
|
||||||
|
'types.require' => '角色类型必须选择',
|
||||||
|
];
|
||||||
|
protected $scene = [
|
||||||
|
'edit' => ['id'],
|
||||||
|
];
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\validate;
|
||||||
|
use think\Validate;
|
||||||
|
/**
|
||||||
|
* 设置模型
|
||||||
|
*/
|
||||||
|
class AdminPost extends Validate{
|
||||||
|
|
||||||
|
protected $rule = [
|
||||||
|
'name' => 'require',
|
||||||
|
];
|
||||||
|
protected $message = [
|
||||||
|
'name.require' => '岗位名称必须填写',
|
||||||
|
];
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\validate;
|
||||||
|
use think\Validate;
|
||||||
|
/**
|
||||||
|
* 设置模型
|
||||||
|
*/
|
||||||
|
class AdminRecord extends Validate{
|
||||||
|
|
||||||
|
protected $rule = [
|
||||||
|
'category' => 'require',
|
||||||
|
'content' => 'require',
|
||||||
|
];
|
||||||
|
protected $message = [
|
||||||
|
'category.require' => '跟进类型必须填写',
|
||||||
|
'content.require' => '日志内容必须填写',
|
||||||
|
];
|
||||||
|
protected $scene = [
|
||||||
|
'edit' => [],
|
||||||
|
];
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\validate;
|
||||||
|
use think\Validate;
|
||||||
|
/**
|
||||||
|
* 设置模型
|
||||||
|
*/
|
||||||
|
class AdminRule extends Validate{
|
||||||
|
|
||||||
|
protected $rule = [
|
||||||
|
'title' => 'require',
|
||||||
|
'name' => 'require',
|
||||||
|
'level' => 'require'
|
||||||
|
];
|
||||||
|
protected $message = [
|
||||||
|
'title.require' => '标题必须填写',
|
||||||
|
'name.require' => '规则定义必须填写',
|
||||||
|
'level.require' => '级别类型必须填写',
|
||||||
|
];
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\validate;
|
||||||
|
use think\Validate;
|
||||||
|
/**
|
||||||
|
* 设置模型
|
||||||
|
*/
|
||||||
|
class AdminStructure extends Validate{
|
||||||
|
|
||||||
|
protected $rule = [
|
||||||
|
'name' => 'require',
|
||||||
|
];
|
||||||
|
protected $message = [
|
||||||
|
'name.require' => '部门名称必须填写',
|
||||||
|
];
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\validate;
|
||||||
|
use think\Validate;
|
||||||
|
/**
|
||||||
|
* 设置模型
|
||||||
|
*/
|
||||||
|
class AdminUser extends Validate{
|
||||||
|
|
||||||
|
protected $rule = array(
|
||||||
|
'realname' => 'require',
|
||||||
|
'username' => 'require|unique:admin_user|regex:^1[3456789][0-9]{9}?$',
|
||||||
|
'structure_id' => 'require',
|
||||||
|
'password' => 'require|regex:^(?![0-9]*$)[a-zA-Z0-9]{6,20}$',
|
||||||
|
);
|
||||||
|
protected $message = array(
|
||||||
|
'realname.require' => '姓名必须填写',
|
||||||
|
'username.require' => '手机号码必须填写',
|
||||||
|
'username.unique' => '手机号码已存在',
|
||||||
|
'username.regex' => '手机号码格式错误',
|
||||||
|
'password.require' => '密码必须填写',
|
||||||
|
'password.regex' => '密码由6-20位字母、数字组成',
|
||||||
|
'structure_id.require' => '请选择所属部门',
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,101 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||||||
|
<title>悟空CRM安装向导</title>
|
||||||
|
<link rel="shortcut icon" href="__STATIC__/icon/favicon.ico">
|
||||||
|
<link rel="stylesheet" href="__STATIC__/style/base.css">
|
||||||
|
<link rel="stylesheet" href="__STATIC__/style/step1.css">
|
||||||
|
<script src="__STATIC__/js/jquery-3.3.1.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="header-wrapper">
|
||||||
|
{include file="public/header"}
|
||||||
|
</div>
|
||||||
|
<div class="top">
|
||||||
|
<div class="step-group">
|
||||||
|
<div class="step active">
|
||||||
|
<div class="sort">1</div>
|
||||||
|
<div class="desc">检查安装环境</div>
|
||||||
|
</div>
|
||||||
|
<div class="step line"></div>
|
||||||
|
<div class="step">
|
||||||
|
<div class="sort">2</div>
|
||||||
|
<div class="desc">创建数据库</div>
|
||||||
|
</div>
|
||||||
|
<div class="step line"></div>
|
||||||
|
<div class="step">
|
||||||
|
<div class="sort">3</div>
|
||||||
|
<div class="desc">安装成功</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="container">
|
||||||
|
<div class="content">
|
||||||
|
<div class="base-top">
|
||||||
|
<span class="title">1 检查安装环境</span>
|
||||||
|
<span class="version">当前版本:{$data['version']['VERSION']} {$data['version']['RELEASE']}</span>
|
||||||
|
</div>
|
||||||
|
<div class="table">
|
||||||
|
<table class="table_01">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>检查项</th>
|
||||||
|
<th>当前环境</th>
|
||||||
|
<th>悟空CRM建议</th>
|
||||||
|
<th>当前状态</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{volist name="data['env']" id="row"}
|
||||||
|
<tr>
|
||||||
|
<td>{$row[0]}</td>
|
||||||
|
<td>{$row[1]}</td>
|
||||||
|
<td>{$row[2]}</td>
|
||||||
|
<td>
|
||||||
|
{if condition="$row['3'] == 'ok'"}
|
||||||
|
<img src="__STATIC__/icon/success.png" width="20">
|
||||||
|
{else /}
|
||||||
|
<img src="__STATIC__/icon/error.png" width="20">
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{/volist}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<table class="catalogue-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>目录文件</th>
|
||||||
|
<th>所需状态</th>
|
||||||
|
<th>当前状态</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<?php foreach($data['dir'] as $value){ ?>
|
||||||
|
<tr>
|
||||||
|
<td>{$value[1]}</td>
|
||||||
|
<td>{$value[3]}</td>
|
||||||
|
<?php if($value[5] =='ok') { ?>
|
||||||
|
<td><img src="__STATIC__/icon/success.png" width="20"></td>
|
||||||
|
<?php } else { ?>
|
||||||
|
<td><img src="__STATIC__/icon/error.png" width="20"></td>
|
||||||
|
<?php } ?>
|
||||||
|
</tr>
|
||||||
|
<?php } ?>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="control">
|
||||||
|
<div class="prev btn">上一步</div>
|
||||||
|
<div class="next btn primary">下一步</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="footer-wrapper">
|
||||||
|
{include file="public/footer"}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
<script src="__STATIC__/js/step1.js"></script>
|
||||||
|
</html>
|
@ -0,0 +1,97 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||||||
|
<title>悟空CRM安装向导</title>
|
||||||
|
<link rel="shortcut icon" href="__STATIC__/icon/favicon.ico">
|
||||||
|
<link rel="stylesheet" href="__STATIC__/style/base.css">
|
||||||
|
<link rel="stylesheet" href="__STATIC__/style/step2.css">
|
||||||
|
<script src="__STATIC__/js/jquery-3.3.1.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="header-wrapper">
|
||||||
|
{include file="public/header"}
|
||||||
|
</div>
|
||||||
|
<div class="top">
|
||||||
|
<div class="step-group">
|
||||||
|
<div class="step active">
|
||||||
|
<div class="sort">1</div>
|
||||||
|
<div class="desc">检查安装环境</div>
|
||||||
|
</div>
|
||||||
|
<div class="step active line"></div>
|
||||||
|
<div class="step active">
|
||||||
|
<div class="sort">2</div>
|
||||||
|
<div class="desc">创建数据库</div>
|
||||||
|
</div>
|
||||||
|
<div class="step line"></div>
|
||||||
|
<div class="step">
|
||||||
|
<div class="sort">3</div>
|
||||||
|
<div class="desc">安装成功</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="content">
|
||||||
|
<div class="base-top">
|
||||||
|
<span class="title">2 创建数据库</span>
|
||||||
|
<span class="version">当前版本:{$envir_data['version']['VERSION']} {$envir_data['version']['RELEASE']}</span>
|
||||||
|
</div>
|
||||||
|
<div class="form">
|
||||||
|
<div class="form-sec-title">请填写数据库信息</div>
|
||||||
|
<div class="form-item">
|
||||||
|
<div class="form-label">数据库主机:</div>
|
||||||
|
<input type="text" name="databaseUrl">
|
||||||
|
<!--<div class="error" style="display: none">数据库主机不能空</div>-->
|
||||||
|
<div class="remind">数据库地址一般为127.0.0.1</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-item">
|
||||||
|
<div class="form-label">数据库名:</div>
|
||||||
|
<input type="text" name="databaseName">
|
||||||
|
</div>
|
||||||
|
<div class="form-item">
|
||||||
|
<div class="form-label">端口:</div>
|
||||||
|
<input type="text" name="databasePort">
|
||||||
|
<div class="remind">一般为 3306</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-item">
|
||||||
|
<div class="form-label">数据库用户名:</div>
|
||||||
|
<input type="text" name="databaseUser">
|
||||||
|
<div class="remind">生产环境建议创建独立账号</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-item">
|
||||||
|
<div class="form-label">数据库密码:</div>
|
||||||
|
<input type="password" name="databasePwd">
|
||||||
|
</div>
|
||||||
|
<div class="form-item">
|
||||||
|
<div class="form-label">表前缀:</div>
|
||||||
|
<input type="text" name="databaseTable">
|
||||||
|
<div class="remind">默认为5kcrm_</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-sec-title">请填写管理员信息</div>
|
||||||
|
<div class="form-item">
|
||||||
|
<div class="form-label">管理员账号:</div>
|
||||||
|
<input type="text" name="root" placeholder="请输入手机号码">
|
||||||
|
</div>
|
||||||
|
<div class="form-item">
|
||||||
|
<div class="form-label">管理员密码:</div>
|
||||||
|
<input type="password" name="pwd">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="install_progress_a">
|
||||||
|
<!-- <progress class="install_progress" max="97" value="8"></progress> -->
|
||||||
|
</div>
|
||||||
|
<div class="control">
|
||||||
|
<div class="prev btn">上一步</div>
|
||||||
|
<div class="next btn primary">下一步</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="footer-wrapper">
|
||||||
|
{include file="public/footer"}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
<!-- <script src="__STATIC__/js/base.js"></script> -->
|
||||||
|
<script src="__STATIC__/js/step2.js"></script>
|
||||||
|
</html>
|
@ -0,0 +1,55 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
|
||||||
|
<title>悟空CRM安装向导</title>
|
||||||
|
<link rel="shortcut icon" href="__STATIC__/icon/favicon.ico">
|
||||||
|
<link rel="stylesheet" href="__STATIC__/style/base.css">
|
||||||
|
<link rel="stylesheet" href="__STATIC__/style/step3.css">
|
||||||
|
<script src="__STATIC__/js/jquery-3.3.1.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="header-wrapper">
|
||||||
|
{include file="public/header"}
|
||||||
|
</div>
|
||||||
|
<div class="top">
|
||||||
|
<div class="step-group">
|
||||||
|
<div class="step active">
|
||||||
|
<div class="sort">1</div>
|
||||||
|
<div class="desc">检查安装环境</div>
|
||||||
|
</div>
|
||||||
|
<div class="step active line"></div>
|
||||||
|
<div class="step active">
|
||||||
|
<div class="sort">2</div>
|
||||||
|
<div class="desc">创建数据库</div>
|
||||||
|
</div>
|
||||||
|
<div class="step line active"></div>
|
||||||
|
<div class="step">
|
||||||
|
<div class="sort">3</div>
|
||||||
|
<div class="desc">安装成功</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="container">
|
||||||
|
<div class="result">
|
||||||
|
<div class="status-box">
|
||||||
|
<img class="pic" src="__STATIC__/icon/error.png" alt="">
|
||||||
|
<span class="status">安装失败</span>
|
||||||
|
</div>
|
||||||
|
<div class="desc">未按照正确的方式进行安装</div>
|
||||||
|
<div class="control">
|
||||||
|
<div class="prev btn primary">返回上一步</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="footer-wrapper">
|
||||||
|
{include file="public/footer"}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
$('.prev').click(function () {
|
||||||
|
window.location = 'step2.html'
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
</html>
|
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
//权限控制
|
||||||
|
\think\Hook::add('check_auth','app\\common\\behavior\\AuthenticateBehavior');
|
||||||
|
|
||||||
|
use think\Db;
|
||||||
|
|
||||||
|
//获取一年中每个月开始结束时间
|
||||||
|
function getMonthStart($year)
|
||||||
|
{
|
||||||
|
$i = 1;
|
||||||
|
for($i=1;$i<13;$i++) {
|
||||||
|
$time = $year.'-'.$i.'-01';
|
||||||
|
$data[$i]= strtotime($time);
|
||||||
|
}
|
||||||
|
$newyear = $year+1;
|
||||||
|
$data[13] = strtotime($newyear.'-01-01');
|
||||||
|
return $data;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
// 基础模块配置文件
|
||||||
|
|
||||||
|
return [
|
||||||
|
//'配置项'=>'配置值'
|
||||||
|
'LANG_SWITCH_ON' => true, //开启语言包功能
|
||||||
|
'LANG_AUTO_DETECT' => true, // 自动侦测语言
|
||||||
|
'DEFAULT_LANG' => 'zh-cn', // 默认语言
|
||||||
|
'LANG_LIST' => 'en-us,zh-cn,zh-tw', //必须写可允许的语言列表
|
||||||
|
'VAR_LANGUAGE' => 'l', // 默认语言切换变量
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,287 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 商业智能-商机分析
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\bi\controller;
|
||||||
|
|
||||||
|
use app\admin\controller\ApiCommon;
|
||||||
|
use app\bi\traits\SortTrait;
|
||||||
|
use think\Db;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class Business extends ApiCommon
|
||||||
|
{
|
||||||
|
use SortTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission'=>[''],
|
||||||
|
'allow'=>[
|
||||||
|
'funnel',
|
||||||
|
'businesstrend',
|
||||||
|
'trendlist',
|
||||||
|
'win',
|
||||||
|
'winlist'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
if (!checkPerByAction('bi', 'business' , 'read')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 销售漏斗
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function funnel()
|
||||||
|
{
|
||||||
|
if (empty($this->param['type_id'])) return resultArray(['error' => '请选择商机组!']);
|
||||||
|
|
||||||
|
$businessModel = new \app\crm\model\Business();
|
||||||
|
|
||||||
|
$param = $this->param;
|
||||||
|
|
||||||
|
$sortField = !empty($param['sort_field']) ? $param['sort_field'] : '';
|
||||||
|
$sortValue = !empty($param['sort_value']) ? $param['sort_value'] : '';
|
||||||
|
unset($param['sort_field']);
|
||||||
|
unset($param['sort_value']);
|
||||||
|
|
||||||
|
if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00');
|
||||||
|
if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59');
|
||||||
|
|
||||||
|
$data = $businessModel->getFunnel($param);
|
||||||
|
foreach ($data['list'] AS $key => $value) {
|
||||||
|
if (empty($value['money']) && empty($value['count'])) unset($data['list'][(int)$key]);
|
||||||
|
}
|
||||||
|
if (empty($data['total']['money_count']) && empty($data['total']['count'])) return resultArray(['data' => ['list' => []]]);
|
||||||
|
|
||||||
|
$data['list'] = array_values($data['list']);
|
||||||
|
|
||||||
|
# 排序
|
||||||
|
if (!empty($data['list'])) $data['list'] = $this->sortCommon($data['list'], $sortField, $sortValue);
|
||||||
|
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增商机数与金额趋势分析
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function businessTrend()
|
||||||
|
{
|
||||||
|
$businessModel = new \app\crm\model\Business();
|
||||||
|
$userModel = new \app\admin\model\User();
|
||||||
|
$adminModel = new \app\admin\model\Admin();
|
||||||
|
$param = $this->param;
|
||||||
|
|
||||||
|
$perUserIds = $userModel->getUserByPer('bi', 'business', 'read'); //权限范围内userIds
|
||||||
|
$whereArr = $adminModel->getWhere($param, '', $perUserIds); //统计条件
|
||||||
|
$userIds = $whereArr['userIds'];
|
||||||
|
|
||||||
|
if(empty($param['type']) && empty($param['start_time'])){
|
||||||
|
$param['type'] = 'month';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00');
|
||||||
|
if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59');
|
||||||
|
$time = getTimeArray($param['start_time'], $param['end_time']);
|
||||||
|
$where = [
|
||||||
|
'owner_user_id' => !empty($userIds) ? implode(',',$userIds) : '9999999999'
|
||||||
|
];
|
||||||
|
$sql = [];
|
||||||
|
|
||||||
|
foreach ($time['list'] as $val) {
|
||||||
|
$whereArr = $where;
|
||||||
|
$whereArr['type'] = $val['type'];
|
||||||
|
$whereArr['start_time'] = $val['start_time'];
|
||||||
|
$whereArr['end_time'] = $val['end_time'];
|
||||||
|
$sql[] = $businessModel->getTrendql($whereArr);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql = implode(' UNION ALL ', $sql);
|
||||||
|
$list = queryCache($sql);
|
||||||
|
return resultArray(['data' => $list]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增商机数与金额趋势分析 列表
|
||||||
|
*
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function trendList()
|
||||||
|
{
|
||||||
|
$businessModel = new \app\bi\model\Business();
|
||||||
|
$crmBusinessModel = new \app\crm\model\Business();
|
||||||
|
$userModel = new \app\admin\model\User();
|
||||||
|
$param = $this->param;
|
||||||
|
unset($param['types']);
|
||||||
|
|
||||||
|
# 日期条件
|
||||||
|
if (!empty($param['type'])) {
|
||||||
|
$param['start_time'] = strtotime($param['type'] . '-01 00:00:00');
|
||||||
|
$endMonth = strtotime(date('Y-m-d', $param['start_time']) . " +1 month -1 day");
|
||||||
|
$param['end_time'] = strtotime(date('Y-m-d 23:59:59', $endMonth));
|
||||||
|
unset($param['type']);
|
||||||
|
} else {
|
||||||
|
if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00');
|
||||||
|
if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59');
|
||||||
|
}
|
||||||
|
|
||||||
|
# 排序参数
|
||||||
|
$sortField = !empty($param['sort_field']) ? $param['sort_field'] : '';
|
||||||
|
$sortValue = !empty($param['sort_value']) ? $param['sort_value'] : '';
|
||||||
|
|
||||||
|
$dataList = $businessModel->getDataList($param);
|
||||||
|
foreach ($dataList['list'] as $k => $v) {
|
||||||
|
$business_info = $crmBusinessModel->getDataById($v['business_id']);
|
||||||
|
$dataList['list'][$k]['business_name'] = $business_info['name'];
|
||||||
|
$dataList['list'][$k]['create_time'] = date('Y-m-d',strtotime($business_info['create_time']));
|
||||||
|
$dataList['list'][$k]['customer_id'] = $v['customer_id'];
|
||||||
|
$customer = db('crm_customer')->field('name')->where('customer_id',$v['customer_id'])->find();
|
||||||
|
$dataList['list'][$k]['customer_name'] = $customer['name'];
|
||||||
|
$create_user_id_info = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
|
||||||
|
$dataList['list'][$k]['create_user_name'] = $create_user_id_info['realname'];
|
||||||
|
$owner_user_id_info = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
|
||||||
|
$dataList['list'][$k]['owner_user_name'] = $owner_user_id_info['realname'];
|
||||||
|
$dataList['list'][$k]['business_stage'] = db('crm_business_status')->where('status_id',$v['status_id'])->value('name');//销售阶段
|
||||||
|
$dataList['list'][$k]['business_type'] = db('crm_business_type')->where('type_id',$v['type_id'])->value('name');//商机状态组
|
||||||
|
}
|
||||||
|
|
||||||
|
# 排序
|
||||||
|
if (!empty($dataList)) $dataList = $this->sortCommon($dataList, $sortField, $sortValue);
|
||||||
|
|
||||||
|
return resultArray(['data' => $dataList]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 赢单机会转化率趋势分析
|
||||||
|
*
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function win()
|
||||||
|
{
|
||||||
|
$businessModel = new \app\crm\model\Business();
|
||||||
|
$userModel = new \app\admin\model\User();
|
||||||
|
$adminModel = new \app\admin\model\Admin();
|
||||||
|
$param = $this->param;
|
||||||
|
|
||||||
|
$perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); //权限范围内userIds
|
||||||
|
$whereArr = $adminModel->getWhere($param, '', $perUserIds); //统计条件
|
||||||
|
$userIds = $whereArr['userIds'];
|
||||||
|
|
||||||
|
if(empty($param['type']) && empty($param['start_time'])){
|
||||||
|
$param['type'] = 'month';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00');
|
||||||
|
if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59');
|
||||||
|
$time = getTimeArray($param['start_time'], $param['end_time']);
|
||||||
|
$sql = db('crm_business')->alias('business')->field([
|
||||||
|
"FROM_UNIXTIME(business.create_time, '{$time['time_format']}')" => 'type',
|
||||||
|
'COUNT(business.business_id)' => 'business_num',
|
||||||
|
'SUM(
|
||||||
|
CASE WHEN
|
||||||
|
`check_status` = 2
|
||||||
|
THEN 1 ELSE 0 END
|
||||||
|
)' => 'business_end'
|
||||||
|
])->join('__CRM_CONTRACT__ contract', 'contract.business_id = business.business_id', 'left')
|
||||||
|
->where([
|
||||||
|
'business.owner_user_id' => ['IN', $userIds],
|
||||||
|
'business.create_time' => ['BETWEEN', $time['between']]
|
||||||
|
])
|
||||||
|
->group('type')
|
||||||
|
->fetchSql()
|
||||||
|
->select();
|
||||||
|
$res = queryCache($sql);
|
||||||
|
$res = array_column($res, null, 'type');
|
||||||
|
foreach ($time['list'] as $key =>$val) {
|
||||||
|
$val['business_num'] = (int) $res[$val['type']]['business_num'];
|
||||||
|
$val['business_end'] = (int) $res[$val['type']]['business_end'];
|
||||||
|
if($res[$val['type']]['business_num']== 0 || $res[$val['type']]['business_end'] == 0){
|
||||||
|
$val['proportion'] = 0;
|
||||||
|
}else{
|
||||||
|
$val['proportion'] = round(($res[$val['type']]['business_end']/$res[$val['type']]['business_num']),4)*100;
|
||||||
|
}
|
||||||
|
$time['list'][$key] = $val;
|
||||||
|
}
|
||||||
|
return resultArray(['data' => $time['list']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商机转化率分析 列表
|
||||||
|
*
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function winList()
|
||||||
|
{
|
||||||
|
$businessModel = new \app\bi\model\Business();
|
||||||
|
$crmBusinessModel = new \app\crm\model\Business();
|
||||||
|
$userModel = new \app\admin\model\User();
|
||||||
|
$param = $this->param;
|
||||||
|
|
||||||
|
# 日期条件
|
||||||
|
if (!empty($param['date'])) {
|
||||||
|
$param['start_time'] = strtotime($param['date'] . '-01 00:00:00');
|
||||||
|
$endMonth = strtotime(date('Y-m-d', $param['start_time']) . " +1 month -1 day");
|
||||||
|
$param['end_time'] = strtotime(date('Y-m-d 23:59:59', $endMonth)) ;
|
||||||
|
unset($param['type']);
|
||||||
|
}
|
||||||
|
|
||||||
|
# 排序参数
|
||||||
|
$sortField = !empty($param['sort_field']) ? $param['sort_field'] : '';
|
||||||
|
$sortValue = !empty($param['sort_value']) ? $param['sort_value'] : '';
|
||||||
|
|
||||||
|
# 赢单条件
|
||||||
|
$param['is_end'] = 1;
|
||||||
|
|
||||||
|
$dataList = $businessModel->getDataList($param);
|
||||||
|
foreach ($dataList as $k => $v) {
|
||||||
|
$business_info = $crmBusinessModel->getDataById($v['business_id']);
|
||||||
|
$dataList[$k]['business_name'] = $business_info['name'];
|
||||||
|
$dataList[$k]['create_time'] = date('Y-m-d',strtotime($business_info['create_time']));
|
||||||
|
$dataList[$k]['customer_id'] = $v['customer_id'];
|
||||||
|
$customer = db('crm_customer')->field('name')->where('customer_id',$v['customer_id'])->find();
|
||||||
|
$dataList[$k]['customer_name'] = $customer['name'];
|
||||||
|
$create_user_id_info = isset($v['create_user_id']) ? $userModel->getUserById($v['create_user_id']) : [];
|
||||||
|
$dataList[$k]['create_user_name'] = $create_user_id_info['realname'];
|
||||||
|
$owner_user_id_info = isset($v['owner_user_id']) ? $userModel->getUserById($v['owner_user_id']) : [];
|
||||||
|
$dataList[$k]['owner_user_name'] = $owner_user_id_info['realname'];
|
||||||
|
$dataList[$k]['business_stage'] = db('crm_business_status')->where('status_id',$v['status_id'])->value('name');//销售阶段
|
||||||
|
$dataList[$k]['business_type'] = db('crm_business_type')->where('type_id',$v['type_id'])->value('name');//商机状态组
|
||||||
|
}
|
||||||
|
|
||||||
|
# 排序
|
||||||
|
if (!empty($dataList)) $dataList = $this->sortCommon($dataList, $sortField, $sortValue);
|
||||||
|
|
||||||
|
return resultArray(['data' => $dataList]);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,359 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 商业智能-员工业绩分析
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\bi\controller;
|
||||||
|
|
||||||
|
use app\admin\controller\ApiCommon;
|
||||||
|
use app\bi\traits\SortTrait;
|
||||||
|
use app\crm\model\Contract as ContractModel;
|
||||||
|
use app\crm\model\Receivables as ReceivablesModel;
|
||||||
|
use think\Db;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
use app\bi\logic\ExcelLogic;
|
||||||
|
class Contract extends ApiCommon
|
||||||
|
{
|
||||||
|
use SortTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission' => [''],
|
||||||
|
'allow' => [
|
||||||
|
'analysis',
|
||||||
|
'summary',
|
||||||
|
'invoice',
|
||||||
|
'excelexport'
|
||||||
|
]
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth', $action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
if (!checkPerByAction('bi', 'contract', 'read')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code' => 102, 'error' => '无权操作']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 合同数量分析/金额分析/回款金额分析
|
||||||
|
*
|
||||||
|
* @param string $param
|
||||||
|
* @return array|\think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function analysis($param='')
|
||||||
|
{
|
||||||
|
$userModel = new \app\admin\model\User();
|
||||||
|
$adminModel = new \app\admin\model\Admin();
|
||||||
|
if ($param['excel_type'] != 1) {
|
||||||
|
$param = $this->param;
|
||||||
|
}
|
||||||
|
|
||||||
|
$perUserIds = $userModel->getUserByPer('bi', 'contract', 'read'); // 权限范围内userIds
|
||||||
|
$whereArr = $adminModel->getWhere($param, '', $perUserIds); // 统计条件
|
||||||
|
$userIds = $whereArr['userIds'];
|
||||||
|
|
||||||
|
$year = !empty($param['year']) ? $param['year'] : date('Y');
|
||||||
|
$start_time = strtotime(date(($year - 1) . '-01-01'));
|
||||||
|
$end_time = strtotime('+2 year', $start_time) - 1;
|
||||||
|
$time = getTimeArray($start_time, $end_time);
|
||||||
|
|
||||||
|
if ($param['type'] == 'back' || $param['excel_type'] == 'back') {
|
||||||
|
$model = new ReceivablesModel;
|
||||||
|
$time_field = 'return_time';
|
||||||
|
} else {
|
||||||
|
$model = new ContractModel;
|
||||||
|
$time_field = 'order_date';
|
||||||
|
}
|
||||||
|
if ($param['type'] == 'count' || $param['$excel_type'] == 'count') {
|
||||||
|
$field['COUNT(*)'] = 'total';
|
||||||
|
} else {
|
||||||
|
$field['SUM(`money`)'] = 'total';
|
||||||
|
}
|
||||||
|
$between_time = [date('Y-m-d', $time['between'][0]), date('Y-m-d', $time['between'][1])];
|
||||||
|
$field["SUBSTR(`{$time_field}`, 1, 7)"] = 'type';
|
||||||
|
$sql = $model->field($field)
|
||||||
|
->where([
|
||||||
|
'owner_user_id' => ['IN', $userIds],
|
||||||
|
'check_status' => 2,
|
||||||
|
$time_field => ['BETWEEN', $between_time]
|
||||||
|
])
|
||||||
|
->group('type')
|
||||||
|
->fetchSql()
|
||||||
|
->select();
|
||||||
|
$res = queryCache($sql);
|
||||||
|
$res = array_column($res, null, 'type');
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
for ($i = 12; $i < 24; $i++) {
|
||||||
|
$k = $time['list'][$i]['type'];
|
||||||
|
$k2 = $time['list'][$i - 1]['type'];
|
||||||
|
$k3 = $time['list'][$i - 12]['type'];
|
||||||
|
$item['month'] = ($i - 11) < 10 ? $param['year']. '0' . $i - 11 : $param['year'] . $i - 11;
|
||||||
|
|
||||||
|
$item['thisMonth'] = $res[$k] ? $res[$k]['total'] : 0; # 本月
|
||||||
|
$item['lastMonthGrowth'] = $res[$k2] ? $res[$k2]['total'] : 0; # 上月
|
||||||
|
$item['lastYearGrowth'] = $res[$k3] ? $res[$k3]['total'] : 0; # 上年本月
|
||||||
|
|
||||||
|
# 环比
|
||||||
|
$item['chain_ratio'] = $item['thisMonth'] && $item['lastMonthGrowth'] ? round(($item['thisMonth'] / $item['lastMonthGrowth']) * 100, 4) : 0;
|
||||||
|
# 同比
|
||||||
|
$item['year_on_year'] = $item['thisMonth'] && $item['lastYearGrowth'] ? round(($item['thisMonth'] / $item['lastYearGrowth']) * 100, 4) : 0;
|
||||||
|
|
||||||
|
$data[] = $item;
|
||||||
|
}
|
||||||
|
//导出使用
|
||||||
|
if (!empty($param['excel_type'])) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 合同汇总表
|
||||||
|
*
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function summary($param='')
|
||||||
|
{
|
||||||
|
$userModel = new \app\admin\model\User();
|
||||||
|
$adminModel = new \app\admin\model\Admin();
|
||||||
|
if($param['excel_type']!=1){
|
||||||
|
$param = $this->param;
|
||||||
|
}
|
||||||
|
|
||||||
|
$perUserIds = $userModel->getUserByPer('bi', 'contract', 'read'); //权限范围内userIds
|
||||||
|
$whereArr = $adminModel->getWhere($param, '', $perUserIds); //统计条件
|
||||||
|
$userIds = $whereArr['userIds'];
|
||||||
|
|
||||||
|
if (empty($param['type']) && empty($param['start_time'])) {
|
||||||
|
$param['type'] = 'month';
|
||||||
|
}
|
||||||
|
|
||||||
|
$sortField = !empty($param['sort_field']) ? $param['sort_field'] : '';
|
||||||
|
$sortValue = !empty($param['sort_value']) ? $param['sort_value'] : '';
|
||||||
|
unset($param['sort_field']);
|
||||||
|
unset($param['sort_value']);
|
||||||
|
|
||||||
|
$year = !empty($param['year']) ? $param['year'] : date('Y');
|
||||||
|
$start_time = strtotime($year . '-01-01');
|
||||||
|
$end_time = strtotime('+1 year', $start_time) - 1;
|
||||||
|
$time = getTimeArray($start_time, $end_time);
|
||||||
|
$ax = 7;
|
||||||
|
if ($time['time_format'] == '%Y-%m-%d') {
|
||||||
|
$ax = 10;
|
||||||
|
}
|
||||||
|
$between_time = [date('Y-m-d', $time['between'][0]), date('Y-m-d', $time['between'][1])];
|
||||||
|
$sql = ContractModel::field([
|
||||||
|
'SUBSTR(`order_date`, 1, ' . $ax . ')' => 'type',
|
||||||
|
'COUNT(*)' => 'count',
|
||||||
|
'SUM(`money`)' => 'money'
|
||||||
|
])
|
||||||
|
->where([
|
||||||
|
'owner_user_id' => ['IN', $userIds],
|
||||||
|
'check_status' => 2,
|
||||||
|
'order_date' => ['BETWEEN', $between_time]
|
||||||
|
])
|
||||||
|
->group('type')
|
||||||
|
->fetchSql()
|
||||||
|
->select();
|
||||||
|
$contract_data = queryCache($sql);
|
||||||
|
$contract_data = array_column($contract_data, null, 'type');
|
||||||
|
$sql = ReceivablesModel::field([
|
||||||
|
'SUBSTR(`return_time`, 1, ' . $ax . ')' => 'type',
|
||||||
|
'SUM(`money`)' => 'money'
|
||||||
|
])
|
||||||
|
->where([
|
||||||
|
'owner_user_id' => ['IN', $userIds],
|
||||||
|
'check_status' => 2,
|
||||||
|
'return_time' => ['BETWEEN', $between_time]
|
||||||
|
])
|
||||||
|
->group('type')
|
||||||
|
->fetchSql()
|
||||||
|
->select();
|
||||||
|
$receivables_data = queryCache($sql);
|
||||||
|
$receivables_data = array_column($receivables_data, null, 'type');
|
||||||
|
|
||||||
|
$items = [];
|
||||||
|
$count_zong = 0;
|
||||||
|
$money_zong = 0;
|
||||||
|
$back_zong = 0;
|
||||||
|
foreach ($time['list'] as $val) {
|
||||||
|
$item = ['type' => $val['type']];
|
||||||
|
$count_zong += $item['count'] = $contract_data[$val['type']]['count'] ?: 0;
|
||||||
|
$money_zong += $item['money'] = $contract_data[$val['type']]['money'] ?: 0;
|
||||||
|
$back_zong += $item['back'] = $receivables_data[$val['type']]['money'] ?: 0;
|
||||||
|
$items[] = $item;
|
||||||
|
}
|
||||||
|
$data = [
|
||||||
|
'list' => $items,
|
||||||
|
'count_zong' => $count_zong,
|
||||||
|
'money_zong' => $money_zong,
|
||||||
|
'back_zong' => $back_zong,
|
||||||
|
'w_back_zong' => $money_zong - $back_zong,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($data['list'])) $data['list'] = $this->sortCommon($data['list'], $sortField, $sortValue);
|
||||||
|
//导出使用
|
||||||
|
if (!empty($param['excel_type'])) return $data;
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发票统计分析
|
||||||
|
*
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function invoice($param='')
|
||||||
|
{
|
||||||
|
$userModel = new \app\admin\model\User();
|
||||||
|
$adminModel = new \app\admin\model\Admin();
|
||||||
|
if($param['excel_type']!=1){
|
||||||
|
$param = $this->param;
|
||||||
|
}
|
||||||
|
|
||||||
|
$perUserIds = $userModel->getUserByPer('bi', 'contract', 'read'); //权限范围内userIds
|
||||||
|
$whereArr = $adminModel->getWhere($param, '', $perUserIds); //统计条件
|
||||||
|
$userIds = $whereArr['userIds'];
|
||||||
|
if (empty($param['type']) && empty($param['start_time'])) {
|
||||||
|
$param['type'] = 'month';
|
||||||
|
}
|
||||||
|
|
||||||
|
$sortField = !empty($param['sort_field']) ? $param['sort_field'] : '';
|
||||||
|
$sortValue = !empty($param['sort_value']) ? $param['sort_value'] : '';
|
||||||
|
unset($param['sort_field']);
|
||||||
|
unset($param['sort_value']);
|
||||||
|
|
||||||
|
$time = getTimeArray();
|
||||||
|
$ax = 7;
|
||||||
|
if ($time['time_format'] == '%Y-%m-%d') {
|
||||||
|
$ax = 10;
|
||||||
|
}
|
||||||
|
$between_time = [date('Y-m-d', $time['between'][0]), date('Y-m-d', $time['between'][1])];
|
||||||
|
$sql = Db::name('crm_invoice')->field([
|
||||||
|
'SUBSTR(`invoice_date`, 1, ' . $ax . ')' => 'type',
|
||||||
|
'SUM(`invoice_money`)' => 'money'
|
||||||
|
])
|
||||||
|
->where([
|
||||||
|
'owner_user_id' => ['IN', $userIds],
|
||||||
|
'check_status' => 2,
|
||||||
|
'invoice_status' => 1,
|
||||||
|
'invoice_date' => ['BETWEEN', $between_time]
|
||||||
|
])
|
||||||
|
->group('type')
|
||||||
|
->fetchSql()
|
||||||
|
->select();
|
||||||
|
$invoice_data = queryCache($sql);
|
||||||
|
$invoice_data = array_column($invoice_data, null, 'type');
|
||||||
|
|
||||||
|
$sql = ReceivablesModel::field([
|
||||||
|
'SUBSTR(`return_time`, 1, ' . $ax . ')' => 'type',
|
||||||
|
'SUM(`money`)' => 'money'
|
||||||
|
])
|
||||||
|
->where([
|
||||||
|
'owner_user_id' => ['IN', $userIds],
|
||||||
|
'check_status' => 2,
|
||||||
|
'return_time' => ['BETWEEN', $between_time]
|
||||||
|
])
|
||||||
|
->group('type')
|
||||||
|
->fetchSql()
|
||||||
|
->select();
|
||||||
|
$receivables_data = queryCache($sql);
|
||||||
|
$receivables_data = array_column($receivables_data, null, 'type');
|
||||||
|
|
||||||
|
$items = [];
|
||||||
|
$invoiceCount = 0;
|
||||||
|
$receivablesCount = 0;
|
||||||
|
foreach ($time['list'] as $val) {
|
||||||
|
$receivablesModel = !empty($receivables_data[$val['type']]['money']) ? $receivables_data[$val['type']]['money'] : 0;
|
||||||
|
$invoiceModel = !empty($invoice_data[$val['type']]['money']) ? $invoice_data[$val['type']]['money'] : 0;
|
||||||
|
|
||||||
|
$items[] = [
|
||||||
|
'type' => $val['type'],
|
||||||
|
'receivables_money' => $receivablesModel,
|
||||||
|
'invoice_money' => $invoiceModel,
|
||||||
|
'not_invoice' => $receivablesModel - $invoiceModel > 0 ? $receivablesModel - $invoiceModel : 0,
|
||||||
|
'not_receivables' => $invoiceModel - $receivablesModel > 0 ? $invoiceModel - $receivablesModel : 0
|
||||||
|
];
|
||||||
|
|
||||||
|
$invoiceCount += $invoiceModel;
|
||||||
|
$receivablesCount += $receivablesModel;
|
||||||
|
|
||||||
|
}
|
||||||
|
$data = [
|
||||||
|
'list' => $items,
|
||||||
|
'receivables_count' => $receivablesCount,
|
||||||
|
'invoice_count' => $invoiceCount
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!empty($data['list'])) $data['list'] = $this->sortCommon($data['list'], $sortField, $sortValue);
|
||||||
|
//导出使用
|
||||||
|
if (!empty($param['excel_type'])) return $data;
|
||||||
|
return resultArray(['data' => $data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出
|
||||||
|
* @param $type
|
||||||
|
* @param $types
|
||||||
|
*/
|
||||||
|
public function excelExport()
|
||||||
|
{
|
||||||
|
|
||||||
|
$param = $this->param;
|
||||||
|
$excel_type = $param['excel_type'];
|
||||||
|
$type=[];
|
||||||
|
$type['excel_types']=$param['excel_types'];
|
||||||
|
|
||||||
|
switch ($param['excel_types']) {
|
||||||
|
case 'analysis':
|
||||||
|
if ($param['type'] == 'count') {
|
||||||
|
$type['type'] = '合同数量分析';
|
||||||
|
|
||||||
|
} elseif ($param['type'] == 'back') {
|
||||||
|
$type['type'] = '回款金额分析';
|
||||||
|
} else {
|
||||||
|
$type['type'] = '金额分析';
|
||||||
|
}
|
||||||
|
$list = $this->analysis($param);
|
||||||
|
break;
|
||||||
|
case 'summary':
|
||||||
|
$list = $this->summary($excel_type);
|
||||||
|
$type['type'] = '合同汇总表';
|
||||||
|
break;
|
||||||
|
case 'invoice':
|
||||||
|
$list = $this->invoice($excel_type);
|
||||||
|
$type['type'] = '发票统计分析表';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(empty($list)){
|
||||||
|
return resultArray(['data'=>'数据不存在']);
|
||||||
|
}
|
||||||
|
$excelLogic = new ExcelLogic();
|
||||||
|
$data = $excelLogic->contractExcel($type, $list);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,173 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 商业智能-审核统计
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: zhi | zhijunfu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\bi\controller;
|
||||||
|
|
||||||
|
use app\admin\controller\ApiCommon;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
use think\Db;
|
||||||
|
|
||||||
|
class Examine extends ApiCommon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission'=>[''],
|
||||||
|
'allow'=>['statistics','index','excelexport']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
if (!checkPerByAction('bi', 'oa', 'read')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 审核统计列表
|
||||||
|
*
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function statistics()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
if ($param['type']) {
|
||||||
|
$timeArr = getTimeByType($param['type']);
|
||||||
|
$param['start_time'] = $timeArr[0];
|
||||||
|
$param['end_time'] = $timeArr[1];
|
||||||
|
} else {
|
||||||
|
if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00');
|
||||||
|
if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59');
|
||||||
|
}
|
||||||
|
$examineModel = new \app\bi\model\Examine();
|
||||||
|
$list = $examineModel->getStatistics($param) ? : [];
|
||||||
|
return resultArray(['data'=>$list]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 审核统计详情列表
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$examineModel = new \app\oa\model\Examine();
|
||||||
|
$param = $this->param;
|
||||||
|
$user_id = $param['user_id'];
|
||||||
|
$category_id = $param['category_id'];
|
||||||
|
$type = $param['type'];
|
||||||
|
if (!$user_id || !$category_id) {
|
||||||
|
return resultArray(['error'=>'参数错误']);
|
||||||
|
}
|
||||||
|
//时间
|
||||||
|
if ($type) {
|
||||||
|
$timeArr = getTimeByType($type);
|
||||||
|
$start_time = $timeArr[0];
|
||||||
|
$end_time = $timeArr[1];
|
||||||
|
} else {
|
||||||
|
$start_time = $param['start_time'] ? : strtotime(date('Y-m-d',time()));
|
||||||
|
$end_time = $param['end_time'] ? : strtotime(date('Y-m-d',time()))+86399;
|
||||||
|
}
|
||||||
|
$create_time = array('between',array($start_time,$end_time));
|
||||||
|
|
||||||
|
$where = [];
|
||||||
|
$where['create_user_id'] = $user_id;
|
||||||
|
$where['check_status'] = 2;
|
||||||
|
$where['create_time'] = $create_time;
|
||||||
|
$where['category_id'] = $category_id;
|
||||||
|
$sumData = 0;
|
||||||
|
$categoryName = '普通审批';
|
||||||
|
switch ($category_id) {
|
||||||
|
case '2' :
|
||||||
|
$sumData = db('oa_examine')->where($where)->sum('duration');
|
||||||
|
$categoryName = '请假审批';
|
||||||
|
break;
|
||||||
|
case '3' :
|
||||||
|
$sumData = db('oa_examine')->where($where)->sum('duration');
|
||||||
|
$categoryName = '出差审批';
|
||||||
|
break;
|
||||||
|
case '4' :
|
||||||
|
$sumData = db('oa_examine')->where($where)->sum('duration');
|
||||||
|
$categoryName = '加班审批';
|
||||||
|
break;
|
||||||
|
case '5' :
|
||||||
|
$sumData = db('oa_examine')->where($where)->sum('money');
|
||||||
|
$categoryName = '差旅报销';
|
||||||
|
break;
|
||||||
|
case '6' :
|
||||||
|
$sumData = db('oa_examine')->where($where)->sum('money');
|
||||||
|
$categoryName = '借款申请';
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
$categoryName = db('oa_examine_category')->where(['category_id' => $category_id])->value('title');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
unset($where['create_time']);
|
||||||
|
unset($where['create_user_id']);
|
||||||
|
unset($where['create_user_id']);
|
||||||
|
$where['check_status'] = 'all';
|
||||||
|
$where['page'] = $param['page'];
|
||||||
|
$where['limit'] = $param['limit'];
|
||||||
|
$where['user_id'] = $user_id;
|
||||||
|
$where['between_time'] = array($start_time,$end_time);
|
||||||
|
$list = $examineModel->getDataList($where);
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
$data['list'] = $list ? : [];
|
||||||
|
$data['sumData'] = $sumData;
|
||||||
|
$data['categoryName'] = $categoryName;
|
||||||
|
return resultArray(['data'=>$data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计导出
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function excelExport()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
$excelModel = new \app\admin\model\Excel();
|
||||||
|
// 导出的字段列表
|
||||||
|
$category_list = db('oa_examine_category')->where(['status' => 1,'is_deleted' => ['neq',1]])->field('title,category_id')->select();
|
||||||
|
$field_list = [];
|
||||||
|
$field_list[0]['name'] = '员工';
|
||||||
|
$field_list[0]['field'] = 'realname';
|
||||||
|
$i = 1;
|
||||||
|
foreach ($category_list as $k=>$v) {
|
||||||
|
$field_list[$i]['name'] = strstr($v['title'],'审批') ? str_replace('审批','次数',$v['title']) : $v['title'].'次数';
|
||||||
|
$field_list[$i]['field'] = 'count_'.$v['category_id'];
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
// 文件名
|
||||||
|
$file_name = '5kcrm_examine_'.date('Ymd');
|
||||||
|
$excelModel->dataExportCsv($file_name, $field_list, function($list) use ($param){
|
||||||
|
$examineModel = new \app\bi\model\Examine();
|
||||||
|
if ($param['type']) {
|
||||||
|
$timeArr = getTimeByType($param['type']);
|
||||||
|
$param['start_time'] = $timeArr[0];
|
||||||
|
$param['end_time'] = $timeArr[1];
|
||||||
|
}
|
||||||
|
$list = $examineModel->getStatistics($param);
|
||||||
|
return $list['userList'];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 商业智能-日志分析
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\bi\controller;
|
||||||
|
|
||||||
|
use app\admin\controller\ApiCommon;
|
||||||
|
use think\Db;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class Log extends ApiCommon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission'=>[''],
|
||||||
|
'allow'=>['statistics','excelexport']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
if (!checkPerByAction('bi', 'oa', 'read')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志统计列表
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function statistics()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
|
||||||
|
if ($param['type']) {
|
||||||
|
$timeArr = getTimeByType($param['type']);
|
||||||
|
$param['start_time'] = $timeArr[0];
|
||||||
|
$param['end_time'] = $timeArr[1];
|
||||||
|
} else {
|
||||||
|
if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00');
|
||||||
|
if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59');
|
||||||
|
}
|
||||||
|
$loglModel = new \app\bi\model\Log();
|
||||||
|
$list = $loglModel->getStatistics($param) ? : [];
|
||||||
|
return resultArray(['data'=>$list]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计导出
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function excelExport()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
$excelModel = new \app\admin\model\Excel();
|
||||||
|
// 导出的字段列表
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['field' => 'realname','name' => '员工'],
|
||||||
|
'1' => ['field' => 'count','name' => '填写数'],
|
||||||
|
'2' => ['field' => 'unReadCont','name' => '接收人未读数'],
|
||||||
|
'3' => ['field' => 'unCommentCount','name' => '未评论数'],
|
||||||
|
'4' => ['field' => 'commentCount','name' => '已评论数'],
|
||||||
|
];
|
||||||
|
// 文件名
|
||||||
|
$file_name = '5kcrm_log_'.date('Ymd');
|
||||||
|
$excelModel->dataExportCsv($file_name, $field_list, function($list) use ($param){
|
||||||
|
$loglModel = new \app\bi\model\Log();
|
||||||
|
if ($param['type']) {
|
||||||
|
$timeArr = getTimeByType($param['type']);
|
||||||
|
$param['start_time'] = $timeArr[0];
|
||||||
|
$param['end_time'] = $timeArr[1];
|
||||||
|
}
|
||||||
|
$list = $loglModel->getStatistics($param);
|
||||||
|
return $list ? : [];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,150 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 商业智能-产品分析
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\bi\controller;
|
||||||
|
|
||||||
|
use app\admin\controller\ApiCommon;
|
||||||
|
use think\Db;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
use app\bi\logic\ExcelLogic;
|
||||||
|
|
||||||
|
class Product extends ApiCommon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission' => [''],
|
||||||
|
'allow' => ['statistics', 'productcategory', 'excelexport']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth', $action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
if (!checkPerByAction('bi', 'product', 'read')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code' => 102, 'error' => '无权操作']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品销量统计
|
||||||
|
*
|
||||||
|
* @param string $param
|
||||||
|
* @return mixed|\think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function statistics($param = '')
|
||||||
|
{
|
||||||
|
$productModel = new \app\crm\model\Product();
|
||||||
|
if($param['excel_type']!=1){
|
||||||
|
$param = $this->param;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00');
|
||||||
|
if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59');
|
||||||
|
|
||||||
|
$list = $productModel->getStatistics($param);
|
||||||
|
|
||||||
|
//导出使用
|
||||||
|
if (!empty($param['excel_type'])) {
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
return resultArray(['data' => $list]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品分类销量分析
|
||||||
|
*
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function productCategory()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
|
||||||
|
$productModel = new \app\bi\model\Product();
|
||||||
|
|
||||||
|
if (!empty($param['start_time'])) $param['start_time'] = strtotime($param['start_time'] . ' 00:00:00');
|
||||||
|
if (!empty($param['end_time'])) $param['end_time'] = strtotime($param['end_time'] . ' 23:59:59');
|
||||||
|
|
||||||
|
$list = $productModel->getStatistics($param);
|
||||||
|
|
||||||
|
return resultArray(['data' => $list]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function excelExport()
|
||||||
|
{
|
||||||
|
$param = $this->param;
|
||||||
|
$list = $this->statistics($param);
|
||||||
|
$data = [];
|
||||||
|
$subtotalCount = [];
|
||||||
|
$sumCount = [];
|
||||||
|
$item = [];
|
||||||
|
$unm = 0;
|
||||||
|
$subtotal = 0;
|
||||||
|
$res = [];
|
||||||
|
foreach ($list as $val) {
|
||||||
|
$res[] = $val['product_id'];
|
||||||
|
$data[$val['product_id']][] = $val;
|
||||||
|
}
|
||||||
|
$res = array_unique($res);
|
||||||
|
foreach ($res as $e) {
|
||||||
|
foreach ($list as $v) {
|
||||||
|
if ($e == $v['product_id']) {
|
||||||
|
$unm += $v['num'];
|
||||||
|
$subtotal += $v['subtotal'];
|
||||||
|
$sumCount[$e] = $unm + $v['num'];
|
||||||
|
$subtotalCount[$e] = (float)$subtotal + $v['subtotal'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$item[$e][] = [
|
||||||
|
'type' => '',
|
||||||
|
'category_id_info' => '',
|
||||||
|
'product_name' => '',
|
||||||
|
'contract_name' => '',
|
||||||
|
'realname' => '',
|
||||||
|
'name' => '',
|
||||||
|
'price' => '合计',
|
||||||
|
'num' => $sumCount[$e],
|
||||||
|
'subtotal' => $subtotalCount[$e],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
$items = [];
|
||||||
|
foreach ($data as $key => $value) {
|
||||||
|
$items[] = array_merge($data[$key], $item[$key]);
|
||||||
|
}
|
||||||
|
foreach ($items as $u) {
|
||||||
|
foreach ($u as $d) {
|
||||||
|
$field[] = $d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$excelLogic = new ExcelLogic();
|
||||||
|
$data = $excelLogic->productExcel($param, $field);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Description: 商业智能-回款分析
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: Michael_xu | gengxiaoxu@5kcrm.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\bi\controller;
|
||||||
|
|
||||||
|
use app\admin\controller\ApiCommon;
|
||||||
|
use think\Hook;
|
||||||
|
use think\Request;
|
||||||
|
|
||||||
|
class Receivables extends ApiCommon
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 用于判断权限
|
||||||
|
* @permission 无限制
|
||||||
|
* @allow 登录用户可访问
|
||||||
|
* @other 其他根据系统设置
|
||||||
|
**/
|
||||||
|
public function _initialize()
|
||||||
|
{
|
||||||
|
$action = [
|
||||||
|
'permission'=>[''],
|
||||||
|
'allow'=>['statistics','statisticlist']
|
||||||
|
];
|
||||||
|
Hook::listen('check_auth',$action);
|
||||||
|
$request = Request::instance();
|
||||||
|
$a = strtolower($request->action());
|
||||||
|
if (!in_array($a, $action['permission'])) {
|
||||||
|
parent::_initialize();
|
||||||
|
}
|
||||||
|
if (!checkPerByAction('bi', 'receivables' , 'read')) {
|
||||||
|
header('Content-Type:application/json; charset=utf-8');
|
||||||
|
exit(json_encode(['code'=>102,'error'=>'无权操作']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//回款统计列表
|
||||||
|
public function statisticList()
|
||||||
|
{
|
||||||
|
$receivablesModel = new \app\crm\model\Receivables();
|
||||||
|
$param = $this->param;
|
||||||
|
$ret = $receivablesModel->getstatisticsData($param);
|
||||||
|
return resultArray(['data'=>$ret]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回款统计 柱状图
|
||||||
|
* @author Michael_xu
|
||||||
|
* @param year 年份 , month 月份
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public function statistics()
|
||||||
|
{
|
||||||
|
$receivablesModel = new \app\crm\model\Receivables();
|
||||||
|
$userModel = new \app\admin\model\User();
|
||||||
|
$param = $this->param;
|
||||||
|
$adminModel = new \app\admin\model\Admin();
|
||||||
|
$perUserIds = $userModel->getUserByPer('bi', 'receivables', 'read'); //权限范围内userIds
|
||||||
|
$whereData = $adminModel->getWhere($param, '', $perUserIds); //统计条件
|
||||||
|
$userIds = $whereData['userIds'];
|
||||||
|
|
||||||
|
$year = $param['year'];
|
||||||
|
//时间段
|
||||||
|
if ($param['month']) {
|
||||||
|
//根据月份计算天数
|
||||||
|
$days = getmonthdays(strtotime($param['month']));
|
||||||
|
//获取时间范围内的每日时间戳数组(当月)
|
||||||
|
$start = strtotime($param['month'].'-'.'01');
|
||||||
|
$end = (strtotime($param['month'].'-'.$days) > time()) ? time() : strtotime($date.'-'.$days);
|
||||||
|
$create_time = array($start,$end);
|
||||||
|
} elseif ($param['year']) {
|
||||||
|
$next_year = $param['year']+1;
|
||||||
|
$create_time = array(strtotime($param['year'].'-01-01'),strtotime($next_year.'-01-01'));
|
||||||
|
} else {
|
||||||
|
$create_time = getTimeByType('year');
|
||||||
|
}
|
||||||
|
unset($param['month']);
|
||||||
|
unset($param['year']);
|
||||||
|
$param['create_time']['start'] = $create_time[0];
|
||||||
|
$param['create_time']['end'] = $create_time[1];
|
||||||
|
$chartParam = $param;
|
||||||
|
$chartParam['year'] = $year;
|
||||||
|
$chartParam['userIds'] = $userIds ? : [];
|
||||||
|
$chartList = $receivablesModel->getStatistics($chartParam); //柱状图
|
||||||
|
return resultArray(['data' => $chartList]);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'hello thinkphp' => 'hello thinkphp',
|
||||||
|
'data type error' => 'data type error',
|
||||||
|
];
|
@ -0,0 +1,4 @@
|
|||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'CUSTOMER' => '客户',
|
||||||
|
];
|
@ -0,0 +1,145 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 员工客户分析逻辑类
|
||||||
|
*
|
||||||
|
* @author qifan
|
||||||
|
* @date 2020-12-24
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace app\bi\logic;
|
||||||
|
|
||||||
|
use app\bi\traits\SortTrait;
|
||||||
|
use think\Db;
|
||||||
|
|
||||||
|
class BiCustomerLogic
|
||||||
|
{
|
||||||
|
use SortTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工客户满意度分析
|
||||||
|
*
|
||||||
|
* @param $param
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function getCustomerSatisfaction($param)
|
||||||
|
{
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
$userModel = new \app\admin\model\User();
|
||||||
|
|
||||||
|
$perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); # 权限范围内userIds
|
||||||
|
$userIds = $perUserIds; # 数组交集
|
||||||
|
if (empty($userIds)) return [];
|
||||||
|
|
||||||
|
# 员工信息
|
||||||
|
$userList = db('admin_user')->field(['id', 'realname'])->whereIn('id', $userIds)->select();
|
||||||
|
foreach ($userList AS $key => $value) {
|
||||||
|
$result[$value['id']] = [
|
||||||
|
'realname' => $value['realname'],
|
||||||
|
'visitContractNum' => 0,
|
||||||
|
'很满意' => 0,
|
||||||
|
'满意' => 0,
|
||||||
|
'一般' => 0,
|
||||||
|
'不满意' => 0,
|
||||||
|
'很不满意' => 0,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$visitField = ['owner_user_id', 'satisfaction', 'count(`satisfaction`) AS satisfactionCount', 'count(`contract_id`) AS contractCount'];
|
||||||
|
$where['owner_user_id'] = ['in', $userIds];
|
||||||
|
$where['create_time'] = ['between', [$param['start_time'], $param['end_time']]];
|
||||||
|
$where['deleted_state'] = 0;
|
||||||
|
$visitList = db('crm_visit')->field($visitField)->where($where)->group('owner_user_id, satisfaction')->select();
|
||||||
|
foreach ($visitList AS $key => $value) {
|
||||||
|
if (!empty($value['satisfaction']) && trim($value['satisfaction']) == '很满意') {
|
||||||
|
$result[$value['owner_user_id']]['很满意'] += $value['satisfactionCount'];
|
||||||
|
}
|
||||||
|
if (!empty($value['satisfaction']) && trim($value['satisfaction']) == '满意') {
|
||||||
|
$result[$value['owner_user_id']]['满意'] += $value['satisfactionCount'];
|
||||||
|
}
|
||||||
|
if (!empty($value['satisfaction']) && trim($value['satisfaction']) == '一般') {
|
||||||
|
$result[$value['owner_user_id']]['一般'] += $value['satisfactionCount'];
|
||||||
|
}
|
||||||
|
if (!empty($value['satisfaction']) && trim($value['satisfaction']) == '不满意') {
|
||||||
|
$result[$value['owner_user_id']]['不满意'] += $value['satisfactionCount'];
|
||||||
|
}
|
||||||
|
if (!empty($value['satisfaction']) && trim($value['satisfaction']) == '很不满意') {
|
||||||
|
$result[$value['owner_user_id']]['很不满意'] += $value['satisfactionCount'];
|
||||||
|
}
|
||||||
|
$result[$value['owner_user_id']]['visitContractNum'] += $value['contractCount'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->sortCommon($result, 'visitContractNum', 'desc');
|
||||||
|
|
||||||
|
return array_values($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品满意度分析
|
||||||
|
*
|
||||||
|
* @param $param
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function getProductSatisfaction($param)
|
||||||
|
{
|
||||||
|
$productData = [];
|
||||||
|
|
||||||
|
$userModel = new \app\admin\model\User();
|
||||||
|
|
||||||
|
$perUserIds = $userModel->getUserByPer('bi', 'customer', 'read'); # 权限范围内userIds
|
||||||
|
$userIds = !empty($param['user_id']) ? array_intersect([$param['user_id']], $perUserIds) : $perUserIds; # 数组交集
|
||||||
|
if (empty($userIds)) return [];
|
||||||
|
|
||||||
|
# 产品列表(上架中)
|
||||||
|
$productList = db('crm_product')->field(['product_id', 'name'])->where('status', '上架')->select();
|
||||||
|
foreach ($productList AS $key => $value) {
|
||||||
|
$productData[$value['product_id']] = [
|
||||||
|
'productName' => $value['name'],
|
||||||
|
'visitNum' => 0,
|
||||||
|
'很满意' => 0,
|
||||||
|
'满意' => 0,
|
||||||
|
'一般' => 0,
|
||||||
|
'不满意' => 0,
|
||||||
|
'很不满意' => 0,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
# 回访条件
|
||||||
|
$where['visit.owner_user_id'] = ['in', $userIds];
|
||||||
|
$where['visit.create_time'] = ['between', [$param['start_time'], $param['end_time']]];
|
||||||
|
$where['visit.deleted_state'] = 0;
|
||||||
|
|
||||||
|
# 回访数据
|
||||||
|
$visitList = db('crm_visit')->alias('visit')->field(['visit.contract_id', 'visit.satisfaction'])
|
||||||
|
->join('__CRM_CONTRACT__ contract', 'contract.contract_id = visit.contract_id')
|
||||||
|
->where($where)->select();
|
||||||
|
|
||||||
|
# 整理数据
|
||||||
|
foreach ($visitList AS $key => $value) {
|
||||||
|
if (empty($value['satisfaction'])) continue;
|
||||||
|
|
||||||
|
$productIds = db('crm_contract_product')->where('contract_id', $value['contract_id'])->column('product_id');
|
||||||
|
foreach ($productIds AS $k => $v) {
|
||||||
|
if ($productData[$v]) {
|
||||||
|
if (trim($value['satisfaction']) == '很满意') $productData[$v]['很满意']++;
|
||||||
|
if (trim($value['satisfaction']) == '满意') $productData[$v]['满意']++;
|
||||||
|
if (trim($value['satisfaction']) == '一般') $productData[$v]['一般']++;
|
||||||
|
if (trim($value['satisfaction']) == '不满意') $productData[$v]['不满意']++;
|
||||||
|
if (trim($value['satisfaction']) == '很不满意') $productData[$v]['很不满意']++;
|
||||||
|
|
||||||
|
$productData[$v]['visitNum']++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$productData = $this->sortCommon($productData, 'visitNum', 'desc');
|
||||||
|
|
||||||
|
return array_values($productData);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,300 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\bi\logic;
|
||||||
|
|
||||||
|
class ExcelLogic
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 员工客户分析导出
|
||||||
|
* @param $type
|
||||||
|
* @param $param
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function biexcle($type, $param)
|
||||||
|
{
|
||||||
|
$excelModel = new \app\admin\model\Excel();
|
||||||
|
$file_name='';
|
||||||
|
$field_list=[];
|
||||||
|
switch ($type['excel_types']) {
|
||||||
|
case 'statistics':
|
||||||
|
$file_name = 'totalCustomerTable';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '员工姓名', 'field' => 'realname'],
|
||||||
|
'1' => ['name' => '新增客户数', 'field' => 'customer_num'],
|
||||||
|
'2' => ['name' => '成交客户数', 'field' => 'deal_customer_num'],
|
||||||
|
'3' => ['name' => '客户成交率', 'field' => 'deal_customer_rate'],
|
||||||
|
'4' => ['name' => '合同总金额', 'field' => 'un_receivables_money'],
|
||||||
|
'5' => ['name' => '回款金额', 'field' => 'receivables_money'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'recordList':
|
||||||
|
$file_name = 'customerRecordInfo';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '员工姓名', 'field' => 'realname'],
|
||||||
|
'1' => ['name' => '跟进次数', 'field' => 'record_num'],
|
||||||
|
'2' => ['name' => '跟进客户数', 'field' => 'customer_num'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'recordMode':
|
||||||
|
$file_name = 'customerRecordCategoryStats';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '员工姓名', 'field' => 'realname'],
|
||||||
|
'1' => ['name' => '跟进次数', 'field' => 'record_num'],
|
||||||
|
'2' => ['name' => '跟进客户数', 'field' => 'customer_num'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'poolList':
|
||||||
|
$file_name = 'poolTable';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '员工姓名', 'field' => 'realname'],
|
||||||
|
'1' => ['name' => '部门', 'field' => 'username'],
|
||||||
|
'2' => ['name' => '公海池领取客户数', 'field' => 'receive'],
|
||||||
|
'3' => ['name' => '进入公海客户数', 'field' => 'put_in'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'userCycle':
|
||||||
|
$file_name = 'employeeCycleInfo';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '员工姓名', 'field' => 'realname'],
|
||||||
|
'1' => ['name' => '成交周期(天)', 'field' => 'cycle'],
|
||||||
|
'2' => ['name' => '成交客户数', 'field' => 'customer_num'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'customerSatisfaction':
|
||||||
|
$file_name = 'customerSatisfaction';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '员工姓名', 'field' => 'realname'],
|
||||||
|
'1' => ['name' => '回访合同总数', 'field' => 'visit'],
|
||||||
|
'2' => ['name' => '很满意', 'field' => 'satisfaction1'],
|
||||||
|
'3' => ['name' => '满意', 'field' => 'satisfaction2'],
|
||||||
|
'4' => ['name' => '一般', 'field' => 'satisfaction3'],
|
||||||
|
'5' => ['name' => '不满意', 'field' => 'satisfaction4'],
|
||||||
|
'6' => ['name' => '很不满意', 'field' => 'satisfaction5'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'productSatisfaction':
|
||||||
|
$file_name = 'productSatisfaction';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '员工姓名', 'field' => 'realname'],
|
||||||
|
'1' => ['name' => '回访合同总数', 'field' => 'visit'],
|
||||||
|
'2' => ['name' => '很满意', 'field' => 'satisfaction1'],
|
||||||
|
'3' => ['name' => '满意', 'field' => 'satisfaction2'],
|
||||||
|
'4' => ['name' => '一般', 'field' => 'satisfaction3'],
|
||||||
|
'5' => ['name' => '不满意', 'field' => 'satisfaction4'],
|
||||||
|
'6' => ['name' => '很不满意', 'field' => 'satisfaction5'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $excelModel->biExportExcel($file_name, $field_list, $type['type'], $param);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 员工业绩分析
|
||||||
|
* @param $type
|
||||||
|
* @param $param
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function contractExcel($type, $param)
|
||||||
|
{
|
||||||
|
|
||||||
|
$excelModel = new \app\admin\model\Excel();
|
||||||
|
if($type['excel_types']=='analysis'){
|
||||||
|
$file_name = 'contractNumStats';
|
||||||
|
$field_list = [];
|
||||||
|
p($excelModel->template_download($file_name, $field_list, $type['type'], $param));
|
||||||
|
return $excelModel->template_download($file_name, $field_list, $type['type'], $param);
|
||||||
|
}elseif ($type['excel_types']=='summary'){
|
||||||
|
$file_name = 'totalContract';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '日期', 'field' => 'type'],
|
||||||
|
'1' => ['name' => '签约合同数(个)', 'field' => 'count'],
|
||||||
|
'2' => ['name' => '签约合同金额(元)', 'field' => 'money'],
|
||||||
|
'3' => ['name' => '回款金额(元)', 'field' => 'back'],
|
||||||
|
];
|
||||||
|
return $excelModel->biExportExcel($file_name, $field_list, $type['type'], $param['items']);
|
||||||
|
}elseif ($type['excel_types']=='invoice'){
|
||||||
|
$file_name = 'invoiceStats';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '日期', 'field' => 'type'],
|
||||||
|
'1' => ['name' => '回款金额(元)', 'field' => 'receivables_money'],
|
||||||
|
'2' => ['name' => '开票金额(元)', 'field' => 'invoice_money'],
|
||||||
|
'3' => ['name' => '已回款未开票(元)', 'field' => 'not_invoice'],
|
||||||
|
'4' => ['name' => '已开票未回款(元)', 'field' => 'not_receivables'],
|
||||||
|
];
|
||||||
|
return $excelModel->biExportExcel($file_name, $field_list, $type['type'], $param);
|
||||||
|
}
|
||||||
|
// switch ($type['excel_types']) {
|
||||||
|
// case 'analysis':
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// break;
|
||||||
|
// case 'summary':
|
||||||
|
// $file_name = 'totalContract';
|
||||||
|
// $field_list = [
|
||||||
|
// '0' => ['name' => '日期', 'field' => 'type'],
|
||||||
|
// '1' => ['name' => '签约合同数(个)', 'field' => 'count'],
|
||||||
|
// '2' => ['name' => '签约合同金额(元)', 'field' => 'money'],
|
||||||
|
// '3' => ['name' => '回款金额(元)', 'field' => 'back'],
|
||||||
|
// ];
|
||||||
|
// return $excelModel->biExportExcel($file_name, $field_list, $type['type'], $param['items']);
|
||||||
|
// break;
|
||||||
|
// case 'invoice':
|
||||||
|
// $file_name = 'invoiceStats';
|
||||||
|
// $field_list = [
|
||||||
|
// '0' => ['name' => '日期', 'field' => 'type'],
|
||||||
|
// '1' => ['name' => '回款金额(元)', 'field' => 'receivables_money'],
|
||||||
|
// '2' => ['name' => '开票金额(元)', 'field' => 'invoice_money'],
|
||||||
|
// '3' => ['name' => '已回款未开票(元)', 'field' => 'not_invoice'],
|
||||||
|
// '4' => ['name' => '已开票未回款(元)', 'field' => 'not_receivables'],
|
||||||
|
// ];
|
||||||
|
// return $excelModel->biExportExcel($file_name, $field_list, $type['type'], $param);
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品分析
|
||||||
|
* @param $type
|
||||||
|
* @param $param
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function productExcel($type, $param)
|
||||||
|
{
|
||||||
|
$file_name = 'contractNumStats';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '日期', 'field' => 'type'],
|
||||||
|
'1' => ['name' => '产品分类', 'field' => 'category_id_info'],
|
||||||
|
'2' => ['name' => '产品名称', 'field' => 'product_name'],
|
||||||
|
'3' => ['name' => '合同编号', 'field' => 'contract_name'],
|
||||||
|
'4' => ['name' => '负责人', 'field' => 'realname'],
|
||||||
|
'5' => ['name' => '客户名称', 'field' => 'name'],
|
||||||
|
'6' => ['name' => '销售单价', 'field' => 'price'],
|
||||||
|
'7' => ['name' => '数量', 'field' => 'num'],
|
||||||
|
'8' => ['name' => '订单产品小计', 'field' => 'subtotal'],
|
||||||
|
];
|
||||||
|
$type = '产品销售情况统计';
|
||||||
|
$excelModel = new \app\admin\model\Excel();
|
||||||
|
return $excelModel->biExportExcel($file_name, $field_list, $type, $param);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排行榜
|
||||||
|
* @param $type
|
||||||
|
* @param $param
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function rankingExcle($type, $param)
|
||||||
|
{
|
||||||
|
|
||||||
|
$excelModel = new \app\admin\model\Excel();
|
||||||
|
switch ($type['excel_types']) {
|
||||||
|
case 'contract':
|
||||||
|
$file_name = 'contractRanKing';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '公司总排名', 'field' => 'id'],
|
||||||
|
'1' => ['name' => '签订人', 'field' => 'user_name'],
|
||||||
|
'2' => ['name' => '部门', 'field' => 'structure_name'],
|
||||||
|
'3' => ['name' => '合同金额(元)', 'field' => 'money'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'receivables':
|
||||||
|
$file_name = 'receivablesRanKing';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '公司总排名', 'field' => 'id'],
|
||||||
|
'1' => ['name' => '签订人', 'field' => 'user_name'],
|
||||||
|
'2' => ['name' => '部门', 'field' => 'structure_name'],
|
||||||
|
'3' => ['name' => '回款金额(元)', 'field' => 'money'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'signing':
|
||||||
|
$file_name = 'signingRanKing';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '公司总排名', 'field' => 'id'],
|
||||||
|
'1' => ['name' => '签订人', 'field' => 'user_name'],
|
||||||
|
'2' => ['name' => '部门', 'field' => 'structure_name'],
|
||||||
|
'3' => ['name' => '签约合同', 'field' => 'count'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'product':
|
||||||
|
$file_name = 'productCountRanKing';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '公司总排名', 'field' => 'id'],
|
||||||
|
'1' => ['name' => '签订人', 'field' => 'user_name'],
|
||||||
|
'2' => ['name' => '部门', 'field' => 'structure_name'],
|
||||||
|
'3' => ['name' => '产品销量', 'field' => 'num'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'addCustomer':
|
||||||
|
$file_name = 'customerCountRanKing';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '公司总排名', 'field' => 'id'],
|
||||||
|
'1' => ['name' => '签订人', 'field' => 'user_name'],
|
||||||
|
'2' => ['name' => '部门', 'field' => 'structure_name'],
|
||||||
|
'3' => ['name' => '新增客户数(个)', 'field' => 'count'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'addContacts':
|
||||||
|
$file_name = 'contactsCountRanKing';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '公司总排名', 'field' => 'id'],
|
||||||
|
'1' => ['name' => '签订人', 'field' => 'user_name'],
|
||||||
|
'2' => ['name' => '部门', 'field' => 'structure_name'],
|
||||||
|
'3' => ['name' => '新增联系人数(个)', 'field' => 'count'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'recordNun':
|
||||||
|
$file_name = 'FollowupRecordCountRanKing';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '公司总排名', 'field' => 'id'],
|
||||||
|
'1' => ['name' => '签订人', 'field' => 'user_name'],
|
||||||
|
'2' => ['name' => '部门', 'field' => 'structure_name'],
|
||||||
|
'3' => ['name' => '跟进次数(个)', 'field' => 'count'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'recordCustomer':
|
||||||
|
$file_name = 'customerFollowupCountRanKing';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '公司总排名', 'field' => 'id'],
|
||||||
|
'1' => ['name' => '签订人', 'field' => 'user_name'],
|
||||||
|
'2' => ['name' => '部门', 'field' => 'structure_name'],
|
||||||
|
'3' => ['name' => '跟进客户数(个)', 'field' => 'count'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
case 'examine':
|
||||||
|
$file_name = 'travelCountRanKing';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '公司总排名', 'field' => 'id'],
|
||||||
|
'1' => ['name' => '签订人', 'field' => 'user_name'],
|
||||||
|
'2' => ['name' => '部门', 'field' => 'structure_name'],
|
||||||
|
'3' => ['name' => '出差次数(次)', 'field' => 'count'],
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $excelModel->biExportExcel($file_name, $field_list, $type['type'], $param);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业绩目标完成情况
|
||||||
|
* @param $type
|
||||||
|
* @param $param
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function achienementExcel($type, $param)
|
||||||
|
{
|
||||||
|
$file_name = 'contractNumStats';
|
||||||
|
$field_list = [
|
||||||
|
'0' => ['name' => '名称', 'field' => 'name'],
|
||||||
|
'1' => ['name' => '月份', 'field' => 'month'],
|
||||||
|
'2' => ['name' => '目标', 'field' => 'achievement'],
|
||||||
|
'3' => ['name' => '完成', 'field' => 'money'],
|
||||||
|
'4' => ['name' => 'rate', 'field' => 'realname'],
|
||||||
|
];
|
||||||
|
$type = '业绩目标完成情况';
|
||||||
|
$excelModel = new \app\admin\model\Excel();
|
||||||
|
return $excelModel->biExportExcel($file_name, $field_list, $type, $param);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue