Notice.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 控制器
  16. */
  17. class Notice extends AdminControl
  18. {
  19. public function initialize()
  20. {
  21. parent::initialize();
  22. Lang::load(base_path().'admin/lang/'.config('lang.default_lang').'/notice.lang.php');
  23. }
  24. /**
  25. * 发送通知列表
  26. */
  27. public function index()
  28. {
  29. $special_condition = array();
  30. $special_condition['message_type'] = 1;
  31. $message_model = model('message');
  32. $message_list = $message_model->getMessageList($special_condition,10);
  33. foreach($message_list as $key=>$val){
  34. $message_list[$key]['message_body'] = preg_replace("/<a[^>]*>(.*?)<\/a>/is","$1", htmlspecialchars_decode($val['message_body']));
  35. }
  36. View::assign('message_list', $message_list);
  37. View::assign('show_page', $message_model->page_info->render());
  38. $this->setAdminCurItem('index');
  39. return View::fetch();
  40. }
  41. /**
  42. * 会员通知
  43. */
  44. public function notice(){
  45. //提交
  46. if (request()->isPost()) {
  47. $notice_validate = ds_validate('notice');
  48. $content = trim(input('param.content1')); //信息内容
  49. $send_type = intval(input('param.send_type'));
  50. //验证
  51. switch ($send_type) {
  52. //指定会员
  53. case 1:
  54. $data = [
  55. "user_name" => input("param.user_name")
  56. ];
  57. if (!$notice_validate->scene('notice1')->check($data)) {
  58. $this->error($notice_validate->getError());
  59. }
  60. break;
  61. //全部会员
  62. case 2:
  63. break;
  64. }
  65. $data = [
  66. "content1" => $content
  67. ];
  68. if (!$notice_validate->scene('notice2')->check($data)) {
  69. $this->error($notice_validate->getError());
  70. } else {
  71. //发送会员ID 数组
  72. $memberid_list = array();
  73. //整理发送列表
  74. //指定会员
  75. if ($send_type == 1) {
  76. $member_model = model('member');
  77. $tmp = explode("\n", input('param.user_name'));
  78. if (!empty($tmp)) {
  79. foreach ($tmp as $k => $v) {
  80. $tmp[$k] = trim($v);
  81. }
  82. //查询会员列表
  83. $member_list = $member_model->getMemberList(array(array('member_name' ,'in', $tmp)));
  84. unset($membername_str);
  85. if (!empty($member_list)) {
  86. foreach ($member_list as $k => $v) {
  87. $memberid_list[] = $v['member_id'];
  88. }
  89. }
  90. unset($member_list);
  91. }
  92. unset($tmp);
  93. }
  94. if (empty($memberid_list) && $send_type != 2) {
  95. $this->error(lang('notice_index_member_error'));
  96. }
  97. //接收内容
  98. $array = array();
  99. $array['send_mode'] = 1;
  100. $array['user_name'] = $memberid_list;
  101. $array['content'] = $content;
  102. //添加短消息
  103. $message_model = model('message');
  104. $insert_arr = array();
  105. $insert_arr['from_member_id'] = 0;
  106. if ($send_type == 2) {
  107. $insert_arr['member_id'] = 'all';
  108. } else {
  109. $insert_arr['member_id'] = "," . implode(',', $memberid_list) . ",";
  110. }
  111. $insert_arr['msg_content'] = $content;
  112. $insert_arr['message_type'] = 1;
  113. $insert_arr['message_ismore'] = 1;
  114. $message_model->addMessage($insert_arr);
  115. //跳转
  116. $this->log(lang('notice_index_send'), 1);
  117. dsLayerOpenSuccess(lang('notice_index_send_succ'));
  118. // $this->success(lang('notice_index_send_succ'), 'notice/notice');
  119. }
  120. } else {
  121. return View::fetch('notice_add');
  122. }
  123. }
  124. protected function getAdminItemList()
  125. {
  126. $menu_array=array(
  127. array(
  128. 'name'=>'index','text'=>lang('notice_index_member_notice'),'url'=>(string)url('Notice/index')
  129. ),
  130. array(
  131. 'name'=>'notice','text'=>lang('notice_index_send'),'url'=>"javascript:dsLayerOpen('".(string)url('Notice/notice')."','".lang('notice_index_send')."')"
  132. )
  133. );
  134. return $menu_array;
  135. }
  136. }