12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace App\Http\Controllers\Admin\Interaction;
- use App\Models\CommentInfoModel;
- use App\Models\DreamInfoModel;
- use App\Models\InteractionInfo;
- use App\Widget\Tools\VideoUpload;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Admin\Controller;
- class InfoController extends Controller
- {
- public function view(Request $request)
- {
- $dream_id = $request->id;
- $dream = DreamInfoModel::where('id',$request->id)->with('interactions')->first();
- $list = $dream->interactions;
- foreach ($list as $item){
- $comments = CommentInfoModel::where('interaction_id',$item->id)->orderBy('created_at')->get();
- $item->comms = $comments;
- }
- return view('admin.dream.interaction.view',compact('list','dream_id'));
- }
- public function update(Request $request,$id)
- {
- $data = (array) request('data');
- $ok =CommentInfoModel::where('id',$id)->update($data);
- if($ok) {
- $url[] = array('url'=>U( 'Dream/Info/index'),'title'=>'返回列表');
- return $this->showMessage('操作成功',urldecode(request('_referer')));
- }else{
- $url[] = array('url'=>U( 'Dream/Info/index'),'title'=>'返回列表');
- return $this->showWarning('操作失败',$url);
- }
- }
- // 新增动态
- public function create(Request $reqeust)
- {
- if($reqeust->method() == 'POST') {
- return $this->_createSave();
- }
- $dream_id = $reqeust->dream_id;
- return view('admin.interaction.info.edit',compact('dream_id'));
- }
- /**
- * 保存修改
- */
- private function _createSave(){
- $data = (array) request('data');
- $pics = (array) request('pic');
- if($pics){
- foreach ($pics['url'] as $key => $pic) {
- $data['pic'.($key+1)] = getenv('APP_URL').$pic;
- }
- }
- if (request("file")) {
- $file = request("file");
- $fileSize = $file->getSize();
- $size = 200 * 1024 * 1024;
- if ($fileSize > $size) {
- return back()->with('error','请上传小于200MB的文件!');
- }
- $mimeType = [
- 'video/mp4',
- ];
- $fileMimeType = $file->getMimeType();
- if (!empty($mimeType) && !in_array($fileMimeType, $mimeType)) {
- return back()->with('error','File type allow MP4!');
- }
- if (!$file = VideoUpload::mvFile('file')) return back()->with('error','上传失败');
- $data["video"] = $file;
- }
- $id = InteractionInfo::create($data);
- if($id) {
- $url[] = array('url'=>U( 'Dream/Info/index'),'title'=>'返回列表');
- $this->showMessage('添加成功',$url);
- }else{
- $url[] = array('url'=>U( 'Dream/Info/index'),'title'=>'返回列表');
- return $this->showWarning('添加失败',$url);
- }
- }
- }
|