InfoController.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace App\Http\Controllers\Admin\Interaction;
  3. use App\Models\CommentInfoModel;
  4. use App\Models\DreamInfoModel;
  5. use App\Models\InteractionInfo;
  6. use App\Widget\Tools\VideoUpload;
  7. use Illuminate\Http\Request;
  8. use App\Http\Controllers\Admin\Controller;
  9. class InfoController extends Controller
  10. {
  11. public function view(Request $request)
  12. {
  13. $dream_id = $request->id;
  14. $dream = DreamInfoModel::where('id',$request->id)->with('interactions')->first();
  15. $list = $dream->interactions;
  16. foreach ($list as $item){
  17. $comments = CommentInfoModel::where('interaction_id',$item->id)->orderBy('created_at')->get();
  18. $item->comms = $comments;
  19. }
  20. return view('admin.dream.interaction.view',compact('list','dream_id'));
  21. }
  22. public function update(Request $request,$id)
  23. {
  24. $data = (array) request('data');
  25. $ok =CommentInfoModel::where('id',$id)->update($data);
  26. if($ok) {
  27. $url[] = array('url'=>U( 'Dream/Info/index'),'title'=>'返回列表');
  28. return $this->showMessage('操作成功',urldecode(request('_referer')));
  29. }else{
  30. $url[] = array('url'=>U( 'Dream/Info/index'),'title'=>'返回列表');
  31. return $this->showWarning('操作失败',$url);
  32. }
  33. }
  34. // 新增动态
  35. public function create(Request $reqeust)
  36. {
  37. if($reqeust->method() == 'POST') {
  38. return $this->_createSave();
  39. }
  40. $dream_id = $reqeust->dream_id;
  41. return view('admin.interaction.info.edit',compact('dream_id'));
  42. }
  43. /**
  44. * 保存修改
  45. */
  46. private function _createSave(){
  47. $data = (array) request('data');
  48. $pics = (array) request('pic');
  49. if($pics){
  50. foreach ($pics['url'] as $key => $pic) {
  51. $data['pic'.($key+1)] = getenv('APP_URL').$pic;
  52. }
  53. }
  54. if (request("file")) {
  55. $file = request("file");
  56. $fileSize = $file->getSize();
  57. $size = 200 * 1024 * 1024;
  58. if ($fileSize > $size) {
  59. return back()->with('error','请上传小于200MB的文件!');
  60. }
  61. $mimeType = [
  62. 'video/mp4',
  63. ];
  64. $fileMimeType = $file->getMimeType();
  65. if (!empty($mimeType) && !in_array($fileMimeType, $mimeType)) {
  66. return back()->with('error','File type allow MP4!');
  67. }
  68. if (!$file = VideoUpload::mvFile('file')) return back()->with('error','上传失败');
  69. $data["video"] = $file;
  70. }
  71. $id = InteractionInfo::create($data);
  72. if($id) {
  73. $url[] = array('url'=>U( 'Dream/Info/index'),'title'=>'返回列表');
  74. $this->showMessage('添加成功',$url);
  75. }else{
  76. $url[] = array('url'=>U( 'Dream/Info/index'),'title'=>'返回列表');
  77. return $this->showWarning('添加失败',$url);
  78. }
  79. }
  80. }