ManufacturerController.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * 系统设置
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-05-14 13:30:36
  7. *
  8. */
  9. namespace App\Http\Controllers\Admin\Album;
  10. use App\Http\Controllers\Admin\Controller;
  11. use App\Models\AlbumManufacturerModel;
  12. use App\Models\AlbumUserModel;
  13. use Illuminate\Http\Request;
  14. use App\Repositories\Base\Criteria\OrderBy;
  15. use App\Repositories\Album\Criteria\MultiWhere;
  16. use App\Repositories\Album\ManufacturerRepository;
  17. class ManufacturerController extends Controller
  18. {
  19. private $repository;
  20. public function __construct(ManufacturerRepository $repository) {
  21. if(!$this->repository) $this->repository = $repository;
  22. }
  23. function list(Request $request){
  24. $search['keyword'] = $request->input('keyword');
  25. $isalbum = request('isalbum')?request('isalbum'):0;
  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. }
  30. $list = $query->paginate(10);
  31. return view('admin.album.manufacturer.index',compact('list','isalbum'));
  32. }
  33. function index(Request $request) {
  34. if($request->method() == 'POST') {
  35. $iscreate = AlbumManufacturerModel::where('store_id',$this->getStoreId())->count();
  36. if($iscreate){
  37. return $this->_updateSave();
  38. }else{
  39. return $this->_createSave();
  40. }
  41. }
  42. $data = AlbumManufacturerModel::where('store_id',$this->getStoreId())->first();
  43. return view('admin.album.manufacturer.edit',compact('data'));
  44. }
  45. /**
  46. * 保存修改
  47. */
  48. private function _createSave(){
  49. $data = (array) request('data');
  50. $data['store_id'] =$this->getStoreId();
  51. if(!empty($data['avatar']))
  52. $data['avatar'] = $this->formatImgUrl($data['avatar']);
  53. if(!empty($data['background_pic']))
  54. $data['background_pic'] = $this->formatImgUrl($data['background_pic']);
  55. if(!empty($data['advertising_pic']))
  56. $data['advertising_pic'] = $this->formatImgUrl($data['advertising_pic']);
  57. if(!empty($data['notice_icon']))
  58. $data['notice_icon'] = $this->formatImgUrl($data['notice_icon']);
  59. if(!empty($data['furniture_ads_pic']))
  60. $data['furniture_ads_pic'] = $this->formatImgUrl($data['furniture_ads_pic']);
  61. $id = $this->repository->create($data);
  62. if($id) {
  63. $this->showMessage('添加成功');
  64. }else{
  65. return $this->showWarning('添加失败');
  66. }
  67. }
  68. /**
  69. * 保存修改
  70. */
  71. private function _updateSave() {
  72. $data = (array) request('data');
  73. if(!empty($data['avatar']))
  74. $data['avatar'] = $this->formatImgUrl($data['avatar']);
  75. if(!empty($data['background_pic']))
  76. $data['background_pic'] = $this->formatImgUrl($data['background_pic']);
  77. if(!empty($data['advertising_pic']))
  78. $data['advertising_pic'] = $this->formatImgUrl($data['advertising_pic']);
  79. if(!empty($data['notice_icon']))
  80. $data['notice_icon'] = $this->formatImgUrl($data['notice_icon']);
  81. if(!empty($data['furniture_ads_pic']))
  82. $data['furniture_ads_pic'] = $this->formatImgUrl($data['furniture_ads_pic']);
  83. $id = AlbumManufacturerModel::where('store_id',$this->getStoreId())->first()->id;
  84. $ok = $this->repository->update($id,$data);
  85. if($ok) {
  86. return $this->showMessage('操作成功');
  87. }else{
  88. return $this->showWarning('操作失败');
  89. }
  90. }
  91. public function view(Request $request) {
  92. $data = $this->repository->find(request('id'));
  93. return view('admin.album.manufacturer.view',compact('data'));
  94. }
  95. /**
  96. *
  97. * 状态改变
  98. *
  99. */
  100. public function status(Request $request) {
  101. $ok = $this->repository->updateStatus(request('id'),request('status'));
  102. if($ok) {
  103. return $this->showMessage('操作成功');
  104. }else{
  105. return $this->showWarning('操作失败');
  106. }
  107. }
  108. /**
  109. * 删除
  110. */
  111. public function destroy(Request $request) {
  112. $bool = $this->repository->destroy($request->get('id'));
  113. if($bool) {
  114. return $this->showMessage('操作成功');
  115. }else{
  116. return $this->showWarning("操作失败");
  117. }
  118. }
  119. }