Notice.php 5.3 KB

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