• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Coupon类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Coupon的典型用法代码示例。如果您正苦于以下问题:PHP Coupon类的具体用法?PHP Coupon怎么用?PHP Coupon使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Coupon类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: generateBulk

 /**
  * Generates child coupons with the $code property generated by the RandomGenerator input settings
  *
  * @param $number
  * @param int $length
  * @param string $type
  * @param string $pattern
  * @param int $separateEvery
  * @param string $separator
  * @return array
  * @throws ShopException
  */
 public function generateBulk($number, $length = 10, $type = RandomGenerator::TYPE_ALPHANUM, $pattern = 'X', $separateEvery = 0, $separator = '-')
 {
     if (!$this->isPersisted()) {
         throw new ShopException('Current coupon is not persisted, can\'t be used as parent');
     }
     $bulk = array();
     $i = 0;
     while ($i < $number) {
         $c = new Coupon();
         //$c->copy($this);
         $c->generateCode($length, $type, $pattern, $separateEvery, $separator);
         $c->module_srl = $this->module_srl;
         $c->parent_srl = $this->srl;
         $c->type = self::TYPE_CHILD;
         //save will throw ShopException if code is not unique
         try {
             $c->save();
         } catch (ShopException $e) {
             continue;
         }
         $i++;
         $bulk[] = $c;
     }
     return $bulk;
 }
开发者ID:haegyung,项目名称:xe-module-shop,代码行数:37,代码来源:Coupon.php


示例2: calculate

 public function calculate(Invoice $invoiceBill)
 {
     $this->coupon = $invoiceBill->getCoupon();
     $this->user = $invoiceBill->getUser();
     $isFirstPayment = $invoiceBill->isFirstPayment();
     foreach ($invoiceBill->getItems() as $item) {
         $item->first_discount = $item->second_discount = 0;
         $item->_calculateTotal();
     }
     if (!$this->coupon) {
         return;
     }
     if ($this->coupon->getBatch()->discount_type == Coupon::DISCOUNT_PERCENT) {
         foreach ($invoiceBill->getItems() as $item) {
             if ($this->coupon->isApplicable($item->item_type, $item->item_id, $isFirstPayment)) {
                 $item->first_discount = moneyRound($item->first_total * $this->coupon->getBatch()->discount / 100);
             }
             if ($this->coupon->isApplicable($item->item_type, $item->item_id, false)) {
                 $item->second_discount = moneyRound($item->second_total * $this->coupon->getBatch()->discount / 100);
             }
         }
     } else {
         // absolute discount
         $discountFirst = $this->coupon->getBatch()->discount;
         $discountSecond = $this->coupon->getBatch()->discount;
         $first_discountable = $second_discountable = array();
         $first_total = $second_total = 0;
         $second_total = array_reduce($second_discountable, create_function('$s,$item', 'return $s+=$item->second_total;'), 0);
         foreach ($invoiceBill->getItems() as $item) {
             if ($this->coupon->isApplicable($item->item_type, $item->item_id, $isFirstPayment)) {
                 $first_total += $item->first_total;
                 $first_discountable[] = $item;
             }
             if ($this->coupon->isApplicable($item->item_type, $item->item_id, false)) {
                 $second_total += $item->second_total;
                 $second_discountable[] = $item;
             }
         }
         if ($first_total) {
             $k = max(0, min($discountFirst / $first_total, 1));
             // between 0 and 1!
             foreach ($first_discountable as $item) {
                 $item->first_discount = moneyRound($item->first_total * $k);
             }
         }
         if ($second_total) {
             $k = max(0, min($discountSecond / $second_total, 1));
             // between 0 and 1!
             foreach ($second_discountable as $item) {
                 $item->second_discount = moneyRound($item->second_total * $k);
             }
         }
     }
     foreach ($invoiceBill->getItems() as $item) {
         $item->_calculateTotal();
     }
 }
开发者ID:subashemphasize,项目名称:test_site,代码行数:57,代码来源:Coupon.php


示例3: loadModel

 public function loadModel($id)
 {
     if (($model = Coupon::model()->findByPk($id)) === null) {
         throw new CHttpException(404, 'Страница не найдена');
     }
     return $model;
 }
开发者ID:kuzmina-mariya,项目名称:happy-end,代码行数:7,代码来源:CouponBackendController.php


示例4: deleteOldItems

 public function deleteOldItems($model, $itemsPk)
 {
     $criteria = new CDbCriteria();
     $criteria->addNotInCondition('coupon_id', $itemsPk);
     $criteria->addCondition("listing_id= {$model->primaryKey}");
     Coupon::model()->deleteAll($criteria);
 }
开发者ID:yasirgit,项目名称:hotmall,代码行数:7,代码来源:CouponManager.php


示例5: 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;
 }
开发者ID:tierous,项目名称:yiirisma,代码行数:8,代码来源:CouponController.php


示例6: 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;
 }
开发者ID:yupe,项目名称:yupe,代码行数:8,代码来源:CouponBackendController.php


示例7: displayMain

 public function displayMain()
 {
     global $smarty;
     $result = Coupon::loadData();
     if ($result) {
         $smarty->assign(array('coupons' => $result));
     }
     return $smarty->fetch('cart.tpl');
 }
开发者ID:yiuked,项目名称:tmcart,代码行数:9,代码来源:CartView.php


示例8: registerCoupon

 function registerCoupon($code)
 {
     $coupon = Coupon::model()->findByPk($code);
     if (!$coupon) {
         return false;
     }
     echo "Coupon registered. {$coupon->description}";
     return $coupon->delete();
 }
开发者ID:moohwaan,项目名称:yii-application-cookbook-2nd-edition-code,代码行数:9,代码来源:CouponTest.php


示例9: coupon

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function coupon()
 {
     if (ACL::checkUserPermission('reports.redeem') == false) {
         return Redirect::action('dashboard');
     }
     $coupon = Coupon::with('playerdetails', 'redeemer')->get();
     $title = 'Points Redeemed Report';
     $data = array('acl' => ACL::buildACL(), 'coupon' => $coupon, 'title' => $title);
     return View::make('reports/redeem', $data);
 }
开发者ID:pacificcasinohotel,项目名称:pointsystem,代码行数:15,代码来源:ReportsController.php


示例10: genCode

 private static function genCode($length = 4)
 {
     $count = 0;
     while ($count < COUPON_CODE_TRIES) {
         $code = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyz"), 0, $length);
         if (!Coupon::try_get_coupon_by_code($code)) {
             return $code;
         }
     }
     return null;
 }
开发者ID:pingwangcs,项目名称:51zhaohu,代码行数:11,代码来源:Coupon.php


示例11: UpdateListCoupon

 public function UpdateListCoupon()
 {
     $input = Input::all();
     $listCouponID = $input['update_list_coupon_id'];
     $listCouponID = explode(",", $listCouponID);
     foreach ($listCouponID as $p) {
         $coupon = Coupon::find($p);
         $coupon->code = $input['code'];
         $coupon->description = $input['description'];
         $coupon->from_date = $input['from_date'];
         $coupon->to_date = $input['to_date'];
         $coupon->save();
     }
 }
开发者ID:hungleon2112,项目名称:giaymaster,代码行数:14,代码来源:CouponController.php


示例12: testDeletion

 public function testDeletion()
 {
     self::authorizeFromEnv();
     $id = 'test-coupon-' . self::randomString();
     $coupon = Coupon::create(array('percent_off' => 25, 'duration' => 'repeating', 'duration_in_months' => 5, 'id' => $id));
     $customer = self::createTestCustomer(array('coupon' => $id));
     $this->assertTrue(isset($customer->discount));
     $this->assertTrue(isset($customer->discount->coupon));
     $this->assertSame($id, $customer->discount->coupon->id);
     $customer->deleteDiscount();
     $this->assertFalse(isset($customer->discount));
     $customer = Customer::retrieve($customer->id);
     $this->assertFalse(isset($customer->discount));
 }
开发者ID:parsonsc,项目名称:dofe,代码行数:14,代码来源:DiscountTest.php


示例13: testSave

 public function testSave()
 {
     self::authorizeFromEnv();
     $id = 'test_coupon-' . self::randomString();
     $c = Coupon::create(array('percent_off' => 25, 'duration' => 'repeating', 'duration_in_months' => 5, 'id' => $id));
     $this->assertSame($id, $c->id);
     // @codingStandardsIgnoreStart
     $this->assertSame(25, $c->percent_off);
     // @codingStandardsIgnoreEnd
     $c->metadata['foo'] = 'bar';
     $c->save();
     $stripeCoupon = Coupon::retrieve($id);
     $this->assertEquals($c->metadata, $stripeCoupon->metadata);
 }
开发者ID:andrewkrug,项目名称:repucaution,代码行数:14,代码来源:CouponTest.php


示例14: 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);
         }
     }
 }
开发者ID:RonLab1987,项目名称:43berega,代码行数:15,代码来源:CouponManager.php


示例15: getPreviewData

 /**
  * プレビューを表示する。
  */
 public function getPreviewData($id)
 {
     $data = $this->getData($id);
     // メニューの情報を置換する。
     App::uses('MenuItem', 'Model');
     $menu = new MenuItem();
     $data['menu'] = $menu->mergeMenuInfo($id, $data['menu']);
     // ニュースの情報を置換する。
     App::uses('News', 'Model');
     $news = new News();
     $data['news']['info'] = $news->getPreviewData($id);
     // クーポン情報を取得してマージ
     App::uses('Coupon', 'Model');
     $coupon = new Coupon();
     $data['coupon'] = $coupon->mergeCouponInfo($id, $data['coupon']);
     // 非表示になっているやつを削除。
     $returnList = array();
     foreach ($data as $key => $value) {
         if ($value['del'] != 1) {
             $returnList[$key] = $value;
         }
     }
     return $returnList;
 }
开发者ID:buiquangquyet,项目名称:ipost,代码行数:27,代码来源:Block.php


示例16: add

 public function add($order, $value = null)
 {
     //Get valid coupon for this order
     $code = Convert::raw2sql($order->CouponCode);
     $date = date('Y-m-d');
     $coupon = Coupon::get()->where("\"Code\" = '{$code}' AND \"Expiry\" >= '{$date}'")->first();
     if ($coupon && $coupon->exists()) {
         //Generate the Modification
         $mod = new CouponModification();
         $mod->Price = $coupon->Amount($order)->getAmount();
         $mod->Currency = $coupon->Currency;
         $mod->Description = $coupon->Label();
         $mod->OrderID = $order->ID;
         $mod->Value = $coupon->ID;
         $mod->CouponID = $coupon->ID;
         $mod->write();
     }
 }
开发者ID:helpfulrobot,项目名称:swipestripe-swipestripe-coupon,代码行数:18,代码来源:CouponModification.php


示例17: 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));
 }
开发者ID:yasirgit,项目名称:hotmall,代码行数:18,代码来源:ListingController.php


示例18: 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]);
 }
开发者ID:alextravin,项目名称:yupe,代码行数:23,代码来源:CartController.php


示例19: 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);
 }
开发者ID:aer123456,项目名称:yougou,代码行数:44,代码来源:LuckybagController.php


示例20: 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);
     }
 }
开发者ID:kirians,项目名称:sf,代码行数:38,代码来源:Vladimir_Yii_ModerationController.php



注:本文中的Coupon类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Course类代码示例发布时间:2022-05-23
下一篇:
PHP Country类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap