0
0

Daily.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <?php
  2. namespace app\api\controller\screen;
  3. use app\api\controller\screen\Index;
  4. use app\hander\HelpHander;
  5. use think\Db;
  6. class Daily extends Index
  7. {
  8. public function taskCount(){
  9. $count = Db::name('daily_task')
  10. ->where('org_id',$this->orgId)
  11. ->where('del',0)
  12. ->count();
  13. $task = Db::name('daily_task')
  14. ->where('org_id',$this->orgId)
  15. ->where('status',2)
  16. ->where('del',0)
  17. ->count();
  18. $recordIds = Db::name('comment')
  19. ->where('org_id',$this->orgId)
  20. ->where('type',0)
  21. ->where('score','<',3)
  22. ->column('from_id');
  23. $taskIds = Db::name('daily_record')
  24. ->where('org_id',$this->orgId)
  25. ->whereIn('id',$recordIds)
  26. ->group('task_id')
  27. ->column('task_id');
  28. $taskCount = Db::name('daily_task')
  29. ->where('org_id',$this->orgId)
  30. ->whereIn('id',$taskIds)
  31. ->where('del',0)
  32. ->where('status',2)
  33. ->count();
  34. //合格数
  35. $nums2 = $count - $taskCount;
  36. $total = $total2 = 0;
  37. if($count > 0){
  38. $total = round($task/$count*100,0);
  39. $total2 = round($nums2/$count*100,0);
  40. }
  41. $data = [
  42. 'list'=>['count'=>$total,'nums'=>$task],
  43. 'list2'=>['count'=>$total2,'nums'=>$nums2],
  44. ];
  45. HelpHander::success($data);
  46. }
  47. //近7日检查情况概览
  48. public function checkNums(){
  49. $dlist = [
  50. date('Ymd',strtotime('-6 days')),
  51. date('Ymd',strtotime('-5 days')),
  52. date('Ymd',strtotime('-4 days')),
  53. date('Ymd',strtotime('-3 days')),
  54. date('Ymd',strtotime('-2 days')),
  55. date('Ymd',strtotime('-1 days')),
  56. date('Ymd'),
  57. ];
  58. $date = $list =$list2 = [];
  59. foreach ($dlist as $k=>$v){
  60. $date[] = date('m-d',strtotime($v));
  61. $tt = date('Ymd',strtotime($v));
  62. $count = Db::name('comment')
  63. ->where('org_id',$this->orgId)
  64. ->where('create_yyyymmdd',$tt)
  65. ->where('type',0)
  66. ->count();
  67. $count2 = Db::name('comment')
  68. ->where('org_id',$this->orgId)
  69. ->where('create_yyyymmdd',$tt)
  70. ->where('type',0)
  71. ->avg('score');
  72. $list[$k]= $count;
  73. $list2[$k] = $count2;
  74. }
  75. $data = [
  76. 'title'=>$date,
  77. 'list'=>[
  78. 'list1'=>$list,
  79. 'list2'=>$list2,
  80. ]
  81. ];
  82. HelpHander::success($data);
  83. }
  84. //员工排行榜
  85. public function userRanking(){
  86. $user = Db::name('daily_record')
  87. ->alias('dr')
  88. ->field('u.real_name,dr.user_id')
  89. ->join('user u','u.id=dr.user_id')
  90. ->where('dr.org_id',$this->orgId)
  91. ->group('dr.user_id')
  92. ->select();
  93. $list = [];
  94. foreach ($user as $k=>$v){
  95. $list[$k]['count'] = Db::name('daily_record')
  96. ->where('user_id',$v['user_id'])
  97. ->where('org_id',$this->orgId)
  98. ->count();
  99. $list[$k]['user_name'] = $v['real_name'];
  100. }
  101. $newList =array_slice(list_sort_by($list,'count','desc'),0,7) ;
  102. $data = [];
  103. foreach ($newList as $k=>$v){
  104. if($k == 0){
  105. $data[$k][] = '<img src="'.config("app.app_host").'/img/top1.png" style="width: 100%;height: 100%" />';
  106. }
  107. if($k == 1){
  108. $data[$k][] = '<img src="'.config("app.app_host").'/img/top2.png" style="width: 100%;height: 100%" />';
  109. }
  110. if($k == 2){
  111. $data[$k][] = '<img src="'.config("app.app_host").'/img/top3.png" style="width: 100%;height: 100%" />';
  112. }
  113. if($k == 3){
  114. $data[$k][] = '<img src="'.config("app.app_host").'/img/top4.png" style="width: 100%;height: 100%" />';
  115. }
  116. if($k == 4){
  117. $data[$k][] = '<img src="'.config("app.app_host").'/img/top5.png" style="width: 100%;height: 100%" />';
  118. }
  119. if($k == 5){
  120. $data[$k][] = '<img src="'.config("app.app_host").'/img/top6.png" style="width: 100%;height: 100%" />';
  121. }
  122. if($k == 6){
  123. $data[$k][] = '<img src="'.config("app.app_host").'/img/top7.png" style="width: 100%;height: 100%" />';
  124. }
  125. $data[$k][] = $v['user_name'];
  126. $data[$k][] = $v['count'];
  127. }
  128. HelpHander::success($data);
  129. }
  130. public function dailyStatus(){
  131. $lists = model('WorkTypeMode')->getRolesUserApp(9,$this->orgId);
  132. $curday = date('Ymd');
  133. $users = Db::name('daily_record')
  134. ->alias('dr')
  135. ->field('dr.user_id')
  136. ->join('daily_task dt','dt.id=dr.task_id')
  137. ->where('dt.del',0)
  138. ->where('dr.create_yyyymmdd',$curday)
  139. ->where('dt.status',1)
  140. ->where('dr.org_id',$this->orgId)
  141. ->group('dr.user_id')
  142. ->select();
  143. $users = $users?$users:[];
  144. $userIds = [];
  145. foreach ($users as $k=>$v){
  146. $userIds[] = $v['user_id'];
  147. }
  148. $nlists = $nlists2 = [];
  149. foreach ($lists as $k=>$v){
  150. if(!in_array($v['id'],$userIds)){
  151. $nlists[] = $v;
  152. }
  153. }
  154. //待命中的
  155. $slist = $slist2 = [];
  156. foreach ($nlists as $k=>$v){
  157. $count = Db::name('daily_record')
  158. ->where('org_id',$this->orgId)
  159. ->where('user_id',$v['id'])
  160. ->where('create_yyyymmdd',$curday)
  161. ->count();
  162. $addr = Db::name('daily_record')
  163. ->alias('dr')
  164. ->join('daily d','d.id=dr.daily_id')
  165. ->where('dr.org_id',$this->orgId)
  166. ->where('dr.user_id',$v['id'])
  167. ->where('dr.create_yyyymmdd',$curday)
  168. ->value('d.title');
  169. $slist[$k][] = '<span style="color: #2A88F7">'.$v['real_name'].'</span>';
  170. $slist[$k][] = '<span style="color: #2A88F7">'.$count.'</span>';
  171. $slist[$k][] = '<span style="color: #2A88F7">'.$addr.'</span>';
  172. }
  173. //任务中的
  174. foreach ($lists as $k=>$v){
  175. if(in_array($v['id'],$userIds)){
  176. $nlists2[] = $v;
  177. }
  178. }
  179. foreach ($nlists2 as $k=>$v){
  180. $count = Db::name('daily_record')
  181. ->where('org_id',$this->orgId)
  182. ->where('user_id',$v['id'])
  183. ->where('create_yyyymmdd',$curday)
  184. ->count();
  185. $addr = Db::name('daily_record')
  186. ->alias('dr')
  187. ->join('daily d','d.id=dr.daily_id')
  188. ->where('dr.org_id',$this->orgId)
  189. ->where('dr.user_id',$v['id'])
  190. ->where('dr.create_yyyymmdd',$curday)
  191. ->value('d.title');
  192. $slist2[$k][] = '<span style="color: #2DF8F5">'.$v['real_name'].'</span>';
  193. $slist2[$k][] = '<span style="color: #2DF8F5">'.$count.'</span>';
  194. $slist2[$k][] = '<span style="color: #2DF8F5">'.$addr.'</span>';
  195. }
  196. $data = [
  197. 'list1'=>[
  198. 'list'=>$slist2,
  199. 'count'=>count($slist2),
  200. ],// 任务中
  201. 'list2'=>[
  202. 'list'=>$slist,
  203. 'count'=>count($slist),
  204. ],// 待命中
  205. ];
  206. HelpHander::success($data);
  207. }
  208. public function taskRecordOne(){
  209. $map[] = ['enable', '=', 1];
  210. $map[] = ['org_id', '=', $this->orgId];
  211. $map[] = ['del', '=', 0];
  212. $lists = Db::name('daily')->where($map)->field('id,title')->order('id desc')->select();
  213. $hours = model('Daily')->getTimeDaily($this->orgId);
  214. foreach ($lists as $k=>$v){
  215. $m = [];
  216. $m[] = ['org_id','=',$this->orgId];
  217. $m[] = ['daily_id','=',$v['id']];
  218. $m[] = ['create_time','>=',$hours['start']];
  219. $m[] = ['create_time','<',$hours['end']];
  220. $count = Db::name('daily_record')->where($m)->count();
  221. $lists[$k]['count'] = $count;
  222. }
  223. HelpHander::success($lists);
  224. }
  225. public function recordList(){
  226. $list = Db::name('daily_record')
  227. ->field('task_id,user_id,create_time,daily_id')
  228. ->where('create_yyyymmdd',date('Ymd'))
  229. ->where('org_id',$this->orgId)
  230. ->order('id desc')
  231. ->select();
  232. $data = [];
  233. foreach ($list as $k=>$v){
  234. $data[$k][] = Db::name('daily')->where('id',$v['daily_id'])->value('title');
  235. $data[$k][] = Db::name('user')->where('id',$v['user_id'])->value('real_name');
  236. $data[$k][] = date('m-d H:i:s',strtotime($v['create_time']));
  237. }
  238. HelpHander::success($data);
  239. }
  240. }