emailmModel.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. class flow_emailmClassModel extends flowModel
  3. {
  4. private $readunarr = array();//未读人员
  5. //判断是否有读取权限
  6. protected function flowisreadqx()
  7. {
  8. $to = m('emails')->rows('`mid`='.$this->id.' and `uid`='.$this->adminid.'');
  9. return $to>0;
  10. }
  11. //删除时
  12. protected function flowdeletebill($sm)
  13. {
  14. m('emails')->delete('`mid`='.$this->id.'');
  15. }
  16. protected function flowoptmenu($ors, $crs)
  17. {
  18. //撤回未读的
  19. if($ors['num']=='chemail'){
  20. $where = '`mid`='.$this->id.' and `type`<>2 and `zt`=0';
  21. $drows = m('emails')->getall($where);
  22. m('emails')->delete($where);
  23. $uids = '0';
  24. foreach($drows as $k1=>$rs1)$uids.=','.$rs1['uid'].'';
  25. m('todo')->deltodo($this->modenum, $this->id, $uids);
  26. }
  27. }
  28. protected function flowgetoptmenu($opt)
  29. {
  30. if($opt=='chemail'){
  31. $to = $this->flogmodel->rows("".$this->mwhere." and `name`='撤回'");
  32. if($to>0)return false;
  33. }
  34. }
  35. //立即发送提醒
  36. protected function flowsubmit($na, $sm)
  37. {
  38. if($this->rs['isturn']==1 && $this->rs['type']==0){
  39. $h = c('html');
  40. $cont = $h->htmlremove($this->rs['content']);
  41. $cont = $h->substrstr($cont,0, 50);
  42. $receid = $this->rs['receid'];
  43. if(!isempt($this->rs['ccid']))$receid.=','.$this->rs['ccid'];
  44. $this->push($receid, '邮件', $cont.'...', $this->rs['title']);
  45. }
  46. }
  47. //重写方法将邮件标识已读邮件了
  48. protected function flowdatalog($arr)
  49. {
  50. $where = '`mid`='.$this->id.' and `uid`='.$this->adminid.'';
  51. $dbs = m('emails');
  52. $dbs->update('`zt`=1', $where);
  53. //判断我是否可以回复
  54. $ishuifu = 0;
  55. $readunarr = array();
  56. if($this->rs['isturn']==1){
  57. $tos = $dbs->rows($where.' and `type` in(0,1)');
  58. if($tos>0)$ishuifu = 1;
  59. //读取未读人员
  60. $uids = '';
  61. $uarrs = $dbs->getall('`mid`='.$this->id.' and `zt`=0 and `type` in(0,1) and `isdel`=0');
  62. foreach($uarrs as $k=>$rs)$uids.=','.$rs['uid'].'';
  63. if($uids!='')$readunarr = $this->adminmodel->getuserinfo(substr($uids,1));
  64. }
  65. $arr['ishuifu'] = $ishuifu;
  66. $arr['readunarr'] = $readunarr;
  67. return $arr;
  68. }
  69. private function dtssss($dt)
  70. {
  71. $cnw = c('date')->cnweek($dt);
  72. return date('Y年m月d日(星期'.$cnw.')H:i:s',strtotime($dt));
  73. }
  74. public function flowrsreplace($rs, $lx=0)
  75. {
  76. $rs['senddt'] = $this->dtssss($rs['senddt']);
  77. if($lx == 1 && $rs['hid']>0){
  78. $rs['oldcontent'] = $this->getoldcont($rs['hid']);
  79. }
  80. return $rs;
  81. }
  82. /**
  83. * 读取原来邮件内容
  84. */
  85. public function getoldcont($hid, $bo=true)
  86. {
  87. $hid = (int)$hid;
  88. if($hid==0)return '';
  89. $hrs = $this->getone($hid);
  90. if(!$hrs)return '';
  91. $dts = $this->dtssss($hrs['senddt']);
  92. $fstr = m('file')->getstr($this->mtable, $hrs['id'], 1);
  93. $s = '<div style="color:#888888;font-size:12px;margin-top:20px">------------------ 原始邮件 ------------------</div>';
  94. $s.= '<div style="font-size: 12px;background:#efefef;padding:8px;line-height:18px;">发件人: '.$hrs['sendname'].'<br>
  95. 发送时间: '.$dts.'<br>
  96. 收件人: '.$hrs['recename'].'<br>
  97. 主题: '.$hrs['title'].'</div>';
  98. $s.= '<div style="margin-top:10px">'.$hrs['content'].'<br>'.$fstr.'</div>';
  99. if($bo)$s.= $this->getoldcont($hrs['hid'], $bo);
  100. return $s;
  101. }
  102. protected function flowbillwhere($uid, $lx)
  103. {
  104. $where = '1=2';
  105. $onwhere= '';
  106. $key = $this->rock->post('key');
  107. $dt = $this->rock->post('dt');
  108. $dbs = m('emailm');
  109. //所有邮件
  110. if($lx=='' || $lx=='def' || $lx=='sjx'){
  111. $where = $dbs->gettowhere($uid, 0);
  112. }
  113. //未读邮件
  114. if($lx=='wdyj'){
  115. $where = $dbs->gettowhere($uid, 1);
  116. }
  117. //草稿箱
  118. if($lx == 'cgx'){
  119. $where = $dbs->gettowhere($uid, 2);
  120. }
  121. //已发送
  122. if($lx == 'yfs'){
  123. $where = $dbs->gettowhere($uid, 3);
  124. }
  125. //已删除
  126. if($lx == 'ysc'){
  127. $where = $dbs->gettowhere($uid, 4);
  128. }
  129. if(!isempt($key))$where.=" and (a.`title` like '%$key%' or a.`recename` like '%$key%' or a.`sendname` like '%$key%')";
  130. if(!isempt($dt))$where.=" and a.`senddt` like '$dt%'";
  131. return array(
  132. 'where' => 'and '.$where,
  133. 'fields'=> 'a.`id`,a.`title`,a.`sendname`,a.`recename`,a.`senddt`,a.`isfile`,b.`ishui`,b.`zt`,a.`outzt`,a.`type`',
  134. 'order' => 'a.`senddt` desc',
  135. 'table' => '`[Q]emailm` a left join `[Q]emails` b on a.`id`=b.`mid` '.$onwhere.''
  136. );
  137. }
  138. private function getmid($uid, $type, $isdel=0)
  139. {
  140. $rows = m('emails')->getrows('`uid`='.$uid.' and `type` in('.$type.') and `isdel`='.$isdel.'','`mid`');
  141. $ids = '0';
  142. foreach($rows as $k=>$rs)$ids.=','.$rs['mid'].'';
  143. return $ids;
  144. }
  145. public function savesubmid($tuid, $mid, $type, $zt=0)
  146. {
  147. $now = $this->rock->now;
  148. if(is_numeric($tuid)){
  149. $uids = $tuid;
  150. }else{
  151. $uids = m('admin')->gjoin($tuid);
  152. }
  153. if($uids!=''){
  154. $this->db->insert('[Q]emails','mid,uid,email,personal,type,optdt,zt',"select '$mid',id,email,name,'$type','$now','$zt' from `[Q]admin` where id in($uids)", true);
  155. }
  156. }
  157. /**
  158. * 邮件回复
  159. * $cont 回复内容
  160. */
  161. public function huifu($cont)
  162. {
  163. $rs = $this->rs;
  164. $rers = $this->gethuifuarr();
  165. if(!$rers)return '没有发送人';
  166. $cont = str_replace("\n", '<br>', $cont);
  167. $arr['title'] = '回复:'.$rs['title'].'';
  168. $arr['content'] = $cont;
  169. $arr['sendid'] = $this->adminid;
  170. $arr['uid'] = $this->adminid;
  171. $arr['sendname'] = $this->adminname;
  172. $arr['senddt'] = $this->rock->now;
  173. $arr['applydt'] = $this->rock->date;
  174. $arr['hid'] = $this->id;
  175. $arr['type'] = $rs['type'];
  176. $arr['receid'] = $rers['uid'];
  177. $arr['recename'] = $rers['personal'];
  178. $arr['isturn'] = 1;
  179. $arr['outzt'] = 0;
  180. $arr['toemail'] = ''.$rers['personal'].'('.$rers['email'].')';
  181. $arr['optdt'] = $this->rock->now;
  182. $id = $this->insert($arr);
  183. $sarr['mid'] = $id;
  184. $sarr['uid'] = $rers['uid'];
  185. $sarr['type'] = 0;
  186. $sarr['optdt'] = $this->rock->now;
  187. $sarr['email'] = $rers['email'];
  188. $sarr['personal'] = $rers['personal'];
  189. m('emails')->insert($sarr);
  190. $this->savesubmid($arr['sendid'], $id, 2,1);
  191. m('emails')->update('ishui=1','`mid`='.$this->id.' and `uid`='.$this->adminid.' and `type`=0');//更新已回复
  192. //需要外发
  193. if($rs['type']==1 && !isempt($rers['email'])){
  194. $cont = $arr['content'];
  195. $cont .= $this->getoldcont($this->id, false);
  196. m('email')->sendemailout($this->adminid, array(
  197. 'title' => $arr['title'],
  198. 'body' => $cont,
  199. 'receemail' => $rers['email'],
  200. 'recename' => $arr['recename'],
  201. 'mid' => $id,
  202. ));
  203. }
  204. $this->loaddata($id, false);
  205. $this->submit('回复');
  206. return 'ok';
  207. }
  208. //获取要回复的接收人
  209. public function gethuifuarr()
  210. {
  211. $rs = m('emails')->getone('`mid`='.$this->id.' and `type`=2');
  212. return $rs;
  213. }
  214. }
粤ICP备19079148号