public function interviewFund($id) { $check = Input::get('check', 0); $remark = Input::get('remark', ''); try { $fund = Fund::find($id); if (empty($fund)) { throw new Exception("没有找到请求的基金记录", 10001); } $booth = Booth::find($fund->b_id); if (empty($booth)) { throw new Exception("无与基金相关的店铺数据", 10001); } if ($check) { $fund->t_status = 3; $booth->b_status = 1; } else { $fund->t_status = 1; $booth->b_status = 2; } $booth->save(); $fund->remark = $remark; $fund->interview(); $re = Tools::reTrue('操作成功'); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '操作失败:' . $e->getMessage()); } return Response::json($re); }
public function postFavorite($id) { $token = Input::get('token', ''); $u_id = Input::get('u_id', 0); $type = Input::get('type', 0); try { $user = User::chkUserByToken($token, $u_id); $booth = Booth::find($id); if (empty($booth)) { throw new Exception("请求的店铺不存在", 2001); } $chk = $booth->favorites()->where('favorites.u_id', '=', $u_id)->first(); if ($type == 1) { if (empty($chk)) { $data = ['u_id' => $u_id, 'created_at' => Tools::getNow(), 'u_name' => $user->u_nickname]; $favorite = new Favorite($data); $booth->favorites()->save($favorite); } } else { if (!empty($chk)) { $booth->favorites()->detach($chk->id); $chk->delete(); } } $re = Tools::reTrue('操作成功'); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '操作失败:' . $e->getMessage()); } return Response::json($re); }
/** * Run the migrations. * * @return void */ public function up() { Schema::table('booths', function ($table) { $table->integer('pv_id'); // 省id }); Schema::table('crowd_fundings', function ($table) { $table->integer('pv_id'); // 省id }); Schema::table('promotion_infos', function ($table) { $table->integer('pv_id'); }); $list = Booth::with(['school'])->get(); foreach ($list as $key => $booth) { $pv_id = $booth->school->t_province; $booth->pv_id = $pv_id; $booth->save(); } $list = CrowdFunding::with(['school'])->get(); foreach ($list as $key => $funding) { $pv_id = $funding->school->t_province; $funding->pv_id = $pv_id; $funding->save(); } $list = PromotionInfo::with(['school'])->get(); foreach ($list as $key => $promo) { $pv_id = $promo->school->t_province; $promo->pv_id = $pv_id; $promo->save(); } }
public function unfollow() { $chk = BoothFollow::where('b_id', '=', $this->b_id)->where('u_id', '=', $this->u_id)->first(); if (!empty($chk)) { $chk->delete(); } else { throw new Exception("已取消关注", 7004); } $booth = Booth::find($this->b_id); $booth->b_fans_count -= 1; if ($booth->b_fans_count <= 0) { $booth->b_fans_count = 0; } $booth->save(); return true; }
public function getBooth($id) { $token = Input::get('token', ''); $u_id = Input::get('u_id', 0); try { $user = User::chkUserByToken($token, $u_id); $booth = Booth::find($id); if (empty($booth) || $booth->u_id != $u_id) { throw new Exception("无法获取请求的店铺", 7001); } $data = $booth->showDetail(); $re = Tools::reTrue('获取店铺信息成功', $data); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '获取店铺信息失败:' . $e->getMessage()); } return Response::json($re); }
public function updateBooth($id) { $token = Input::get('token', ''); $u_id = Input::get('u_id', 0); $lat = Input::get('lat', 0); $lng = Input::get('lng', 0); try { $user = User::chkUserByToken($token, $u_id); $booth = Booth::find($id); if ($booth->u_id != $user->u_id) { throw new Exception("您无法操作该店铺", 7001); } $booth->latitude = $lat; $booth->longitude = $lng; $booth->save(); $re = Tools::reTrue('更新店铺地址成功'); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '更新店铺地址:' . $e->getMessage()); } }
public function checkoutCrowdFunding() { if ($this->c_type != 2) { return true; } // push msg to seller $booth = Booth::find($this->b_id); $product = CrowdFundingProduct::find($this->p_id); $product->confirmProduct($this->c_quantity); $funding = CrowdFunding::find($product->cf_id); $funding->c_amount += $this->c_amount; $funding->save(); $msg = new MessageDispatcher($booth->u_id); $msg->fireCateToUser('您的众筹' . $funding->c_title . '已有人认购', 1, $funding->cf_id); return true; }
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 listFavoriteBooth() { $token = Input::get('token', ''); $u_id = Input::get('u_id'); $per_page = Input::get('per_page', 0); try { $user = User::chkUserByToken($token, $u_id); $list = Booth::select('booths.*', 'favorites.created_at')->with(['user', 'school', 'city', 'praises' => function ($q) { $q->where('praises.u_id', '=', $this->u_id); }])->join('favoriables', function ($q) { $q->on('booths.b_id', '=', 'favoriables.favoriable_id')->where('favoriables.favoriable_type', '=', 'Booth'); })->join('favorites', function ($q) { $q->on('favorites.id', '=', 'favoriables.favorite_id')->where('favorites.u_id', '=', $this->u_id); })->orderBy('favorites.created_at', 'DESC')->paginate($per_page); $data = []; foreach ($list as $key => $booth) { $tmp = $booth->showInList(); $tmp['is_praised'] = 0; if (count($booth->praises) > 0) { $tmp['is_praised'] = 1; } $data[] = $tmp; } $re = Tools::reTrue('获取店铺成功', $data); } 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); }
public function listLoans($id) { try { $booth = Booth::with(['fund', 'fund.loans'])->find($id); if (empty($booth)) { throw new Exception("没有找到请求的店铺", 10001); } $income = $booth->fund->getCurrentPeriodIncome(); $boothData = $booth->showDetail(); $fundData = $booth->fund->showDetail(); $data = ['last_income' => $income, 'booth' => $boothData, 'fund' => $fundData]; $re = Tools::reTrue('获取店铺贷款信息成功', $data); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '获取店铺信息失败:' . $e->getMessage()); } return Response::json($re); }
public static function clearByUser($u_id) { $record = Booth::where('u_id', '=', $u_id)->where('b_status', '=', 0)->first(); if (!empty($record)) { $record->delete(); } }
public function postFunding() { $u_id = Tools::getOfficialUserId(); $b_id = Tools::getOfficialBoothId(); $title = Input::get('title', ''); $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); $range = Input::get('range', 1); $cities = Input::get('cities', 0); $schools = Input::get('schools', 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', ''); $content = urldecode($content); DB::beginTransaction(); try { $user = User::find($u_id); $user->load('profileBase', 'school'); $booth = Booth::find($b_id); // add event $event = new EventItem(); $event->e_title = $title; $event->e_brief = $brief; $event->e_range = $range; $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(); $e_id = $event->e_id; // add funding $crowd_funding = new CrowdFunding(); $crowd_funding->u_id = $u_id; $crowd_funding->b_id = $booth->b_id; $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_amount = 0.0; $crowd_funding->c_local_only = $local_only; $crowd_funding->c_praise_count = 0; $crowd_funding->c_remark = ''; $crowd_funding->c_open_file = $open_file; $crowd_funding->c_status = 4; $crowd_funding->c_cate = 8; $crowd_funding->e_id = $e_id; $crowd_funding->addCrowdFunding(); if ($img_token) { $imgObj = new Img('crowd_funding', $img_token); $crowd_funding->c_imgs = $imgObj->getSavedImg($crowd_funding->cf_id); $crowd_funding->save(); $imgObj = new Img('event', $img_token); $event->cover_img = $imgObj->getSavedImg($event->e_id); $event->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(); if ($range == 1) { $event_range = new EventRange(['c_id' => 0, 'p_id' => 0, 's_id' => 0]); $event->ranges()->save($event_range); } if ($cities && $range == 2) { $city_sets = explode(',', $cities); foreach ($city_sets as $key => $set) { $array = explode('|', $set); $event_range = new EventRange(['c_id' => $array[0], 'p_id' => $array[1]]); if ($key) { $new_event = $crowd_funding->cloneCrowdFunding(); } else { $new_event = $event; } $new_event->ranges()->save($event_range); } } if ($schools && $range == 3) { $schools = explode(',', $schools); foreach ($schools as $key => $school) { $event_range = new EventRange(['s_id' => $school]); if ($key) { $new_event = $crowd_funding->cloneCrowdFunding(); } else { $new_event = $event; } $new_event->ranges()->save($event_range); } } $re = Tools::reTrue('添加众筹成功'); DB::commit(); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '添加众筹失败:' . $e->getMessage()); DB::rollback(); } return Response::json($re); }
public function confirm() { $this->getSummary(); foreach ($this->_bills as $key => $bill) { $booth = Booth::find($key); $wallet = UsersWalletBalances::find($booth->u_id); if ($booth->b_with_fund) { $fund = Fund::where('b_id', '=', $key)->where('t_is_close', '=', 0)->first(); if (empty($fund)) { $wallet->putIn($bill['total']['paied']); } } else { $wallet->putIn($bill['total']['paied']); } } $this->o_shipping_status = 10; return $this->save(); }
public function postOrder() { $now = new DateTime(); $token = Input::get('token', ''); $u_id = Input::get('u_id', 0); $amount_origin = Input::get('amount_origin', 0); $amount = Input::get('amount', 0); $shipping_fee = Input::get('shipping_fee', 0); $shipping_name = Input::get('shipping_name', ''); $shipping_phone = Input::get('shipping_phone', ''); $shipping_address = Input::get('shipping_address', ''); $shipping = Input::get('shipping', 1); $delivery_time = Input::get('delivery_time', $now->format('Y-m-d H:i:s')); $comment = Input::get('comment', ''); $carts = Input::get('carts', null); DB::beginTransaction(); try { if (empty($carts)) { throw new Exception("请传入有效的购物车", 1); } $carts = explode(',', $carts); $user = User::chkUserByToken($token, $u_id); $list = Cart::whereIn('c_id', $carts)->get(); $total_amount = 0; $total_amount_origin = 0; $b_ids = []; $amount_origin_sum = 0; $amount_sum = 0; $groups = []; foreach ($list as $key => $cart) { if ($cart->u_id != $u_id) { throw new Exception("没有权限操作该购物车", 7001); } if ($cart->c_status > 1) { throw new Exception("购物车无效", 7005); } $cart->updateCart($cart->c_quantity); if (empty($groups[$cart->b_id]['amount_origin'])) { $groups[$cart->b_id]['amount_origin'] = 0; $groups[$cart->b_id]['amount'] = 0; $groups[$cart->b_id]['carts_ids'] = []; } $groups[$cart->b_id]['amount_origin'] += $cart->c_amount_origin; $groups[$cart->b_id]['amount'] += $cart->c_amount; $groups[$cart->b_id]['carts_ids'][] = $cart->c_id; $b_ids[] = $cart->b_id; $amount_sum += $groups[$cart->b_id]['amount']; $amount_origin_sum += $groups[$cart->b_id]['amount_origin']; } if ($amount_origin_sum != $amount_origin || $amount_sum != $amount) { throw new Exception("支付金额已刷新, 请重新提交订单", 9003); } $order_group_no = Order::generateOrderGroupNo($u_id); foreach ($groups as $b_id => $group) { $rnd_str = rand(10, 99); $order_no = $order_group_no . $b_id . $rnd_str; $order = new Order(); $order->u_id = $u_id; $order->b_id = $b_id; $order->o_amount_origin = $group['amount_origin']; $order->o_amount = $group['amount']; $order->o_shipping_fee = $shipping_fee; $order->o_shipping_name = $shipping_name; $order->o_shipping_phone = $shipping_phone; $order->o_shipping_address = $shipping_address; $order->o_delivery_time = $delivery_time; $order->o_shipping = $shipping; $order->o_comment = $comment; $order->o_number = $order_no; $order->o_group_number = $order_group_no; $o_id = $order->addOrder(); Cart::bindOrder([$order->o_id => $group['carts_ids']]); } // push msg to seller $list = Booth::whereIn('b_id', $b_ids)->get(); foreach ($list as $key => $booth) { $obj = new MessageDispatcher($booth->u_id); $obj->fireTextToUser('您有新的订单, 请及时发货'); } $re = Tools::reTrue('提交订单成功', ['order_no' => $order_group_no]); DB::commit(); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), $e->getMessage()); DB::rollback(); } return Response::json($re); }