Log.php 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Description: 日志统计
  4. // +----------------------------------------------------------------------
  5. // | Author: zhi | zhijunfu@5kcrm.com
  6. // +----------------------------------------------------------------------
  7. namespace app\bi\model;
  8. use think\Db;
  9. use app\admin\model\Common;
  10. use think\Request;
  11. use app\admin\model\User as UserModel;
  12. class Log extends Common
  13. {
  14. /**
  15. * 为了数据库的整洁,同时又不影响Model和Controller的名称
  16. * 我们约定每个模块的数据表都加上相同的前缀,比如CRM模块用crm作为数据表前缀
  17. */
  18. protected $name = 'oa_log';
  19. /**
  20. * [getDataList 日志统计]
  21. * @author Michael_xu
  22. * @param
  23. * @return
  24. */
  25. public function getStatistics($param)
  26. {
  27. //时间
  28. $start_time = $param['start_time'] ? : strtotime(date('Y-m-d',time()));
  29. $end_time = $param['end_time'] ? : strtotime(date('Y-m-d',time()))+86399;
  30. $create_time = array('between',array($start_time,$end_time));
  31. $where = ['type' => 1];
  32. getWhereUserByParam($where, 'id');
  33. $userList = UserModel::where($where)
  34. ->field(['id','username','realname'])
  35. ->select();
  36. foreach ($userList as $k=>$v) {
  37. $log_list = [];
  38. $count = 0; //填写数
  39. $unReadCont = 0; //接收人未读数
  40. $unCommentCount = 0; //未评论数
  41. $commentCount = 0; //已评论数
  42. $log_list = $this->where(['create_time' => $create_time,'create_user_id' => $v['id']])->field('send_user_ids,read_user_ids,log_id')->select();
  43. $count = count($log_list);
  44. if ($log_list) {
  45. //获取评论过的日志id集合
  46. $w_c['ac.type'] = 'oa_log';
  47. $log_ids = $this->alias('l')
  48. ->join('AdminComment ac', 'ac.type_id = l.log_id', 'LEFT')
  49. ->where($w_c)
  50. ->group('l.log_id')
  51. ->column('log_id');
  52. foreach ($log_list as $key=>$val) {
  53. if (stringToArray($val['send_user_ids']) && !array_intersect(stringToArray($val['send_user_ids']),stringToArray($val['read_user_ids']))) {
  54. $unReadCont += 1;
  55. }
  56. //判断日志id是否在评论过的id集合内
  57. if (in_array($val['log_id'], $log_ids) ) {
  58. $commentCount += 1;
  59. } else {
  60. $unCommentCount += 1;
  61. }
  62. }
  63. }
  64. $userList[$k]['count'] = $count;
  65. $userList[$k]['unReadCont'] = $unReadCont;
  66. $userList[$k]['unCommentCount'] = $unCommentCount;
  67. $userList[$k]['commentCount'] = $commentCount;
  68. }
  69. return $userList ? : [];
  70. }
  71. }