MessageReadController.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php
  2. /**
  3. * 系统设置
  4. */
  5. namespace App\Http\Controllers\Admin;
  6. use App\Http\Controllers\Controller;
  7. use Illuminate\Http\Request as Req;
  8. use Request;
  9. /**
  10. *
  11. */
  12. class MessageReadController extends Controller {
  13. /**
  14. * 消息
  15. */
  16. function Index(Req $req) {
  17. $request=array();
  18. $request['title'] = isset($req->title) ? trim($req->title) : null;
  19. $request['type'] = isset($req->type) ? trim($req->type) : null;
  20. $request['status'] = isset($req->status) ? trim($req->status) : null;
  21. $request['toname'] = isset($req->toname) ? trim($req->toname) : null;
  22. $request['fromname'] = isset($req->fromname) ? trim($req->fromname) : null;
  23. $dt = \App\Lib\DataTable\DataTable::init();
  24. $dt->setDataSource('/admin/MessageRead/getArticle');
  25. $dt->setLang('notice');
  26. // $dt->addColsFields('id');
  27. $dt->addColsFields('title');
  28. // $dt->addColsFields('toname');
  29. $dt->addColsFields('formname');
  30. $dt->addColsFields('status',array('sort' => false, 'templet' => '#agent', 'width' => 80));
  31. $dt->addColsFields('add_time');
  32. // $dt->addColsFields('message_type');
  33. // $dt->addColsFields('type');
  34. $dt->enableCheckBox();
  35. $arr[] = 'view';
  36. $dt->setToolBar($arr, array('width' => 140));
  37. return view('admin.ManagerRead/arictle',$dt->render($request));
  38. }
  39. //获取信息
  40. //获取活动信息
  41. function getArticle() {
  42. $limit = Request::has('limit') ? Request::get('limit') : 10;
  43. $title = Request::has('title') ? Request::get('title') : '';
  44. // $content = Request::has('content') ? Request::get('content') : '';
  45. $message_type = Request::has('message_type') ? Request::get('message_type') : '';
  46. $type = Request::has('type') ? Request::get('type') : '';
  47. // $forname = Request::has('forname') ? Request::get('forname') : '';
  48. // $toname = Request::has('toname') ? Request::get('toname') : '';
  49. // $add_time = Request::has('add_time') ? Request::get('add_time') : '';
  50. // var_dump($type);
  51. $where = array();
  52. if (!empty($title)) {
  53. $where[] = array('title', 'like', '%' . $title . '%');
  54. }
  55. if (empty($type)) {
  56. $where[] = array('type', '=', '4');
  57. }
  58. if (empty($message_type)) {
  59. $where[] = array('type', '=', '2');
  60. }
  61. $db = new \App\Models\Manager();
  62. $data = $db->getlist($limit, $where);
  63. $admin_id=session('adminInfo.admin_id');
  64. $dbs = new \App\Models\MessageRead;
  65. $datas=$dbs->getlist($admin_id);
  66. if (!empty($datas)){
  67. foreach ($data['data'] as $k=>$v){
  68. foreach ($datas as $vv){
  69. if($vv['type'] == '1' && $v['id'] == $vv['message_id']){
  70. $data['data'][$k]['type']='1';
  71. }
  72. }
  73. }
  74. foreach ($data['data'] as $k=>$v){
  75. if($v['type'] == '2'){
  76. $dat[$k]=$v;
  77. }
  78. }
  79. if (!empty($dat)){
  80. $data['data']= $dat;
  81. }else{
  82. $data['data']="";
  83. }
  84. }
  85. // var_dump($dat);
  86. if (!empty($data['data'])) {
  87. foreach ($data['data'] as $k=>$v){
  88. foreach ($datas as $val){
  89. if ($v['id'] == $val['message_id']){
  90. $data['data'][$k]['status']='1';
  91. }
  92. }
  93. }
  94. $langinfo = trans('status.managerread');
  95. foreach ($data['data'] as $k => $v) {
  96. $data['data'][$k]['status'] = $langinfo[$v['status']];
  97. }
  98. }
  99. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
  100. }
  101. function view(Req $req) {
  102. return $this->MessageView($req);
  103. }
  104. function Edit(Req $req) {
  105. $id = $req->id;
  106. // $id=Request::has('id')?Request::get('id'):'';
  107. if (intval($id) < 1) {
  108. abort(404);
  109. }
  110. $db = new \App\Models\Manager;
  111. if (!$req->isMethod('post')) {
  112. $data = $db->getDmsg($id, 1);
  113. if (!$data) {
  114. return responseToJson($data);
  115. }
  116. return view('admin.ManagerRead/editNotice', ['data' => $data]);
  117. } else {
  118. $data['title'] = $req->input('title');
  119. $data['content'] = $req->desc;
  120. $res = $db->updateMsg($data, $id);
  121. // $log = array(
  122. // session('adminInfo.admin_name'),
  123. // );
  124. // OperationLog(session('adminInfo.admin_id'), 'edit_game', $log);
  125. return responseToJson($res);
  126. }
  127. }
  128. /**
  129. * 批量删除
  130. * [delete description]
  131. * @return [type] [description]
  132. */
  133. function delete(Req $req) {
  134. $id = $req->input('id');
  135. $admin_id=session('adminInfo.admin_id');
  136. if (empty($id)) {
  137. return responseToJson(-2001); //id
  138. }
  139. $ids = explode(',', $id);
  140. if (!is_array($ids) && intval($ids) < 0) {
  141. return responseToJson(-2002); //id
  142. }
  143. if (is_array($ids) && count($ids) > 0) {
  144. foreach ($ids as $k => $v) {
  145. if (intval($v) < 1) {
  146. unset($ids[$k]);
  147. }
  148. }
  149. }
  150. $ids= explode(",",$id);
  151. foreach ($ids as $va){
  152. $rows = new \App\Models\MessageRead;
  153. $rtt=$rows->Messagelist($va,$admin_id);
  154. if($rtt > 0){
  155. $data=[
  156. 'type'=>'1'
  157. ];
  158. $rowt=$rows->updateMsg($va,$admin_id,$data);
  159. if (!$rowt) {
  160. return responseToJson(-2003); //id
  161. }
  162. }else{
  163. $dataWhwew=[
  164. 'message_id'=>$va,
  165. 'account_identity'=>$admin_id,
  166. 'type'=>'1',
  167. 'add_time'=>date("Y-m-d H:i",time())
  168. ];
  169. $dat = $rows->addMessage($dataWhwew);
  170. if (!$dat) {
  171. return responseToJson(-2003); //id
  172. }
  173. }
  174. }
  175. return responseToJson(1); //id
  176. }
  177. function addNotice(Req $req){
  178. // $dataName=array();
  179. if (!$req->isMethod('post')) {
  180. return view('admin.Manager/editNotice',['select'=>1]);
  181. }else{
  182. $data['title'] = $req->input('title');
  183. $data['type'] =$req->type;
  184. $data['content'] = $req->desc;
  185. $log = array(
  186. session('adminInfo.admin_name'),
  187. $data['title']
  188. );
  189. $data['add_time']=date('Y-m-d H:i:s');
  190. $data['formname']=$req->input('formname');
  191. $data['toname']=$req->input('toname');
  192. // $data['message_type']=$req->input('message_type');
  193. $db = new \App\Models\Manager;
  194. $user = new \App\Models\Account;
  195. //普通消息
  196. if ($data['type'] == 2){
  197. $dataName=explode(',',$data['toname']);
  198. foreach ($dataName as $v){
  199. $data['toname']=$v;
  200. $res = $db->addNotice($data);
  201. }
  202. }
  203. //系统消息
  204. if ($data['type'] == 1){
  205. $data['formname']='system';
  206. $data['toname']='all';
  207. $db->addNotice($data);
  208. }
  209. //系统通知
  210. if ($data['type'] == 3){
  211. $data['formname']='notice';
  212. $data['toname']='all';
  213. $db->addNotice($data);
  214. }
  215. //系统通知
  216. if ($data['type'] == 4){
  217. $data['formname']='admin';
  218. $data['toname']='admin_all';
  219. $db->addNotice($data);
  220. }
  221. // $res = $db->addNotice($data);
  222. OperationLog(session('adminInfo.admin_id'), 'add_notice', $log);
  223. return responseToJson(1);
  224. }
  225. }
  226. function MessageView(Req $req){
  227. $id = $req->input('id');
  228. $admin_id=session('adminInfo.admin_id');
  229. $where=[
  230. 'id',
  231. $id
  232. ];
  233. $dataWhwew=[
  234. 'message_id'=>$id,
  235. 'account_identity'=>$admin_id,
  236. 'add_time'=>date("Y-m-d H:i",time())
  237. ];
  238. $db = new \App\Models\Manager();
  239. $dbRead = new \App\Models\MessageRead;
  240. $data = $db->getlistd($where);
  241. $dataRead = $dbRead->Messagelist($id,$admin_id);
  242. if ($dataRead < 0){
  243. $dat = $dbRead->addMessage($dataWhwew);
  244. }
  245. return view('admin.ManagerRead/view',['data'=>$data]);
  246. }
  247. }
  248. ?>