/** * Run the migrations. * * @return void */ public function up() { set_time_limit(0); Schema::table('crowd_fundings', function ($table) { $table->integer('e_id'); }); $list = CrowdFunding::get(); foreach ($list as $key => $funding) { // handle event $event = new EventItem(); $event->e_title = $funding->c_title; $imgs = Img::toArray($funding->c_imgs); if (empty($imgs['cover_img'])) { $cover = ''; } else { $cover = $imgs['cover_img']; unset($imgs['cover_img']); } $event->cover_img = $cover; $event->e_brief = $funding->c_brief; $event->e_range = 0; $event->e_start_at = $funding->active_at; $event->e_end_at = $funding->end_at; $event->created_at = $funding->created_at; $event->e_status = 1; $event->save(); // handle ranges $range = new EventRange(); $range->e_id = $event->e_id; $range->s_id = $funding->s_id; $range->c_id = $funding->c_id; $range->p_id = $funding->pv_id; $range->save(); // handle imgs $funding->c_imgs = implode(',', $imgs); $funding->e_id = $event->e_id; $funding->save(); } }
public function postCrowdFunding() { $token = Input::get('token', ''); $u_id = Input::get('u_id', 0); $title = Input::get('title', ''); $cate = Input::get('cate', 1); $amount = Input::get('amount', 0); $time = Input::get('time', 0); $yield_time = Input::get('yield_time', 0); $shipping = Input::get('shipping', 0); $shipping_fee = Input::get('shipping_fee', 0); $brief = Input::get('brief', ''); $yield_desc = Input::get('yield_desc', ''); $content = Input::get('content', ''); $open_file = Input::get('open_file', 0); $active_at = Input::get('active_at'); $local_only = Input::get('local_only', 0); $is_schedule = Input::get('is_schedule', 0); if (empty($active_at)) { $active_at = Tools::getNow(); } $mobile = Input::get('mobile', ''); $price = Input::get('price', 0); $quantity = Input::get('quantity', 0); $is_limit = Input::get('is_limit', 0); $img_token = Input::get('img_token', ''); $img_token_2 = Input::get('img_token_2', ''); $apartment_no = Input::get('apartment_no', ''); $content = urldecode($content); DB::beginTransaction(); try { $user = User::chkUserByToken($token, $u_id); if ($cate == 8 && $user->u_type != 2) { throw new Exception("错误的发布类型", 2001); } $base = new DateTime(); $base->modify('+90 days'); $target = new DateTime($active_at); if ($base < $target) { throw new Exception("最大预发布时间不能超过3个月", 2001); } $user->load('booth', 'profileBase', 'school'); if ($apartment_no) { $tmp_base = TmpUserProfileBase::find($user->u_id); $tmp_base->u_apartment_no = $apartment_no; $tmp_base->save(); } if (empty($user->booth)) { $booth = new Booth(); $booth->u_id = $u_id; $booth->b_type = 7; $booth->c_id = $user->school->t_city; $booth->s_id = $user->school->t_id; $booth->b_with_fund = 0; $booth->latitude = $user->latitude; $booth->longitude = $user->longitude; $booth->save(); } else { $booth = $user->booth; } // add event $event = new EventItem(); $event->e_title = $title; $event->e_range = 0; $event->e_brief = $brief; $event->e_start_at = $active_at; $date_obj = new DateTime($active_at); $date_obj->modify('+' . $time . ' days'); $event->e_end_at = $date_obj->format('Y-m-d H:i:s'); $event->addEvent(); $range = new EventRange(); $range->e_id = $event->e_id; $range->s_id = $user->school->t_id; $range->c_id = $user->school->t_city; $range->p_id = $user->school->t_province; $range->save(); // add funding $crowd_funding = new CrowdFunding(); $crowd_funding->u_id = $u_id; $crowd_funding->b_id = $booth->b_id; $crowd_funding->e_id = $event->e_id; $crowd_funding->c_is_schedule = $is_schedule; $crowd_funding->c_yield_desc = $yield_desc; $crowd_funding->c_content = $content; $crowd_funding->c_yield_time = $yield_time; $crowd_funding->u_mobile = $mobile; $crowd_funding->c_time = $time; $crowd_funding->c_shipping = $shipping; $crowd_funding->c_shipping_fee = $shipping_fee; $crowd_funding->c_target_amount = $amount; $crowd_funding->c_cate = $cate; $crowd_funding->c_local_only = $local_only; $crowd_funding->c_open_file = $open_file; if ($amount <= 50000) { $crowd_funding->c_status = 4; } else { $crowd_funding->c_status = 1; $msg = new MessageDispatcher($u_id); $msg->fireTextToUser('你此次众筹总金额已超过50000元,我们将在24小时以内进行审核,请耐心等待。'); } // if the user is an official user, set funding type to offical if ($user->u_type == 2) { $crowd_funding->c_cate = 8; } $crowd_funding->addCrowdFunding(); if ($img_token) { $imgObj = new Img('event', $img_token); $event->cover_img = $imgObj->getSavedImg($event->e_id); $event->save(); } if ($img_token_2) { $imgObj = new Img('crowd_funding', $img_token_2); $crowd_funding->c_imgs = $imgObj->getSavedImg($crowd_funding->cf_id); $crowd_funding->save(); } // add funding product $funding_product = new CrowdFundingProduct(); $funding_product->cf_id = $crowd_funding->cf_id; $funding_product->u_id = $u_id; $funding_product->b_id = $booth->b_id; $funding_product->p_title = $title; $funding_product->p_desc = ''; $funding_product->p_price = $price; $funding_product->p_target_quantity = $quantity; $funding_product->p_sort = 0; if ($is_limit) { $funding_product->p_max_quantity = $quantity; } else { $funding_product->p_max_quantity = 0; } $funding_product->addProduct(); $re = Tools::reTrue('添加众筹成功'); DB::commit(); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '添加众筹失败:' . $e->getMessage()); DB::rollback(); } return Response::json($re); }