public function getWaterList() { /** @var $activity \App\Model\Activity */ $activity = new Activity(); $activity_result = $activity->StatusOk()->Qingshuiquan()->orderBy('created_at', 'desc')->paginate(10); $list = []; $activity_id_list = []; foreach ($activity_result->toArray()['data'] as $activity_result_v) { array_push($activity_id_list, $activity_result_v['activity_id']); $list[] = ['active_id' => $activity_result_v['activity_id'], 'content' => $activity_result_v['desc'], 'create_time' => $activity_result_v['created_at'], 'support' => $activity_result_v['focus_count'], 'image_url' => ActivityImage::defaultImage()]; } //获得关注信息 //获得图片 $activity_image_result = ActivityImage::whereIn('activity_id', $activity_id_list)->GIF()->get(); $activity_image_info = []; if (!empty($activity_image_result)) { foreach ($activity_image_result as $activity_image_result_v) { $activity_image_info[$activity_image_result_v->activity_id] = $activity_image_result_v->path(); } } foreach ($list as &$v) { if (isset($activity_image_info[$v['active_id']])) { $v['image_url'] = $activity_image_info[$v['active_id']]; } } return ['list' => $list, 'obj' => $activity_result]; }
public function editSubmit(Request $request) { $activity_id = $request->input('activity_id'); if (!$activity_id) { return $this->returnAddJs('非法操作!'); } $title = $request->input('title'); if (!$title) { return $this->returnAddJs('请填写标题!'); } $url = $request->input('url'); if (!$url) { return $this->returnAddJs('请填写活动链接!'); } $description = $request->input('description'); if (!$description) { return $this->returnAddJs('请填写描述!'); } $statement = $request->input('statement'); if (!$statement) { return $this->returnAddJs('请填写声明!'); } $price = $request->input('price'); if (!$price || !intval($price)) { return $this->returnAddJs('请填写捐赠额度!'); } $video_w = $request->input('video'); if ($video_w) { if ($request->input('video_id')) { $activity_image = new ActivityImage(); $activity_image->where('id', $request->input('video_id'))->update(['image_url' => $video_w]); } else { $activity_image = new ActivityImage(); $activity_image->activity_id = $activity_id; $activity_image->image_url = $video_w; $activity_image->type = ActivityImage::TYPE_IMAGE_IS_GIF; $activity_image->save(); } } $image1 = $request->file('image1'); if (!empty($image1)) { if (strpos($image1->getMimeType(), 'image/') === false) { return $this->returnAddJs('第一张图片格式不正确!'); } $image1_w = $this->updateFile($image1); if (!$image1_w) { return $this->returnAddJs('第一张图片上传失败,请重新上传!'); } else { if ($request->input('image1_id')) { $activity_image = new ActivityImage(); $activity_image->where('id', $request->input('image1_id'))->update(['image_url' => $image1_w]); } else { $activity_image = new ActivityImage(); $activity_image->activity_id = $activity_id; $activity_image->image_url = $image1_w; $activity_image->type = ActivityImage::TYPE_IMAGE_IS_PIC; $activity_image->save(); } } } $image2 = $request->file('image2'); if (!empty($image2)) { if (strpos($image2->getMimeType(), 'image/') === false) { return $this->returnAddJs('第二张图片格式不正确!'); } $image2_w = $this->updateFile($image2); if (!$image2_w) { return $this->returnAddJs('第二张图片上传失败,请重新上传!'); } else { if ($request->input('image2_id')) { $activity_image = new ActivityImage(); $activity_image->where('id', $request->input('image2_id'))->update(['image_url' => $image2_w]); } else { $activity_image = new ActivityImage(); $activity_image->activity_id = $activity_id; $activity_image->image_url = $image2_w; $activity_image->type = ActivityImage::TYPE_IMAGE_IS_PIC; $activity_image->save(); } } } $image3 = $request->file('image3'); if (!empty($image3)) { if (strpos($image3->getMimeType(), 'image/') === false) { return $this->returnAddJs('第三张图片格式不正确'); } $image3_w = $this->updateFile($image3); if (!$image3_w) { return $this->returnAddJs('第三张图片上传失败,请重新上传'); } else { if ($request->input('image3_id')) { $activity_image = new ActivityImage(); $activity_image->where('id', $request->input('image3_id'))->update(['image_url' => $image3_w]); } else { $activity_image = new ActivityImage(); $activity_image->activity_id = $activity_id; $activity_image->image_url = $image3_w; $activity_image->type = ActivityImage::TYPE_IMAGE_IS_PIC; $activity_image->save(); } } } $activity = new Activity(); $bool = $activity->where('activity_id', $activity_id)->update(['title' => $title, 'desc' => $description, 'statement' => $statement, 'url' => $url]); if ($bool) { //插入捐赠额度 $activity_fundraising = new ActivityFundraising(); $activity_fundraising->where('activity_id', $activity_id)->update(['total_amount_price' => $price]); return $this->returnAddJs('活动修改成功!'); } return $this->returnAddJs('创建失败,请重新操作!'); }