示例#1
0
 public function createOrder($bookId, $count)
 {
     $orderId = Orders::create();
     if ($orderId !== false) {
         OrderBooks::create($orderId, $bookId, $count);
     } else {
         return -1;
     }
     return $orderId;
 }
示例#2
0
 public function postNewItem()
 {
     date_default_timezone_set('Asia/Shanghai');
     $rand = (string) rand(1000, 9999);
     $products = DB::table('product')->select('id', 'MName', 'PName', 'PBarcode', 'PSize', 'mode', 'FDAcode', 'FDAexpire', 'SId')->get();
     foreach ($products as $p) {
         $number = (int) Input::get($p->id);
         if ($number > 0) {
             $HName = Cache::get('HName');
             $h = DB::table('hospital_barcode')->where('Pid', '=', $p->id)->where('HName', '=', $HName)->select('id', 'HBarcode')->first();
             if (is_null($h)) {
                 $barcode = '未找到院内码';
             } else {
                 $barcode = $h->HBarcode;
             }
             $items = Orders::create(array('orderNum' => (string) date('YmdHi') . $rand, 'MName' => $p->MName, 'PName' => $p->PName, 'PSize' => $p->PSize, 'PCount' => $number, 'PBarcode' => $p->PBarcode, 'HBarcode' => $barcode, 'expire' => '', 'HName' => Cache::get('HName'), 'HUser' => Cache::get('username'), 'SId' => $p->SId, 'SUser' => '', 'status' => 'pending', 'OrderDate' => date('Y-m-d H:i:s'), 'SendDate' => '', 'ReceivedDate' => ''));
         }
     }
     return Redirect::route('hospital-list')->with('global', '商品已加入购物车');
 }
示例#3
0
 public function create($params)
 {
     $this->authenticate();
     $uuid = $params['uuid'];
     $customers = Customers::find($uuid);
     if (empty($customers)) {
         throw new Shineisp_Api_Exceptions(400006, ":: 'uuid' not valid");
         exit;
     }
     $trancheid = intval($params['trancheid']);
     $tranche = ProductsTranches::getTranchebyId($trancheid);
     if (empty($tranche)) {
         throw new Shineisp_Api_Exceptions(400006, ":: 'trancheid' not valid");
         exit;
     }
     #Check Products
     if (empty($params['products']) && !is_array($params['products'])) {
         throw new Shineisp_Api_Exceptions(400006, ":: not 'products' choose");
         exit;
     }
     foreach ($params['products'] as $product) {
         $productid = intval($product['productid']);
         $billingid = intval($product['billingid']);
         $ttry = ProductsTranches::getTranchesBy_ProductId_BillingId($productid, $billingid);
         if (empty($ttry)) {
             throw new Shineisp_Api_Exceptions(400006, ":: 'productid' or 'bilingid' not valid");
             exit;
         }
         $ttry = array_shift($ttry);
         if ($ttry['tranche_id'] != $trancheid) {
             throw new Shineisp_Api_Exceptions(400006, ":: 'bilingid' not valid");
             exit;
         }
     }
     $id = $customers['customer_id'];
     $isVATFree = Customers::isVATFree($id);
     if ($params['status'] == "complete") {
         $status = Statuses::id('complete', 'orders');
     } else {
         $status = Statuses::id('tobepaid', 'orders');
     }
     $theOrder = Orders::create($customers['customer_id'], $status, $params['note']);
     foreach ($params['products'] as $product) {
         $productid = intval($product['productid']);
         $billingid = intval($product['billingid']);
         $quantity = intval($product['quantity']);
         $p = Products::getAllInfo($productid);
         Orders::addItem($productid, $quantity, $billingid, $trancheid, $p['ProductsData'][0]['name'], array());
     }
     $orderID = $theOrder['order_id'];
     if ($params['sendemail'] == 1) {
         Orders::sendOrder($orderID);
     }
     $banks = Banks::find($params['payment'], "*", true);
     if (!empty($banks[0]['classname'])) {
         $class = $banks[0]['classname'];
         if (class_exists($class)) {
             // Get the payment form object
             $banks = Banks::findbyClassname($class);
             $gateway = new $class($orderID);
             $gateway->setFormHidden(true);
             $gateway->setRedirect(true);
             $gateway->setUrlOk($_SERVER['HTTP_HOST'] . "/orders/response/gateway/" . md5($banks['classname']));
             $gateway->setUrlKo($_SERVER['HTTP_HOST'] . "/orders/response/gateway/" . md5($banks['classname']));
             $gateway->setUrlCallback($_SERVER['HTTP_HOST'] . "/common/callback/gateway/" . md5($banks['classname']));
             return $gateway->CreateForm();
         }
     }
     throw new Shineisp_Api_Exceptions(400006, ":: bad request");
     exit;
 }
示例#4
0
文件: Cart.php 项目: kokkez/shineisp
 /**
  * Create a new Order
  *
  * @return boolean
  */
 public function createOrder()
 {
     if (!$this->getOrderid()) {
         $theOrder = Orders::create($this->getCustomerId(), Statuses::id('tobepaid', 'orders'), null);
         // For each item in the cart
         foreach ($this->getItems() as $item) {
             $item = Orders::addOrderItem($item);
         }
         $this->setOrderid($theOrder['order_id']);
         // Send the email to confirm the order
         Orders::sendOrder($theOrder['order_id']);
         return Orders::getOrder();
     } else {
         return Orders::find($this->getOrderid());
     }
 }
示例#5
0
 public function placeorder(Request $request)
 {
     if ($request->session()->get('ordertime') != "ASAP") {
         $shiptime = Carbon::createFromTimestamp($request->session()->get('ordertime'))->toDateTimeString();
     } else {
         $shiptime = Carbon::now();
     }
     $paymentflat = 1;
     $data = ['ordernumber' => date('Ymd') . random_int(100000, 999999), 'total' => $this->totalprice, 'totaldue' => $this->totalprice, 'status' => '1', 'ordertype' => $request->session()->get('ordertype'), 'name' => $request->session()->get('user_details')['name'], 'email' => $request->session()->get('user_details')['email'], 'phonenumber' => $request->session()->get('user_details')['phone'], 'paymentflag' => $paymentflat, 'staff_id' => 1, 'paymentmethod_id' => $request->session()->get('paymentmethod'), 'paymenttime' => Carbon::now(), 'shiptime' => $shiptime, 'useraddress_id' => $request->ip(), 'shipmethod' => 'take away', 'message' => $request->input('message')];
     $order = Orders::create($data);
     foreach ($this->cart as $item) {
         $order->dishes()->attach($item->id, array('amount' => $item->qty, 'price' => $item->price, 'total' => $item->price * $item->qty));
     }
     if ($request->session()->get('ordertype') == 'delivery') {
         $address = new Address(['address' => $request->session()->get('user_details')['address'], 'suburb' => $request->session()->get('user_details')['suburb'], 'city' => $request->session()->get('user_details')['city']]);
         // 			$address->address = $request->session()->get('user_details')['address'];
         // 			$address->suburb = $request->session()->get('user_details')['suburb'];
         // 			$address->city = $request->session()->get('user_details')['city'];
         // 			$user_address = ['address'=>$request->session()->get('user_details')['address'],
         // 						'suburb'=>$request->session()->get('user_details')['suburb'],
         // 						'city'=>$request->session()->get('user_details')['city']
         // 			];
         // 			$address = Address::create($user_address);
         $order->address()->save($address);
     }
     if (!Auth::guest()) {
         // 			dd($this->user);
         $this->user->attachorder($order);
     }
     event(new OrderReceipt($order));
     event(new OrderPrinter($order));
     event(new DashboardOrder());
     /* clear shopping cart		 */
     Cart::clean();
     sweetalert_message()->top_message(trans("front_home.order_cancel"));
     Mail::queue('emails.order.receipt', compact('order'), function ($message) use($order) {
         $message->from(env('MAIL_USERNAME'))->to($order->email)->subject('Noodle Canteen Receipt');
     });
     return view('frontend.home.payment.ordercreated')->withOrder($order);
 }
示例#6
0
 public function create($params)
 {
     $this->authenticate();
     $uuid = $params['uuid'];
     $customers = Customers::findWithUuid($uuid);
     if (empty($customers)) {
         throw new Shineisp_Api_Exceptions(400006, ":: 'uuid' not valid");
         exit;
     }
     $trancheid = intval($params['trancheid']);
     $tranche = ProductsTranches::getTranchebyId($trancheid);
     if (empty($tranche)) {
         throw new Shineisp_Api_Exceptions(400006, ":: 'trancheid' not valid");
         exit;
     }
     #Check Products
     if (empty($params['products']) && !is_array($params['products'])) {
         throw new Shineisp_Api_Exceptions(400006, ":: not 'products' choose");
         exit;
     }
     foreach ($params['products'] as $product) {
         $productid = intval($product['productid']);
         $billingid = intval($product['billingid']);
         $ttry = ProductsTranches::getTranchesBy_ProductId_BillingId($productid, $billingid);
         if (empty($ttry)) {
             throw new Shineisp_Api_Exceptions(400006, ":: 'productid' or 'bilingid' not valid");
             exit;
         }
         $ttry = array_shift($ttry);
         if ($ttry['tranche_id'] != $trancheid) {
             throw new Shineisp_Api_Exceptions(400006, ":: 'bilingid' not valid");
             exit;
         }
     }
     $id = $customers['customer_id'];
     if ($params['status'] == "complete") {
         $status = Statuses::id('complete', 'orders');
     } else {
         $status = Statuses::id('tobepaid', 'orders');
     }
     $theOrder = Orders::create($customers['customer_id'], $status, $params['note']);
     foreach ($params['products'] as $product) {
         $productid = intval($product['productid']);
         $billingid = intval($product['billingid']);
         $quantity = intval($product['quantity']);
         $p = Products::getAllInfo($productid);
         $options = array('uuid' => $product['uuid']);
         $upgrade = false;
         if (array_key_exists('upgrade', $product) && $product['upgrade'] != false) {
             $orderItemsUpgrade = OrdersItems::findByUUID($product['upgrade']);
             $fromUpgrade = $orderItemsUpgrade->toArray();
             $upgrade = $fromUpgrade['detail_id'];
         }
         $ts_start = false;
         if (array_key_exists('ts_start', $product) && $product['ts_start'] != false) {
             $ts_start = $product['ts_start'];
         }
         Orders::addItem($productid, $quantity, $billingid, $trancheid, $p['ProductsData'][0]['name'], $options, $upgrade, $ts_start);
     }
     $orderID = $theOrder['order_id'];
     if ($params['sendemail'] == 1) {
         Orders::sendOrder($orderID);
     }
 }