Repair.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <?php
  2. namespace app\api\controller\screen;
  3. use app\hander\HelpHander;
  4. use app\api\controller\screen\Index;
  5. use think\Db;
  6. class Repair extends Index
  7. {
  8. public function todoCountData(){
  9. $count = Db::name('todo')
  10. ->where('org_id',$this->orgId)
  11. ->where('work_type_mode',1)
  12. ->where('create_yyyymmdd',date('Ymd'))
  13. ->where('del',0)
  14. ->count();
  15. $count2 = Db::name('todo')
  16. ->where('org_id',$this->orgId)
  17. ->where('work_type_mode',1)
  18. ->where('create_yyyymmdd',date('Ymd'))
  19. ->where('del',0)
  20. ->where('todo_mode',3)
  21. ->count();
  22. $bl = 100;
  23. if($count > 0 ){
  24. $bl = round($count2/$count*100,1);
  25. }
  26. $user = model('WorkTypeMode')->getRolesUserApp(1,$this->orgId);
  27. $count3 = count($user);
  28. $count4 = Db::name('todo')
  29. ->where('org_id',$this->orgId)
  30. ->where('work_type_mode',1)
  31. ->where('create_yyyymmdd',date('Ymd'))
  32. ->where('del',0)
  33. ->where('todo_mode',3)
  34. ->avg('xy_time');
  35. $count5 = Db::name('todo')
  36. ->where('org_id',$this->orgId)
  37. ->where('work_type_mode',1)
  38. ->where('create_yyyymmdd',date('Ymd'))
  39. ->where('del',0)
  40. ->where('todo_mode',3)
  41. ->avg('wc_time');
  42. $data = [
  43. 'count'=>$count,
  44. 'count2'=>$count3,
  45. 'count3'=>round($count4/3600,1),
  46. 'count4'=>round($count5/3600,1),
  47. 'bl'=>$bl,
  48. ];
  49. HelpHander::success($data);
  50. }
  51. //维修订单数据状态分析、
  52. public function wxOrderStatus(){
  53. $orderMode = [
  54. ['name'=>'待派工','value'=>1],
  55. ['name'=>'已取消','value'=>[2,3]],
  56. ['name'=>'进行中','value'=>4],
  57. ['name'=>'已完成','value'=>5],
  58. ['name'=>'已评价','value'=>6],
  59. ];
  60. $list = [];
  61. foreach ($orderMode as $k=>$v){
  62. $list[$k]['name'] = $v['name'];
  63. $list[$k]['value'] = Db::name('orders')
  64. ->where('work_type_mode',1)
  65. ->where('org_id',$this->orgId)
  66. ->where('del',0)
  67. // ->where('create_yyyymmdd',date('Ymd'))
  68. ->whereIn('order_mode',$v['value'])
  69. ->count();
  70. }
  71. HelpHander::success($list);
  72. }
  73. //维修工单周分析
  74. public function wxWeekTodo(){
  75. $dlist = [
  76. date('Ymd',strtotime('-6 days')),
  77. date('Ymd',strtotime('-5 days')),
  78. date('Ymd',strtotime('-4 days')),
  79. date('Ymd',strtotime('-3 days')),
  80. date('Ymd',strtotime('-2 days')),
  81. date('Ymd',strtotime('-1 days')),
  82. date('Ymd'),
  83. ];
  84. $title = $list = $list2 = [];
  85. foreach ($dlist as $k=>$v){
  86. $title[] = date('m-d',strtotime($v));
  87. $list[] = Db::name('todo')
  88. ->where('work_type_mode',1)
  89. ->where('org_id',$this->orgId)
  90. ->where('del',0)
  91. ->where('create_yyyymmdd',$v)
  92. ->count();
  93. $list2[] = Db::name('todo')
  94. ->where('work_type_mode',1)
  95. ->where('org_id',$this->orgId)
  96. ->where('del',0)
  97. ->where('create_yyyymmdd',$v)
  98. ->where('todo_mode',3)
  99. ->count();
  100. }
  101. $data = [
  102. 'title'=>$title,
  103. 'list'=>$list,
  104. 'list2'=>$list2,
  105. ];
  106. HelpHander::success($data);
  107. }
  108. public function wxUserStatus(){
  109. $lists = model('WorkTypeMode')->getRolesUserApp(1,$this->orgId);
  110. $curday = date('Ymd');
  111. $users = Db::name('todo')
  112. ->field('to_user_id')
  113. ->where('org_id',$this->orgId)
  114. ->whereIn('todo_mode',[1,2])
  115. ->where('work_type_mode',1)
  116. ->where('del',0)
  117. ->where('create_yyyymmdd',$curday)
  118. ->group('to_user_id')
  119. ->order('id desc')
  120. ->select();
  121. $users = $users?$users:[];
  122. $userIds = [];
  123. foreach ($users as $k=>$v){
  124. $userIds[] = $v['to_user_id'];
  125. }
  126. $nlists = $nlists2 = [];
  127. foreach ($lists as $k=>$v){
  128. if(!in_array($v['id'],$userIds)){
  129. $nlists[] = $v;
  130. }
  131. }
  132. $slist = $slist2 = [];
  133. foreach ($nlists as $k=>$v){
  134. $count = Db::name('todo')
  135. ->where('org_id',$this->orgId)
  136. ->where('to_user_id',$v['id'])
  137. ->whereIn('todo_mode',[1,2,3])
  138. ->where('del',0)
  139. ->where('create_yyyymmdd',$curday)
  140. ->where('work_type_mode',1)
  141. ->count();
  142. $addr = Db::name('todo')
  143. ->alias('t')
  144. ->join('order_repair or','t.order_id=or.order_id')
  145. ->join('address a','a.id=or.address_id')
  146. ->where('t.to_user_id',$v['id'])
  147. ->whereIn('t.todo_mode',[1,2,3])
  148. ->where('t.del',0)
  149. ->where('t.create_yyyymmdd',$curday)
  150. ->where('t.work_type_mode',1)
  151. ->order('t.id desc')
  152. ->value('a.title');
  153. $slist[$k][] = '<span style="color: #FFE400">'.$v['real_name'].'</span>';
  154. $slist[$k][] = '<span style="color: #FFE400">'.$count.'</span>';
  155. $slist[$k][] = '<span style="color: #FFE400">'.$addr.'</span>';
  156. }
  157. foreach ($lists as $k=>$v){
  158. if(in_array($v['id'],$userIds)){
  159. $nlists2[] = $v;
  160. }
  161. }
  162. foreach ($nlists2 as $k=>$v){
  163. $count = Db::name('todo')
  164. ->where('org_id',$this->orgId)
  165. ->where('to_user_id',$v['id'])
  166. ->whereIn('todo_mode',[1,2,3])
  167. ->where('del',0)
  168. ->where('create_yyyymmdd',$curday)
  169. ->count();
  170. $addr = Db::name('todo')
  171. ->alias('t')
  172. ->join('order_repair or','t.order_id=or.order_id')
  173. ->join('address a','a.id=or.address_id')
  174. ->where('t.to_user_id',$v['id'])
  175. ->whereIn('t.todo_mode',[1,2,3])
  176. ->where('t.del',0)
  177. ->where('t.create_yyyymmdd',$curday)
  178. ->where('t.work_type_mode',1)
  179. ->order('t.id desc')
  180. ->value('a.title');
  181. $slist2[$k][] = '<span style="color: #11E799">'.$v['real_name'].'</span>';
  182. $slist2[$k][] = '<span style="color: #11E799">'.$count.'</span>';
  183. $slist2[$k][] = '<span style="color: #11E799">'.$addr.'</span>';
  184. }
  185. $data = [
  186. 'list'=>[
  187. 'list'=>$slist,
  188. 'count'=>count($slist),
  189. ],
  190. 'list2'=>[
  191. 'list'=>$slist2,
  192. 'count'=>count($slist2),
  193. ],
  194. ];
  195. HelpHander::success($data);
  196. }
  197. public function wxTodoData(){
  198. $list = Db::name('todo')
  199. ->field('id,order_id,todo_mode,create_time,to_user_id')
  200. ->where('org_id',$this->orgId)
  201. ->whereIn('todo_mode',[1,2,3])
  202. ->where('del',0)
  203. // ->where('create_yyyymmdd',date('Ymd'))
  204. ->where('work_type_mode',1)
  205. ->limit(20)
  206. ->order('id desc')
  207. ->select();
  208. foreach ($list as $k=>$v){
  209. if($v['todo_mode'] == 1){
  210. $list[$k]['status'] = '新任务';
  211. }elseif ($v['todo_mode'] == 2){
  212. $list[$k]['status'] = '进行中';
  213. }elseif ($v['todo_mode'] == 3){
  214. $list[$k]['status'] = '已完成';
  215. }
  216. $repair = Db::name('order_type')
  217. ->alias('ot')
  218. ->field('ot.id,ot.title,ot.parent_id')
  219. ->join('order_repair or','or.type_id=ot.id')
  220. ->where('or.order_id',$v['order_id'])
  221. ->find();
  222. $list[$k]['cate_title'] = Db::name('order_type')->where('id',$repair['parent_id'])->value('title');
  223. $list[$k]['address'] = Db::name('address')
  224. ->alias('a')
  225. ->join('order_repair or','or.address_id=a.id')
  226. ->where('or.order_id',$v['order_id'])
  227. ->where('a.org_id',$this->orgId)
  228. ->value('a.title');
  229. $list[$k]['create_time'] = date('H:i',strtotime($v['create_time']));
  230. $list[$k]['user_name'] = Db::name('user')->where('id',$v['to_user_id'])->value('real_name');
  231. }
  232. $data = [];
  233. foreach ($list as $k=>$v){
  234. if($v['todo_mode'] == 1){
  235. $data[$k][] = $v['status'];
  236. $data[$k][] = $v['cate_title'];
  237. $data[$k][] = $v['address'];
  238. $data[$k][] = $v['create_time'];
  239. $data[$k][] = $v['user_name'];
  240. }elseif ($v['todo_mode'] == 2){
  241. $data[$k][] = '<span style="color:#0FC2DD;">'.$v['status'].'</span>';
  242. $data[$k][] = '<span style="color:#0FC2DD;">'.$v['cate_title'].'</span>';
  243. $data[$k][] = '<span style="color:#0FC2DD;">'.$v['address'].'</span>';
  244. $data[$k][] = '<span style="color:#0FC2DD;">'.$v['create_time'].'</span>';
  245. $data[$k][] = '<span style="color:#0FC2DD;">'.$v['user_name'].'</span>';
  246. }elseif ($v['todo_mode'] == 3){
  247. $data[$k][] = '<span style="color:#2E73D1 ;">'.$v['status'].'</span>';
  248. $data[$k][] = '<span style="color:#2E73D1;">'.$v['cate_title'].'</span>';
  249. $data[$k][] = '<span style="color:#2E73D1;">'.$v['address'].'</span>';
  250. $data[$k][] = '<span style="color:#2E73D1;">'.$v['create_time'].'</span>';
  251. $data[$k][] = '<span style="color:#2E73D1;">'.$v['user_name'].'</span>';
  252. }
  253. }
  254. HelpHander::success($data);
  255. }
  256. public function wxCateData(){
  257. $type = Db::name('order_type')
  258. ->field('id,title as name')
  259. ->where('org_id',$this->orgId)
  260. ->where('del',0)
  261. ->where('enable',1)
  262. ->where('parent_id',0)
  263. ->select();
  264. foreach ($type as $k=>$v){
  265. //获取类型下的报修事项
  266. $cc = Db::name('order_type')
  267. ->where('parent_id',$v['id'])
  268. ->where('del',0)
  269. ->where('enable',1)
  270. ->column('id');
  271. $type[$k]['value'] = Db::name('todo')
  272. ->alias('t')
  273. ->join('order_repair or','or.order_id=t.order_id')
  274. ->whereIn('or.type_id',$cc)
  275. ->where('t.del',0)
  276. ->where('t.org_id',$this->orgId)
  277. ->where('t.todo_mode',3)
  278. ->where('t.work_type_mode',1)
  279. ->where('t.create_yyyymmdd',date('Ymd'))
  280. ->count();
  281. unset($type[$k]['id']);
  282. }
  283. $list = array_slice(list_sort_by($type,'value','desc'),0,6);
  284. HelpHander::success($list);
  285. }
  286. public function wxMateItemData(){
  287. $type = input('type',1); // 1=月
  288. if($type == 1){
  289. $where[] = ['create_time','>=',date('Y-m').'-01 00:00:00'];
  290. $where[] = ['create_time','<=',date('Y-m').'-31 00:00:00'];
  291. }else{
  292. $where[] = ['create_time','>=',date('Y').'-01-01 00:00:00'];
  293. $where[] = ['create_time','<=',date('Y').'-12-31 00:00:00'];
  294. }
  295. $list = Db::name('mate_goods')
  296. ->field('id,title')
  297. ->where('org_id',$this->orgId)
  298. ->where('del',0)
  299. ->where('enable',1)
  300. ->limit(6)
  301. ->select();
  302. $title = $count = [];
  303. foreach ($list as $k=>$v){
  304. $title[]= $v['title'];
  305. $nums = Db::name('todo_mate_item')
  306. ->where('items_id',$v['id'])
  307. ->where($where)
  308. ->sum('total');
  309. $count[] = $nums;
  310. }
  311. $data = [
  312. 'list'=>$count,
  313. 'title'=>$title,
  314. ];
  315. HelpHander::success($data);
  316. }
  317. public function wxDepData(){
  318. $date = date('Ymd');
  319. $edate = date('Ymd',strtotime("-1 months",strtotime($date)));
  320. $dep = Db::name('dep')
  321. ->field('id,title')
  322. ->where('org_id',$this->orgId)
  323. ->where('del',0)
  324. ->where('enable',1)
  325. ->limit(6)
  326. ->select();
  327. $title = $count = $count2 = [];
  328. foreach ($dep as $k=>$v){
  329. $title[] =$v['title'];
  330. $count[] = Db::name('orders')
  331. ->alias('o')
  332. ->join('todo t','t.order_id=o.id')
  333. ->where('o.dep_id',$v['id'])
  334. ->where('t.work_type_mode',1)
  335. ->where('t.create_yyyymmdd',$date)
  336. ->where('t.del',0)
  337. ->where('t.org_id',$this->orgId)
  338. ->count();
  339. $nums= Db::name('orders')
  340. ->alias('o')
  341. ->join('todo t','t.order_id=o.id')
  342. ->where('o.dep_id',$v['id'])
  343. ->where('t.work_type_mode',1)
  344. ->where('t.create_yyyymmdd','<=',$date)
  345. ->where('t.create_yyyymmdd','>=',$edate)
  346. ->where('t.del',0)
  347. ->where('t.org_id',$this->orgId)
  348. ->count();
  349. $count2[] = round($nums/30,1);
  350. }
  351. $data =[
  352. 'title' =>$title,
  353. 'list' =>$count,
  354. 'list2' =>$count2,
  355. ];
  356. HelpHander::success($data);
  357. }
  358. }