本文整理汇总了PHP中Coupon::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Coupon::model方法的具体用法?PHP Coupon::model怎么用?PHP Coupon::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Coupon
的用法示例。
在下文中一共展示了Coupon::model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadModel
public function loadModel($id)
{
if (($model = Coupon::model()->findByPk($id)) === null) {
throw new CHttpException(404, 'Страница не найдена');
}
return $model;
}
示例2: deleteOldItems
public function deleteOldItems($model, $itemsPk)
{
$criteria = new CDbCriteria();
$criteria->addNotInCondition('coupon_id', $itemsPk);
$criteria->addCondition("listing_id= {$model->primaryKey}");
Coupon::model()->deleteAll($criteria);
}
示例3: loadModel
public function loadModel($id)
{
$model = Coupon::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
示例4: loadModel
public function loadModel($id)
{
$model = Coupon::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, Yii::t('CouponModule.coupon', 'Page not found!'));
}
return $model;
}
示例5: registerCoupon
function registerCoupon($code)
{
$coupon = Coupon::model()->findByPk($code);
if (!$coupon) {
return false;
}
echo "Coupon registered. {$coupon->description}";
return $coupon->delete();
}
示例6: check
public function check()
{
if (Yii::app()->cart->isEmpty()) {
$this->clear();
return;
}
$price = Yii::app()->cart->getCost();
foreach ($this->coupons as $code) {
/* @var $coupon Coupon */
$coupon = Coupon::model()->getCouponByCode($code);
if (!$coupon->getIsAvailable($price)) {
$this->remove($code);
}
}
}
示例7: actionCoupon
public function actionCoupon($id = '')
{
$id = $this->checkCorrectness($id);
if ($id != 0) {
$coupon = Coupon::model()->getFrontendCoupon($id);
} else {
$coupon = null;
}
if ($coupon == null) {
$this->render('missing_coupon');
return null;
}
Yii::app()->user->setLastCouponId($id);
ViewsTrack::addCouponView($id);
$listing = Listing::model()->getFrontendListing($coupon->listing_id);
// render normal listing
$this->render('coupon_detail', array('coupon' => $coupon, 'listing' => $listing, 'listingId' => $listing->listing_id));
}
示例8: actionIndex
/**
*
*/
public function actionIndex()
{
$positions = Yii::app()->cart->getPositions();
$order = new Order(Order::SCENARIO_USER);
if (Yii::app()->getUser()->isAuthenticated()) {
$user = Yii::app()->getUser()->getProfile();
$order->name = $user->getFullName();
$order->email = $user->email;
$order->city = $user->location;
}
$coupons = [];
if (Yii::app()->hasModule('coupon')) {
$couponCodes = Yii::app()->cart->couponManager->coupons;
foreach ($couponCodes as $code) {
$coupons[] = Coupon::model()->getCouponByCode($code);
}
}
$deliveryTypes = Delivery::model()->published()->findAll();
$this->render('index', ['positions' => $positions, 'order' => $order, 'coupons' => $coupons, 'deliveryTypes' => $deliveryTypes]);
}
示例9: actionRestrank
/**
* 福袋领取单
* GET /api/activity/luckybag/rank
*/
public function actionRestrank()
{
$this->checkRestAuth();
// 活动
$criteria = new CDbCriteria();
$criteria->compare('code', '2015ACODEFORGREETINGFROMWEIXIN');
$criteria->compare('archived', 1);
$activities = Activity::model()->findAll($criteria);
if (count($activities) == 0) {
return $this->sendResponse(400, "no code");
}
// 已领的奖品
$criteria = new CDbCriteria();
$criteria->compare('activity_id', $activities[0]->id);
$criteria->compare('archived', 1);
$criteria->addCondition('open_id IS NOT NULL');
$criteria->order = 'achieved_time desc';
$criteria->limit = 100;
$prizes = Coupon::model()->findAll($criteria);
$openIds = array();
foreach ($prizes as $prize) {
array_push($openIds, $prize->open_id);
}
// 获奖人
$criteria = new CDbCriteria();
$criteria->addInCondition('open_id', $openIds);
$result = Luckybag::model()->findAll($criteria);
$winners = $this->JSONArrayMapper($result);
/*
$idx = 0;
foreach ($winners as $winner) {
foreach ($prizes as $prize) {
if ($winner['openId'] == $prize->open_id) {
$winners[$idx]['prize'] = $prize->code;
}
}
$idx++;
}*/
echo CJSON::encode($winners);
}
示例10: repMails
public function repMails($email, $id)
{
//получаю шаблон письма
$sms = Mails::model()->findByPk(1);
if ($sms) {
//вставляю тело
$html = $sms['body'];
//тема
$subject = $sms['theme'];
//нахожу нужный купон
$coupon = Coupon::model()->findByPk($id);
//название купона
$product = $coupon['title'];
//скидка
$sale = $coupon['discount'];
//цен до скидки
$before = $coupon['discountPrice'] . " рублей";
if ($before == 0) {
$before = "Не ограничена";
$after = "Не ограничена";
} else {
//цена после скидки
$after = round($before - $sale * $before / 100, 2);
$after .= " рублей";
}
//ссылка на купон
$link = $_SERVER['HTTP_HOST'] . Yii::app()->createUrl("/coupon", array('id' => $coupon['id'], 'title' => $coupon['title']));
$link = "<a href='http://" . $link . "'>" . $link . "</a>";
//подставляю в шаблон
$html = str_replace('[product]', $product, $html);
$html = str_replace('[before]', $before, $html);
$html = str_replace('[after]', $after, $html);
$html = str_replace('[sale]', $sale, $html);
$html = str_replace('[link]', $link, $html);
//отправляем письмо
$this->sendMail($email, $subject, $html);
}
}
示例11: saveOrderCoupon
/**
* 保存优惠券信息
*/
protected function saveOrderCoupon($order_id, $couponInfo)
{
if (empty($couponInfo)) {
return false;
}
if ($couponInfo['type'] == 'A') {
return false;
}
//A(固定券码 暂不保存数据)
$couponInfo = Coupon::model()->findByAttributes(array('coupon_sn' => $couponInfo['coupon_sn']));
if (empty($couponInfo)) {
throw new Exception("优惠券不存在!", 1);
}
$couponInfo->order_id = $order_id;
$couponInfo->use_time = time();
$flag = $couponInfo->save();
if (empty($flag)) {
throw new Exception("优惠券保存失败!", 1);
}
return true;
}
示例12: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
Yii::app()->clientScript->registerPackage('discount-edit');
$id = null;
if (isset($_GET['id'])) {
$id = (int) $_GET['id'];
} elseif (isset($_POST['Discount']['id'])) {
$id = (int) $_POST['Discount']['id'];
}
$model = $this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
$coupons = $model->coupons;
if (isset($_POST['Discount'])) {
if (!isset($_POST['Coupon'])) {
$model->addError('status', Yii::t('errors', 'В предложении должен быть хотябы один купон'));
} else {
$data = $_POST['Coupon'];
$coupons = array();
foreach ($data as $c) {
$coupon = null;
if (isset($c['id']) && $c['id'] > 0) {
$coupon = Coupon::model()->findByPk($c['id']);
if (isset($c['delete'])) {
$coupon->delete();
}
}
if (!isset($c['delete'])) {
if ($coupon === null) {
$coupon = new Coupon();
}
$coupon->attributes = $c;
$coupons[] = $coupon;
}
}
}
$model->attributes = $_POST['Discount'];
if (!$model->hasErrors() && $model->save()) {
$fail = false;
foreach ($coupons as $coupon) {
$coupon->discount_id = $model->id;
if (!$coupon->save()) {
$fail = true;
}
}
if (!$fail) {
if (isset($_POST['Cats'])) {
$cats = array_map('intval', explode(',', $_POST['Cats']));
//Normalize
$dicats = DiscountCategory::model()->findAllByAttributes(array('discount_id' => $model->id));
foreach ($dicats as $i => $d) {
if (FALSE !== ($k = array_search($d->category_id, $cats))) {
unset($cats[$k]);
unset($dicats[$i]);
} else {
$d->delete();
}
}
if (!empty($cats)) {
$cats = Category::model()->findAllByAttributes(array('id' => $cats));
foreach ($cats as $c) {
$DC = new DiscountCategory();
$DC->discount_id = $model->id;
$DC->category_id = $c->id;
if (!$DC->save()) {
echo CHtml::errorSummary($DC);
}
}
}
}
if (isset($_POST['Region'])) {
$cats = array_map('intval', explode(',', $_POST['Region']));
//Normalize
$dicats = DiscountRange::model()->findAllByAttributes(array('discount_id' => $model->id));
foreach ($dicats as $i => $d) {
if (FALSE !== ($k = array_search($d->category_id, $cats))) {
unset($cats[$k]);
unset($dicats[$i]);
} else {
$d->delete();
}
}
if (!empty($cats)) {
$cats = City::model()->findAllByAttributes(array('id' => $cats));
foreach ($cats as $c) {
$DC = new DiscountRange();
$DC->discount_id = $model->id;
$DC->city_id = $c->id;
if (!$DC->save()) {
echo CHtml::errorSummary($DC);
}
}
}
}
$this->redirect('/business/discount');
}
//.........这里部分代码省略.........
示例13: isActiveCouponsExists
public function isActiveCouponsExists()
{
return Coupon::model()->active()->count() > 0 ? true : false;
}
示例14: array
<th>наименование программы</th>
<th width="100">Стоимость</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="2" class="cart-table__td-promo">
<div class="cart-table__promo"
data-add-url="<?php
echo Yii::app()->createUrl("/subscription/order/addCoupon", array('subscriptionId' => $subscription->id));
?>
">
<?php
if (Coupon::model()->isActiveCouponsExists()) {
?>
<span class="form-control-input form-control-input_type_2">
<input id="coupon" placeholder="Введите промо-код (если есть)" type="text" value="<?php
if (!empty($subscription->coupon)) {
echo $subscription->coupon->code;
}
?>
" class="coupon" maxlength="10" />
</span>
<button class="btn_ok" id="coupon-apply"></button>
<i class="icn icn_checkbox"></i>
<div class="promo-error"></div>
<?php
}
?>
示例15: getValidCoupons
/**
* Фильтрует переданные коды купонов и возвращает объекты купонов
* @param $codes - массив кодов купонов
* @return Coupon[] - массив объектов-купонов
*/
public function getValidCoupons($codes)
{
if ($this->_validCoupons !== null) {
return $this->_validCoupons;
}
$productsTotalPrice = $this->getProductsCost();
$validCoupons = [];
/* @var $coupon Coupon */
/* проверим купоны на валидность */
foreach ($codes as $code) {
$coupon = Coupon::model()->getCouponByCode($code);
if (null !== $coupon && $coupon->getIsAvailable($productsTotalPrice)) {
$validCoupons[] = $coupon;
}
}
return $validCoupons;
}