ListController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * 通话列表
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-12-18 16:38:51
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\Call;
  10. use App\Http\Controllers\Admin\Controller;
  11. use App\Models\CallListModel;
  12. use Illuminate\Http\Request;
  13. use App\Repositories\Base\Criteria\OrderBy;
  14. use App\Repositories\Call\Lists\Criteria\MultiWhere;
  15. use App\Repositories\Call\ListRepository;
  16. class ListController extends Controller
  17. {
  18. private $repository;
  19. public function __construct(ListRepository $repository) {
  20. if(!$this->repository) $this->repository = $repository;
  21. }
  22. /**
  23. * 列表页
  24. */
  25. function index(Request $request) {
  26. $search = $request->all();
  27. $order = array();
  28. if (isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  29. $order[$request['sort_field']] = $request['sort_field_by'];
  30. } else {
  31. $order['id'] = 'DESC';
  32. }
  33. $list = $this->repository->searchList($search, $order);
  34. $allIds = $list->pluck('id');
  35. $list = $list->paginate(16);
  36. if ($request->ajax()) {
  37. $view = view('admin.call.list.data', compact('list','allIds'))->render();
  38. return response()->json(['html' => $view]);
  39. }
  40. return view('admin.call.list.index',compact('list','allIds'));
  41. }
  42. /**
  43. * 添加
  44. */
  45. public function create(Request $request)
  46. {
  47. if($request->method() == 'POST') {
  48. return $this->_createSave();
  49. }
  50. return view('admin.call.list.edit');
  51. }
  52. /**
  53. * 保存修改
  54. */
  55. private function _createSave(){
  56. $data = (array) request('data');
  57. $id = $this->repository->create($data);
  58. if($id) {
  59. $url[] = array('url'=>U( 'Call/List/index'),'title'=>'返回列表');
  60. $url[] = array('url'=>U( 'Call/List/create'),'title'=>'继续添加');
  61. $this->showMessage('添加成功',$url);
  62. }else{
  63. $url[] = array('url'=>U( 'Call/List/index'),'title'=>'返回列表');
  64. return $this->showWarning('添加失败',$url);
  65. }
  66. }
  67. /**
  68. * 修改
  69. */
  70. public function update(Request $request) {
  71. if($request->method() == 'POST') {
  72. return $this->_updateSave();
  73. }
  74. $data = $this->repository->find($request->get('id'));
  75. return view('admin.call.list.edit',compact('data'));
  76. }
  77. /**
  78. * 保存修改
  79. */
  80. private function _updateSave() {
  81. $data = (array) request('data');
  82. $ok = $this->repository->update(request('id'),$data);
  83. if($ok) {
  84. $url[] = array('url'=>U( 'Call/List/index'),'title'=>'返回列表');
  85. return $this->showMessage('操作成功',urldecode(request('_referer')));
  86. }else{
  87. $url[] = array('url'=>U( 'Call/List/index'),'title'=>'返回列表');
  88. return $this->showWarning('操作失败',$url);
  89. }
  90. }
  91. public function view(Request $request) {
  92. $data = $this->repository->find(request('id'));
  93. return view('admin.call.list.view',compact('data'));
  94. }
  95. /**
  96. * 删除
  97. */
  98. public function destroy(Request $request) {
  99. $bool = $this->repository->destroy($request->get('id'));
  100. if($bool) {
  101. return $this->showMessage('操作成功');
  102. }else{
  103. return $this->showWarning("操作失败");
  104. }
  105. }
  106. public function alldelete(Request $request){
  107. $list_ids = $request->get('list_ids');
  108. CallListModel::destroy($list_ids);
  109. return 200;
  110. }
  111. }