function _allowApply() { $rs = new tw_tours(); return $rs->_allowApply($this); /* $dt=date("Y-m-d"); if ($this->tourStatus!='normal') return false; if (!($this->tourAvPlaces>0)) return false; if (strtotime($this->tourAppStartDate)!=0 && strtotime($dt)<strtotime($this->tourAppStartDate)) return false; //if (strtotime($this->tourAppEndDate)!=0 && strtotime($dt)>strtotime($this->tourAppEndDate)) return false; return true; */ /* return $this->tourStatus=='normal' && ($this->tourAvPlaces>0 ) && (strtotime($this->tourAppStartDate)==0 || strtotime($dt)>=strtotime($this->tourAppStartDate)) && (strtotime($this->tourAppEndDate)==0 || strtotime($dt)<=strtotime($this->tourAppEndDate)) ; */ }
function apply_discount($user_id, $tour_id) { $tw_user = tw_users::record_by_id($user_id); $tw_tour = tw_tours::record_by_id($tour_id); $discount = new tw_discount(); $prs = array(); if ($tw_user->userCompletedTours >= 1) { $prs['retcust'] = $discount->find_records(array('AutoKey' => 'retcust1'))->first(); } if ($tw_user->userType == 'guard') { $prs['retcust'] = $discount->find_records(array('AutoKey' => 'retcust2'))->first(); } $friends = new projectfriends(); $friends->find_records(array('User_id' => $tw_user->get_id())); if ($friends->count() > 0) { $prs['projectfriends'] = $discount->find_records(array('AutoKey' => 'projectfriends'))->first(); } foreach ($prs as $ppr) { $pr = record_by_id($ppr->get_id(), 'tw_discount'); $pm = new tw_payments(); $pm->find_records(array('tourID' => $tour_id, 'userID' => $user_id, 'Discount_id' => $pr->get_id())); if ($pm->count() > 0) { return; } $r = $pm->new_record(); $r->Discount_id = $pr->get_id(); $r->Title = "{$pr->Type} {$pr->Title}"; $r->Amount = $pr->Amount; if ($pr->AmountType == '%') { $r->Amount = round($pr->Amount * 0.01 * $tw_tour->tourPrice1); } $r->Type = "скидка"; $r->Hidden = 0; $r->tourID = $tw_tour->get_id(); $r->userID = $tw_user->get_id(); $pm->commit(); } }