Index.php 42 KB

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