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