CommentController.php 4.3 KB

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