AppController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <?php
  2. /**
  3. * 应用上传
  4. *
  5. * @author MEOWWEI
  6. * @Time: 2019-11-12 11:04:05
  7. * @version 1.0 版本号
  8. */
  9. namespace App\Http\Controllers;
  10. use App\Http\Requests\StoreRequest;
  11. use App\Service\DataService;
  12. use http\Env\Response;
  13. use Illuminate\Session\Store;
  14. use Illuminate\Support\Facades\Storage;
  15. use Illuminate\Support\Facades\Input;
  16. use Illuminate\Http\Request;
  17. use Illuminate\Support\Facades\DB;
  18. class AppController extends BaseController
  19. {
  20. /**
  21. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  22. * 应用大致显示
  23. */
  24. public function index()
  25. {
  26. $data = DB::table('admin_app')->orderBy('id', 'desc')->select('id', 'app_title', 'icon', 'edition', 'a_down', 'a_down_limit')->get()->toArray();
  27. foreach ($data as $k => $v) {
  28. $data[$k] = (array)$v;
  29. }
  30. return view('app.list', compact('data'));
  31. }
  32. /**
  33. * @param $id
  34. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  35. * 应用详情
  36. */
  37. public function applist($id)
  38. {
  39. $data = DB::table('admin_app')->where('id', $id)->first();
  40. $data = get_object_vars($data);//转数组
  41. $img = $data['img'];
  42. if (strpos($img, '|') == false) {
  43. $data['img'] = $img;
  44. $data['img1'] = $img;
  45. } else {
  46. $data['img1'] = substr($img, 0, strrpos($img, '|'));
  47. $data['img'] = substr($img, strripos($img, '|') + 1);
  48. }
  49. return view('app.appxq', compact('data'));
  50. }
  51. /**
  52. * @param $id
  53. * @param Request $request
  54. * 图标icon上传
  55. */
  56. public function appicon($id, Request $request)
  57. {
  58. if ($request->isMethod('POST')) { //判断文件是否是 POST的方式上传
  59. $tmp = $request->file('file');
  60. $path = '/uploads/ico'; //public下的article
  61. if ($tmp->isValid()) { //判断文件上传是否有效
  62. $FileType = $tmp->getClientOriginalExtension(); //获取文件后缀
  63. $FilePath = $tmp->getRealPath(); //获取文件临时存放位置
  64. $FileName = date('YmdHis') . uniqid() . '.' . $FileType; //定义文件名
  65. Storage::disk('article')->put($FileName, file_get_contents($FilePath)); //存储文件
  66. //路径存数据库
  67. $pathdb = $path . '/' . $FileName;
  68. $db = DB::table('admin_app')->where('id', $id)->update(['icon' => $pathdb]);
  69. if ($db > 0) {
  70. return redirect('/apps');
  71. }
  72. }
  73. }
  74. }
  75. /**
  76. * @param $id
  77. * @param Request $request
  78. * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  79. * 二维码
  80. */
  81. public function appeq($id, Request $request)
  82. {
  83. if ($request->isMethod('POST')) { //判断文件是否是 POST的方式上传
  84. $tmp = $request->file('file');
  85. $path = '/uploads/ico'; //public下的article
  86. if ($tmp->isValid()) { //判断文件上传是否有效
  87. $FileType = $tmp->getClientOriginalExtension(); //获取文件后缀
  88. $FilePath = $tmp->getRealPath(); //获取文件临时存放位置
  89. $FileName = date('YmdHis') . uniqid() . '.' . $FileType; //定义文件名
  90. Storage::disk('article')->put($FileName, file_get_contents($FilePath)); //存储文件
  91. //路径存数据库
  92. $pathdb = $path . '/' . $FileName;
  93. $db = DB::table('admin_app')->where('id', $id)->update(['a_qr' => $pathdb]);
  94. if ($db > 0) {
  95. return redirect('/apps');
  96. }
  97. }
  98. }
  99. }
  100. /**
  101. * @return int
  102. * 既点既改
  103. */
  104. public function apptitles()
  105. {
  106. $arr = Input::get();//接收ajax传递的参数
  107. $result = DB::table('admin_app')->where('id', $arr['id'])->update(['app_title' => $arr['username']]);
  108. //var_dump($result);
  109. if ($result) {
  110. $status = 1;
  111. } else {
  112. $status = 2;
  113. }
  114. return $status; //将结果返回给展示页面
  115. }
  116. public function editjdjg()
  117. {
  118. $arr = Input::get();//接收ajax传递的参数
  119. $result = DB::table('admin_app')->where('id', $arr['id'])->update(['f_title' => $arr['username']]);
  120. //var_dump($result);
  121. if ($result) {
  122. $status = 1;
  123. } else {
  124. $status = 2;
  125. }
  126. return $status; //将结果返回给展示页面
  127. }
  128. public function fage()
  129. {
  130. $arr = Input::get();
  131. $result = DB::table('admin_app')->where('id', $arr['id'])->update(['f_age' => $arr['username']]);
  132. if ($result) {
  133. $status = 1;
  134. } else {
  135. $status = 2;
  136. }
  137. return $status; //将结果返回给展示页面
  138. }
  139. public function clas()
  140. {
  141. $arr = Input::get();
  142. $result = DB::table('admin_app')->where('id', $arr['id'])->update(['f_class' => $arr['username']]);
  143. if ($result) {
  144. $status = 1;
  145. } else {
  146. $status = 2;
  147. }
  148. return $status; //将结果返回给展示页面
  149. }
  150. public function rlak()
  151. {
  152. $arr = Input::get();
  153. $result = DB::table('admin_app')->where('id', $arr['id'])->update(['f_ranking' => $arr['username']]);
  154. if ($result) {
  155. $status = 1;
  156. } else {
  157. $status = 2;
  158. }
  159. return $status; //将结果返回给展示页面
  160. }
  161. public function score()
  162. {
  163. $arr = Input::get();
  164. $result = DB::table('admin_app')->where('id', $arr['id'])->update(['f_score' => $arr['username']]);
  165. if ($result) {
  166. $status = 1;
  167. } else {
  168. $status = 2;
  169. }
  170. return $status; //将结果返回给展示页面
  171. }
  172. public function nums()
  173. {
  174. $arr = Input::get();
  175. $result = DB::table('admin_app')->where('id', $arr['id'])->update(['f_score_num' => $arr['username']]);
  176. if ($result) {
  177. $status = 1;
  178. } else {
  179. $status = 2;
  180. }
  181. return $status; //将结果返回给展示页面
  182. }
  183. public function brief()
  184. {
  185. $arr = Input::get();
  186. $result = DB::table('admin_app')->where('id', $arr['id'])->update(['f_brief' => $arr['username']]);
  187. if ($result) {
  188. $status = 1;
  189. } else {
  190. $status = 2;
  191. }
  192. return $status; //将结果返回给展示页面
  193. }
  194. public function atitle()
  195. {
  196. $arr = Input::get();
  197. $result = DB::table('admin_app')->where('id', $arr['id'])->update(['a_title' => $arr['username']]);
  198. if ($result) {
  199. $status = 1;
  200. } else {
  201. $status = 2;
  202. }
  203. return $status; //将结果返回给展示页面
  204. }
  205. public function aname()
  206. {
  207. $arr = Input::get();
  208. $result = DB::table('admin_app')->where('id', $arr['id'])->update(['a_name' => $arr['username']]);
  209. if ($result) {
  210. $status = 1;
  211. } else {
  212. $status = 2;
  213. }
  214. return $status; //将结果返回给展示页面
  215. }
  216. public function limitnum()
  217. {
  218. $arr = Input::get();
  219. $result = DB::table('admin_app')->where('id', $arr['id'])->update(['a_down_limit' => $arr['username']]);
  220. if ($result) {
  221. $status = 1;
  222. } else {
  223. $status = 2;
  224. }
  225. return $status; //将结果返回给展示页面
  226. }
  227. public function adesc()
  228. {
  229. $arr = Input::get();
  230. $result = DB::table('admin_app')->where('id', $arr['id'])->update(['a_desc' => $arr['username']]);
  231. if ($result) {
  232. $status = 1;
  233. } else {
  234. $status = 2;
  235. }
  236. return $status; //将结果返回给展示页面
  237. }
  238. /**
  239. * @param $id
  240. * @param Request $request
  241. * @return mixed
  242. * 图片
  243. */
  244. public function uploadsimgs($id, Request $request)
  245. {
  246. $datass = DB::table('admin_app')->where('id',$id)->select('img')->first();
  247. $datass = get_object_vars($datass);
  248. $datass = $datass['img'];
  249. $file = $request->except('_token');
  250. $file = $file['goods_imgs'];
  251. $path = '/uploads/ico';
  252. if (!is_array($file)) {
  253. //if ($file->isValid()) {
  254. //获取文件相关信息
  255. $originalName = $file->getClientOriginalName(); // 文件原名
  256. echo 111;
  257. var_dump($originalName);
  258. $ext = $file->getClientOriginalExtension(); // 扩展名
  259. $realPath = $file->getRealPath(); //临时文件的绝对路径
  260. $type = $file->getClientMimeType(); // image/jpeg
  261. if (!in_array($ext, ['jpg', 'jpeg', 'gif', 'png'])) return false;
  262. // 上传
  263. $filename = date('YmdHis') . '-' . uniqid() . '.' . $ext;
  264. Storage::disk('article')->put($filename, file_get_contents($realPath)); //存储文件
  265. //路径存数据库
  266. $pathdb = $path . '/' . $filename;
  267. if($datass !='' || $datass != null){
  268. $pathdb = $datass.'|'.$pathdb;
  269. $db = DB::table('admin_app')->where('id', $id)->update(['img' => $pathdb]);
  270. }else{
  271. $db = DB::table('admin_app')->where('id', $id)->update(['img' => $pathdb]);
  272. }
  273. if ($db > 0) {
  274. return redirect('/apps');
  275. }
  276. } else {
  277. $data = [];
  278. $path = '/uploads/ico';
  279. foreach ($file as $files) {
  280. //if ($files->isValid()) {
  281. // 获取文件相关信息
  282. $originalName = $files->getClientOriginalName(); // 文件原名
  283. $ext = $files->getClientOriginalExtension(); // 扩展名
  284. $realPath = $files->getRealPath(); //临时文件的绝对路径
  285. $type = $files->getClientMimeType(); // image/jpeg
  286. if (!in_array($ext, ['jpg', 'jpeg', 'gif', 'png'])) return false;
  287. // 上传文件
  288. $file_name = date('YmdHis') . '-' . uniqid() . '.' . $ext;
  289. Storage::disk('article')->put($file_name, file_get_contents($realPath)); //存储文件
  290. //路径存数据库
  291. $pathdb = $path . '/' . $file_name;
  292. if($datass !='' || $datass != null){
  293. $pathdb = $datass.'|'.$pathdb;
  294. $db = DB::table('admin_app')->where('id', $id)->update(['img' => $pathdb]);
  295. }else{
  296. $db = DB::table('admin_app')->where('id', $id)->update(['img' => $pathdb]);
  297. }
  298. if ($db > 0) {
  299. return redirect('/apps');
  300. }
  301. }
  302. }
  303. }
  304. /*if ($request->isMethod('POST')) { //判断文件是否是 POST的方式上传
  305. $tmp = $request->file('file');
  306. $path = '/uploads/ico'; //public下的article
  307. if ($tmp->isValid()) { //判断文件上传是否有效
  308. $FileType = $tmp->getClientOriginalExtension(); //获取文件后缀
  309. $FilePath = $tmp->getRealPath(); //获取文件临时存放位置
  310. $FileName = date('YmdHis') . uniqid() . '.' . $FileType; //定义文件名
  311. Storage::disk('article')->put($FileName, file_get_contents($FilePath)); //存储文件
  312. //路径存数据库
  313. $pathdb = $path.'/'.$FileName;
  314. $cat = DB::table('admin_app')->where('id',$id)->select('img')->first();
  315. $cat = get_object_vars($cat);
  316. $cat = $cat['img'];
  317. if($cat != ''){
  318. $pathdb = $cat.'|'.$pathdb;
  319. $db= DB::table('admin_app')->where('id',$id)->update(['img'=>$pathdb]);
  320. }else{
  321. $db = DB::table('admin_app')->where('id',$id)->update(['img'=>$pathdb]);
  322. }
  323. if($db>0){
  324. return redirect('/apps');
  325. }
  326. }
  327. }*/
  328. /**
  329. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  330. * 应用上传显示
  331. */
  332. public function uploads()
  333. {
  334. return view('app.upload');
  335. }
  336. /**
  337. * @param Request $request
  338. * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  339. * 上传处理
  340. */
  341. public function fileuploads(Request $request)
  342. {
  343. //$data = $request->all();
  344. $file = $request->file('picture'); //获取文件所有信息
  345. if ($file == null || $file == '') {
  346. return redirect('/apps');
  347. }
  348. $path = '';
  349. $fileextension = $file->getClientOriginalName();//获取文件原名称
  350. $filesize = $file->getClientSize();//文件大小b
  351. $filesize = round($filesize / 1024 / 1024, 2);//文件大小
  352. //var_dump($filesize);
  353. if ($file->isValid()) { //判断文件是否存在
  354. $clientName = $file->getClientOriginalName(); //客户端文件名称..
  355. $entension = $file->getClientOriginalExtension(); //上传文件的后缀.
  356. $newName = md5(date('Ymdhis') . $clientName) . "." . $entension; //定义 上传文件的新名称
  357. $path = $file->move('/uploads', $newName); //把缓存文件移动到指定文件夹
  358. //var_dump($path);die;
  359. $db = DB::table('admin_app')->insert(['app_title' => $fileextension, 'app_id' => $fileextension, 'filesize' => $filesize, 'a_title' => $fileextension, 'path' => $path]);
  360. if ($db > 0) {
  361. return redirect('/apps');
  362. }
  363. }
  364. }
  365. /**
  366. * @param $id
  367. * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  368. * 软件删除,注会同时删除本地上传的
  369. */
  370. public function deldata($id)
  371. {
  372. $src = DB::table('admin_app')->select('path')->where('id', $id)->first();
  373. $src = (array)$src;
  374. $src = $src['path'];
  375. $db = DB::table('admin_app')->where('id', $id)->delete();
  376. if ($db > 0) {
  377. if ($src != null || $src != '') {
  378. $res = unlink($src);
  379. return redirect('/apps/');
  380. } else {
  381. return redirect('/apps/');
  382. }
  383. } else {
  384. return redirect('/apps/');
  385. }
  386. }
  387. }