| xqd
@@ -2,9 +2,11 @@
|
|
|
|
|
|
namespace App\Http\Controllers\Admin\Interaction;
|
|
|
|
|
|
+use App\Models\BaseAttachmentModel;
|
|
|
use App\Models\CommentInfoModel;
|
|
|
use App\Models\DreamInfoModel;
|
|
|
use App\Models\InteractionInfo;
|
|
|
+use App\Models\UserInfoModel;
|
|
|
use App\Widget\Tools\VideoUpload;
|
|
|
use Illuminate\Http\Request;
|
|
|
use App\Http\Controllers\Admin\Controller;
|
| xqd
@@ -85,4 +87,126 @@ class InfoController extends Controller
|
|
|
return $this->showWarning('添加失败',$url);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+// 修改动态
|
|
|
+ public function updateInteraction(Request $reqeust) {
|
|
|
+ if($reqeust->method() == 'POST') {
|
|
|
+ return $this->_updateSave();
|
|
|
+ }
|
|
|
+ $data = InteractionInfo::find($reqeust->get('id'));
|
|
|
+ $arr = [];
|
|
|
+ for ($i = 1; $i <=9; $i++) {
|
|
|
+ if (!empty($data['pic'.($i)])) {
|
|
|
+ $arr[] = $data['pic'.($i)];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $data->imgs = $arr;
|
|
|
+ return view('admin.interaction.info.edit',compact('data'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存修改
|
|
|
+ */
|
|
|
+ private function _updateSave() {
|
|
|
+ $data = (array) request('data');
|
|
|
+ $interaction_id = request('id');
|
|
|
+ $interaction = InteractionInfo::find($interaction_id)->toArray();
|
|
|
+ $old_pics = [];
|
|
|
+ for ($i = 1; $i <=9; $i++) {
|
|
|
+ if (!empty($interaction['pic'.($i)])) {
|
|
|
+ $old_pics[] = $interaction['pic'.($i)];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $new_pics = (array) request('pic');
|
|
|
+ $a = array_diff($new_pics['url'],$old_pics);
|
|
|
+ $b = array_diff($old_pics,$new_pics['url']);
|
|
|
+ if (!empty($a) || !empty($b)) { //有图片变化执行
|
|
|
+ // 删除以前图片 重新插入
|
|
|
+ if (!empty($b)) {
|
|
|
+ foreach ($b as $old_pic){
|
|
|
+ $key = array_search($old_pic,$interaction);
|
|
|
+ $interaction[$key] = '';
|
|
|
+ if (is_file('.'.str_replace(getenv('APP_URL'),'',$old_pic))) {
|
|
|
+ unlink('.'.str_replace(getenv('APP_URL'),'',$old_pic));
|
|
|
+ }
|
|
|
+ BaseAttachmentModel::where('url',$old_pic)->delete();
|
|
|
+ InteractionInfo::find(request('id'))->update($interaction);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $a = array_values($a);
|
|
|
+ for ($i = 1; $i <=9; $i++) {
|
|
|
+ if (empty($interaction['pic'.($i)])) {
|
|
|
+ $c = -1;
|
|
|
+ $c++;
|
|
|
+ $interaction['pic'.($i)] = getenv('APP_URL').$a[$c];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ $ok = InteractionInfo::find(request('id'))->update($interaction);
|
|
|
+ if($ok) {
|
|
|
+ $url[] = array('url'=>U( 'Interaction/Info/index'),'title'=>'返回列表');
|
|
|
+ return $this->showMessage('操作成功',urldecode(request('_referer')));
|
|
|
+ }else{
|
|
|
+ $url[] = array('url'=>U( 'Interaction/Info/index'),'title'=>'返回列表');
|
|
|
+ return $this->showWarning('操作失败',$url);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ */
|
|
|
+ public function destroy(Request $reqeust)
|
|
|
+ {
|
|
|
+
|
|
|
+ $ok = InteractionInfo::destroy($reqeust->get('id'));
|
|
|
+ if ($ok) {
|
|
|
+ return $this->showMessage('操作成功');
|
|
|
+ } else {
|
|
|
+ return $this->showWarning("操作失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function comment(Request $request)
|
|
|
+ {
|
|
|
+ $interaction_id = $request->input('id');
|
|
|
+ $comment_id = $request->input('comment_id');
|
|
|
+ if ($request->isMethod('POST')) {
|
|
|
+ $comment = $request->input('comment');
|
|
|
+ $interaction = InteractionInfo::find($interaction_id);
|
|
|
+ $user_id = empty($interaction->dream) ? 0 : $interaction->dream->user_id;
|
|
|
+ $user = UserInfoModel::find($user_id);
|
|
|
+ if(!empty($comment_id)){
|
|
|
+ $comment = CommentInfoModel::find($comment_id);
|
|
|
+ $arr = [
|
|
|
+ 'interaction_id'=>$comment->interaction_id,
|
|
|
+ 'user_id'=>$comment->user_id,
|
|
|
+ 'user_avatar'=>$comment->user_avatar,
|
|
|
+ 'user_nickname'=>$comment->user_nickname,
|
|
|
+ 'to_user_id'=>$user_id,
|
|
|
+ 'content'=>$comment,
|
|
|
+ 'to_user_avatar'=>empty($user) ? '' : $user->avatar ,
|
|
|
+ 'to_user_nickname'=>empty($user) ? '' : $user->nickname ,
|
|
|
+ ];
|
|
|
+// dug
|
|
|
+ $ok = CommentInfoModel::create($arr);
|
|
|
+ }else{
|
|
|
+ $arr = [
|
|
|
+ 'interaction_id'=>$interaction_id,
|
|
|
+ 'user_id'=>$user_id,
|
|
|
+ 'content'=>$comment,
|
|
|
+ 'user_avatar'=>empty($user) ? '' : $user->avatar ,
|
|
|
+ 'user_nickname'=>empty($user) ? '' : $user->nickname ,
|
|
|
+ ];
|
|
|
+ $ok = CommentInfoModel::create($arr);
|
|
|
+ }
|
|
|
+ if ($ok) {
|
|
|
+ return $this->showMessage('操作成功');
|
|
|
+ } else {
|
|
|
+ return $this->showWarning("操作失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return view('admin.comment.edit',compact('interaction_id'));
|
|
|
+ }
|
|
|
}
|