ManufacturerController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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\AgentBannerModel;
  12. use App\Models\AlbumManufacturerModel;
  13. use App\Models\AlbumUserModel;
  14. use App\Services\OSS;
  15. use Illuminate\Http\Request;
  16. use App\Repositories\Base\Criteria\OrderBy;
  17. use App\Repositories\Album\Criteria\MultiWhere;
  18. use App\Repositories\Album\ManufacturerRepository;
  19. class ManufacturerController extends Controller
  20. {
  21. private $repository;
  22. public function __construct(ManufacturerRepository $repository) {
  23. if(!$this->repository) $this->repository = $repository;
  24. }
  25. function list(Request $request){
  26. $search['keyword'] = $request->input('keyword');
  27. $isalbum = request('isalbum')?request('isalbum'):0;
  28. $query = $this->repository->pushCriteria(new MultiWhere($search));
  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. }
  32. $list = $query->paginate(10);
  33. return view('admin.album.manufacturer.index',compact('list','isalbum'));
  34. }
  35. function index(Request $request)
  36. {
  37. if ($request->method() == 'POST') {
  38. $iscreate = AlbumManufacturerModel::where('store_id', $this->getStoreId())->first();
  39. if ($iscreate) {
  40. return $this->_updateSave();
  41. } else {
  42. return $this->_createSave();
  43. }
  44. }
  45. $data = AlbumManufacturerModel::where('store_id', $this->getStoreId())->first();
  46. if ($data) {
  47. $data['banner'] = json_decode($data['banner'], true);
  48. }
  49. $banner = AgentBannerModel::where([['store_id',$this->getStoreId()],['type',0]])->get();
  50. $imgs = array();
  51. foreach ($banner as $key => $val) {
  52. $imgs[] = $val['url'];
  53. }
  54. $data['agent_banner'] = $imgs;
  55. $video = AgentBannerModel::where([['store_id',$this->getStoreId()],['type',1]])->first();
  56. return view('admin.album.manufacturer.edit', compact('data', 'video'));
  57. }
  58. public function viewShare(Request $request)
  59. {
  60. $img = '/base/img/share.jpg';
  61. return view('admin.album.poster.view', compact('img'));
  62. }
  63. public function platform(Request $request)
  64. {
  65. if ($request->method() == 'POST') {
  66. $iscreate = AlbumManufacturerModel::where('store_id', $this->getStoreId())->first();
  67. if ($iscreate) {
  68. return $this->_updateSave();
  69. } else {
  70. return $this->_createSave();
  71. }
  72. }
  73. $data = AlbumManufacturerModel::where('store_id', $this->getStoreId())->first();
  74. if ($data) {
  75. $data['banner'] = json_decode($data['banner'], true);
  76. }
  77. $banner = AgentBannerModel::where([['store_id',$this->getStoreId()],['type',0]])->get();
  78. $imgs = array();
  79. foreach ($banner as $key => $val) {
  80. $imgs[] = $val['url'];
  81. }
  82. $data['agent_banner'] = $imgs;
  83. $video = AgentBannerModel::where([['store_id',$this->getStoreId()],['type',1]])->first();
  84. return view('admin.album.manufacturer.platform-edit', compact('data', 'video'));
  85. }
  86. public function furniturePlatform(Request $request)
  87. {
  88. if ($request->method() == 'POST') {
  89. $iscreate = AlbumManufacturerModel::where('store_id', $this->getStoreId())->first();
  90. if ($iscreate) {
  91. return $this->_updateSave();
  92. } else {
  93. return $this->_createSave();
  94. }
  95. }
  96. $data = AlbumManufacturerModel::where('store_id', $this->getStoreId())->first();
  97. if ($data) {
  98. $data['banner'] = json_decode($data['banner'], true);
  99. }
  100. return view('admin.album.manufacturer.furniture-platform', compact('data', 'video'));
  101. }
  102. public function furnitureSystem(Request $request)
  103. {
  104. if ($request->method() == 'POST') {
  105. $iscreate = AlbumManufacturerModel::where('store_id', $this->getStoreId())->first();
  106. if ($iscreate) {
  107. return $this->_updateSave();
  108. } else {
  109. return $this->_createSave();
  110. }
  111. }
  112. $data = AlbumManufacturerModel::where('store_id', $this->getStoreId())->first();
  113. return view('admin.album.manufacturer.furniture-system', compact('data', 'video'));
  114. }
  115. public function albumSystem(Request $request)
  116. {
  117. if ($request->method() == 'POST') {
  118. $iscreate = AlbumManufacturerModel::where('store_id', $this->getStoreId())->first();
  119. if ($iscreate) {
  120. return $this->_updateSave();
  121. } else {
  122. return $this->_createSave();
  123. }
  124. }
  125. $data = AlbumManufacturerModel::where('store_id', $this->getStoreId())->first();
  126. if ($data) {
  127. $data['banner'] = json_decode($data['banner'], true);
  128. }
  129. $banner = AgentBannerModel::where([['store_id',$this->getStoreId()],['type',0]])->get();
  130. $imgs = array();
  131. foreach ($banner as $key => $val) {
  132. $imgs[] = $val['url'];
  133. }
  134. $data['agent_banner'] = $imgs;
  135. $video = AgentBannerModel::where([['store_id',$this->getStoreId()],['type',1]])->first();
  136. return view('admin.album.manufacturer.album-edit', compact('data', 'video'));
  137. }
  138. function indexFurniture(Request $request) {
  139. if ($request->method() == 'POST') {
  140. $iscreate = AlbumManufacturerModel::where('store_id', $this->getStoreId())->first();
  141. if ($iscreate) {
  142. return $this->_updateSave();
  143. } else {
  144. return $this->_createSave();
  145. }
  146. }
  147. $data = AlbumManufacturerModel::where('store_id', $this->getStoreId())->first();
  148. if ($data) {
  149. $data['banner'] = json_decode($data['banner'], true);
  150. }
  151. return view('admin.album.manufacturer.edit-furniture', compact('data'));
  152. }
  153. function create(Request $request)
  154. {
  155. if ($request->method() == 'POST') {
  156. return $this->_createSave();
  157. }
  158. return view('admin.album.manufacturer.edit-all');
  159. }
  160. /**
  161. * 保存修改
  162. */
  163. private function _createSave(){
  164. $data = (array) request('data');
  165. $ma = AlbumManufacturerModel::where('id','!=',0)->orderByDesc('id')->first();
  166. $data['store_id'] =$ma->id+1;
  167. if (!empty($data['banner']['url'])) {
  168. foreach ($data['banner']['url'] as $key => $val) {
  169. $data['banner']['url'][$key] = $this->formatImgUrl($val);
  170. }
  171. $data['banner'] = json_encode($data['banner']['url']);
  172. }
  173. if (isset($data['banner_agent']['url'])) {
  174. $agent_banner = $data['banner_agent']['url'];
  175. unset($data['banner_agent']);
  176. if ($agent_banner) {
  177. foreach($agent_banner as $key => $val){
  178. $add['url'] = $this->formatImgUrl($val);
  179. $add['agent_id'] = request('id');
  180. $add['type'] = 0;
  181. AgentBannerModel::create($add);
  182. }
  183. }
  184. }
  185. if(!empty($data['avatar']))
  186. $data['avatar'] = $this->formatImgUrl($data['avatar']);
  187. if (!empty($data['logo'])) {
  188. $data['logo'] = $this->formatImgUrl($data['logo']);
  189. }
  190. if (!empty($data['qrcode'])) {
  191. $data['qrcode'] = $this->formatImgUrl($data['qrcode']);
  192. }
  193. if (!empty($data['share_image'])) {
  194. $data['share_image'] = $this->formatImgUrl($data['share_image']);
  195. }if (!empty($data['circleOfFriends'])) {
  196. $data['circleOfFriends'] = $this->formatImgUrl($data['circleOfFriends']);
  197. }
  198. if(!empty($data['background_pic']))
  199. $data['background_pic'] = $this->formatImgUrl($data['background_pic']);
  200. if(!empty($data['advertising_pic']))
  201. $data['advertising_pic'] = $this->formatImgUrl($data['advertising_pic']);
  202. if(!empty($data['notice_icon']))
  203. $data['notice_icon'] = $this->formatImgUrl($data['notice_icon']);
  204. if(!empty($data['furniture_ads_pic']))
  205. $data['furniture_ads_pic'] = $this->formatImgUrl($data['furniture_ads_pic']);
  206. $id = $this->repository->create($data);
  207. if ($id) {
  208. $this->showMessage('添加成功');
  209. } else {
  210. return $this->showWarning('添加失败');
  211. }
  212. }
  213. /**
  214. * 保存修改
  215. */
  216. private function _updateSave() {
  217. $data = (array) request('data');
  218. // dd($data);
  219. $saveData = AlbumManufacturerModel::where('store_id', $this->getStoreId())->first();
  220. if (!empty($data['avatar'])) {
  221. $data['avatar'] = $this->formatImgUrl($data['avatar']);
  222. //$this->deleteUrl($saveData->avatar);
  223. }
  224. $banner = AgentBannerModel::where([['store_id',$this->getStoreId()],['type',0]])->get();
  225. if($banner){
  226. foreach ($banner as $key=>$val){
  227. $url = str_replace(env('APP_URL'),public_path(),$val['url']);
  228. if(file_exists($url)) unlink($url);
  229. }
  230. }
  231. AgentBannerModel::where([['store_id',$this->getStoreId()],['type',0]])->delete();
  232. if(!empty($data['agent_banner']['url'])){
  233. foreach($data['agent_banner']['url'] as $key=>$val){
  234. $add['url'] = $this->formatImgUrl($val);
  235. $add['store_id'] = $this->getStoreId();
  236. $add['type'] = 0;
  237. AgentBannerModel::create($add);
  238. }
  239. }
  240. unset($data['agent_banner']);
  241. if (!empty($data['logo'])) {
  242. $data['logo'] = $this->formatImgUrl($data['logo']);
  243. }
  244. if (!empty($data['background_pic'])) {
  245. $data['background_pic'] = $this->formatImgUrl($data['background_pic']);
  246. //$this->deleteUrl($saveData->background_pic);
  247. }
  248. if (!empty($data['advertising_pic'])) {
  249. $data['advertising_pic'] = $this->formatImgUrl($data['advertising_pic']);
  250. // $this->deleteUrl($saveData->advertising_pic);
  251. }
  252. if (!empty($data['circleOfFriends'])) {
  253. $data['circleOfFriends'] = $this->formatImgUrl($data['circleOfFriends']);
  254. // $this->deleteUrl($saveData->advertising_pic);
  255. }
  256. if (!empty($data['share_image'])) {
  257. $data['share_image'] = $this->formatImgUrl($data['share_image']);
  258. }
  259. if (!empty($data['qrcode'])) {
  260. $data['qrcode'] = $this->formatImgUrl($data['qrcode']);
  261. }
  262. if (!empty($data['notice_icon'])) {
  263. $data['notice_icon'] = $this->formatImgUrl($data['notice_icon']);
  264. // $this->deleteUrl($saveData->notice_icon);
  265. }
  266. if (!empty($data['furniture_ads_pic'])) {
  267. $data['furniture_ads_pic'] = $this->formatImgUrl($data['furniture_ads_pic']);
  268. // $this->deleteUrl($saveData->furniture_ads_pic);
  269. }
  270. if (!empty($data['banner']['url'])) {
  271. foreach ($data['banner']['url'] as $key => $val) {
  272. $data['banner']['url'][$key] = $this->formatImgUrl($val);
  273. }
  274. $data['banner'] = json_encode($data['banner']['url']);
  275. /*$banner = json_decode($data['banner'], true);
  276. foreach ($banner as $val) {
  277. $this->deleteUrl($val);
  278. }*/
  279. }
  280. $id = $saveData->id;
  281. $ok = $this->repository->update($id,$data);
  282. if($ok) {
  283. return $this->showMessage('操作成功');
  284. }else{
  285. return $this->showWarning('操作失败');
  286. }
  287. }
  288. public function view(Request $request) {
  289. $data = $this->repository->find(request('id'));
  290. return view('admin.album.manufacturer.view',compact('data'));
  291. }
  292. /**
  293. *
  294. * 状态改变
  295. *
  296. */
  297. public function status(Request $request) {
  298. $ok = $this->repository->updateStatus(request('id'),request('status'));
  299. if($ok) {
  300. return $this->showMessage('操作成功');
  301. }else{
  302. return $this->showWarning('操作失败');
  303. }
  304. }
  305. /**
  306. * 删除
  307. */
  308. public function destroy(Request $request)
  309. {
  310. $bool = $this->repository->destroy($request->get('id'));
  311. if ($bool) {
  312. return $this->showMessage('操作成功');
  313. } else {
  314. return $this->showWarning("操作失败");
  315. }
  316. }
  317. public function uploadVideo(Request $request)
  318. {
  319. $video = $request->file('video');
  320. // 判断图片有效性
  321. if (!$video) {
  322. return back()->withErrors('上传视频无效..');
  323. }
  324. $check = AgentBannerModel::where([['store_id',$this->getStoreId()],['type',1]])->first();
  325. if($check) OSS::publicDeleteObject(config('alioss.BucketName'),$check->oss_key);
  326. // 获取图片在临时文件中的地址
  327. $videoPath = $video->getRealPath();
  328. // 制作文件名
  329. $ex = $video->getClientOriginalExtension();
  330. $key = time() . rand(10000, 99999999) . '.' . $ex;
  331. //阿里 OSS 文件上传
  332. $result = OSS::publicUpload(config('alioss.BucketName'), $key, $videoPath);
  333. if ($result) {
  334. $data['name'] = $video->getClientOriginalName();
  335. $data['type'] = 1;
  336. $data['store_id'] = $this->getStoreId();
  337. $data['oss_key'] = $key;
  338. $data['url'] = config('alioss.FileUrl') . $key;
  339. $video = AgentBannerModel::create($data);
  340. if (!$video) {
  341. return back()->withErrors('上传视频失败..');
  342. }
  343. return $this->showMessage('上传成功');
  344. } else {
  345. return back()->withErrors('上传视频失败..');
  346. }
  347. }
  348. public function videoDel(Request $request)
  349. {
  350. $check = AgentBannerModel::find($request->get('id'));
  351. if($check) $osskey = $check->oss_key;
  352. if(!$check) return $this->showWarning("操作失败");
  353. $bool = AgentBannerModel::where('id',$request->get('id'))->delete();
  354. if($bool) {
  355. OSS::publicDeleteObject(config('alioss.BucketName'),$osskey);
  356. return $this->showMessage('操作成功');
  357. }else{
  358. return $this->showWarning("操作失败");
  359. }
  360. }
  361. }