/** * show Discounts */ public function getDiscounts($filters = array(), $paginateItems = 50) { if (key($filters) == "status") { $items = \Veer\Models\UserDiscount::where('status', '=', head($filters)); } else { $items = $this->buildFilterWithElementsQuery($filters, "\\Veer\\Models\\UserDiscount"); } return $items->orderBy('created_at', 'desc')->with('user', 'orders')->with($this->loadSiteTitle())->paginate($paginateItems); }
/** * 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); }
/** * @param mixed $data * @return \Veer\Services\Administration\Elements\User */ public function cancelDiscount($data) { if (!empty($data)) { $id = is_array($data) ? head($data) : $data; \Veer\Models\UserDiscount::where('id', '=', $id)->update(['status' => 'canceled']); event('veer.message.center', trans('veeradmin.discount.cancel')); } return $this; }
public function delete($id) { \Veer\Models\UserDiscount::destroy($id); event('veer.message.center', trans('veeradmin.discount.delete') . " " . $this->restore_link('UserDiscount', $id)); return $this; }