Notice.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 控制器
  10. */
  11. class Notice extends AdminControl
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. Lang::load(base_path().'admin/lang/'.config('lang.default_lang').'/notice.lang.php');
  17. }
  18. /**
  19. * 发送通知列表
  20. */
  21. public function index()
  22. {
  23. $special_condition = array();
  24. $special_condition['message_type'] = 1;
  25. $message_model = model('message');
  26. $message_list = $message_model->getMessageList($special_condition,10);
  27. foreach($message_list as $key=>$val){
  28. $message_list[$key]['message_body'] = preg_replace("/<a[^>]*>(.*?)<\/a>/is","$1", htmlspecialchars_decode($val['message_body']));
  29. }
  30. View::assign('message_list', $message_list);
  31. View::assign('show_page', $message_model->page_info->render());
  32. $this->setAdminCurItem('index');
  33. return View::fetch();
  34. }
  35. /**
  36. * 会员通知
  37. */
  38. public function notice(){
  39. //提交
  40. if (request()->isPost()) {
  41. $notice_validate = ds_validate('notice');
  42. $content = trim(input('param.content1')); //信息内容
  43. $send_type = intval(input('param.send_type'));
  44. //验证
  45. switch ($send_type) {
  46. //指定会员
  47. case 1:
  48. $data = [
  49. "user_name" => input("param.user_name")
  50. ];
  51. if (!$notice_validate->scene('notice1')->check($data)) {
  52. $this->error($notice_validate->getError());
  53. }
  54. break;
  55. //全部会员
  56. case 2:
  57. break;
  58. }
  59. $data = [
  60. "content1" => $content
  61. ];
  62. if (!$notice_validate->scene('notice2')->check($data)) {
  63. $this->error($notice_validate->getError());
  64. } else {
  65. //发送会员ID 数组
  66. $memberid_list = array();
  67. //整理发送列表
  68. //指定会员
  69. if ($send_type == 1) {
  70. $member_model = model('member');
  71. $tmp = explode("\n", input('param.user_name'));
  72. if (!empty($tmp)) {
  73. foreach ($tmp as $k => $v) {
  74. $tmp[$k] = trim($v);
  75. }
  76. //查询会员列表
  77. $member_list = $member_model->getMemberList(array(array('member_name' ,'in', $tmp)));
  78. unset($membername_str);
  79. if (!empty($member_list)) {
  80. foreach ($member_list as $k => $v) {
  81. $memberid_list[] = $v['member_id'];
  82. }
  83. }
  84. unset($member_list);
  85. }
  86. unset($tmp);
  87. }
  88. if (empty($memberid_list) && $send_type != 2) {
  89. $this->error(lang('notice_index_member_error'));
  90. }
  91. //接收内容
  92. $array = array();
  93. $array['send_mode'] = 1;
  94. $array['user_name'] = $memberid_list;
  95. $array['content'] = $content;
  96. //添加短消息
  97. $message_model = model('message');
  98. $insert_arr = array();
  99. $insert_arr['from_member_id'] = 0;
  100. if ($send_type == 2) {
  101. $insert_arr['member_id'] = 'all';
  102. } else {
  103. $insert_arr['member_id'] = "," . implode(',', $memberid_list) . ",";
  104. }
  105. $insert_arr['msg_content'] = $content;
  106. $insert_arr['message_type'] = 1;
  107. $insert_arr['message_ismore'] = 1;
  108. $message_model->addMessage($insert_arr);
  109. //跳转
  110. $this->log(lang('notice_index_send'), 1);
  111. dsLayerOpenSuccess(lang('notice_index_send_succ'));
  112. // $this->success(lang('notice_index_send_succ'), 'notice/notice');
  113. }
  114. } else {
  115. return View::fetch('notice_add');
  116. }
  117. }
  118. protected function getAdminItemList()
  119. {
  120. $menu_array=array(
  121. array(
  122. 'name'=>'index','text'=>lang('notice_index_member_notice'),'url'=>(string)url('Notice/index')
  123. ),
  124. array(
  125. 'name'=>'notice','text'=>lang('notice_index_send'),'url'=>"javascript:dsLayerOpen('".(string)url('Notice/notice')."','".lang('notice_index_send')."')"
  126. )
  127. );
  128. return $menu_array;
  129. }
  130. }