Notice.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\shop\controller;
  11. use app\model\web\Notice as NoticeModel;
  12. /**
  13. * 网站公告
  14. */
  15. class Notice extends BaseShop
  16. {
  17. /**
  18. * 公告管理
  19. * @return \think\mixed
  20. */
  21. public function index()
  22. {
  23. if (request()->isAjax()) {
  24. $page = input('page', 1);
  25. $limit = input('page_size', PAGE_LIST_ROWS);
  26. $search_text = input('search_text', '');
  27. $condition = [ [ 'site_id', '=', $this->site_id ] ];
  28. $notice = new NoticeModel();
  29. if ($search_text) $condition[] = [ 'title', 'like', '%' . $search_text . '%' ];
  30. //排序
  31. $link_sort = input('order', 'sort');
  32. $sort = input('sort', 'desc');
  33. if ($link_sort == 'sort') {
  34. $order_by = $link_sort . ' ' . $sort;
  35. } else {
  36. $order_by = $link_sort . ' ' . $sort . ',sort desc';
  37. }
  38. $list = $notice->getNoticePageList($condition, $page, $limit, $order_by);
  39. foreach ($list[ 'data' ][ 'list' ] as $key => $val) {
  40. $list[ 'data' ][ 'list' ][ $key ][ 'content' ] = preg_replace("/[^\x{4e00}-\x{9fa5}^0-9^A-Z^a-z]+/u", '', $val[ 'content' ]);
  41. }
  42. return $list;
  43. } else {
  44. $this->assign('pc_is_exit', addon_is_exit('pc'));
  45. return $this->fetch('notice/index');
  46. }
  47. }
  48. /**
  49. * 公告管理
  50. * @return \think\mixed
  51. */
  52. public function noticeSelect()
  53. {
  54. if (request()->isAjax()) {
  55. $page = input('page', 1);
  56. $limit = input('page_size', PAGE_LIST_ROWS);
  57. $condition = [ [ 'site_id', '=', $this->site_id ] ];
  58. $notice = new NoticeModel();
  59. $list = $notice->getNoticePageList($condition, $page, $limit);
  60. return $list;
  61. } else {
  62. $select_id = input('select_id', '');
  63. $this->assign('select_id', $select_id);
  64. return $this->fetch("notice/notice_select");
  65. }
  66. }
  67. /**
  68. * 公告add
  69. */
  70. public function addNotice()
  71. {
  72. if (request()->isAjax()) {
  73. $data = [
  74. 'site_id' => $this->site_id,
  75. 'title' => input('title', ''),
  76. 'content' => input('content', ''),
  77. 'is_top' => input('is_top', 0),
  78. 'create_time' => time(),
  79. 'receiving_type' => input('receiving_type', 'mobile'),
  80. 'receiving_name' => input('receiving_name', '手机端')
  81. ];
  82. // if (!empty($data['receiving_type'])) {
  83. // $data['receiving_name'] .= in_array('mobile', $data['receiving_type']) ? ' 手机端' : '';
  84. // $data['receiving_type'] = implode(',', $data['receiving_type']);
  85. // }
  86. $notice = new NoticeModel();
  87. $this->addLog("发布公告:" . $data[ 'title' ]);
  88. $res = $notice->addNotice($data);
  89. return $res;
  90. } else {
  91. return $this->fetch('notice/add_notice');
  92. }
  93. }
  94. /**
  95. * 公告编辑
  96. */
  97. public function editNotice()
  98. {
  99. $notice = new NoticeModel();
  100. if (request()->isAjax()) {
  101. $id = input('id', 0);
  102. $data = [
  103. 'site_id' => $this->site_id,
  104. 'title' => input('title', ''),
  105. 'content' => input('content', ''),
  106. 'is_top' => input('is_top', 0),
  107. 'receiving_type' => input('receiving_type', 'mobile'),
  108. 'receiving_name' => input('receiving_name', '手机端')
  109. ];
  110. // if (!empty($data['receiving_type'])) {
  111. // $data['receiving_name'] .= in_array('mobile', $data['receiving_type']) ? ' 手机端' : '';
  112. // $data['receiving_type'] = implode(',', $data['receiving_type']);
  113. // }
  114. $res = $notice->editNotice($data, [ [ 'id', '=', $id ] ]);
  115. return $res;
  116. } else {
  117. $id = input('id', 0);
  118. $info = $notice->getNoticeInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
  119. $this->assign('info', $info[ 'data' ]);
  120. echo $this->fetch('notice/edit_notice');
  121. }
  122. }
  123. /**
  124. * 公告删除
  125. * @return string[]|mixed[]
  126. */
  127. public function deleteNotice()
  128. {
  129. if (request()->isAjax()) {
  130. $id = input('id', '');
  131. $notice = new NoticeModel();
  132. $res = $notice->deleteNotice([ [ 'id', 'in', $id ], [ 'site_id', '=', $this->site_id ] ]);
  133. return $res;
  134. }
  135. }
  136. /**
  137. * 公告置顶
  138. */
  139. public function modifyNoticeTop()
  140. {
  141. $id = input('id', '');
  142. $notice = new NoticeModel();
  143. $res = $notice->editNotice([ 'is_top' => 1 ], [ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
  144. return $res;
  145. }
  146. /**
  147. * 公告详情
  148. */
  149. public function detail()
  150. {
  151. $id = input('id', 1);
  152. $notice_model = new NoticeModel();
  153. $info = $notice_model->getNoticeInfo([ [ 'id', '=', $id ] ]);
  154. $this->assign("info", $info[ 'data' ]);
  155. $this->assign("menu_info", [ 'title' => "网站公告" ]);
  156. return $this->fetch('notice/detail');
  157. }
  158. /**
  159. * 修改排序
  160. */
  161. public function modifySort()
  162. {
  163. $sort = input('sort', 0);
  164. $id = input('id', 0);
  165. $notice_model = new NoticeModel();
  166. return $notice_model->modifyNoticeSort($sort, $id);
  167. }
  168. /**
  169. * 推广
  170. * @return array
  171. */
  172. public function promote()
  173. {
  174. if (request()->isAjax()) {
  175. $notice_id = input('notice_id', 0);
  176. $notice_model = new NoticeModel();
  177. $notice_info = $notice_model->getNoticeInfo([ [ 'id', '=', $notice_id ] ], 'id')[ 'data' ];
  178. if (!empty($notice_info)) {
  179. $res = $notice_model->urlQrcode([ 'notice_id' => $notice_id ], $this->site_id);
  180. return $res;
  181. }
  182. }
  183. }
  184. }