InfoController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /**
  3. * 消息列表
  4. * @author system
  5. * @version 1.0
  6. * @date 2017-06-30 10:16:20
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\System;
  10. use App\Http\Controllers\Admin\Controller;
  11. use App\Models\SystemInfoModel;
  12. use App\Models\UserInfoModel;
  13. use Illuminate\Http\Request;
  14. use App\Repositories\Base\Criteria\OrderBy;
  15. use App\Repositories\System\Criteria\MultiWhere;
  16. use App\Repositories\System\InfoRepository;
  17. class InfoController extends Controller
  18. {
  19. private $repository;
  20. public function __construct(InfoRepository $repository) {
  21. if(!$this->repository) $this->repository = $repository;
  22. }
  23. function index(Request $reqeust) {
  24. $search['keyword'] = $reqeust->input('keyword');
  25. $query = $this->repository->pushCriteria(new MultiWhere($search));
  26. $request = $reqeust->all();
  27. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  28. $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
  29. }
  30. $list = $query->paginate();
  31. foreach ($list as $item) {
  32. $user = UserInfoModel::find($item->user_id);
  33. $item->nickname = empty($user) ? '' : $user->nickname;
  34. }
  35. return view('admin.system.info.index',compact('list'));
  36. }
  37. function check(Request $reqeust) {
  38. $request = $reqeust->all();
  39. $search['keyword'] = $reqeust->input('keyword');
  40. $orderby = array();
  41. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  42. $orderby[$request['sort_field']] = $request['sort_field_by'];
  43. }
  44. $list = $this->repository->search($search,$orderby);
  45. return view('admin.system.info.check',compact('list'));
  46. }
  47. /**
  48. * 添加
  49. *
  50. */
  51. public function create(Request $reqeust)
  52. {
  53. if($reqeust->method() == 'POST') {
  54. return $this->_createSave();
  55. }
  56. return view('admin.system.info.edit');
  57. }
  58. /**
  59. * 保存修改
  60. */
  61. private function _createSave(){
  62. $data = (array) request('data');
  63. $id = $this->repository->create($data);
  64. if($id) {
  65. $url[] = array('url'=>U( 'System/Info/index'),'title'=>'返回列表');
  66. $url[] = array('url'=>U( 'System/Info/create'),'title'=>'继续添加');
  67. $this->showMessage('添加成功',$url);
  68. }else{
  69. $url[] = array('url'=>U( 'System/Info/index'),'title'=>'返回列表');
  70. return $this->showWarning('添加失败',$url);
  71. }
  72. }
  73. /**
  74. *
  75. * 修改
  76. *
  77. *
  78. */
  79. public function update(Request $reqeust) {
  80. if($reqeust->method() == 'POST') {
  81. return $this->_updateSave();
  82. }
  83. $data = $this->repository->find($reqeust->get('id'));
  84. return view('admin.system.info.edit',compact('data'));
  85. }
  86. /**
  87. * 保存修改
  88. */
  89. private function _updateSave() {
  90. $data = (array) request('data');
  91. $ok = $this->repository->update(request('id'),$data);
  92. if($ok) {
  93. $url[] = array('url'=>U( 'System/Info/index'),'title'=>'返回列表');
  94. return $this->showMessage('操作成功',urldecode(request('_referer')));
  95. }else{
  96. $url[] = array('url'=>U( 'System/Info/index'),'title'=>'返回列表');
  97. return $this->showWarning('操作失败',$url);
  98. }
  99. }
  100. public function view(Request $reqeust) {
  101. $data = $this->repository->find(request('id'));
  102. return view('admin.system.info.view',compact('data'));
  103. }
  104. /**
  105. *
  106. * 状态改变
  107. *
  108. */
  109. public function status(Request $reqeust) {
  110. $ok = $this->repository->updateStatus(request('id'),request('status'));
  111. if($ok) {
  112. return $this->showMessage('操作成功');
  113. }else{
  114. return $this->showWarning('操作失败');
  115. }
  116. }
  117. /**
  118. * 删除
  119. */
  120. public function destroy(Request $reqeust) {
  121. $bool = $this->repository->destroy($reqeust->get('id'));
  122. if($bool) {
  123. return $this->showMessage('操作成功');
  124. }else{
  125. return $this->showWarning("操作失败");
  126. }
  127. }
  128. public function systemInfo(Request $request)
  129. {
  130. $users = UserInfoModel::select('id')->get()->toArray();
  131. if (empty($users)) return 404;
  132. $message = $request->msg;
  133. $arr = [] ;
  134. foreach ($users as $user) {
  135. $arr[] = [
  136. 'user_id' =>$user['id'],
  137. 'message' =>$message,
  138. 'created_at'=>date("Y-m-d H:i:s"),
  139. 'updated_at'=>date("Y-m-d H:i:s"),
  140. ];
  141. }
  142. $ok = SystemInfoModel::insert($arr);
  143. if ($ok) {
  144. return 200;
  145. }else{
  146. return 500;
  147. }
  148. }
  149. }