InfoController.php 3.5 KB

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