InfoController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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\Base\Criteria\OrderBy;
  13. use App\Repositories\Company\Info\Criteria\MultiWhere;
  14. use App\Repositories\Company\InfoRepository;
  15. class InfoController extends Controller
  16. {
  17. private $repository;
  18. public function __construct(InfoRepository $repository)
  19. {
  20. if (!$this->repository) $this->repository = $repository;
  21. }
  22. /**
  23. * 列表页
  24. */
  25. function index(Request $request)
  26. {
  27. $search = $request->all();
  28. $order = array();
  29. if (isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  30. $order[$request['sort_field']] = $request['sort_field_by'];
  31. } else {
  32. $order['id'] = 'DESC';
  33. }
  34. $list = $this->repository->searchCompany($search, $order);
  35. if($request->ajax()){
  36. $view = view('admin.company.info.data',compact('list'))->render();
  37. return response()->json(['html'=>$view]);
  38. }
  39. return view('admin.company.info.index', compact('list'));
  40. }
  41. /**
  42. * 添加
  43. */
  44. public function create(Request $request)
  45. {
  46. if ($request->method() == 'POST') {
  47. return $this->_createSave();
  48. }
  49. return view('admin.company.info.edit');
  50. }
  51. /**
  52. * 保存修改
  53. */
  54. private function _createSave()
  55. {
  56. $data = (array)request('data');
  57. $id = $this->repository->create($data);
  58. if ($id) {
  59. $url[] = array('url' => U('Company/Info/index'), 'title' => '返回列表');
  60. $url[] = array('url' => U('Company/Info/create'), 'title' => '继续添加');
  61. $this->showMessage('添加成功', $url);
  62. } else {
  63. $url[] = array('url' => U('Company/Info/index'), 'title' => '返回列表');
  64. return $this->showWarning('添加失败', $url);
  65. }
  66. }
  67. /**
  68. * 修改
  69. */
  70. public function update(Request $request)
  71. {
  72. if ($request->method() == 'POST') {
  73. return $this->_updateSave();
  74. }
  75. $data = $this->repository->find($request->get('id'));
  76. return view('admin.company.info.edit', compact('data'));
  77. }
  78. /**
  79. * 保存修改
  80. */
  81. private function _updateSave()
  82. {
  83. $data = (array)request('data');
  84. $ok = $this->repository->update(request('id'), $data);
  85. if ($ok) {
  86. $url[] = array('url' => U('Company/Info/index'), 'title' => '返回列表');
  87. return $this->showMessage('操作成功', urldecode(request('_referer')));
  88. } else {
  89. $url[] = array('url' => U('Company/Info/index'), 'title' => '返回列表');
  90. return $this->showWarning('操作失败', $url);
  91. }
  92. }
  93. public function view(Request $request)
  94. {
  95. $data = $this->repository->find(request('id'));
  96. return view('admin.company.info.view', compact('data'));
  97. }
  98. /**
  99. * 删除
  100. */
  101. public function destroy(Request $request)
  102. {
  103. $bool = $this->repository->destroy($request->get('id'));
  104. if ($bool) {
  105. return $this->showMessage('操作成功');
  106. } else {
  107. return $this->showWarning("操作失败");
  108. }
  109. }
  110. }