public function postBooth() { // base infos $token = Input::get('token', ''); $u_id = Input::get('u_id', ''); // booth type $boothType = Input::get('type'); // product category $productCate = Input::get('prod_cate'); // booth title $boothTitle = Input::get('title'); // booth position $boothLng = Input::get('lng'); $boothLat = Input::get('lat'); // product source $productSource = Input::get('prod_source'); // customer group $cusomerGroup = Input::get('cust_group'); // promo strategy $promoStratege = Input::get('promo_strategy'); // with fund $withFund = Input::get('fund', 0); $booth_cate = Input::get('cate', 0); // profit ratio $profitRate = Input::get('profit'); // loan amount $loan = Input::get('loan'); // how to drow loan $loanSchema = Input::get('loan_schema', ''); DB::beginTransaction(); try { $user = User::chkUserByToken($token, $u_id); $user->load(['school']); $booth = Booth::where('u_id', '=', $u_id)->first(); if (empty($booth)) { $booth = new Booth(); } else { if ($booth->b_status == 1) { throw new Exception("您已经申请过店铺了", 7001); } } $school = $user->school; $booth->s_id = $school->t_id; $booth->c_id = $school->t_city; $booth->pv_id = $school->t_province; $booth->u_id = $u_id; $booth->b_title = $boothTitle; $booth->b_desc = ''; $booth->latitude = $boothLat; $booth->longitude = $boothLng; $booth->b_product_source = $productSource; $booth->b_product_category = $productCate; $booth->b_customer_group = $cusomerGroup; $booth->b_promo_strategy = $promoStratege; $booth->b_with_fund = $withFund; $booth->b_type = $boothType; $booth->b_cate = $booth_cate; $b_id = $booth->register(); if ($withFund == 1) { $fund = Fund::where('b_id', '=', $booth->b_id)->first(); if (empty($fund)) { $fund = new Fund(); } else { if ($fund->t_status > 2) { throw new Exception("基金已经发放", 1); } } $fund->u_id = $u_id; $fund->t_apply_money = $loan; $fund->b_id = $b_id; $fund->t_profit_rate = $profitRate; $f_id = $fund->apply(); $schema = 0; $allotedAmount = 0; $loanSchema = json_decode($loanSchema, true); if (!is_array($loanSchema)) { throw new Exception("请传入正确的提款计划", 7001); } // clear all exists schema DB::table('repayments')->where('f_id', '=', $f_id)->delete(); foreach ($loanSchema as $key => $percentage) { $percentage = $percentage / 100; $schema++; if ($schema == count($loanSchema)) { $amount = $loan - $allotedAmount; } else { $amount = $loan * $percentage; $allotedAmount += $amount; } $repayment = new Repayment(); $repayment->f_id = $f_id; $repayment->f_re_money = $amount; $repayment->f_schema = $schema; $repayment->f_percentage = $percentage * 100; $repayment->apply(); } } else { // if without fund, no need to censor $booth->b_status = 1; $booth->save(); } $re = Tools::reTrue('申请成功'); DB::commit(); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '申请失败:' . $e->getMessage()); DB::rollback(); } return Response::json($re); }
public function postFlea() { $token = Input::get('token', ''); $u_id = Input::get('u_id', 0); $mobile = Input::get('mobile', ''); $prodName = Input::get('prod_name', ''); $prodDesc = Input::get('content', ''); $prodBrief = Input::get('prod_brief', ''); $price = Input::get('price', ''); $publish = Input::get('publish', 1); $product_cate = Input::get('cate', 7); $active_at = Input::get('active_at'); if (empty($active_at)) { $active_at = Tools::getNow(); } $open_file = Input::get('open_file', 0); if (!$product_cate) { $product_cate = 7; } $prodDesc = urldecode($prodDesc); $img_token = Input::get('img_token', ''); try { $user = User::chkUserByToken($token, $u_id); $booth = Booth::where('u_id', '=', $u_id)->first(); if (empty($booth)) { $user->load('school'); $school = $user->school; $booth = new Booth(); $booth->u_id = $u_id; $booth->b_type = 7; $booth->c_id = $school->t_city; $booth->s_id = $school->t_id; $booth->pv_id = $school->t_province; $booth->b_with_fund = 0; $booth->latitude = $user->latitude; $booth->longitude = $user->longitude; $booth->save(); } $product = new Product(); $product->b_id = $booth->b_id; $product->p_title = $prodName; $product->u_id = $u_id; $product->p_cost = 0; $product->p_price_origin = $price; $product->p_price = $price; $product->p_discount = 0; $product->p_desc = $prodDesc; $product->p_brief = $prodBrief; $product->p_status = $publish == 1 ? 1 : 2; $product->p_cate = $product_cate; $product->active_at = $active_at; $product->p_type = 2; $product->open_file = $open_file; $product->p_mobile = $mobile; $p_id = $product->addProduct(); $quantity = new ProductQuantity(); $quantity->p_id = $p_id; $quantity->b_id = $booth->b_id; $quantity->u_id = $u_id; $quantity->q_total = 1; $quantity->addQuantity(); if ($img_token) { $imgObj = new Img('product', $img_token); $imgs = $imgObj->getSavedImg($p_id, '', true); $product->p_imgs = implode(',', $imgs); $product->save(); } $re = Tools::reTrue('添加产品成功'); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '添加产品失败:' . $e->getMessage()); } return Response::json($re); }
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); }