Index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. declare (strict_types = 1);
  14. namespace app\home\controller;
  15. use app\base\BaseController;
  16. use app\home\model\AdminLog;
  17. use app\user\validate\AdminCheck;
  18. use think\exception\ValidateException;
  19. use think\facade\Db;
  20. use think\facade\View;
  21. class Index extends BaseController
  22. {
  23. public function index()
  24. {
  25. $mobile = is_mobile();
  26. if($mobile){
  27. return redirect('/qiye/index/index');
  28. }
  29. $admin = Db::name('Admin')->where('id',$this->uid)->find();
  30. if (get_cache('menu' . $this->uid)) {
  31. $list = get_cache('menu' . $this->uid);
  32. } else {
  33. $adminGroup = Db::name('PositionGroup')->where(['pid' => $admin['position_id']])->column('group_id');
  34. $adminMenu = Db::name('AdminGroup')->where('id', 'in', $adminGroup)->column('rules');
  35. $adminMenus = [];
  36. foreach ($adminMenu as $k => $v) {
  37. $v = explode(',', $v);
  38. $adminMenus = array_merge($adminMenus, $v);
  39. }
  40. $menu = Db::name('AdminRule')->where(['menu' => 1, 'status' => 1])->where('id', 'in', $adminMenus)->order('sort asc,id asc')->select()->toArray();
  41. $list = list_to_tree($menu);
  42. \think\facade\Cache::tag('adminMenu')->set('menu' . $this->uid, $list);
  43. }
  44. View::assign('menu', $list);
  45. View::assign('admin',$admin);
  46. View::assign('system',get_system_config('system'));
  47. View::assign('web',get_system_config('web'));
  48. return View();
  49. }
  50. public function main()
  51. {
  52. $install = false;
  53. if (file_exists(CMS_ROOT . 'app/install')) {
  54. $install = true;
  55. }
  56. $uid = $this->uid;
  57. $dids = get_role_departments($uid);
  58. $total = [];
  59. $whereFinance= array();
  60. $whereFinanceOr = array();
  61. $whereFinance[] = ['delete_time', '=', 0];
  62. $whereFinance[] = ['check_status', '=', 2];
  63. $whereFinancerOr[] =['admin_id', '=', $uid];
  64. if(!empty($dids)){
  65. $whereFinancerOr[] =['did', 'in', $dids];
  66. }
  67. $total[] = array(
  68. 'name' => '报销总数',
  69. 'num' => Db::name('Expense')->where($whereFinance)
  70. ->where(function ($query) use($whereFinancerOr) {
  71. $query->whereOr($whereFinancerOr);
  72. })
  73. ->count()
  74. );
  75. $total[] = array(
  76. 'name' => '开票总数',
  77. 'num' => Db::name('Invoice')->where($whereFinance)
  78. ->where(function ($query) use($whereFinancerOr) {
  79. $query->whereOr($whereFinancerOr);
  80. })
  81. ->count()
  82. );
  83. $total[] = array(
  84. 'name' => '收票总数',
  85. 'num' => Db::name('Ticket')->where($whereFinance)
  86. ->where(function ($query) use($whereFinancerOr) {
  87. $query->whereOr($whereFinancerOr);
  88. })
  89. ->count()
  90. );
  91. $whereHandle = [];
  92. $whereHandle[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  93. $whereHandle[] = ['delete_time', '=', 0];
  94. $handle=[];
  95. $handle[] = array(
  96. 'name' => '待审公文',
  97. 'num' => Db::name('OfficialDocs')->where($whereHandle)->count(),
  98. 'id' => 182,
  99. 'url' => '/adm/official/datalist',
  100. );
  101. $handle[] = array(
  102. 'name' => '待审用章',
  103. 'num' => Db::name('Seal')->where($whereHandle)->count(),
  104. 'id' => 176,
  105. 'url' => '/adm/seal/datalist',
  106. );
  107. $handle[] = array(
  108. 'name' => '待审销售合同',
  109. 'num' => Db::name('Contract')->where($whereHandle)->count(),
  110. 'id' => 319,
  111. 'url' => '/contract/contract/datalist',
  112. );
  113. $handle[] = array(
  114. 'name' => '待审采购合同',
  115. 'num' => Db::name('Purchase')->where($whereHandle)->count(),
  116. 'id' => 323,
  117. 'url' => '/contract/purchase/datalist',
  118. );
  119. $handle[] = array(
  120. 'name' => '待审报销',
  121. 'num' => Db::name('Expense')->where($whereHandle)->count(),
  122. 'id' => 218,
  123. 'url' => '/finance/expense/datalist',
  124. );
  125. $handle[] = array(
  126. 'name' => '待审发票',
  127. 'num' => Db::name('Invoice')->where($whereHandle)->where([['invoice_type','>',0]])->count(),
  128. 'id' => 238,
  129. 'url' => '/finance/invoice/datalist',
  130. );
  131. $handle[] = array(
  132. 'name' => '待审收票',
  133. 'num' => Db::name('ticket')->where($whereHandle)->where([['invoice_type','>',0]])->count(),
  134. 'id' => 242,
  135. 'url' => '/finance/ticket/datalist',
  136. );
  137. $handle[] = array(
  138. 'name' => '待完成任务',
  139. 'num' => Db::name('ProjectTask')->where([['director_uid', '=', $uid],['status', '<', 3],['delete_time', '=', 0]])->count(),
  140. 'id' => 348,
  141. 'url' => '/project/task/datalist',
  142. );
  143. $whereCustomer = array();
  144. $whereCustomerOr = array();
  145. $whereCustomer[] = ['delete_time', '=', 0];
  146. $whereCustomerOr[] =['belong_uid', '=', $uid];
  147. if(!empty($dids)){
  148. $whereCustomerOr[] =['belong_did', 'in', $dids];
  149. }
  150. $whereCustomerOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
  151. $customerCount = Db::name('Customer')->where($whereCustomer)
  152. ->where(function ($query) use($whereCustomerOr) {
  153. $query->whereOr($whereCustomerOr);
  154. })
  155. ->count();
  156. $total[] = array(
  157. 'name' => '客户总数',
  158. 'num' => $customerCount,
  159. );
  160. $whereContract = array();
  161. $whereContractOr = array();
  162. $whereContract[] = ['delete_time', '=', 0];
  163. $whereContractOr[] =['admin_id|prepared_uid|sign_uid|keeper_uid', '=', $uid];
  164. $whereContractOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
  165. $whereContractOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_uids)")];
  166. $whereContractOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',check_history_uids)")];
  167. if(!empty($dids)){
  168. $whereContractOr[] =['did', 'in', $dids];
  169. }
  170. $contractCount = Db::name('Contract')->where($whereContract)
  171. ->where(function ($query) use($whereContractOr) {
  172. $query->whereOr($whereContractOr);
  173. })
  174. ->count();
  175. $total[] = array(
  176. 'name' => '销售合同',
  177. 'num' => $contractCount,
  178. );
  179. $purchaseCount = Db::name('Purchase')->where($whereContract)
  180. ->where(function ($query) use($whereContractOr) {
  181. $query->whereOr($whereContractOr);
  182. })
  183. ->count();
  184. $total[] = array(
  185. 'name' => '采购合同',
  186. 'num' => $purchaseCount,
  187. );
  188. $project_ids = Db::name('ProjectUser')->where(['uid' => $uid, 'delete_time' => 0])->column('project_id');
  189. $whereProject = [];
  190. $whereProject[] = ['delete_time', '=', 0];
  191. $whereProject[] = ['id', 'in', $project_ids];
  192. $projectCount = Db::name('Project')->where($whereProject)->count();
  193. $whereOr = array();
  194. $map1 = [];
  195. $map2 = [];
  196. $map3 = [];
  197. $map4 = [];
  198. $map1[] = ['admin_id', '=', $uid];
  199. $map2[] = ['director_uid', '=', $uid];
  200. $map3[] = ['', 'exp', Db::raw("FIND_IN_SET({$uid},assist_admin_ids)")];
  201. $map4[] = ['project_id', 'in', $project_ids];
  202. $whereOr =[$map1,$map2,$map3];
  203. $taskCount = Db::name('ProjectTask')
  204. ->where(function ($query) use ($whereOr) {
  205. if (!empty($whereOr))
  206. $query->whereOr($whereOr);
  207. })
  208. ->where([['delete_time', '=', 0]])->count();
  209. $total[] = array(
  210. 'name' => '项目总数',
  211. 'num' => $projectCount,
  212. );
  213. $total[] = array(
  214. 'name' => '任务总数',
  215. 'num' => $taskCount,
  216. );
  217. $todue=[];
  218. $delay_day = valueAuth('contract_admin','conf_10');
  219. if(empty($delay_day)){
  220. $delay_day = 30;
  221. }
  222. $delay_time = time()+$delay_day*60*60*24;
  223. $mapContract = array();
  224. $mapContractOr = array();
  225. $mapContract[] = ['delete_time', '=', 0];
  226. $mapContract[] = ['check_status', '=', 2];
  227. $mapContract[] = ['end_time','<',$delay_time];
  228. $mapContractOr[] =['admin_id|prepared_uid|sign_uid|keeper_uid', '=', $uid];
  229. $mapContractOr[] = ['', 'exp', Db::raw("FIND_IN_SET('{$uid}',share_ids)")];
  230. if(!empty($dids)){
  231. $mapContractOr[] =['did', 'in', $dids];
  232. }
  233. $todue[] = array(
  234. 'name' => '快到期的销售合同',
  235. 'num' => Db::name('Contract')->where($mapContract)
  236. ->where(function ($query) use($mapContractOr) {
  237. $query->whereOr($mapContractOr);
  238. })->count(),
  239. 'id' => 319,
  240. 'url' => '/contract/contract/datalist',
  241. );
  242. $todue[] = array(
  243. 'name' => '快到期的采购合同',
  244. 'num' => Db::name('Purchase')->where($mapContract)
  245. ->where(function ($query) use($mapContractOr) {
  246. $query->whereOr($mapContractOr);
  247. })->count(),
  248. 'id' => 323,
  249. 'url' => '/contract/purchase/datalist',
  250. );
  251. $delay_day_b = valueAuth('project_admin','conf_10');
  252. if(empty($delay_day_b)){
  253. $delay_day_b = 3;
  254. }
  255. $delay_day_b_time = time()+$delay_day_b*60*60*24;
  256. $todue[] = array(
  257. 'name' => '快到期的项目',
  258. 'num' => Db::name('Project')->where($whereProject)->where([['status','<',3],['end_time','<',$delay_day_b_time]])->count(),
  259. 'id' => 343,
  260. 'url' => '/project/index/datalist',
  261. );
  262. $todue[] = array(
  263. 'name' => '快到期的任务',
  264. 'num' => Db::name('ProjectTask')
  265. ->where(function ($query) use ($whereOr) {
  266. if (!empty($whereOr))
  267. $query->whereOr($whereOr);
  268. })
  269. ->where([['delete_time', '=', 0],['status','<',3],['end_time','<',$delay_day_b_time]])->count(),
  270. 'id' => 348,
  271. 'url' => '/project/task/datalist',
  272. );
  273. $position_id = Db::name('Admin')->where('id',$uid)->value('position_id');
  274. $adminGroup = Db::name('PositionGroup')->where(['pid' => $position_id])->column('group_id');
  275. $adminLayout = Db::name('AdminGroup')->where('id', 'in', $adminGroup)->column('layouts');
  276. $adminLayouts = [];
  277. foreach ($adminLayout as $k => $v) {
  278. $v = explode(',', $v);
  279. $adminLayouts = array_merge($adminLayouts, $v);
  280. }
  281. $layouts = get_config('layout');
  282. $layout_selected = [];
  283. foreach ($layouts as $key =>$vo) {
  284. if (!empty($adminLayouts) and in_array($vo['id'], $adminLayouts)) {
  285. $layout_selected[] = $vo;
  286. }
  287. }
  288. View::assign('layout_selected',$layout_selected);
  289. View::assign('total', $total);
  290. View::assign('handle', $handle);
  291. View::assign('todue', $todue);
  292. View::assign('install', $install);
  293. View::assign('TP_VERSION', \think\facade\App::version());
  294. return View();
  295. }
  296. //权限不足
  297. public function role()
  298. {
  299. return View('../../base/view/common/roletemplate');
  300. }
  301. //通讯录
  302. public function contacts_book()
  303. {
  304. if (request()->isAjax()) {
  305. $param = get_params();
  306. $where = array();
  307. $whereOr = array();
  308. if (!empty($param['keywords'])) {
  309. $where[] = ['a.id|a.username|a.name|a.nickname|a.mobile|a.desc', 'like', '%' . $param['keywords'] . '%'];
  310. }
  311. if (!empty($param['did'])) {
  312. $admin_array = Db::name('DepartmentAdmin')->where('department_id',$param['did'])->column('admin_id');
  313. $map1=[
  314. ['a.id','in',$admin_array],
  315. ];
  316. $map2=[
  317. ['a.did', '=', $param['did']],
  318. ];
  319. $whereOr =[$map1,$map2];
  320. }
  321. $where[] = ['a.status', '=', 1];
  322. $where[] = ['a.id', '>', 1];
  323. $admin = \app\user\model\Admin::alias('a')
  324. ->with('departments')
  325. ->field('a.*,p.title as position,d.title as department')
  326. ->join('Department d', 'd.id = a.did','left')
  327. ->join('Position p', 'p.id = a.position_id','left')
  328. ->where($where)
  329. ->where(function ($query) use($whereOr) {
  330. if (!empty($whereOr)){
  331. $query->whereOr($whereOr);
  332. }
  333. })
  334. ->paginate(intval($this->pageSize))
  335. ->order('a.id desc')
  336. ->each(function ($item, $key) {
  337. //遍历次要部门数据
  338. $departments = $item->departments->toArray();
  339. if(empty($departments)){
  340. $item->departments = '-';
  341. }
  342. else{
  343. $item->departments = split_array_field($departments,'title');
  344. }
  345. if($item->is_hide ==1){
  346. $item->mobile = hidetel($item->mobile);
  347. $item->email = hidetel($item->email);
  348. }
  349. $item->entry_time = empty($item->entry_time) ? '-' : to_date($item->entry_time,'Y-m-d',);
  350. });
  351. return table_assign(0, '', $admin);
  352. } else {
  353. return view();
  354. }
  355. }
  356. //修改个人信息
  357. public function edit_personal()
  358. {
  359. if (request()->isAjax()) {
  360. $param = get_params();
  361. $uid = $this->uid;
  362. Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($param);
  363. return to_assign();
  364. }
  365. else{
  366. View::assign('admin',get_admin($this->uid));
  367. return view();
  368. }
  369. }
  370. //修改密码
  371. public function edit_password()
  372. {
  373. if (request()->isAjax()) {
  374. $param = get_params();
  375. try {
  376. validate(AdminCheck::class)->scene('editPwd')->check($param);
  377. } catch (ValidateException $e) {
  378. // 验证失败 输出错误信息
  379. return to_assign(1, $e->getError());
  380. }
  381. $uid = $this->uid;
  382. $admin = Db::name('Admin')->where(['id' => $uid])->find();
  383. $old_psw = set_password($param['old_pwd'], $admin['salt']);
  384. if ($admin['pwd'] != $old_psw) {
  385. return to_assign(1, '旧密码错误');
  386. }
  387. $salt = set_salt(20);
  388. $new_pwd = set_password($param['pwd'], $salt);
  389. $data = [
  390. 'reg_pwd' => '',
  391. 'salt' => $salt,
  392. 'pwd' => $new_pwd,
  393. 'update_time' => time(),
  394. ];
  395. Db::name('Admin')->where(['id' => $uid])->strict(false)->field(true)->update($data);
  396. return to_assign();
  397. }
  398. else{
  399. View::assign('admin',get_admin($this->uid));
  400. return view();
  401. }
  402. }
  403. //系统操作日志
  404. public function log_list()
  405. {
  406. if (request()->isAjax()) {
  407. $param = get_params();
  408. $log = new AdminLog();
  409. $content = $log->get_log_list($param);
  410. return table_assign(0, '', $content);
  411. }else{
  412. return view();
  413. }
  414. }
  415. //设置theme
  416. public function set_theme()
  417. {
  418. if (request()->isAjax()) {
  419. $param = get_params();
  420. Db::name('Admin')->where('id',$this->uid)->update(['theme'=>$param['theme']]);
  421. return to_assign();
  422. }
  423. else{
  424. return to_assign(1,'操作错误');
  425. }
  426. }
  427. //办公工具
  428. public function get_links()
  429. {
  430. if (request()->isAjax()) {
  431. $links = Db::name('Links')->where('delete_time',0)->order('sort desc')->select();
  432. return to_assign(0, '', $links);
  433. }else{
  434. return view();
  435. }
  436. }
  437. }