InfoController.php 3.1 KB

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