ThreadsController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * 我的线索
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-11-20 02:55:06
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\User;
  10. use App\Http\Controllers\Admin\Controller;
  11. use Illuminate\Http\Request;
  12. use App\Repositories\Base\Criteria\OrderBy;
  13. use App\Repositories\User\Threads\Criteria\MultiWhere;
  14. use App\Repositories\User\ThreadsRepository;
  15. class ThreadsController extends Controller
  16. {
  17. private $repository;
  18. public function __construct(ThreadsRepository $repository) {
  19. if(!$this->repository) $this->repository = $repository;
  20. }
  21. /**
  22. * 列表页
  23. */
  24. function index(Request $request) {
  25. $search['keyword'] = $request->input('keyword');
  26. $query = $this->repository->pushCriteria(new MultiWhere($search));
  27. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  28. $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
  29. }else{
  30. $query = $query->pushCriteria(new OrderBy('updated_at','DESC'));
  31. }
  32. $list = $query->paginate(16);
  33. return view('admin.user.threads.index',compact('list'));
  34. }
  35. /**
  36. * 添加线索
  37. */
  38. public function create(Request $request)
  39. {
  40. $data['ower_id'] = \Auth::guard('admin')->user()->id;
  41. $data['company_id'] = $request->get('company_id');
  42. $data['status'] = 0;
  43. $id = $this->repository->create($data);
  44. if($id) {
  45. $url[] = array('url'=>U( 'User/Threads/index'),'title'=>'我的线索');
  46. $this->showMessage('添加成功',$url);
  47. }else{
  48. $url[] = array('url'=>U( 'User/Threads/index'),'title'=>'我的线索');
  49. return $this->showWarning('添加失败',$url);
  50. }
  51. }
  52. /**
  53. * 修改
  54. */
  55. public function update(Request $request) {
  56. if($request->method() == 'POST') {
  57. return $this->_updateSave();
  58. }
  59. $data = $this->repository->find($request->get('id'));
  60. return view('admin.user.threads.edit',compact('data'));
  61. }
  62. /**
  63. * 保存修改
  64. */
  65. private function _updateSave() {
  66. $data = (array) request('data');
  67. $ok = $this->repository->update(request('id'),$data);
  68. if($ok) {
  69. $url[] = array('url'=>U( 'User/Threads/index'),'title'=>'返回列表');
  70. return $this->showMessage('操作成功',urldecode(request('_referer')));
  71. }else{
  72. $url[] = array('url'=>U( 'User/Threads/index'),'title'=>'返回列表');
  73. return $this->showWarning('操作失败',$url);
  74. }
  75. }
  76. public function view(Request $request) {
  77. $data = $this->repository->find(request('id'));
  78. return view('admin.user.threads.view',compact('data'));
  79. }
  80. /**
  81. * 删除
  82. */
  83. public function destroy(Request $request) {
  84. $bool = $this->repository->destroy($request->get('id'));
  85. if($bool) {
  86. return $this->showMessage('操作成功');
  87. }else{
  88. return $this->showWarning("操作失败");
  89. }
  90. }
  91. }