Notice.php 5.1 KB

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