ProjectController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * 单项项目
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-09-06 05:36:14
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\Medical\Single;
  10. use App\Http\Controllers\Admin\Controller;
  11. use App\Models\MedicalSingleCateModel;
  12. use App\Models\MedicalSingleProjectModel;
  13. use Illuminate\Http\Request;
  14. use App\Repositories\Base\Criteria\OrderBy;
  15. use App\Repositories\Medical\Single\Criteria\MultiWhere;
  16. use App\Repositories\Medical\Single\ProjectRepository;
  17. class ProjectController extends Controller
  18. {
  19. private $repository;
  20. public function __construct(ProjectRepository $repository) {
  21. if(!$this->repository) $this->repository = $repository;
  22. }
  23. function index(Request $request) {
  24. $search['keyword'] = $request->input('keyword');
  25. $query = $this->repository->pushCriteria(new MultiWhere($search));
  26. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  27. $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
  28. }else{
  29. $query = $query->pushCriteria(new OrderBy('id','DESC'));
  30. }
  31. $list = $query->paginate();
  32. foreach($list as $key=>$val){
  33. $cate = MedicalSingleCateModel::find($val['cate_id']);
  34. $list[$key]['cate_id'] = $cate->name;
  35. }
  36. return view('admin.medical.single.project.index',compact('list'));
  37. }
  38. function check(Request $request) {
  39. $request = $request->all();
  40. $search['keyword'] = $request->input('keyword');
  41. $orderby = array();
  42. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  43. $orderby[$request['sort_field']] = $request['sort_field_by'];
  44. }
  45. $list = $this->repository->search($search,$orderby);
  46. return view('admin.medical.single.project.check',compact('list'));
  47. }
  48. /**
  49. * 添加
  50. *
  51. */
  52. public function create(Request $request)
  53. {
  54. if($request->method() == 'POST') {
  55. return $this->_createSave();
  56. }
  57. $cat = MedicalSingleCateModel::all();
  58. return view('admin.medical.single.project.edit',compact('cat'));
  59. }
  60. /**
  61. * 保存修改
  62. */
  63. private function _createSave(){
  64. $data = (array) request('data');
  65. $id = $this->repository->create($data);
  66. if($id) {
  67. $url[] = array('url'=>U( 'Medical/Single/Project/index'),'title'=>'返回列表');
  68. $url[] = array('url'=>U( 'Medical/Single/Project/create'),'title'=>'继续添加');
  69. $this->showMessage('添加成功',$url);
  70. }else{
  71. $url[] = array('url'=>U( 'Medical/Single/Project/index'),'title'=>'返回列表');
  72. return $this->showWarning('添加失败',$url);
  73. }
  74. }
  75. /**
  76. *
  77. * 修改
  78. *
  79. *
  80. */
  81. public function update(Request $request) {
  82. if($request->method() == 'POST') {
  83. return $this->_updateSave();
  84. }
  85. $data = $this->repository->find($request->get('id'));
  86. $cat = MedicalSingleCateModel::all();
  87. return view('admin.medical.single.project.edit',compact('data','cat'));
  88. }
  89. /**
  90. * 保存修改
  91. */
  92. private function _updateSave() {
  93. $data = (array) request('data');
  94. $ok = $this->repository->update(request('id'),$data);
  95. if($ok) {
  96. $url[] = array('url'=>U( 'Medical/Single/Project/index'),'title'=>'返回列表');
  97. return $this->showMessage('操作成功',urldecode(request('_referer')));
  98. }else{
  99. $url[] = array('url'=>U( 'Medical/Single/Project/index'),'title'=>'返回列表');
  100. return $this->showWarning('操作失败',$url);
  101. }
  102. }
  103. public function view(Request $request) {
  104. $data = $this->repository->find(request('id'));
  105. return view('admin.medical.single.project.view',compact('data'));
  106. }
  107. /**
  108. *
  109. * 状态改变
  110. *
  111. */
  112. public function status(Request $request) {
  113. $ok = $this->repository->updateStatus(request('id'),request('status'));
  114. if($ok) {
  115. return $this->showMessage('操作成功');
  116. }else{
  117. return $this->showWarning('操作失败');
  118. }
  119. }
  120. /**
  121. * 删除
  122. */
  123. public function destroy(Request $request) {
  124. $cat = MedicalSingleProjectModel::find($request->get('id'));
  125. $bool = $cat->delete();
  126. if($bool) {
  127. return $this->showMessage('操作成功');
  128. }else{
  129. return $this->showWarning("操作失败");
  130. }
  131. }
  132. }