本文整理汇总了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;
}
示例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();
}
}
示例3: loadModel
public function loadModel($id)
{
if (($model = Coupon::model()->findByPk($id)) === null) {
throw new CHttpException(404, 'Страница не найдена');
}
return $model;
}
示例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);
}
示例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;
}
示例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;
}
示例7: displayMain
public function displayMain()
{
global $smarty;
$result = Coupon::loadData();
if ($result) {
$smarty->assign(array('coupons' => $result));
}
return $smarty->fetch('cart.tpl');
}
示例8: registerCoupon
function registerCoupon($code)
{
$coupon = Coupon::model()->findByPk($code);
if (!$coupon) {
return false;
}
echo "Coupon registered. {$coupon->description}";
return $coupon->delete();
}
示例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);
}
示例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;
}
示例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();
}
}
示例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));
}
示例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);
}
示例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);
}
}
}
示例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;
}