public static function getInstance($diafan) { if (self::$instance instanceof dfnUserAuth) { return self::$instance; } return self::$instance = new self($diafan); }
/** * @param $cart_summ * @param null $userId * @return bool */ private function get_discount_total($cart_summ, $userId = null) { PayqrLog::log("get_discount_total"); $discount = false; $order_summ = 0; if ($userId) { $order_summ = DB::query_result("SELECT SUM(summ) FROM {shop_order} WHERE user_id=%d AND (status='1' OR status='3')", $userId); } PayqrLog::log("Order sum : " . $order_summ); //скидка на общую сумму заказа $person_discount_ids = $this->diafan->_shop->price_get_person_discounts(); PayqrLog::log("Получили скидки клиенту: ", print_r($person_discount_ids, true)); $userRoleId = dfnUserAuth::getInstance($this->diafan)->_dfnGetUserRoleId($userId); PayqrLog::log("Получили роль пользователя: " . $userRoleId); $rows = DB::query_fetch_all("SELECT id, discount, amount, deduction, threshold, threshold_cumulative FROM" . " {shop_discount} WHERE act='1' AND trash='0' AND (threshold_cumulative>0 OR threshold>0)" . " AND role_id" . ($userRoleId ? ' IN (0, ' . $userRoleId . ')' : '=0') . " AND (person='0'" . ($person_discount_ids ? " OR id IN(" . implode(",", $person_discount_ids) . ")" : "") . ")" . " AND date_start<=%d AND (date_finish=0 OR date_finish>=%d)" . " AND (threshold_cumulative>0 AND threshold_cumulative<=%f" . " OR threshold>0 AND threshold<=%f)", time(), time(), $order_summ, $cart_summ); PayqrLog::log("После получения скидки: ", print_r($rows, true)); foreach ($rows as $row) { $row["discount_id"] = $row["id"]; if ($row['deduction']) { if ($row['deduction'] < $cart_summ) { $row["discount_summ"] = $row["deduction"]; } else { $row["discount_summ"] = 0; } } else { $row["discount_summ"] = $cart_summ * $row["discount"] / 100; } if (empty($discount) || $discount["discount_summ"] < $row["discount_summ"]) { $discount = $row; } } return $discount; }