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); }
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 censorBooth($id) { $check = Input::get('check', 0); $remark = Input::get('remark', ''); $interview = Input::get('interview', 0); DB::beginTransaction(); try { $booth = Booth::find($id); if (empty($booth)) { throw new Exception("无法获取到店铺信息", 10001); } // get fund if there is one if ($booth->b_with_fund) { $fund = Fund::where('b_id', '=', $id)->first(); if (empty($fund)) { throw new Exception("基金数据不匹配", 10001); } } else { $fund = false; } if ($check == 1) { if ($booth->b_status == 1) { throw new Exception("店铺已经审核过了", 10002); } if ($interview != 1) { $booth->b_status = 1; } if ($fund) { $fund->censorPass($interview); } } elseif ($check == 0) { $booth->b_status = 2; $booth->remark = $remark; if ($fund) { $fund->censorFailed(); } } $booth->censor(); $re = Tools::reTrue('审核店铺成功'); DB::commit(); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '审核店铺失败:' . $e->getMessage()); DB::rollback(); } return Response::json($re); }
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 financialReport() { $token = Input::get('token', ''); $u_id = Input::get('u_id', 0); $day = Input::get('day', 0); $month = Input::get('month', 0); $year = Input::get('year', 0); $b_id = Input::get('b_id', 0); try { // $user = User::chkUserByToken($token, $u_id); $booth = Booth::find($b_id); if (empty($booth)) { throw new Exception("请求的店铺无效", 7001); } $query = DB::table('products')->leftJoin('carts', function ($q) { $q->on('products.p_id', '=', 'carts.p_id'); })->select('products.p_id as id', 'products.p_title as title', 'products.p_cost as cost', 'carts.c_quantity as quantity', 'carts.c_amount as amount', 'carts.c_id'); $query = $query->where('carts.b_id', '=', $b_id); $date_obj = new DateTime(); $today = $date_obj->format('Y-m-d'); if ($day) { $date_obj->modify('+1 day'); $tomorrow = $date_obj->format('Y-m-d'); $query = $query->where('carts.checkout_at', '>', $today)->where('carts.checkout_at', '<', $tomorrow); } if ($month) { $date_obj->modify('-1 month'); $one_month_ago = $date_obj->format('Y-m-d'); $query = $query->where('carts.checkout_at', '>', $one_month_ago)->where('carts.checkout_at', '<', $today); } if ($year) { $date_obj->modify('-1 year'); $one_year_ago = $date_obj->format('Y-m-d'); $query = $query->where('carts.checkout_at', '>', $one_year_ago)->where('carts.checkout_at', '<', $today); } $list = $query->get(); $report = []; $total_quantity = 0; $total_cost = 0; $total_amount = 0; $total_profit = 0; $cart_ids = []; foreach ($list as $key => $product) { if (empty($report[$product->id])) { $report[$product->id]['title'] = ''; $report[$product->id]['quantity'] = ''; $report[$product->id]['cost'] = ''; $report[$product->id]['amount'] = ''; } $report[$product->id]['title'] = $product->title; $report[$product->id]['quantity'] += $product->quantity; $report[$product->id]['cost'] += $product->cost * $product->quantity; $report[$product->id]['amount'] += $product->amount; $cart_ids[] = $product->c_id; } foreach ($report as $key => $product) { $report[$key]['id'] = $key; $report[$key]['profit'] = $product['amount'] - $product['cost']; $total_quantity += $product['quantity']; $total_cost += $product['cost']; $total_amount += $product['amount']; $total_profit += $report[$key]['profit']; } $report = array_values($report); $data = ['report' => $report, 'carts' => implode(',', $cart_ids), 'total_quantity' => $total_quantity, 'total_cost' => $total_cost, 'total_amount' => $total_amount, 'total_profit' => $total_profit]; $re = Tools::reTrue('获取报表成功', $data); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), $e->getMessage()); } return Response::json($re); }
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 getBooth($id) { $u_id = Input::get('u_id', 0); try { if (!$u_id) { throw new Exception("需要传入用户ID", 2001); } $booth = Booth::find($id); if (empty($booth->b_id)) { throw new Exception("无法获取到请求的店铺", 7001); } if ($booth->b_status != 1) { throw new Exception("店铺当前不可用", 7001); } $booth->load(['user', 'praises' => function ($q) { $q->where('praise.u_id', '=', $this->u_id); }, 'favorites' => function ($q) { $q->where('favorites.u_id', '=', $this->u_id); }]); $boothInfo = $booth->showDetail(); $products_count = Product::where('b_id', '=', $booth->b_id)->where('p_status', '=', 1)->count(); $chk = BoothFollow::where('b_id', '=', $booth->b_id)->where('u_id', '=', $u_id)->first(); if (empty($chk)) { $is_follow = 0; } else { $is_follow = 1; } $boothInfo['prodct_count'] = (int) $products_count; $boothInfo['is_follow'] = $is_follow; $boothInfo['is_praised'] = 0; $boothInfo['is_favorited'] = 0; if (count($booth->praises) > 0) { $boothInfo['is_praised'] = 1; } if (count($booth->favorites) > 0) { $boothInfo['is_favorited'] = 1; } $data = ['booth' => $boothInfo]; $re = Tools::reTrue('获取他的店铺成功', $data); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '获取他的店铺失败:' . $e->getMessage()); } return Response::json($re); }