Index.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\model\Config;
  4. use think\Db;
  5. class Index extends Auth
  6. {
  7. public function index(){
  8. $fRolesId = Db::name('roles')->where('id',$this->rolesId)->where('del',0)->value('parent_id');
  9. $rolesId = $this->rolesId;
  10. $rid = 0;
  11. if($fRolesId != 3){
  12. $menus = model('Menu')->getMenuTree($this->rolesId,$this->orgId);
  13. $curUrl = 'index/def';
  14. }else{
  15. $auths = model('Roles')->getRolesAuths($this->rolesId,1);
  16. if($auths){
  17. $map[] = ['id','in',$auths];
  18. }else{
  19. $map[] = ['id','=',0];
  20. }
  21. if($rolesId!=1){
  22. /*3.只有admin管理员可见
  23. 系统设置: 菜单管理、配置管理、安卓版本管理、苹果版本管理、
  24. 模块管理、这些项目,在权限分配里面就不要出现了,不需要分配*/
  25. $map[] = ['id','not in',[37,38,39,47,48]];
  26. }
  27. $lists = Db::name('menu')
  28. ->where($map)
  29. ->field('id,title,url,icons,pid,is_btn')
  30. ->order('sort asc,id asc')
  31. ->select();
  32. $lists = $lists?$lists:[];
  33. $arr = [];
  34. $curUrl = '';
  35. foreach ($lists as $k=>$v){
  36. $v['url'] = model('Menu')->getNavUrl($v['url']);
  37. $arr[] = $v;
  38. }
  39. $menus = list_to_tree($arr, 'pid', 'child');
  40. // $curUrl = isset($arr[0])?$arr[0]['url']:'';
  41. $rid = isset($menus[0])?$menus[0]['id']:'';
  42. $f = Db::name('menu')->where('pid',$rid)->where('del',0)->where('enable',1)->where($map)->order('sort asc,id asc')->find();
  43. if($f['url'] && $f['is_btn'] == 0){
  44. $curUrl = $f['url'];
  45. }else{
  46. $ff = Db::name('menu')->where('pid',$f['id'])->where('del',0)->where('enable',1)->where($map)->order('sort asc,id asc')->find();
  47. if($ff['url'] && $f['is_btn'] == 0){
  48. $curUrl = $ff['url'];
  49. }
  50. }
  51. if(!$menus){
  52. $curUrl ='';
  53. }
  54. }
  55. $this->assign('menus',$menus);
  56. $this->assign('curUrl',$curUrl);
  57. $this->assign('fRolesId',$fRolesId);
  58. $this->assign('rid',$rid);
  59. $userInfo = Db::name('user')
  60. ->where('id',$this->userId)
  61. ->find();
  62. $this->assign('userInfo',$userInfo);
  63. // 判断用户是否有派单权限
  64. $isDispatch = 0;
  65. if(get_dispatch_auth($this->userId)){
  66. $isDispatch = 1;
  67. }
  68. $this->assign('isDispatch',$isDispatch);
  69. $map[] = ['org_id','=',$this->orgId];
  70. $map[] = ['del','=',0];
  71. $map[] = ['order_mode','=',1];
  72. if(!is_admin($this->userId)){
  73. $auth = get_dispatch_auth($this->userId);
  74. if($auth){
  75. $map[] = ['work_type_mode', 'in', $auth];
  76. $where[] = ['o.work_type_mode', 'in', $auth];
  77. }else{
  78. $map[] = ['work_type_mode', '=', -1];
  79. $where[] = ['o.work_type_mode', '=', -1];
  80. }
  81. }
  82. $order = Db::name('orders')->where($map)->count();
  83. //$驳回的订单
  84. $where[] = ['o.del','=',0];
  85. $where[] = ['t.del','=',0];
  86. $bh = Db::name('orders')
  87. ->alias('o')
  88. ->join('todo t','t.order_id=o.id')
  89. ->where('t.todo_mode',4)
  90. ->where('t.org_id',$this->orgId)
  91. ->where('o.order_mode',4)
  92. ->where('o.org_id',$this->orgId)
  93. ->where($where)
  94. ->group('o.id')
  95. ->count();
  96. $order = $order + $bh;
  97. $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  98. $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  99. $endCount = $order+$complainCount+$hiddendangerCount;
  100. $this->assign('orderNums',$endCount);
  101. return $this->fetch();
  102. }
  103. public function ocount(){
  104. $map[] = ['org_id','=',$this->orgId];
  105. $map[] = ['del','=',0];
  106. $map[] = ['order_mode','=',1];
  107. $order = 0;
  108. $auth = get_dispatch_auth($this->userId);
  109. if(!is_admin($this->userId)){
  110. // if(!is_admin($this->userId)){
  111. // $auth = get_dispatch_auth($this->userId);
  112. // if($auth){
  113. // $map[] = ['work_type_mode', 'in', $auth];
  114. // $where[] = ['o.work_type_mode', 'in', $auth];
  115. // }else{
  116. // $map[] = ['work_type_mode', '=', -1];
  117. // $where[] = ['work_type_mode', '=', -1];
  118. // }
  119. // }
  120. if($auth){
  121. $map[] = ['work_type_mode', 'in', $auth];
  122. $where[] = ['o.work_type_mode', 'in', $auth];
  123. }else{
  124. $map[] = ['work_type_mode', '=', -1];
  125. $where[] = ['work_type_mode', '=', -1];
  126. }
  127. $order = Db::name('orders')->where($map)->count();
  128. //$驳回的订单
  129. $where[] = ['o.del','=',0];
  130. $where[] = ['t.del','=',0];
  131. $bh = Db::name('orders')
  132. ->alias('o')
  133. ->join('todo t','t.order_id=o.id')
  134. ->where('t.todo_mode',4)
  135. ->where('t.org_id',$this->orgId)
  136. ->where('o.order_mode',4)
  137. ->where('o.org_id',$this->orgId)
  138. ->where($where)
  139. ->group('o.id')
  140. ->count();
  141. $order = $order + $bh;
  142. }
  143. $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  144. $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  145. $endCount = $order+$complainCount+$hiddendangerCount;
  146. $this->success('成功','',['count'=>$endCount]);
  147. }
  148. public function def(){
  149. // APP下载二维码
  150. $download = think_encrypt(url('h5/Index/download','',true,true));
  151. $this->assign('download',$download);
  152. // 小程序二维码
  153. $wxcode = Db::name('org')->where('id',$this->orgId)->value('wxqrcode');
  154. $this->assign('wxcode',$wxcode);
  155. // 陪护小程序二维码
  156. $wxcode2 = Db::name('org')->where('id',$this->orgId)->value('wxqrcode2');
  157. $this->assign('wxcode2',$wxcode2);
  158. // 陪护h5
  159. $phcode = think_encrypt(config("app.app_host").config('app.ph_url').'?orgId='.$this->orgId);
  160. $this->assign('phcode',$phcode);
  161. // 点餐h5
  162. $shopcode = think_encrypt(config('app.shop_url').'?orgId='.$this->orgId);
  163. $this->assign('shopcode',$shopcode);
  164. // 商城h5
  165. $xshopcode = think_encrypt(config('app.xshop_url').'?orgId='.$this->orgId);
  166. $this->assign('xshopcode',$xshopcode);
  167. //本月
  168. $month = date('Y-m');
  169. $sMonth = $month.'-1 00:00:00';
  170. $eMonth = $month.'31 23:59:59';
  171. //上月
  172. $tmp_year=substr($month,0,4);
  173. //切割出月份
  174. $tmp_mon =substr($month,5,2);
  175. $tmp_forwardmonth=mktime(0,0,0,$tmp_mon-1,1,$tmp_year);
  176. $lastMonth=date("Y-m",$tmp_forwardmonth);
  177. $sLastMonth = $lastMonth.'-1 00:00:00';
  178. $eLastMonth = $lastMonth.'31 23:59:59';
  179. $userNums = Db::name('user')
  180. ->alias('u')
  181. ->join('user_org uo','uo.user_id=u.id')
  182. ->where('uo.org_id',$this->orgId)
  183. ->where('u.del',0)
  184. ->where('u.enable',1)
  185. ->count();
  186. $monthUserNums = Db::name('user')
  187. ->alias('u')
  188. ->join('user_org uo','uo.user_id=u.id')
  189. ->where('uo.org_id',$this->orgId)
  190. ->where('u.del',0)
  191. ->where('u.enable',1)
  192. ->where('u.create_time','>=',$sMonth)
  193. ->where('u.create_time','<=',$eMonth)
  194. ->count();
  195. $lastMonthUserNums = Db::name('user')
  196. ->alias('u')
  197. ->join('user_org uo','uo.user_id=u.id')
  198. ->where('uo.org_id',$this->orgId)
  199. ->where('u.del',0)
  200. ->where('u.enable',1)
  201. ->where('u.create_time','>=',$sLastMonth)
  202. ->where('u.create_time','<=',$eLastMonth)
  203. ->count();
  204. $userLastNums = $monthUserNums-$lastMonthUserNums;
  205. $userCount = [
  206. 'userNums'=>$userNums,
  207. 'userLastNums'=>$userLastNums,
  208. ];
  209. $this->assign('userCount',$userCount);
  210. $monthOrderNums = Db::name('orders')
  211. ->where('org_id',$this->orgId)
  212. ->where('create_yyyymm',date('Ym'))
  213. ->where('del',0)
  214. ->count();
  215. $lastMonthOrderNums = Db::name('orders')
  216. ->where('org_id',$this->orgId)
  217. ->where('create_yyyymm',date('Ym',strtotime('-1 month')))
  218. ->where('del',0)
  219. ->count();
  220. $orderLastNums = $monthOrderNums -$lastMonthOrderNums;
  221. $orderCount = [
  222. 'orderNums'=>$monthOrderNums,
  223. 'orderLastNums'=>$orderLastNums,
  224. ];
  225. $this->assign('orderCount',$orderCount);
  226. $yearOrderNums = Db::name('orders')
  227. ->where('org_id',$this->orgId)
  228. ->where('create_yyyy',date('Y'))
  229. ->where('del',0)
  230. ->count();
  231. $lastYearOrderNums = Db::name('orders')
  232. ->where('org_id',$this->orgId)
  233. ->where('create_yyyy',date('Y',strtotime('-1 year')))
  234. ->where('del',0)
  235. ->count();
  236. $endYearOrderCount = $yearOrderNums - $lastYearOrderNums;
  237. if($lastYearOrderNums < 1){
  238. $orderLastYearNums = 100;
  239. }else{
  240. $orderLastYearNums = round($endYearOrderCount/$lastYearOrderNums,2)*100;
  241. }
  242. $orderYearCount = [
  243. 'orderYearNums'=>$yearOrderNums,
  244. 'orderLastYearNums'=>$orderLastYearNums,
  245. ];
  246. $this->assign('orderYearCount',$orderYearCount);
  247. $activeUserNums = Db::name('user')
  248. ->alias('u')
  249. ->join('user_org uo','uo.user_id=u.id')
  250. ->where('uo.org_id',$this->orgId)
  251. ->where('u.del',0)
  252. ->where('u.enable',1)
  253. ->where('u.last_login_time','>=',$sMonth)
  254. ->where('u.last_login_time','<=',$eMonth)
  255. ->count();
  256. $lastActiveUserNums = Db::name('user')
  257. ->alias('u')
  258. ->join('user_org uo','uo.user_id=u.id')
  259. ->where('uo.org_id',$this->orgId)
  260. ->where('u.del',0)
  261. ->where('u.enable',1)
  262. ->where('u.last_login_time','>=',$sLastMonth)
  263. ->where('u.last_login_time','<=',$eLastMonth)
  264. ->count();
  265. $activeUserLastNums = $activeUserNums-$lastActiveUserNums;
  266. $activeUserCount = [
  267. 'activeUserNums'=>$activeUserNums,
  268. 'activeUserLastNums'=>$activeUserLastNums,
  269. ];
  270. $this->assign('activeUserCount',$activeUserCount);
  271. $dayOrderNums1 = Db::name('orders')
  272. ->where('org_id',$this->orgId)
  273. ->where('del',0)
  274. ->where('order_mode',1)
  275. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  276. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  277. ->count();
  278. $dayOrderNums2 = Db::name('orders')
  279. ->where('org_id',$this->orgId)
  280. ->where('del',0)
  281. ->where('order_mode',4)
  282. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  283. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  284. ->count();
  285. $dayOrderNums3 = Db::name('orders')
  286. ->where('org_id',$this->orgId)
  287. ->where('del',0)
  288. ->where('order_mode',5)
  289. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  290. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  291. ->count();
  292. $dayOrderNums4 = Db::name('orders')
  293. ->where('org_id',$this->orgId)
  294. ->where('del',0)
  295. ->where('order_mode',6)
  296. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  297. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  298. ->count();
  299. $dayOrderNums5 = Db::name('orders')
  300. ->where('org_id',$this->orgId)
  301. ->where('del',0)
  302. ->where('order_mode',2)
  303. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  304. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  305. ->count();
  306. $dayOrderNums6 = Db::name('orders')
  307. ->where('org_id',$this->orgId)
  308. ->where('del',0)
  309. ->where('order_mode',3)
  310. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  311. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  312. ->count();
  313. $dayOrderCount =[
  314. 'count1'=> $dayOrderNums1,
  315. 'count2'=> $dayOrderNums2,
  316. 'count3'=> $dayOrderNums3,
  317. 'count4'=> $dayOrderNums4,
  318. 'count5'=> $dayOrderNums5,
  319. 'count6'=> $dayOrderNums6,
  320. ];
  321. $this->assign('dayOrderCount',$dayOrderCount);
  322. $mode = input('mode',1);
  323. $todoList = Db::name('todo')
  324. ->where('org_id',$this->orgId)
  325. ->where('del',0)
  326. ->where('work_type_mode',$mode)
  327. ->limit(11)
  328. ->order('id desc')
  329. ->select();
  330. foreach ($todoList as $k=>$v){
  331. $todoList[$k]['user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  332. $todoList[$k]['create_user_name'] = Db::name('user')->where('id',$v['create_user_id'])->value('real_name');
  333. $todoList[$k]['content'] = Db::name('orders')->where('id',$v['order_id'])->value('content');
  334. }
  335. $this->assign('mode',$mode);
  336. $this->assign('todoList',$todoList);
  337. $group = Db::name('attendance_group')
  338. ->where('del',0)
  339. ->where('org_id',$this->orgId)
  340. ->select();
  341. $groupsId = [];
  342. $groupsId2 = [];
  343. $week = date('w');
  344. foreach ($group as $k=>$v){
  345. $content = json_decode($v['content'],true);
  346. if($v['type'] == 1){
  347. foreach ($content['week'] as $kk=>$vv){
  348. if($vv['week'] == $week && $vv['class_id'] > 0){
  349. $groupsId[] = $v['id'];
  350. }
  351. }
  352. }
  353. if($v['type'] == 2){
  354. $groupClass = Db::name('attendance_group_class')
  355. ->where('group_id',$v['id'])
  356. ->where('org_id',$this->orgId)
  357. ->where('day',date('Y-m-d'))
  358. ->find();
  359. if($groupClass){
  360. $groupsId2[] = $v['id'];
  361. }
  362. }
  363. }
  364. $endGroupIds = array_unique(array_merge($groupsId,$groupsId2));
  365. $userCount = Db::name('attendance_group_user')
  366. ->where('org_id',$this->orgId)
  367. ->whereIn('group_id',$endGroupIds)
  368. ->count();
  369. $userIds = Db::name('attendance_group_user')
  370. ->where('org_id',$this->orgId)
  371. ->whereIn('group_id',$endGroupIds)
  372. ->column('user_id');
  373. $attendanceNums = 0;
  374. foreach ($userIds as $k=>$v){
  375. $attendanceRecord = Db::name('attendance_record')
  376. ->where('user_id',$v)
  377. ->where('org_id',$this->orgId)
  378. // ->where('status',1)
  379. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  380. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  381. ->select();
  382. $flag = 0;
  383. if($attendanceRecord){
  384. foreach ($attendanceRecord as $kk=>$vv){
  385. if($vv['status'] == 1){
  386. }else{
  387. $flag = 1;
  388. }
  389. }
  390. if($flag == 0){
  391. $attendanceNums +=1;
  392. }
  393. }
  394. }
  395. $attendanceNums3 = $userCount-$attendanceNums;
  396. $attendanceCount1 = [
  397. 'count1' => $userCount, //总人数
  398. 'count2' => $attendanceNums, //在职人数
  399. 'count3' => $attendanceNums3>0?$attendanceNums3:0, //缺勤人数
  400. 'bl' => $userCount>0?round($attendanceNums/$userCount,2)*100:0,
  401. 'bl2' => $userCount>0?round($attendanceNums3/$userCount,2)*100:0,
  402. ];
  403. $this->assign('attendanceCount1',$attendanceCount1);
  404. return $this->fetch();
  405. }
  406. public function todo(){
  407. $mode = input('mode',1);
  408. $todoList = Db::name('todo')
  409. ->where('org_id',$this->orgId)
  410. ->where('del',0)
  411. ->where('work_type_mode',$mode)
  412. ->limit(11)
  413. ->order('id desc')
  414. ->select();
  415. foreach ($todoList as $k=>$v){
  416. $todoList[$k]['work_type_mode_text'] = Db::name('work_type_mode')->where('id',$v['work_type_mode'])->value('name');
  417. $todoList[$k]['to_user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  418. $todoList[$k]['user_name'] = Db::name('user')->where('id',$v['create_user_id'])->value('real_name');
  419. $todoList[$k]['content'] = Db::name('orders')->where('id',$v['order_id'])->value('content');
  420. $todomode = Db::name('todo_mode')->where('id',$v['todo_mode'])->find();
  421. $todoList[$k]['todo_mode_text'] = $todomode?$todomode['in_content']:'';
  422. $todoList[$k]['todo_mode_color'] = $todomode?$todomode['color']:'';
  423. }
  424. //数据返回
  425. $totalCount = count($todoList);
  426. $totalPage = 1;
  427. $result['page'] = 1;
  428. $result['total'] = $totalPage;
  429. $result['records'] = $totalCount;
  430. $result['rows'] = $todoList;
  431. return json($result);
  432. }
  433. public function attendanceCount1(){
  434. $group = Db::name('attendance_group')
  435. ->where('del',0)
  436. ->where('org_id',$this->orgId)
  437. ->select();
  438. $groupsId = [];
  439. $groupsId2 = [];
  440. $week = date('w');
  441. foreach ($group as $k=>$v){
  442. $content = json_decode($v['content'],true);
  443. if($v['type'] == 1){
  444. foreach ($content['week'] as $kk=>$vv){
  445. if($vv['week'] == $week && $vv['class_id'] > 0){
  446. $groupsId[] = $v['id'];
  447. }
  448. }
  449. }
  450. if($v['type'] == 2){
  451. $groupClass = Db::name('attendance_group_class')
  452. ->where('group_id',$v['id'])
  453. ->where('org_id',$this->orgId)
  454. ->where('day',date('Y-m-d'))
  455. ->find();
  456. if($groupClass){
  457. $groupsId2[] = $v['id'];
  458. }
  459. }
  460. }
  461. $endGroupIds = array_unique(array_merge($groupsId,$groupsId2));
  462. $userCount = Db::name('attendance_group_user')
  463. ->where('org_id',$this->orgId)
  464. ->whereIn('group_id',$endGroupIds)
  465. ->count();
  466. $userIds = Db::name('attendance_group_user')
  467. ->where('org_id',$this->orgId)
  468. ->whereIn('group_id',$endGroupIds)
  469. ->column('user_id');
  470. $attendanceNums = 0;
  471. foreach ($userIds as $k=>$v){
  472. $attendanceRecord = Db::name('attendance_record')
  473. ->where('user_id',$v)
  474. ->where('org_id',$this->orgId)
  475. // ->where('status',1)
  476. ->where('create_time','>=',date('Y-m-d').' 00:00:00')
  477. ->where('create_time','<=',date('Y-m-d').' 23:59:59')
  478. ->select();
  479. $flag = 0;
  480. if($attendanceRecord){
  481. foreach ($attendanceRecord as $kk=>$vv){
  482. if($vv['status'] == 1){
  483. }else{
  484. $flag = 1;
  485. }
  486. }
  487. if($flag == 0){
  488. $attendanceNums +=1;
  489. }
  490. }
  491. }
  492. $attendanceNums3 = $userCount-$attendanceNums;
  493. $attendanceCount1 = [
  494. 'count1' => $userCount, //总人数
  495. 'count2' => $attendanceNums, //在职人数
  496. 'count3' => $attendanceNums3>0?$attendanceNums3:0, //缺勤人数
  497. 'bl' => $userCount>0?round($attendanceNums/$userCount,2)*100:0,
  498. 'bl2' => $userCount>0?round($attendanceNums3/$userCount,2)*100:0,
  499. ];
  500. $this->success('','',$attendanceCount1);
  501. }
  502. public function changeOrg(){
  503. if(request()->isAjax()){
  504. $id = input('id/d');
  505. $info = Db::name('org')->where('id',$id)->find();
  506. if($info['type'] != 2){
  507. $this->error('管理机构不能切换');
  508. }
  509. session('orgId',$info['id']);
  510. session('orgName',$info['name']);
  511. $this->success('切换成功');
  512. }else{
  513. $tree = model('Org')->getTreeByRoles($this->rolesId,$this->userId);
  514. $this->assign('tree',$tree);
  515. return $this->fetch();
  516. }
  517. }
  518. public function order(){
  519. // 判断用户是否是调度
  520. $level = get_dispatch_auth($this->userId);
  521. if(!$level){
  522. $this->error('无权限');
  523. }
  524. $map[] = ['org_id','=',$this->orgId];
  525. $map[] = ['del','=',0];
  526. $map[] = ['order_mode','=',1];
  527. $order = 0;
  528. if(!is_admin($this->userId)){
  529. $auth = get_dispatch_auth($this->userId);
  530. if($auth){
  531. $map[] = ['work_type_mode', 'in', $auth];
  532. $where[] = ['o.work_type_mode', 'in', $auth];
  533. }else{
  534. $map[] = ['work_type_mode', '=', -1];
  535. $where[] = ['o.work_type_mode', '=', -1];
  536. }
  537. $order = Db::name('orders')->where($map)->count();
  538. //$驳回的订单
  539. $where[] = ['o.del','=',0];
  540. $where[] = ['t.del','=',0];
  541. $bh = Db::name('orders')
  542. ->alias('o')
  543. ->join('todo t','t.order_id=o.id')
  544. ->where('t.todo_mode',4)
  545. ->where('t.org_id',$this->orgId)
  546. ->where('o.order_mode',4)
  547. ->where('o.org_id',$this->orgId)
  548. ->where($where)
  549. ->group('o.id')
  550. ->count();
  551. $order = $order + $bh;
  552. }
  553. $complainCount = Db::name('complain')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  554. $hiddendangerCount = Db::name('hiddendanger')->where('del',0)->where('org_id',$this->orgId)->where('status',0)->where('order_id',0)->count();
  555. $endCount = $order+$complainCount+$hiddendangerCount;
  556. if(!empty($endCount)){
  557. $this->success('','',$endCount);
  558. }else{
  559. $this->error('无订单');
  560. }
  561. }
  562. public function ordersList() {
  563. $orderType = input('orderType',1);
  564. $mode = input('mode', 0);
  565. // $level1 = check_is_dispatch($this->userId);
  566. // $level2 = check_two_dispatch($this->userId);
  567. // $turnoff = two_dispatch_off($this->orgId);
  568. if (request()->isAjax()) {
  569. //分页参数
  570. $length = input('rows', 10, 'intval'); //每页条数
  571. $page = input('page', 1, 'intval'); //第几页
  572. $start = ($page - 1) * $length; //分页开始位置
  573. //排序
  574. $sortRow = input('sidx', 'id', 'trim'); //排序列
  575. $sort = input('sord', 'desc', 'trim'); //排序方式
  576. $order = $sortRow . ' ' . $sort;
  577. if($orderType == 1){
  578. $content = input('content', '', 'trim');
  579. if ($content) {
  580. $map[] = ['content', 'like', '%' . $content . '%'];
  581. }
  582. $dep_id = input('dep_id', '', 'trim');
  583. if ($dep_id != '') {
  584. $map[] = ['dep_id', '=', $dep_id];
  585. }
  586. $order_mode = input('order_mode', 1);
  587. $map6 = [];
  588. if ($order_mode != '') {
  589. // if($level1 && $turnoff && $mode != 15){ // 一级调度且二级调度开关开着,品质整改例外
  590. // if ($order_mode == 1) {
  591. // $map[] = ['is_deal', '=', 0];
  592. // }else if ($order_mode == 4) {
  593. // $map6[] = ['is_deal', '=', 1];
  594. // }
  595. // }
  596. if($order_mode==100){//已挂起
  597. $gq = Db::name('todo')
  598. ->where('work_type_mode',1)
  599. ->where('todo_mode',2)
  600. ->where('pause',1)
  601. ->column('order_id');
  602. if(empty($gq)){
  603. $map[] = ['id', '=', -1];
  604. }else{
  605. $map[] = ['id', 'in', $gq];
  606. }
  607. }else{
  608. $map[] = ['order_mode', '=', $order_mode];
  609. }
  610. }
  611. $b = input('start', '', 'trim');
  612. $e = input('end', '', 'trim');
  613. if ($b) {
  614. $b = date('Ymd', strtotime($b));
  615. $map[] = ['create_yyyymmdd', '>=', $b];
  616. }
  617. if ($e) {
  618. $e = date('Ymd', strtotime($e));
  619. $map[] = ['create_yyyymmdd', '<=', $e];
  620. }
  621. $map[] = ['del', '=', 0];
  622. $map[] = ['org_id', '=', $this->orgId];
  623. if($mode==-1){
  624. $map[] = ['source_type', '=', 4];
  625. }
  626. $type = input('type', '', 'trim');
  627. $oids = [];
  628. if ($type != '') {
  629. $map1[] = ['parent_id', '=', $type];
  630. $type_id = Db::name('order_type')
  631. ->where($map1)
  632. ->where('org_id', $this->orgId)
  633. ->where('enable', 1)
  634. ->column('id');
  635. if (!empty($type_id)) {
  636. $map3[] = ['type_id', 'in', $type_id];
  637. $ids = Db::name('order_repair')
  638. ->where($map3)
  639. ->column('order_id');
  640. if (!empty($ids)) {
  641. $oids = $ids;
  642. }
  643. else {
  644. $oids = [];
  645. }
  646. }
  647. else {
  648. $oids = [];
  649. }
  650. }
  651. if($type != ''){
  652. if($oids){
  653. $map[] = ['id', 'in', $oids];
  654. }else{
  655. $map[] = ['id', '=', 0];
  656. }
  657. }
  658. if($mode == 15){ // 品质检查,单独处理
  659. $map[] = ['work_type_mode','=',$mode];
  660. }else{
  661. $work_type_mode = input('work_type_mode','','trim');
  662. if(!is_admin($this->userId)){
  663. $auth = get_dispatch_auth($this->userId);
  664. if($auth){
  665. $map[] = ['work_type_mode', 'in', $auth];
  666. if($mode > 0){
  667. $map[] = ['work_type_mode', '=', $mode];
  668. }else{
  669. if($work_type_mode!=''){
  670. $map[] = ['work_type_mode','=',$work_type_mode];
  671. }
  672. }
  673. }else{
  674. $map[] = ['work_type_mode', '=', -1];
  675. }
  676. }else{
  677. if($mode > 0){
  678. $map[] = ['work_type_mode', '=', $mode];
  679. }else{
  680. if($work_type_mode!=''){
  681. $map[] = ['work_type_mode','=',$work_type_mode];
  682. }
  683. }
  684. }
  685. }
  686. $map = empty($map) ? true : $map;
  687. //数据查询
  688. $lists = db('orders')->where($map)
  689. ->whereOr($map6)
  690. ->limit($start, $length)->order($order)->select();
  691. foreach ($lists as $k => $v) {
  692. $lists[$k] = model('orders')->formatOrder($v);
  693. $lists[$k]['bh_nums'] = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',4)->count();
  694. $gq = Db::name('todo')
  695. ->where('order_id',$v['id'])
  696. ->where('work_type_mode',1)
  697. ->where('todo_mode',2)
  698. ->where('pause',1)
  699. ->find();
  700. $lists[$k]['gq'] = $gq?'存在挂起':'';
  701. }
  702. //数据返回
  703. $totalCount = db('orders')->where($map)->count();
  704. }elseif($orderType == 2){
  705. $map[] = ['del','=',0];
  706. $map[] = ['org_id','=',$this->orgId];
  707. $hour = (new Config())->getConfig('org_complain_hour',$this->orgId);
  708. $hour = $hour>0?$hour:0;
  709. $endTime = date('Y-m-d H:i:s',time() - $hour*60*60);
  710. $type = input('type/d',0);
  711. if($hour > 0 && $type == 1){
  712. $map[] = ['create_time','<',$endTime];
  713. $map[] = ['status','=',0];
  714. }
  715. $from = input('from', '', 'trim');
  716. if ($from!='') {
  717. $map[] = ['from','=',$from];
  718. }
  719. $map[] = ['status','=',0];
  720. $map[] = ['order_id','=',0];
  721. $map= empty($map) ? true: $map;
  722. //数据查询
  723. $lists = db('complain')->where($map)
  724. ->limit($start,$length)->order($order)->select();
  725. foreach ($lists as $k=>$v){
  726. $lists[$k]['depName'] = Db::name('dep')
  727. ->where('id',$v['dep_id'])
  728. ->value('title');
  729. // $lists[$k]['fromName'] = model('Complain')->from[$v['from']];
  730. $lists[$k]['fromName'] = '';
  731. if($v['order_id'] > 0 && $v['bus_type'] != 0){
  732. if($v['to_from']){
  733. $lists[$k]['fromName'] = '一键呼叫';
  734. }else{
  735. $lists[$k]['fromName'] = '隐患';
  736. }
  737. }
  738. $lists[$k]['worktypemode'] = '';
  739. if($v['order_id'] > 0 && in_array($v['bus_type'],[0,1])){
  740. $worktype = Db::name('orders')
  741. ->alias('o')
  742. ->join('work_type_mode w','o.work_type_mode = w.id')
  743. ->where('o.id',$v['order_id'])
  744. ->value('w.name');
  745. $lists[$k]['worktypemode'] = $worktype?$worktype:'';
  746. }
  747. if($v['hide'] == 1){
  748. $lists[$k]['realName'] = '匿名';
  749. }else{
  750. $lists[$k]['realName'] = Db::name('user')
  751. ->where('id',$v['create_user_id'])
  752. ->value('real_name');
  753. }
  754. $orderMode = 0;
  755. if($v['order_id'] > 0){
  756. $orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
  757. }
  758. $lists[$k]['statusTxt'] = model('Complain')->formatStatus($v['status'],$v['order_id'],$v['id']);
  759. $lists[$k]['order_mode'] = $orderMode;
  760. if($v['create_time'] < $endTime && $v['status']==0){
  761. $lists[$k]['statusTxt'] = $lists[$k]['statusTxt'].'<span style="color:red;">(已超时)</span>';
  762. }
  763. }
  764. //数据返回
  765. $totalCount = db('complain')->where($map)->count();
  766. }elseif ($orderType == 3){
  767. $map[] = ['del','=',0];
  768. $map[] = ['org_id','=',$this->orgId];
  769. $map[] = ['status','=',0];
  770. $map[] = ['order_id','=',0];
  771. $from = input('from', '', 'trim');
  772. if ($from!='') {
  773. $map[] = ['from','=',$from];
  774. }
  775. $map= empty($map) ? true: $map;
  776. //数据查询
  777. $lists = db('hiddendanger')->where($map)
  778. ->limit($start,$length)->order($order)->select();
  779. foreach ($lists as $k=>$v){
  780. $lists[$k]['depName'] = Db::name('dep')
  781. ->where('id',$v['dep_id'])
  782. ->value('title');
  783. // $lists[$k]['fromName'] = model('Hiddendanger')->from[$v['from']];
  784. $lists[$k]['fromName'] = '';
  785. if($v['order_id'] > 0 && $v['bus_type'] != 0){
  786. if($v['to_from']){
  787. $lists[$k]['fromName'] = '一键呼叫';
  788. }else{
  789. $lists[$k]['fromName'] = '投诉';
  790. }
  791. }
  792. $lists[$k]['worktypemode'] = '';
  793. if($v['order_id'] > 0 && in_array($v['bus_type'],[0,1])){
  794. $worktype = Db::name('orders')
  795. ->alias('o')
  796. ->join('work_type_mode w','o.work_type_mode = w.id')
  797. ->where('o.id',$v['order_id'])
  798. ->value('w.name');
  799. $lists[$k]['worktypemode'] = $worktype?$worktype:'';
  800. }
  801. $lists[$k]['realName'] = Db::name('user')
  802. ->where('id',$v['create_user_id'])
  803. ->value('real_name');
  804. // $lists[$k]['statusTxt'] = $v['status']==1?'已处理':"未处理";
  805. $orderMode = 0;
  806. if($v['order_id'] > 0){
  807. $orderMode = Db::name('orders')->where('id',$v['order_id'])->value('order_mode');
  808. }
  809. $lists[$k]['statusTxt'] = model('Hiddendanger')->formatStatus($v['status'],$v['order_id'],$v['id']);
  810. $lists[$k]['order_mode'] = $orderMode;
  811. }
  812. //数据返回
  813. $totalCount = db('hiddendanger')->where($map)->count();
  814. }elseif($orderType == 4){
  815. $order_mode = input('order_mode', 4);
  816. $map6 = [];
  817. if ($order_mode != '') {
  818. if($order_mode==100){//已挂起
  819. $gq = Db::name('todo')
  820. ->where('work_type_mode',1)
  821. ->where('todo_mode',2)
  822. ->where('pause',1)
  823. ->column('order_id');
  824. if(empty($gq)){
  825. $map[] = ['id', '=', -1];
  826. }else{
  827. $map[] = ['id', 'in', $gq];
  828. }
  829. }else{
  830. $map[] = ['order_mode', '=', $order_mode];
  831. }
  832. }
  833. $map[] = ['del', '=', 0];
  834. $map[] = ['org_id', '=', $this->orgId];
  835. if($mode==-1){
  836. $map[] = ['source_type', '=', 4];
  837. }
  838. $type = input('type', '', 'trim');
  839. $oids = [];
  840. if ($type != '') {
  841. $map1[] = ['parent_id', '=', $type];
  842. $type_id = Db::name('order_type')
  843. ->where($map1)
  844. ->where('org_id', $this->orgId)
  845. ->where('enable', 1)
  846. ->column('id');
  847. if (!empty($type_id)) {
  848. $map3[] = ['type_id', 'in', $type_id];
  849. $ids = Db::name('order_repair')
  850. ->where($map3)
  851. ->column('order_id');
  852. if (!empty($ids)) {
  853. $oids = $ids;
  854. }
  855. else {
  856. $oids = [];
  857. }
  858. }
  859. else {
  860. $oids = [];
  861. }
  862. }
  863. if($type != ''){
  864. if($oids){
  865. $map[] = ['id', 'in', $oids];
  866. }else{
  867. $map[] = ['id', '=', 0];
  868. }
  869. }
  870. if($mode == 15){ // 品质检查,单独处理
  871. $map[] = ['work_type_mode','=',$mode];
  872. }else{
  873. $work_type_mode = input('work_type_mode','','trim');
  874. if(!is_admin($this->userId)){
  875. $auth = get_dispatch_auth($this->userId);
  876. if($auth){
  877. $map[] = ['work_type_mode', 'in', $auth];
  878. if($mode > 0){
  879. $map[] = ['work_type_mode', '=', $mode];
  880. }else{
  881. if($work_type_mode!=''){
  882. $map[] = ['work_type_mode','=',$work_type_mode];
  883. }
  884. }
  885. }else{
  886. $map[] = ['work_type_mode', '=', -1];
  887. }
  888. }else{
  889. if($mode > 0){
  890. $map[] = ['work_type_mode', '=', $mode];
  891. }else{
  892. if($work_type_mode!=''){
  893. $map[] = ['work_type_mode','=',$work_type_mode];
  894. }
  895. }
  896. }
  897. }
  898. $orderIds = Db::name('todo')
  899. ->where('todo_mode',4)
  900. ->where('org_id',$this->orgId)
  901. ->where('del',0)
  902. ->group('order_id')
  903. ->column('order_id');
  904. $map[] = ['id','in',$orderIds];
  905. $map = empty($map) ? true : $map;
  906. //数据查询
  907. $lists = db('orders')
  908. ->where($map)
  909. // ->whereOr($map6)
  910. ->limit($start, $length)
  911. ->order($order)
  912. ->select();
  913. foreach ($lists as $k => $v) {
  914. $lists[$k] = model('orders')->formatOrder($v);
  915. $lists[$k]['bh_nums'] = Db::name('todo')->where('order_id',$v['id'])->where('del',0)->where('todo_mode',4)->count();
  916. $gq = Db::name('todo')
  917. ->where('order_id',$v['id'])
  918. ->where('work_type_mode',1)
  919. ->where('todo_mode',2)
  920. ->where('pause',1)
  921. ->find();
  922. $lists[$k]['gq'] = $gq?'存在挂起':'';
  923. }
  924. //数据返回
  925. $totalCount = db('orders')->where($map)->count();
  926. }
  927. $totalPage = ceil($totalCount / $length);
  928. $result['page'] = $page;
  929. $result['total'] = $totalPage;
  930. $result['records'] = $totalCount;
  931. $result['rows'] = $lists;
  932. return json($result);
  933. }
  934. else {
  935. if($mode >0){
  936. $mode_name = $this->getTableField('work_type_mode', ['id' => $mode], 'name');
  937. }else{
  938. $mode_name = '';
  939. }
  940. $auths = [1,2,3,4,15,0];
  941. if(!is_admin($this->userId)){
  942. $auth = get_dispatch_auth($this->userId);
  943. if($auth){
  944. $auths = array_intersect($auths,$auth);
  945. if($mode > 0){
  946. $auths = array_intersect($auths,[$mode]);
  947. }
  948. }else{
  949. $auths = [];
  950. }
  951. }
  952. $this->assign('auths',$auths);
  953. $dep_list = (new \app\common\model\Dep())->getList();
  954. $order_type = (new \app\common\model\OrderType())->list();
  955. $order_mode = Db::name('order_mode')
  956. ->select();
  957. $this->assign('dep_list', $dep_list);
  958. $this->assign('order_type_list', $order_type);
  959. $this->assign('m_name', $mode_name);
  960. $this->assign('mode', $mode);
  961. $this->assign('order_mode_list', $order_mode);
  962. $this->assign('dispatch_type', check_two_dispatch($this->userId));
  963. $this->assign('orderType',$orderType);
  964. return $this->fetch('index/orders');
  965. }
  966. }
  967. //调度查看订单详情
  968. public function ordersDetail2($id) {
  969. if (!$id) {
  970. $this->error('参数错误');
  971. }
  972. $type = input('type/d',0);
  973. $this->assign('type', $type);
  974. $order = Db::name('orders')->where(['id' => $id])->find();
  975. $order = model('Orders')->formatOrder($order, 1);
  976. $order['images'] = !empty($order['images']) ? explode(',', $order['images']) : '';
  977. $this->assign('info', $order);
  978. $workTypeName = $this->getTableField('work_type_mode', ['id' => $order['work_type_mode']], 'name');
  979. $this->assign('meta_title', $workTypeName . '订单详情');
  980. $level2 = check_two_dispatch($this->userId);
  981. $level1 = check_is_dispatch($this->userId);
  982. $turnoff = two_dispatch_off($this->orgId);
  983. $this->assign('level1', $level1);
  984. $this->assign('level2', $level2);
  985. $this->assign('turnoff', $turnoff);
  986. $this->assign('dispatch_type', $level2);
  987. return $this->fetch();
  988. }
  989. }