0
0

Index.php 41 KB

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