/** * show Statuses */ public function getStatuses($paginateItems = 50) { app('veer')->loadedComponents['counted']['orders'] = \Veer\Models\Order::select(\DB::raw('count(*) as orders_count, status_id'))->groupBy('status_id')->lists('orders_count', 'status_id'); app('veer')->loadedComponents['counted']['orders_history'] = \Veer\Models\OrderHistory::select(\DB::raw('count(*) as orders_count, status_id'))->groupBy('status_id')->lists('orders_count', 'status_id'); app('veer')->loadedComponents['counted']['bills'] = \Veer\Models\OrderBill::select(\DB::raw('count(*) as orders_count, status_id'))->groupBy('status_id')->lists('orders_count', 'status_id'); return \Veer\Models\OrderStatus::orderBy('manual_order', 'asc')->paginate($paginateItems); }
public function update($id, $data) { $o = \Veer\Models\OrderStatus::find($id); if (is_object($o)) { $data += $o->toArray(); $this->addOrUpdateGlobalStatus($o, ['name' => $data['name'], 'manual_order' => $data['manual_order'], 'color' => $data['color'], 'flag' => $data['flag']]); } return $this; }
/** * add New Order * * pin, close_time, type, status_id, cluster, cluster_oid, * users_id, user_type, userdiscount_id, userbook_id, country, city, address, hash * * @param $order * @param $usersId * @return array */ public function addNewOrder($order, $usersId, $book = array(), $pretend = false) { $order->pin = false; $order->close_time = null; $order->type = 'reg'; $firststatus = \Veer\Models\OrderStatus::firststatus()->pluck('id'); $order->status_id = !empty($firststatus) ? $firststatus : 0; $cluster = \Veer\Models\Configuration::where('sites_id', '=', $order->sites_id)->where('conf_key', '=', 'CLUSTER')->pluck('conf_val'); if (empty($cluster)) { $cluster = 0; } $order->cluster = $cluster; $order->cluster_oid = \Veer\Models\Order::where('sites_id', '=', $order->sites_id)->where('cluster', '=', $cluster)->max('cluster_oid') + 1; if (empty($usersId) && !empty($order->email)) { $findUser = \Veer\Models\User::where('sites_id', '=', $order->sites_id)->where('email', '=', $order->email)->first(); if (is_object($findUser)) { $order->users_id = $findUser->id; if (empty($order->phone)) { $order->phone = $findUser->phone; } if (empty($order->name)) { $order->name = $findUser->firstname . " " . $findUser->lastname; } } else { $newUser = new \Veer\Models\User(); $newUser->sites_id = $order->sites_id; $newUser->email = $order->email; $newUser->phone = $order->phone; $password2Email = str_random(16); $newUser->password = $password2Email; $newUser->save(); $order->users_id = $newUser->id; $order->type = 'unreg'; $unregStatus = \Veer\Models\OrderStatus::unregstatus()->pluck('id'); if (!empty($unregStatus)) { $order->status_id = $unregStatus; } } } if (!empty($usersId) && (empty($order->email) || empty($order->phone) || empty($order->name))) { $findUser = \Veer\Models\User::where('id', '=', $usersId)->first(); if (is_object($findUser)) { if (empty($order->email)) { $order->email = $findUser->email; } if (empty($order->phone)) { $order->phone = $findUser->phone; } if (empty($order->name)) { $order->name = $findUser->firstname . " " . $findUser->lastname; } } } $userRole = \Veer\Models\UserRole::whereHas('users', function ($q) use($order) { $q->where('users.id', '=', $order->users_id); })->pluck('role'); $order->user_type = !empty($userRole) ? $userRole : ''; if (!empty($order->userdiscount_id)) { $checkDiscount = \Veer\Models\UserDiscount::where('id', '=', $order->userdiscount_id)->where('sites_id', '=', $order->sites_id)->whereNested(function ($q) use($order) { $q->where('users_id', '=', 0)->orWhere('users_id', '=', $order->users_id); })->whereNested(function ($q) { $q->where('status', '=', 'wait')->orWhere('status', '=', 'active'); })->first(); if (is_object($checkDiscount)) { $checkDiscount->users_id = $order->users_id; $checkDiscount->status = 'active'; $checkDiscount->save(); } else { $order->userdiscount_id = 0; } } if (!empty($book)) { $book['fill']['users_id'] = $order->users_id; $newBook = $this->updateOrNewBook($book, $pretend); } if (isset($newBook) && is_object($newBook)) { $order->userbook_id = $newBook->id; $order->country = !empty($newBook->country) ? $newBook->country : ''; $order->city = !empty($newBook->city) ? $newBook->city : ''; $order->address = trim($newBook->postcode . " " . $newBook->address); } $order->hash = bcrypt($order->cluster . $order->cluster_oid . $order->users_id . $order->sites_id . str_random(16)); if ($pretend == false) { $order->save(); $this->incrementOrdersCount($order->users_id); $secret = new \Veer\Models\Secret(array("secret" => str_random(64))); $order->secrets()->save($secret); } return array($order, isset($checkDiscount) ? $checkDiscount : null); }
/** * make Order */ protected function makeOrder() { $cart = $this->showUser->getUserCart(app('veer')->siteId, \Auth::id(), app('session')->getId()); // rules if (\Auth::id() <= 0 && \Input::get('email') == null || $cart->count() <= 0) { \Session::flash('errorMessage', \Lang::get('veershop.order.error')); return \Redirect::route('user.cart.show'); } $grouped = app('veershop')->regroupShoppingCart($cart); $book = null; if (\Input::get('userbook_id') != null) { $book = \Veer\Models\UserBook::find(\Input::get('userbook_id')); } if (\Input::get('book.address') != null) { $book = app('veershop')->updateOrNewBook(\Input::get('book')); } list($order, $checkDiscount, $calculations) = app('veershop')->prepareOrder($grouped, $book, \Input::get('shipping_id'), \Input::get('payment_id'), false); $statusName = \Veer\Models\OrderStatus::where('id', '=', $order->status_id)->pluck('name'); \Veer\Models\OrderHistory::create(array("orders_id" => $order->id, "status_id" => $order->status_id, "name" => !empty($statusName) ? $statusName : '', "comments" => "")); $order->save(); if (isset($checkDiscount) && is_object($checkDiscount)) { app('veershop')->changeUserDiscountStatus($checkDiscount); } //app('veershop')->sendEmailOrderNew($order); // clear cart $this->showUser->getUserLists(app('veer')->siteId, \Auth::id(), app('session')->getId(), '[basket]', false)->delete(); \Session::put('successfulOrder', $order->id); return \Redirect::route('order.success'); }
public function status($history) { array_set($history, 'orders_id', $this->id); array_set($history, 'name', \Veer\Models\OrderStatus::where('id', '=', array_get($history, 'status_id'))->pluck('name')); if (empty($history['name'])) { $history['name'] = '[?]'; } $update = ['status_id' => array_get($history, 'status_id')]; $progress = array_pull($history, 'progress'); if (!empty($progress)) { $update['progress'] = $progress; } $sendEmail = array_pull($history, 'send_to_customer'); \Veer\Models\OrderHistory::create($history); \Veer\Models\Order::where('id', '=', $this->id)->update($update); if (!empty($sendEmail)) { $this->sendEmailOrdersStatus($this->id, ['history' => $history]); } return $this; }
/** * Get all veer shop statuses * @return object */ function statuses($flag = null) { if (empty($flag)) { return \Cache::remember('listOfStatuses', 0.5, function () { return \Veer\Models\OrderStatus::orderBy('manual_order', 'asc')->get(); }); } $statuses = $flag == "secret" ? \Veer\Models\OrderStatus::where($flag, '=', true) : \Veer\Models\OrderStatus::where('flag_' . $flag, '=', true); return \Cache::remember('listofStatuses-' . $flag, 0.5, function () use($statuses) { return $statuses->orderBy('manual_order', 'asc')->get(); }); }
public function add($params, $template = null) { $order = \Veer\Models\Order::find(array_get($params, 'orders_id')); $status = \Veer\Models\OrderStatus::find(array_get($params, 'status_id')); $payment = $payment_method = array_get($params, 'payment_method'); $sendEmail = array_pull($params, 'sendTo', null); if (empty($payment)) { $payment = \Veer\Models\OrderPayment::find(array_get($params, 'payment_method_id')); $payment_method = isset($payment->name) ? $payment->name : $payment_method; } $content = ''; if (!empty($template)) { /* leave 'view' instead of 'viewx' because we always need (rendered) html representation of the bill */ $content = view("components.bills." . $template, ["order" => $order, "status" => $status, "payment" => $payment, "price" => array_get($params, 'price')])->render(); } $b = new \Veer\Models\OrderBill(); $b->fill($params); $b->users_id = isset($order->users_id) ? $order->users_id : 0; $b->payment_method = $payment_method; $b->content = $content; if (!empty($sendEmail)) { $b->sent = true; } $b->save(); if (!empty($sendEmail) && is_object($order)) { $this->sendEmailBillCreate($b, $order); } return $this; }