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 static function clearByUser($u_id) { $record = Booth::where('u_id', '=', $u_id)->where('b_status', '=', 0)->first(); if (!empty($record)) { $record->delete(); } }
public function countSellOrders() { $token = Input::get('token', ''); $u_id = Input::get('u_id', 0); try { $user = User::chkUserByToken($token, $u_id); $booths = Booth::where('u_id', '=', $u_id)->lists('b_id'); if (empty($booths)) { throw new Exception("您还没有任何店铺", 7001); } $count_nonshipping = Order::where('orders.o_shipping_status', '=', 1)->whereIn('carts.b_id', $booths)->leftJoin('carts', function ($q) { $q->on('carts.o_id', '=', 'orders.o_id'); })->groupBy('carts.o_id')->count(); $count_shipped = Order::where('orders.o_shipping_status', '=', 5)->whereIn('carts.b_id', $booths)->leftJoin('carts', function ($q) { $q->on('carts.o_id', '=', 'orders.o_id'); })->groupBy('carts.o_id')->count(); $count_nonpay = Order::where('orders.o_status', '=', 1)->whereIn('carts.b_id', $booths)->leftJoin('carts', function ($q) { $q->on('carts.o_id', '=', 'orders.o_id'); })->groupBy('carts.o_id')->count(); $count_paied = Order::where('orders.o_status', '=', 2)->whereIn('carts.b_id', $booths)->leftJoin('carts', function ($q) { $q->on('carts.o_id', '=', 'orders.o_id'); })->groupBy('carts.o_id')->count(); $count_finished = Order::where('orders.o_shipping_status', '=', 10)->whereIn('carts.b_id', $booths)->leftJoin('carts', function ($q) { $q->on('carts.o_id', '=', 'orders.o_id'); })->groupBy('carts.o_id')->count(); $count_nonfinished = $count_nonshipping + $count_shipped; $data = ['nonshipping' => $count_nonshipping, 'shipped' => $count_shipped, 'nonpay' => $count_nonpay, 'paied' => $count_paied, 'nonfinished' => $count_nonfinished, 'finished' => $count_finished]; $re = Tools::reTrue('获取订单统计成功', $data); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '获取订单统计失败:' . $e->getMessage()); } return Response::json($re); }
public function maker() { $school = Input::get('school', 0); $province = Input::get('province', 0); $city = Input::get('city', 0); $range = Input::get('range', 3); $key = Input::get('key', ''); $cate = Input::get('cate', 0); $u_id = Input::get('u_id', 0); $perPage = Input::get('per_page', 30); try { if (!$u_id) { throw new Exception("需要传入用户ID", 7001); } $query = Booth::where('b_type', '=', 2)->where('b_status', '=', 1)->with(['user', 'school', 'city', 'praises' => function ($q) { $q->where('praises.u_id', '=', $this->u_id); }, 'favorites' => function ($q) { $q->where('favorites.u_id', '=', $this->u_id); }]); if ($key) { $query = $query->where(function ($q) use($key) { $q->where('b_product_source', 'LIKE', '%' . $key . '%')->orWhere('b_product_category', 'LIKE', '%' . $key . '%')->orWhere('b_desc', 'LIKE', '%' . $key . '%')->orWhere('b_title', 'LIKE', '%' . $key . '%'); }); } if ($school && $range == 3) { $query = $query->where('s_id', '=', $school); } if ($city && $province && $range == 2) { $query = $query->where('c_id', '=', $city)->where('pv_id', '=', $province); } if ($cate) { $query = $query->where('b_cate', '=', $cate); } $list = $query->paginate($perPage); $data = []; foreach ($list as $key => $booth) { $tmp = $booth->showDetail(); $tmp['is_praised'] = 0; $tmp['is_favorited'] = 0; if (count($booth->praises) > 0) { $tmp['is_praised'] = 1; } if (count($booth->favorites) > 0) { $tmp['is_favorited'] = 1; } $data[] = $tmp; } $re = Tools::reTrue('获取创的店成功', $data, $list); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '获取创的店失败:' . $e->getMessage()); } return Response::json($re); }