NavController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * 导航栏设置
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-05-16 17:42:12
  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\AlbumNavModel;
  13. use App\Models\AlbumNewsModel;
  14. use App\Repositories\Album\Criteria\NavWhere;
  15. use Illuminate\Http\Request;
  16. use App\Repositories\Base\Criteria\OrderBy;
  17. use App\Repositories\Album\Criteria\MultiWhere;
  18. use App\Repositories\Album\NavRepository;
  19. class NavController extends Controller
  20. {
  21. private $repository;
  22. private $url;
  23. public function __construct(NavRepository $repository) {
  24. if(!$this->repository) $this->repository = $repository;
  25. }
  26. function index(Request $request) {
  27. $search['keyword'] = $request->input('keyword');
  28. $query = $this->repository->pushCriteria(new NavWhere($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. return view('admin.album.nav.index',compact('list'));
  36. }
  37. function check(Request $request) {
  38. $request = $request->all();
  39. $search['keyword'] = $request->input('keyword');
  40. $orderby = array();
  41. if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
  42. $orderby[$request['sort_field']] = $request['sort_field_by'];
  43. }
  44. $list = $this->repository->search($search,$orderby);
  45. return view('admin.album.nav.check',compact('list'));
  46. }
  47. private function getPageData(){
  48. $url = [
  49. ['name'=>'主页','value'=>'/page/homePage/homePage'],
  50. ['name'=>'个人中心','value'=>'/page/user/user'],
  51. ['name'=>'产品列表','value'=>'/pages/goods/list'],
  52. ['name'=>'新品发布','value'=>'/page/newpro/newpro']
  53. ];
  54. $this->url = $url;
  55. }
  56. /**
  57. * 添加
  58. *
  59. */
  60. public function create(Request $request)
  61. {
  62. if($request->method() == 'POST') {
  63. return $this->_createSave();
  64. }
  65. $this->getPageData();
  66. $page = $this->url;
  67. return view('admin.album.nav.edit',compact('page'));
  68. }
  69. /**
  70. * 保存修改
  71. */
  72. private function _createSave(){
  73. $data = (array) request('data');
  74. $data['store_id'] = $this->getStoreId();
  75. $zhi = request('zhi');
  76. //dd($zhi);die;
  77. if($zhi!=null)
  78. $data['url'].=$zhi;
  79. $data['pic_url'] = isset($data['pic_url'])?$this->formatImgUrl($data['pic_url']):null;
  80. $data['pic_url_active'] = isset($data['pic_url_active'])?$this->formatImgUrl($data['pic_url_active']):null;
  81. $id = $this->repository->create($data);
  82. if($id) {
  83. $url[] = array('url'=>U( 'Album/Nav/index'),'title'=>'返回列表');
  84. $url[] = array('url'=>U( 'Album/Nav/create'),'title'=>'继续添加');
  85. $this->showMessage('添加成功',$url);
  86. }else{
  87. $url[] = array('url'=>U( 'Album/Nav/index'),'title'=>'返回列表');
  88. return $this->showWarning('添加失败',$url);
  89. }
  90. }
  91. /**
  92. *
  93. * 修改
  94. *
  95. *
  96. */
  97. public function update(Request $request) {
  98. if($request->method() == 'POST') {
  99. \Log::info($request->all());
  100. return $this->_updateSave();
  101. }
  102. $data = $this->repository->find($request->get('id'));
  103. if($data['open_type'] == 4){
  104. $url = $data['url'];
  105. if(strpos($url,'=')){
  106. $urls = explode('=',$url);
  107. $data['zhi'] = $urls[1];
  108. $data['url'] = $urls[0].'=';
  109. }else{
  110. $data['zhi'] = '';
  111. }
  112. }
  113. //dd($data);
  114. $this->getPageData();
  115. $page = $this->url;
  116. return view('admin.album.nav.edit',compact('data','page'));
  117. }
  118. /**
  119. * 保存修改
  120. */
  121. private function _updateSave() {
  122. $data = (array) request('data');
  123. $zhi = request('zhi');
  124. //dump($zhi);die;
  125. $data['url'].=$zhi;
  126. $data['pic_url'] = isset($data['pic_url'])?$this->formatImgUrl($data['pic_url']):null;
  127. $data['pic_url_active'] = isset($data['pic_url_active'])?$this->formatImgUrl($data['pic_url_active']):null;
  128. $ok = $this->repository->update(request('id'),$data);
  129. if($ok) {
  130. $url[] = array('url'=>U( 'Album/Nav/index'),'title'=>'返回列表');
  131. return $this->showMessage('操作成功',urldecode(request('_referer')));
  132. }else{
  133. $url[] = array('url'=>U( 'Album/Nav/index'),'title'=>'返回列表');
  134. return $this->showWarning('操作失败',$url);
  135. }
  136. }
  137. public function view(Request $request) {
  138. $data = $this->repository->find(request('id'));
  139. return view('admin.album.nav.view',compact('data'));
  140. }
  141. /**
  142. *
  143. * 状态改变
  144. *
  145. */
  146. public function status(Request $request) {
  147. $ok = $this->repository->updateStatus(request('id'),request('status'));
  148. if($ok) {
  149. return $this->showMessage('操作成功');
  150. }else{
  151. return $this->showWarning('操作失败');
  152. }
  153. }
  154. /**
  155. * 删除
  156. */
  157. public function destroy(Request $request) {
  158. $nav = AlbumNavModel::find($request->get('id'));
  159. $ok = $nav->delete();
  160. if($ok) {
  161. return $this->showMessage('操作成功');
  162. }else{
  163. return $this->showWarning("操作失败");
  164. }
  165. }
  166. }