人人商城

broadcast.ctrl.php 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. uni_user_permission_check('mc_broadcast');
  8. $dos = array('display', 'send');
  9. if($_W['isajax']) {
  10. $post = $_GPC['__input'];
  11. if(!empty($post['method'])) {
  12. $do = $post['method'];
  13. }
  14. }
  15. $do = in_array($do, $dos) ? $do : 'display';
  16. if($do == 'display') {
  17. $_W['page']['title'] = '发送通知消息 - 群发消息&通知 - 通知中心';
  18. if($_W['ispost']) {
  19. $sql = 'SELECT COUNT(*) FROM ' . tablename('mc_members') . ' WHERE `uniacid`=:uniacid';
  20. $pars = array();
  21. $pars[':uniacid'] = $_W['uniacid'];
  22. if(!empty($_GPC['group'])) {
  23. $sql .= ' AND `groupid`=:group';
  24. $pars[':group'] = intval($_GPC['group']);
  25. }
  26. if(!empty($_GPC['username'])) {
  27. $sql .= ' AND `nickname` LIKE :nickname';
  28. $pars[':nickname'] = "%{$_GPC['username']}%";
  29. }
  30. if($_GPC['type'] == 'email') {
  31. $sql .= " AND `email`!=''";
  32. }
  33. $count = pdo_fetchcolumn($sql, $pars);
  34. }
  35. $groups = pdo_fetchall('SELECT groupid,title FROM ' . tablename('mc_groups') . " WHERE uniacid = '{$_W['uniacid']}' ");
  36. template('mc/broadcast');
  37. }
  38. if($do == 'send') {
  39. load()->func('communication');
  40. $ret = array(
  41. 'total' => 0,
  42. 'success' => 0,
  43. 'failed' => 0,
  44. 'next' => -1
  45. );
  46. $sql = ' FROM ' . tablename('mc_members') . ' WHERE `uniacid`=:uniacid';
  47. $pars = array();
  48. $pars[':uniacid'] = $_W['uniacid'];
  49. if(!empty($post['group'])) {
  50. $sql .= ' AND `groupid`=:group';
  51. $pars[':group'] = intval($post['group']);
  52. }
  53. if(!empty($post['username'])) {
  54. $sql .= ' AND `nickname` LIKE :nickname';
  55. $pars[':nickname'] = "%{$post['username']}%";
  56. }
  57. if($post['type'] == 'email') {
  58. $sql .= " AND `email`!=''";
  59. $countSql = 'SELECT COUNT(*)' . $sql;
  60. $ret['total'] = pdo_fetchcolumn($countSql, $pars);
  61. $ret['total'] = intval($ret['total']);
  62. $psize = 1;
  63. $pindex = intval($post['next']);
  64. $pindex = max(1, $pindex);
  65. $start = $psize * ($pindex - 1);
  66. $sql = 'SELECT `email`' . $sql . " LIMIT {$start}, {$psize}";
  67. $ds = pdo_fetchall($sql, $pars);
  68. if(is_array($ds)) {
  69. foreach($ds as $row) {
  70. $str_find = array('../attachment/images');
  71. $str_replace = array($_W['siteroot'] . 'attachment/images');
  72. $post['content'] = str_replace($str_find, $str_replace, $post['content']);
  73. $r = ihttp_email($row['email'], $post['title'], $post['content']);
  74. if(is_error($r)) {
  75. $ret['failed']++;
  76. } else {
  77. $ret['success']++;
  78. }
  79. }
  80. }
  81. if($start + $psize < $ret['total']) {
  82. $ret['next'] = $pindex + 1;
  83. }
  84. }
  85. exit(json_encode($ret));
  86. }