Index.php 40 KB

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