当前位置: 首页>>代码示例>>PHP>>正文


PHP Coupon类代码示例

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


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


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