logModel.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. class logClassModel extends Model
  3. {
  4. public function addlog($type='', $remark='', $sarr=array())
  5. {
  6. $arr['type'] = $type;
  7. $arr['ip'] = $this->rock->ip;
  8. $arr['web'] = $this->rock->web;
  9. $arr['optdt'] = $this->rock->now();
  10. $arr['optid'] = $this->adminid;
  11. $arr['optname'] = $this->adminname;
  12. $arr['remark'] = $remark;
  13. //$arr['url'] = $this->rock->nowurl();//不记录这个没用
  14. foreach($sarr as $k=>$v)$arr[$k]=$v;
  15. return $this->insert($arr);
  16. }
  17. /**
  18. * 添加日志的 $level=2错误
  19. */
  20. public function addlogs($type='', $remark='', $level=0, $sarr=array())
  21. {
  22. $sarr['level'] = $level;
  23. return $this->addlog($type, $remark, $sarr);
  24. }
  25. /**
  26. * 提醒返回错误日志添加
  27. */
  28. public function todolog($type,$barr=array())
  29. {
  30. if((int)arrvalue($barr,'errcode',0) != 0)$this->addlogs($type,''.$barr['errcode'].':'.$barr['msg'].'', 2);
  31. }
  32. public function addread($table, $mid, $uid=0)
  33. {
  34. if($uid==0)$uid=$this->adminid;
  35. $where = "`table`='$table' and `mid`='$mid' and `optid`=$uid";
  36. $dbs = m('reads');
  37. $onrs = $dbs->getone($where);
  38. if(!$onrs){
  39. $arr['table'] = $table;
  40. $arr['mid'] = $mid;
  41. $arr['optid'] = $uid;
  42. $arr['stotal'] = 1;
  43. $arr['adddt'] = $this->rock->now();
  44. $where = '';
  45. }else{
  46. $arr['stotal'] = (int)$onrs['stotal']+1;
  47. }
  48. //$arr['ip'] = $this->rock->ip;//存这个没用,不在存储
  49. //$arr['web'] = $this->rock->web;
  50. $arr['optdt'] = $this->rock->now();
  51. $dbs->record($arr, $where);
  52. }
  53. /**
  54. * 获取已读人员
  55. */
  56. public function getreadarr($table, $mid)
  57. {
  58. $rows = $this->db->getrows('[Q]reads',"`table`='$table' and `mid`='$mid' ",'optid,optdt,stotal','`id` desc');
  59. $uids = '0';
  60. $srows= $sssa = array();
  61. foreach($rows as $k=>$rs){
  62. $uid = $rs['optid'];
  63. $uids .=','.$uid.'';
  64. if(!isset($sssa[$uid])){
  65. $srows[] = $rs;
  66. }
  67. $sssa[$uid] = 1;
  68. }
  69. $usarr = array();
  70. if($uids!='0'){
  71. $uarr = $this->db->getarr('[Q]admin',"`id` in($uids) and `status`=1", '`name`,`face`');
  72. foreach($srows as $k=>$rs){
  73. $uid = $rs['optid'];
  74. if(isset($uarr[$uid])){
  75. $usarr[] = array(
  76. 'uid' => $uid,
  77. 'optdt' => $rs['optdt'],
  78. 'stotal' => $rs['stotal'],
  79. 'name' => $uarr[$uid]['name'],
  80. 'face' => $this->rock->repempt($uarr[$uid]['face'],'images/noface.png')
  81. );
  82. }
  83. }
  84. }
  85. return $usarr;
  86. }
  87. public function getread($table, $uid=0)
  88. {
  89. if($uid==0)$uid=$this->adminid;
  90. $sid = $this->db->getjoinval('[Q]reads','mid',"`table`='$table' and `optid`=$uid group by `mid`");
  91. if($sid==''){
  92. $sid = '0';
  93. }else{
  94. $sid = '0,'.$sid.'';
  95. }
  96. return $sid;
  97. }
  98. public function isread($table, $mid, $uid=0)
  99. {
  100. if($uid==0)$uid=$this->adminid;
  101. $where = "`table`='$table' and `mid`='$mid' and `optid`=$uid";
  102. $to = $this->db->rows('[Q]reads', $where);
  103. return $to;
  104. }
  105. //获取已读未读数
  106. public function getreadshu($table, $mid, $receid, $optdt='', $dbs=null)
  107. {
  108. $ydshu = $wdshu = $zzshu = 0;
  109. $ydname = $wdname= '';
  110. if($dbs==null)$dbs = m('admin');
  111. $where = $dbs->gjoin($receid,'ud','where');
  112. if($where=='all')$where = '';
  113. if(!isempt($where))$where = ' and ('.$where.')';
  114. if(!isempt($optdt)){
  115. $dt = substr($optdt,0,10);
  116. $where.=" and `workdate`<='$dt'";
  117. }
  118. $where .= $dbs->getcompanywhere();
  119. $uarr = $dbs->getall('`status`=1'.$where.'','`id`,`name`,`face`','`sort`');
  120. $receas = explode(',', str_replace('u','', $receid));
  121. $rows = $this->db->getall("SELECT `optid` FROM `[Q]reads` where `table`='$table' and `mid`='$mid' GROUP BY `optid`");
  122. $ydarr = array();
  123. foreach($rows as $k=>$rs)$ydarr[] = $rs['optid'];
  124. $wduarr = array(); //未读人员数组
  125. foreach($uarr as $k=>$rs){
  126. $uid = $rs['id'];
  127. $name = $rs['name'];
  128. $rs['face'] = $this->rock->repempt($rs['face'], 'images/noface.png');
  129. if(in_array($uid, $ydarr)){
  130. $ydshu++;
  131. $ydname.=','.$name.'';
  132. }else{
  133. $wdshu++;
  134. $wdname.=','.$name.'';
  135. $wduarr[] = $rs;
  136. }
  137. $zzshu++;
  138. }
  139. if($ydname!='')$ydname = substr($ydname, 1);
  140. if($wdname!='')$wdname = substr($wdname, 1);
  141. return array(
  142. 'zzshu' => $zzshu,
  143. 'ydshu' => $ydshu,
  144. 'wdshu' => $wdshu,
  145. 'ydname' => $ydname,
  146. 'wdname' => $wdname,
  147. 'wduarr' => $wduarr
  148. );
  149. }
  150. }
粤ICP备19079148号