当前位置: 首页>>代码示例>>PHP>>正文


PHP Cart::bindOrder方法代码示例

本文整理汇总了PHP中Cart::bindOrder方法的典型用法代码示例。如果您正苦于以下问题:PHP Cart::bindOrder方法的具体用法?PHP Cart::bindOrder怎么用?PHP Cart::bindOrder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cart的用法示例。


在下文中一共展示了Cart::bindOrder方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fakeCrowdFundingPurches

 public function fakeCrowdFundingPurches($id)
 {
     set_time_limit(0);
     $this->login();
     $bottom = Input::get('bottom', '');
     $top = Input::get('top', '');
     $p_id = Input::get('p_id', '');
     try {
         if (!$p_id || !$top || !$bottom) {
             throw new Exception("需要关键数据", 1);
         }
         $funding = CrowdFunding::find($id);
         $funding->load(['eventItem']);
         $product = CrowdFundingProduct::find($p_id);
         $quantity = 1;
         $users = User::where('u_mobile', '>=', $bottom)->where('u_mobile', '<=', $top)->get();
         foreach ($users as $key => $user) {
             $u_id = $user->u_id;
             // sku need to be calulated before cart generated
             $product->loadProduct($quantity);
             // add cart
             $cart = new Cart();
             $cart->p_id = $p_id;
             $cart->p_name = $product->p_title;
             $cart->u_id = $u_id;
             $cart->b_id = $product->b_id;
             $cart->created_at = Tools::getNow();
             $cart->c_quantity = $quantity;
             $cart->c_price = $product->p_price;
             $cart->c_amount = $product->p_price * $quantity;
             $cart->c_discount = 100;
             $cart->c_price_origin = $product->p_price;
             $cart->c_amount_origin = $product->p_price * $quantity;
             $cart->c_status = 2;
             $cart->c_type = 2;
             $re = $cart->save();
             if (!$re) {
                 throw new Exception("提交库存失败", 7006);
             }
             $shipping_address = 'Fake Purches';
             $shipping_name = $user->u_name;
             $shipping_phone = $user->u_mobile;
             $date_obj = new DateTime($funding->eventItem->e_start_at);
             $delivery_time_obj = $date_obj->modify('+' . ($funding->c_time + $funding->c_yield_time) . 'days');
             // add order
             $order_group_no = Order::generateOrderGroupNo($u_id);
             $rnd_str = rand(10, 99);
             $order_no = $order_group_no . $cart->b_id . $rnd_str;
             $order = new Order();
             $order->u_id = $u_id;
             $order->b_id = $cart->b_id;
             $order->o_amount_origin = $cart->c_amount_origin;
             $order->o_amount = $cart->c_amount;
             $order->o_shipping_fee = $funding->c_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_obj->format('Y-m-d H:i:s');
             $order->o_shipping = $funding->c_shipping;
             $order->o_comment = 'Fake Order';
             $order->o_number = $order_no;
             $order->o_group_number = $order_group_no;
             $o_id = $order->addOrder();
             Cart::bindOrder([$order->o_id => [$cart->c_id]]);
             $cart->checkout();
             $order->o_status = 2;
             $order->o_shipping_status = 10;
             $order->paied_at = Tools::getNow();
             $order->save();
         }
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     echo "done";
 }
开发者ID:qnck,项目名称:qingnianchuangke,代码行数:75,代码来源:EmergencyController.php

示例2: postOrder

 public function postOrder($id)
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', '');
     $shipping_name = Input::get('shipping_name', '');
     $shipping_phone = Input::get('shipping_phone', '');
     $shipping_address = Input::get('shipping_address', '');
     $comment = Input::get('comment', '');
     DB::beginTransaction();
     try {
         $user = User::chkUserByToken($token, $u_id);
         $now = Tools::getNow();
         $auction = Auction::find($id);
         if (empty($auction) || $auction->a_status != 2) {
             throw new Exception("请求的竞拍不存在", 2001);
         }
         $auction->load(['eventItem']);
         $bid = AuctionBid::find($auction->a_win_id);
         if (empty($bid) || $bid->is_pay) {
             throw new Exception("出价信息有误", 2001);
         }
         $limit = new DateTime($auction->eventItem->e_end_at);
         $limit->modify('+3 days');
         $now = Tools::getNow(false);
         if ($limit < $now) {
             $blacklist = new AuctionBlacklist();
             $blacklist->u_id = $u_id;
             $blacklist->a_id = $auction->a_id;
             $blacklist->start_at = $now;
             $now->modify('+7 days');
             $blacklist->end_at = $now->format('Y-m-d H:i:s');
             $blacklist->remark = '超时未购买';
             $blacklist->save();
             $auction->a_status = 4;
             $auction->save();
             throw new Exception("竞拍已超时, 无法购买", 2);
             //when exception code is 2, commit anyway after catch
         }
         // add cart
         $cart = new Cart();
         $cart->p_id = $auction->a_id;
         $cart->p_name = $auction->eventItem->e_title;
         $cart->u_id = $u_id;
         $cart->b_id = Tools::getMakerBooth();
         $cart->created_at = Tools::getNow();
         $cart->c_quantity = 1;
         $cart->c_price = $auction->a_win_price;
         $cart->c_amount = $auction->a_win_price;
         $cart->c_discount = 100;
         $cart->c_price_origin = $auction->a_cost;
         $cart->c_amount_origin = $auction->a_cost;
         $cart->c_status = 2;
         $cart->c_type = 4;
         $re = $cart->save();
         if (!$re) {
             throw new Exception("提交库存失败", 7006);
         }
         $shipping_name = $shipping_name ? $shipping_name : $user->u_name;
         $shipping_phone = $shipping_phone ? $shipping_phone : $user->u_mobile;
         // add order
         $order_group_no = Order::generateOrderGroupNo($u_id);
         $rnd_str = rand(10, 99);
         $order_no = $order_group_no . $cart->b_id . $rnd_str;
         $order = new Order();
         $order->u_id = $u_id;
         $order->b_id = $cart->b_id;
         $order->o_amount_origin = $cart->c_amount_origin;
         $order->o_amount = $cart->c_amount;
         $order->o_shipping_fee = 0.0;
         $order->o_shipping_name = $shipping_name;
         $order->o_shipping_phone = $shipping_phone;
         $order->o_shipping_address = $shipping_address;
         $order->o_delivery_time = Tools::getNow();
         $order->o_shipping = 1;
         $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 => [$cart->c_id]]);
         $data = ['order_no' => $order_group_no];
         $re = Tools::reTrue('提交订单成功', $data);
         DB::commit();
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '提交订单失败:' . $e->getMessage());
         if ($e->getCode() == 2) {
             DB::commit();
         } else {
             DB::rollback();
         }
     }
     return Response::json($re);
 }
开发者ID:qnck,项目名称:qingnianchuangke,代码行数:92,代码来源:MeAuctionController.php

示例3: postOrder


//.........这里部分代码省略.........
         if ($now < $date_start) {
             throw new Exception("抱歉, 众筹还未开始, 请耐心等待", 2001);
         }
         if ($funding->c_status != 4) {
             throw new Exception("抱歉, 无效的众筹状态", 2001);
         }
         if ($funding->u_id == $u_id) {
             throw new Exception("您不能认筹自己发起的众筹", 2001);
         }
         $validator = Validator::make(['收货人电话' => (string) $shipping_phone, '收货人姓名' => $shipping_name, '收获地址' => $shipping_address, '产品' => $p_id, '数量' => $quantity], ['收货人电话' => 'required|numeric|digits:11', '收货人姓名' => 'required', '收获地址' => 'required', '产品' => 'required|numeric', '数量' => 'required|numeric']);
         if ($validator->fails()) {
             $msg = $validator->messages();
             throw new Exception($msg->first(), 7001);
         }
         $user = User::chkUserByToken($token, $u_id);
         if (!$user->u_mobile && ($id = 30)) {
             throw new Exception("此众筹需要绑定联系电话,请到[我的-编辑资料]里绑定后进行支持", 2001);
         }
         if ($funding->c_local_only) {
             $funding_owner = User::find($funding->u_id);
             if ($funding_owner->u_school_id != $user->u_school_id) {
                 throw new Exception("该众筹仅限于同校参与", 2001);
             }
         }
         $product = CrowdFundingProduct::find($p_id);
         if ($product->p_price == 0) {
             if ($quantity != 1) {
                 throw new Exception("此类众筹只能认筹一份", 1);
             }
             // check if user has bought
             $chk = Cart::where('u_id', '=', $u_id)->where('c_type', '=', 2)->where('p_id', '=', $p_id)->where('c_status', '>', 0)->first();
             if (!empty($chk)) {
                 throw new Exception("此类众筹每人限认筹一次", 7001);
             }
         }
         // sku need to be calulated before cart generated
         $product->loadProduct($quantity);
         // add cart
         $cart = new Cart();
         $cart->p_id = $p_id;
         $cart->p_name = $product->p_title;
         $cart->u_id = $u_id;
         $cart->b_id = $product->b_id;
         $cart->created_at = Tools::getNow();
         $cart->c_quantity = $quantity;
         $cart->c_price = $product->p_price;
         $cart->c_amount = $product->p_price * $quantity;
         $cart->c_discount = 100;
         $cart->c_price_origin = $product->p_price;
         $cart->c_amount_origin = $product->p_price * $quantity;
         $cart->c_status = 2;
         $cart->c_type = 2;
         $re = $cart->save();
         if (!$re) {
             throw new Exception("提交库存失败", 7006);
         }
         if (!$funding->c_shipping) {
             $shipping_address = '';
         }
         $shipping_name = $shipping_name ? $shipping_name : $user->u_name;
         $shipping_phone = $shipping_phone ? $shipping_phone : $user->u_mobile;
         $date_obj = new DateTime($funding->eventItem->e_start_at);
         $delivery_time_obj = $date_obj->modify('+' . ($funding->c_time + $funding->c_yield_time) . 'days');
         // add order
         $order_group_no = Order::generateOrderGroupNo($u_id);
         $rnd_str = rand(10, 99);
         $order_no = $order_group_no . $cart->b_id . $rnd_str;
         $order = new Order();
         $order->u_id = $u_id;
         $order->b_id = $cart->b_id;
         $order->o_amount_origin = $cart->c_amount_origin;
         $order->o_amount = $cart->c_amount;
         $order->o_shipping_fee = $funding->c_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_obj->format('Y-m-d H:i:s');
         $order->o_shipping = $funding->c_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 => [$cart->c_id]]);
         // change order to finish if price = 0
         if ($order->o_amount == 0) {
             $cart->checkout();
             $order->o_status = Order::$STATUS_FINISHED;
             $order->o_shipping_status = Order::$SHIPPING_STATUS_FINISHED;
             $order->paied_at = Tools::getNow();
             $order->save();
         }
         $data = ['order_no' => $order_group_no];
         $re = Tools::reTrue('提交订单成功', $data);
         DB::commit();
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '提交订单失败:' . $e->getMessage());
         DB::rollback();
     }
     return Response::json($re);
 }
开发者ID:qnck,项目名称:qingnianchuangke,代码行数:101,代码来源:CrowdFundingController.php

示例4: postOrder

 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);
 }
开发者ID:qnck,项目名称:qingnianchuangke,代码行数:87,代码来源:MarketController.php


注:本文中的Cart::bindOrder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。