/** * 公益捐款 * @param $params * @param $user_id * @return array */ public function activeDonations($params, $user_id) { if (!$params->get('activeID')) { return ['status' => false, 'message' => '活动ID不能为空!', 'info' => []]; } if (!$params->get('money')) { return ['status' => false, 'message' => '金额不能为空!', 'info' => []]; } //金额转换亲水值 $money_to_water = $params->get('money') * ActivityDonationsLog::getRate(); $user_financial = new UserFinancial(); $user_financial_result = $user_financial->where('user_id', $user_id)->first(); if ($user_financial_result->water_count < $money_to_water) { return ['status' => false, 'message' => '你的亲水值不够!', 'info' => []]; } $bool = $user_financial->where('user_id', $user_id)->update(['water_count' => $user_financial_result->water_count - $money_to_water, 'send_water' => $user_financial_result->send_water + $money_to_water]); if ($bool) { $activity_fundraising = new ActivityFundraising(); $activity_fundraising_result = $activity_fundraising->where('activity_id', $params->get('activeID'))->first(); $activity_fundraising->where('activity_id', $params->get('activeID'))->update(['fundraising_count' => $activity_fundraising_result->fundraising_count + 1, 'existing_price' => $activity_fundraising_result->existing_price + $params->get('money')]); //记录日志 $activity_donations_log = new ActivityDonationsLog(); $activity_donations_log->active_id = $params->get('activeID'); $activity_donations_log->user_id = $user_id; $activity_donations_log->water_count = $money_to_water; $activity_donations_log->price = $params->get('money'); $activity_donations_log->rate = ActivityDonationsLog::getRate(); $activity_donations_log->save(); return ['status' => true, 'message' => '捐款成功!', 'info' => []]; } return ['status' => false, 'message' => '系统错误!', 'info' => []]; }
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('创建失败,请重新操作!'); }