public function destroy($transportingId, $goodId) { $good = Good::find($goodId); $good->delete(); $transporting = Transporting::find($transportingId); $goods = $transporting->goods; return redirect(route('dashboard.good.index', ['transporting' => $transporting, 'goods' => $goods])); }
/** * Display a listing of the resource. * * @return Response */ public function index() { //获得数量 $g = Good::count(); $o = Order::count(); $u = User::count(); $c = Comment::count(); return view('admin.index.index', ['g' => $g, 'o' => $o, 'u' => $u, 'c' => $c]); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $admin = Auth::user(); $comments = Comment::with('good', 'user')->find($id); if (!$comments->good) { unset($comments->good); $goods = Good::onlyTrashed()->find($comments->good_id); $comments["good"] = $goods; } return view('admin.comments.show', ['comments' => $comments, 'admin' => $admin]); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $order = Order::with('address', 'express', 'user', 'order_goods.good')->find($id); foreach ($order->order_goods as $k => $v) { if (!$v->good) { unset($v->good); $goods = Good::onlyTrashed()->find($v->good_id); $order->order_goods["{$k}"]["good"] = $goods; } } $order_status = config('wyshop.order_status'); return view('admin.order.edit', ['order' => $order, 'order_status' => $order_status]); }
public function run () { DB::table('good_attribs')->delete(); $goods = Good::all(); $attribs = Attribute::all(); foreach ($goods as $good) { foreach ($attribs as $attrib) { if ($attrib->code == 'price') { GoodAttribute::create([ 'gid' => $good->id, 'aid' => $attrib->id, 'value' => 398, 'active' => 1 ]); } else { GoodAttribute::create([ 'gid' => $good->id, 'aid' => $attrib->id, 'value' => '', 'active' => 1 ]); } } } }
public function actionDelete($id) { $id = intval($id); if ($id <= 0) { throw new HttpException(404, 'Указанный Вами товар не найден'); } $good_current = Good::findOne($id); if (!$good_current) { throw new HttpException(404, 'Указанный Вами товар не найден'); } $transaction = Good::getDb()->beginTransaction(); try { $good_current->delete(); $transaction->commit(); return $this->redirect(Url::To(['category/cat', 'id' => $good_current->category_id])); } catch (\Exception $ex) { $transaction->rollBack(); throw $ex; } }
/** * Display a listing of the resource. * * @return Response */ public function index(Request $request) { $goods = Good::orderBy('id', 'desc')->get(); $gid = empty($request->input('gid')) ? $goods[0]->id : $request->input('gid'); $goodInfos = array(); foreach ($goods as $key => $good) { $goodInfo = GoodAttribsInfo::where('gid', '=', $good->id) ->where('acode', '=', 'price') ->first(); $goodInfos[$key] = $goodInfo; } $data = array ( 'goods' => $goods, 'gid' => $gid, 'active' => 'active', 'goodInfos' => $goodInfos, 'is_select' => true, 'wTitle' => '购买临牌' ); return view('goods/detail', $data); }
public function run () { DB::table('goods')->delete(); Good::create([ 'name' => '上海临时行驶车号牌', 'code' => 'below-three', 'intro' => '每台车累计仅可办理3次上海临时牌照', 'pic' => 'imgs/goods/fraly.jpg', 'active' => 1 ]); Good::create([ 'name' => '外省临时行驶车号牌', 'code' => 'beyond-three', 'intro' => '省市随机;上海临牌累计已满3次者购买外省临牌', 'pic' => 'imgs/goods/bujiadi.jpg', 'active' => 1 ]); }
/** * Show the application dashboard to the user. * * @return Response */ public function index(Request $request) { $goodDatas = Good::orderBy('id', 'desc')->get(); $goods = array(); $banners = Advertise::where('type', '=', 'index_banner') ->where('active', '=', 1) ->orderBy('seq', 'asc') ->get(); foreach ($goodDatas as $good) { $gInfo = GoodAttribsInfo::where('gid', '=', $good->id) ->where('acode', '=', 'price') ->first(); $good->price = $gInfo->value; array_push($goods, $good); } $homeGoodsDisplay = array(); foreach ($goods as $key => $good) { if (0 == $key % 2) { $homeGoodsDisplay[$key / 2] = array(); } $homeGoodsDisplay[$key / 2][] = $good; } ///// $goods = Good::orderBy('id', 'desc')->get(); $gid = empty($request->input('gid')) ? $goods[0]->id : $request->input('gid'); $goodInfos = array(); foreach ($goods as $key => $good) { $goodInfo = GoodAttribsInfo::where('gid', '=', $good->id) ->where('acode', '=', 'price') ->first(); $goodInfos[$key] = $goodInfo; } ///// return view('home', array( 'goods' => $goods, 'banners' => $banners, 'home' => 1, 'gid' => $gid, 'active' => 'active', 'goodInfos' => $goodInfos, 'is_select' => true, 'wTitle' => '51临牌网-您身边的车辆临时牌照专家' )); }
private function wxJsPay($request) { $state = $request->input('state'); $decodeObject = json_decode($state); $user = Auth::user(); $order_code = $decodeObject->order_code; $order = Order::where('code', '=', $order_code)->first(); if (empty($order->id)) { //todo } else if ($order->status > 0) { return view('mobile/payed'); } $good = Good::where('id', '=', $order->gid)->first(); $orderPrice = OrderPrice::where('oid', '=', $order->id)->first(); $receiver = ReceiverInfo::find($order->rid); require_once "lib/WxPay.Api.php"; require_once "lib/WxPay.JsApiPay.php"; $notify_url = $this->debug ? "http://www.51linpai.com:8000/order/wxpay/" : "http://www.51linpai.com/order/wxpay/"; $tools = new \JsApiPay(); $openId = $tools->GetOpenid("", null); $input = new \WxPayUnifiedOrder(); $input->SetBody($good->name); $input->SetAttach($good->code); $input->SetOut_trade_no($order->code); $input->SetTotal_fee($orderPrice->final_price * 100); $input->SetTime_start(date("YmdHis")); $input->SetTime_expire(date("YmdHis", time() + 600)); $input->SetGoods_tag($good->code); $input->SetNotify_url($notify_url); $input->SetTrade_type("JSAPI"); $input->SetOpenid($openId); $jsWxOrder = \WxPayApi::unifiedOrder($input); $jsApiParameters = $tools->GetJsApiParameters($jsWxOrder); //获取共享收货地址js函数参数 $editAddress = $tools->GetEditAddressParameters(); $data = [ 'editAddress' => $editAddress, 'jsApiParameters' => $jsApiParameters, 'order_code' => $order->code, 'price' => $orderPrice->final_price, 'address' => $receiver->city . ' ' . $receiver->district . ' ' . $receiver->address, 'step' => 4, 'header' => '支付订单' ]; return view('mobile/wechat_js_pay', $data); }
private function new_goods() { $news = Message::make('news')->items(function () { $goods = Good::where('new', true)->get(); $info = array(); foreach ($goods as $good) { $info[] = Message::make('news_item')->title($good->name)->url(url('good', [$good->id]))->picUrl('http://wfhshop.whphp.com/' . $good->thumb); } return $info; }); return $news; }
public function add_cart(Request $request) { //判断购物车,当前商品是否有记录 $cart = Cart::where('good_id', $request->good_id)->where('user_id', $this->user->id)->first(); //当前商品库存数 $number = Good::find($request->good_id)->number; // //如果是初次新增到购物车 if (!$cart) { //如果用户提交数大于库存数,提示商品库存不足 if ($request->num > $number) { return response()->json(['status' => 0, 'info' => '商品库存不足']); } Cart::create(['good_id' => $request->good_id, 'user_id' => $this->user->id, 'number' => $request->num]); return response()->json(['status' => 1, 'info' => '恭喜,已添至购物车~', 'cart_number' => $this->cart_number()]); } //如果购物车已经有该商品的记录 //购物车里的数量+用户新提交的数量 > 库存数 $new_num = $cart->number + $request->num; if ($new_num > $number) { return response()->json(['status' => 0, 'info' => '商品库存不足']); } //如果库存足够,就把原有的数量+新数量,更新数据库 $cart->number = $new_num; $cart->save(); //status起一个壮态标志作用,看是否购买成功 return response()->json(['status' => 1, 'info' => '恭喜,已添至购物车~', 'cart_number' => $this->cart_number()]); }
public function getGoods() { return $this->hasMany(Good::className(), ['category_id' => 'id']); }
public function force_destroy($id) { $good = Good::withTrashed()->find($id); $good->forceDelete(); return back()->with('info', '删除成功'); }
public function sort(Request $request) { $good = Good::find($request->id); $good->sort_order = $request->sort_order; $good->save(); }
public function add_cart(Request $request) { //判断购物车,当前商品是否有记录 $cart = Cart::where('good_id', $request->good_id)->where('user_id', $this->user->id)->first(); //当前商品库存数 $number = Good::find($request->good_id)->number; //如果是初次新增到购物车 if (!$cart) { //如果用户提交数大于库存数,提示商品库存不足 if ($request->num > $number) { return response()->json(['status' => 0, 'info' => '购买量不能超过库存总数']); } Cart::create(['good_id' => $request->good_id, 'user_id' => $this->user->id, 'num' => $request->num]); return response()->json(['status' => 1, 'info' => '恭喜,已添至购物车~', 'cart_number' => $this->cart_number()]); } //如果购物车已经有该商品的记录 //购物车里的数量+用户新提交的数量 > 库存数 $new_num = $cart->num + $request->num; if ($new_num > $number) { return response()->json(['status' => 0, 'info' => '购物车中该商品数量已超过库存']); } $cart->num = $new_num; $cart->save(); return response()->json(['status' => 1, 'info' => '恭喜,已添至购物车~', 'cart_number' => $this->cart_number(), 'total_price' => number_format($this->total_price(), 2)]); }
public function getBuy(Request $request) { $gcode = $request->input('gcode'); $ch = $request->input('car_hand'); if (empty($ch) || strlen($ch) == 0) { return redirect('/miniorder/cartype'); } $user = Auth::user(); $gcode = (empty($gcode) || strlen($gcode) == 0) ? 'beyond-three' : $gcode; $good = Good::where('code', '=', $gcode)->first(); if (empty($good)) { //todo } $carhand = $ch == 1 ? 'one' : 'second'; $cars = Car::where('uid', '=', $user->id)->where('car_hand', '=', $carhand)->orderBy('last_used', 'desc')->get(); $defaultCar = Car::where('uid', '=', $user->id)->where('car_hand', '=', $carhand)->where('last_used', '=', 1)->first(); $receivers = Receiver::where('uid', '=', $user->id)->orderBy('last_used', 'desc')->get(); $defaultReceiver = Receiver::where('uid', '=', $user->id)->where('last_used', '=', 1)->first(); $bouns = Boun::where('uid', '=', $user->id) ->where('type', '=', 1) ->where('active', '=', 1) ->get(); $goodInfo = GoodAttribsInfo::where('gid', '=', $good->id)->where('acode', '=', 'price')->first(); $data = [ 'good' => $good, 'receivers' => $receivers, 'defaultReceiver' => $defaultReceiver, 'cars' => $cars, 'defaultCar' => $defaultCar, 'bouns' => $bouns, 'goodInfo' => $goodInfo, 'formCode' => md5(time()), 'car_hand' => $carhand, 'step' => 2, 'header' => '确认订单' ]; return view('mobile/pay', $data); }