0
0

Headoffice.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\CleanTask;
  4. use app\common\model\Daily;
  5. use app\common\model\DailyTask;
  6. use app\common\model\DeviceTask;
  7. use app\common\model\PatrolTask;
  8. use app\common\util\AppMsg;
  9. use app\hander\HelpHander;
  10. use think\Controller;
  11. use think\Db;
  12. class Headoffice extends Controller
  13. {
  14. public function orgCount(){
  15. $date = date('Ymd');
  16. $todoCount = Db::name('todo')
  17. ->where('create_yyyymmdd',$date)
  18. ->where('del',0)
  19. ->count();
  20. $userCount = Db::name('user')
  21. ->where('del',0)
  22. ->where('type',0)
  23. ->count();
  24. $orgCount = Db::name('org')
  25. ->where('enable',1)
  26. ->where('del',0)
  27. ->where('type',2)
  28. ->count();
  29. $map[] = ['u.del','=',0];
  30. $roles = Db::name('roles')
  31. ->where('parent_id',11)
  32. ->where('del',0)
  33. ->where('enable',1)
  34. ->column('id');
  35. if(empty($roles)){
  36. $escortCount = 0;
  37. }else{
  38. $map[] = ['r.roles_id','in',$roles];
  39. $escortCount = Db::name('worker')
  40. ->alias('a')
  41. ->join('user u','a.user_id=u.id')
  42. ->join('user_org o','a.user_id=o.user_id')
  43. ->join('user_roles r','a.user_id=r.user_id')
  44. ->field('u.real_name,u.mobile,u.create_time,u.head_image,a.*')
  45. ->where($map)
  46. ->count();
  47. }
  48. //今日完成
  49. $todoCount1 =Db::name('todo')
  50. ->where('create_yyyymmdd',$date)
  51. ->where('create_yyyymmdd',$date)
  52. ->where('todo_mode',3)
  53. ->where('del',0)
  54. ->count();
  55. $todoCount2 = $todoCount - $todoCount1 ;
  56. $bl = $todoCount>0?round($todoCount1/$todoCount*100,0):0;
  57. $data = [
  58. 'todoCount'=>$todoCount,
  59. 'userCount'=>$userCount,
  60. 'orgCount'=>$orgCount,
  61. 'escortCount'=>$escortCount,
  62. 'todoCompletion'=>$bl.'%',];
  63. HelpHander::success($data);
  64. }
  65. public function todoCompletion(){
  66. $date = date('Ymd');
  67. $todoCount = Db::name('todo')
  68. ->where('create_yyyymmdd',$date)
  69. ->where('del',0)
  70. ->count();
  71. $todoCount1 = Db::name('todo')
  72. ->where('create_yyyymmdd',$date)
  73. ->where('create_yyyymmdd',$date)
  74. ->where('todo_mode',3)
  75. ->where('del',0)
  76. ->count();
  77. $todoCount2 = $todoCount - $todoCount1 ;
  78. $data = [
  79. ['name'=>'已完成','value'=>$todoCount1],
  80. ['name'=>'未完成','value'=>$todoCount2>0?$todoCount2:0],
  81. ];
  82. HelpHander::success($data);
  83. }
  84. public function userCount(){
  85. $org= Db::name('org')
  86. ->field('id,name')
  87. ->where('enable',1)
  88. ->where('del',0)
  89. ->where('type',2)
  90. ->select();
  91. foreach ($org as $k=>$v){
  92. $org[$k]['value'] = Db::name('user')
  93. ->alias('u')
  94. ->join('user_org uo','uo.user_id=u.id')
  95. ->where('uo.org_id',$v['id'])
  96. ->where('u.enable',1)
  97. ->where('u.del',0)
  98. ->count();
  99. }
  100. HelpHander::success($org);
  101. }
  102. //满意度排名
  103. public function orgRanking(){
  104. $org= Db::name('org')
  105. ->field('id,name')
  106. ->where('enable',1)
  107. ->where('del',0)
  108. ->where('type',2)
  109. ->select();
  110. foreach ($org as $k=>$v){
  111. $score = Db::name('comment')
  112. ->where('org_id',$v['id'])
  113. ->select();
  114. $num = 0;
  115. foreach ($score as $kk=>$vv){
  116. $num +=$vv['score'];
  117. }
  118. $org[$k]['score'] = $num;
  119. }
  120. $column = array_column($org,'score');
  121. array_multisort($column,SORT_DESC,$org);
  122. $data = array_slice($org,0,3);
  123. HelpHander::success($data);
  124. }
  125. public function orgList(){
  126. $org= Db::name('org')
  127. ->field('id as org_id,name,lat,lng')
  128. ->where('enable',1)
  129. ->where('del',0)
  130. ->where('type',2)
  131. ->select();
  132. HelpHander::success($org);
  133. }
  134. //各项目医废统计
  135. public function wasteCount(){
  136. $month = date('Ym');
  137. $year= date('Y');
  138. $org= Db::name('org')
  139. ->field('id,name')
  140. ->where('enable',1)
  141. ->where('del',0)
  142. ->where('type',2)
  143. ->select();
  144. foreach ($org as $k=>$v){
  145. $count =Db::name('waste_record')
  146. ->where('org_id',$v['id'])
  147. ->where('create_yyyymm',$month)
  148. ->where('del',0)
  149. ->select();
  150. $count2 = Db::name('waste_record')
  151. ->where('org_id',$v['id'])
  152. ->where('create_yyyy',$year)
  153. ->where('del',0)
  154. ->select();
  155. $num = 0;
  156. $num2 = 0;
  157. foreach ($count as $kk=>$vv){
  158. $num +=$vv['weight'];
  159. }
  160. foreach ($count2 as $kay=>$val){
  161. $num2 +=$val['weight'];
  162. }
  163. $org[$k]['month_weight'] = $num / 1000;
  164. $org[$k]['year_weight'] = $num2 / 1000;
  165. }
  166. $data = [
  167. 'x'=>array_column($org,'name'),
  168. 'y'=>array_column($org,'month_weight'),
  169. 'y2'=>array_column($org,'year_weight'),
  170. ];
  171. HelpHander::success($data);
  172. }
  173. //各项目工单统计
  174. public function todoCount(){
  175. $month = date('Ym');
  176. $org= Db::name('org')
  177. ->field('id,name')
  178. ->where('enable',1)
  179. ->where('del',0)
  180. ->where('type',2)
  181. ->select();
  182. foreach ($org as $k=>$v){
  183. $org[$k]['count'] = Db::name('todo')
  184. ->where('org_id',$v['id'])
  185. ->where('create_yyyymm',$month)
  186. ->where('del',0)
  187. ->count();
  188. }
  189. HelpHander::success($org);
  190. }
  191. //各项目陪护单统计
  192. public function phCount(){
  193. $month = date('Ym');
  194. $year= date('Y');
  195. $org= Db::name('org')
  196. ->field('id,name')
  197. ->where('enable',1)
  198. ->where('del',0)
  199. ->where('type',2)
  200. ->select();
  201. foreach ($org as $k=>$v){
  202. $count =Db::name('ph_orders')
  203. ->where('org_id',$v['id'])
  204. ->where('create_time','>=',beginMonth())
  205. ->where('create_time','<=',endMonth())
  206. ->count();
  207. $count2 = Db::name('waste_record')
  208. ->where('org_id',$v['id'])
  209. ->where('create_time','>=',beginYear())
  210. ->where('create_time','<=',endYear())
  211. ->count();
  212. $org[$k]['month_weight'] = $count;
  213. $org[$k]['year_weight'] = $count2;
  214. }
  215. $data = [
  216. 'x'=>array_column($org,'name'),
  217. 'y'=>array_column($org,'month_weight'),
  218. 'y2'=>array_column($org,'year_weight'),
  219. ];
  220. HelpHander::success($data);
  221. }
  222. public function todoTimeLength(){
  223. $org= Db::name('org')
  224. ->field('id,name')
  225. ->where('enable',1)
  226. ->where('del',0)
  227. ->where('type',2)
  228. ->select();
  229. foreach ($org as $k=>$v){
  230. $num = Db::name('todo')
  231. ->where('org_id',$v['id'])
  232. ->where('del',0)
  233. ->sum('xy_time');
  234. $num2 = Db::name('todo')
  235. ->where('org_id',$v['id'])
  236. ->where('del',0)
  237. ->sum('wc_time');
  238. $org[$k]['xy_time'] = round($num/60,1);
  239. $org[$k]['wc_time'] = round($num2/60,1);
  240. }
  241. $data = [
  242. 'x'=>array_column($org,'name'),
  243. 'y'=>array_column($org,'xy_time'),
  244. 'y2'=>array_column($org,'wc_time'),
  245. ];
  246. HelpHander::success($data);
  247. }
  248. //巡查图片
  249. public function patrolImg(){
  250. $data = Db::name('patrol_record')
  251. ->where('patrol_mode',3)
  252. ->where('images','<>','')
  253. ->where('org_id',cur_org_id())
  254. ->limit(20)
  255. ->select();
  256. foreach ($data as $k=>$v){
  257. $img = explode(',',$v['images']);
  258. if($img){
  259. $data[$k]['images'] = $img[0];
  260. }
  261. }
  262. if(count($data)>3){
  263. $key = array_rand($data,4);
  264. $list[] = $data[$key[0]];
  265. $list[] = $data[$key[1]];
  266. $list[] = $data[$key[2]];
  267. $list[] = $data[$key[3]];
  268. }
  269. $eList = isset($list)?$list:$data;
  270. HelpHander::success($eList);
  271. }
  272. //
  273. public function patrolRecordCount(){
  274. $dlist = [
  275. date('Y-m-d',strtotime('-6 days')),
  276. date('Y-m-d',strtotime('-5 days')),
  277. date('Y-m-d',strtotime('-4 days')),
  278. date('Y-m-d',strtotime('-3 days')),
  279. date('Y-m-d',strtotime('-2 days')),
  280. date('Y-m-d',strtotime('-1 days')),
  281. date('Y-m-d'),
  282. ];
  283. $date = [];
  284. $yCount = [];
  285. $y2Count = [];
  286. $y3Count = [];
  287. foreach ($dlist as $k=>$v){
  288. $tt = date('Ymd',strtotime($v));
  289. $count = Db::name('patrol_record')
  290. ->where('create_yyyymmdd',$tt)
  291. ->where('org_id',cur_org_id())
  292. ->where('patrol_mode',4)
  293. ->count();
  294. $count2 =Db::name('patrol_record')
  295. ->where('create_yyyymmdd',$tt)
  296. ->where('org_id',cur_org_id())
  297. ->where('patrol_mode',2)
  298. ->count();
  299. $count3 =Db::name('patrol_record')
  300. ->where('create_yyyymmdd',$tt)
  301. ->where('org_id',cur_org_id())
  302. ->where('patrol_mode',3)
  303. ->count();
  304. $date[] = date('m-d',strtotime($v));
  305. $yCount[] = $count;
  306. $y2Count[] = $count2;
  307. $y3Count[] = $count3;
  308. }
  309. $data = [
  310. 'date'=>$date,
  311. 'count1'=>$yCount,
  312. 'count2'=>$y2Count,
  313. 'count3'=>$y3Count,
  314. ];
  315. HelpHander::success($data);
  316. }
  317. }