InformationController.php 4.8 KB

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