InfoController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 App\Imports\CompanyInfoImport;
  12. use App\Models\CompanyContactsModel;
  13. use App\Models\CompanyInfoModel;
  14. use Illuminate\Http\Request;
  15. use App\Repositories\Company\InfoRepository;
  16. use Maatwebsite\Excel\Facades\Excel;
  17. class InfoController extends Controller
  18. {
  19. private $repository;
  20. public function __construct(InfoRepository $repository)
  21. {
  22. if (!$this->repository) $this->repository = $repository;
  23. }
  24. /*
  25. * 搜索页视图
  26. * */
  27. public function search()
  28. {
  29. $fields = (new CompanyInfoModel())->filterFields;
  30. return view('admin.company.info.search', compact('fields'));
  31. }
  32. /**
  33. * 列表页
  34. */
  35. function index(Request $request)
  36. {
  37. $search = $request->all();
  38. $order = array();
  39. if (isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  40. $order[$request['sort_field']] = $request['sort_field_by'];
  41. } else {
  42. $order['id'] = 'DESC';
  43. }
  44. $list = $this->repository->searchCompany($search, $order);
  45. if ($request->ajax()) {
  46. $view = view('admin.company.info.data', compact('list'))->render();
  47. return response()->json(['html' => $view]);
  48. }
  49. $fields = (new CompanyInfoModel())->filterFields;
  50. return view('admin.company.info.index', compact('list', 'fields'));
  51. }
  52. /***
  53. * 导入企业信息
  54. * @param Request $request
  55. */
  56. public function import(Request $request)
  57. {
  58. $res = Excel::import(new CompanyInfoImport, request()->file('company_info'));
  59. $url[] = array('url' => U('Company/Info/index'), 'title' => '返回列表');
  60. $this->showMessage('导入成功', $url);
  61. }
  62. /***
  63. * 企业详情页
  64. * @param Request $request
  65. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  66. */
  67. public function view(Request $request)
  68. {
  69. $data = $this->repository->find(request('id'));
  70. $contacts = $data->contacts()->orderBy('sort', 'desc')->get();
  71. return view('admin.company.info.view', compact('data', 'contacts'));
  72. }
  73. /**
  74. * 删除
  75. */
  76. public function destroy(Request $request)
  77. {
  78. $bool = $this->repository->destroy($request->get('id'));
  79. if ($bool) {
  80. return $this->showMessage('操作成功');
  81. } else {
  82. return $this->showWarning("操作失败");
  83. }
  84. }
  85. public function addremarks(Request $request)
  86. {
  87. $contact = CompanyContactsModel::find($request->get('id'));
  88. $contact->remark = $request->get('remark');
  89. $contact->save();
  90. return 200;
  91. }
  92. }