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


PHP Coupon::save方法代码示例

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


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

示例1: postAddbatch

 public function postAddbatch()
 {
     $batchuniqid = Input::get('label') . date('d-m-y-h-i-s');
     $temp_array = "";
     for ($i = 0; $i < intval(Input::get('number')); $i++) {
         $temp_array[] = substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, 7);
     }
     $unique_array = array_unique($temp_array);
     if (count($unique_array) == Input::get('number')) {
         for ($i = 0; $i < intval(Input::get('number')); $i++) {
             $coupon = new Coupon();
             $coupon->code = strtoupper(Input::get('label') . $unique_array[$i]);
             $coupon->discount = Input::get('discount');
             $coupon->expiry = Date('Y-m-d', strtotime(Input::get('validity')));
             $coupon->type = Input::get('category_id') == 'cb' ? 'cashback' : 'discount';
             $coupon->status = 'activated';
             $coupon->min_val = Input::get('min_val');
             $coupon->parent_id = Input::get('referal');
             $coupon->batchuniqid = $batchuniqid;
             $coupon->save();
         }
         Session::flash('message', 'Coupon has been added sccessfully.');
         return View::make('coupons.addcoupons');
     } else {
         Session::flash('message', 'Some issue with code generation please try again.');
         return View::make('coupons.addcoupons');
     }
 }
开发者ID:abaecor,项目名称:funfest,代码行数:28,代码来源:CouponsController.php

示例2: 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

示例3: actionCreate

 public function actionCreate()
 {
     IsAuth::Admin();
     $model = new Coupon();
     if (isset($_POST['Coupon'])) {
         $model->date_added = new CDbExpression('NOW()');
         $model->attributes = $_POST['Coupon'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->coupon_id));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:tierous,项目名称:yiirisma,代码行数:13,代码来源:CouponController.php

示例4: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Coupon();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Coupon'])) {
         $model->attributes = $_POST['Coupon'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:BGCX067,项目名称:facecom-svn-to-git,代码行数:17,代码来源:CouponController.php

示例5: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Coupon();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Coupon'])) {
         $model->attributes = $_POST['Coupon'];
         $model->created_at = new CDbExpression('NOW()');
         $model->updated_at = new CDbExpression('NOW()');
         if ($model->save()) {
             $this->redirect(yii::app()->createUrl('/admin/coupon'));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:rajveer4155,项目名称:vidmgr,代码行数:19,代码来源:CouponController.php

示例6: actionCreate

 public function actionCreate()
 {
     $model = new Coupon();
     $attributes = Yii::app()->getRequest()->getPost('Coupon');
     if ($attributes) {
         $model->attributes = $attributes;
         if ($model->save()) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('CouponModule.coupon', 'Record created!'));
             $submitType = Yii::app()->getRequest()->getPost('submit-type');
             if ($submitType) {
                 $this->redirect([$submitType]);
             }
             $this->redirect(['update', 'id' => $model->id]);
         }
     }
     $this->render('create', ['model' => $model]);
 }
开发者ID:yupe,项目名称:yupe,代码行数:17,代码来源:CouponBackendController.php

示例7: actionCreate

 public function actionCreate()
 {
     $model = new Coupon();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Coupon'])) {
         $model->attributes = $_POST['Coupon'];
         if ($model->save()) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('CouponModule.coupon', 'Record created!'));
             if (!isset($_POST['submit-type'])) {
                 $this->redirect(['update', 'id' => $model->id]);
             } else {
                 $this->redirect([$_POST['submit-type']]);
             }
         }
     }
     $this->render('create', ['model' => $model]);
 }
开发者ID:alextravin,项目名称:yupe,代码行数:18,代码来源:CouponBackendController.php

示例8: gen

 public static function gen($user, $event)
 {
     $result = false;
     $coupon = new Coupon();
     $code = Coupon::genCode(COUPON_CODE_LEN);
     if ($code == null) {
         elgg_log("ZHError ,Coupon::gen, genCode failed, zhaohu_id {$event->guid} logged_user_id " . elgg_get_logged_in_user_guid(), "ERROR");
         return $result;
     }
     $coupon->used = false;
     $coupon->code = $code;
     $coupon->user_guid = $user->guid;
     $coupon->event_guid = $event->guid;
     //$coupon->owner_guid = $user->guid;
     $coupon->count = 0;
     $coupon->save();
     return true;
     //for test
     //notifyOnCoupon($user, $event, $coupon, $group);
 }
开发者ID:pingwangcs,项目名称:51zhaohu,代码行数:20,代码来源:Coupon.php

示例9: save_coupon

 public function save_coupon()
 {
     $id = Input::get('id');
     $coupon = Coupon::find($id);
     if (!$coupon) {
         $coupon = new Coupon();
     }
     $coupon->coupon_code = Input::get('coupon_code');
     $coupon->amount = Input::get('amount');
     $coupon->status = Input::get('status');
     $coupon->save();
     $message = "Successfully updated the coupon";
     $type = "success";
     return Redirect::to('/admin/coupons')->with('type', $type)->with('message', $message);
 }
开发者ID:sohelrana820,项目名称:mario-gomez,代码行数:15,代码来源:AdminController.php

示例10: procShopToolInsertCoupon

 /**
  * Inserts single codes, generates bulks
  */
 public function procShopToolInsertCoupon()
 {
     $repository = new CouponRepository();
     $args = Context::getRequestVars();
     $args->active = (int) $args->active;
     $args->module_srl = $this->module_info->module_srl;
     $logged_info = Context::get('logged_info');
     if ($logged_info->member_srl) $args->member_srl = $logged_info->member_srl;
     $args->ip = $_SERVER['REMOTE_ADDR'];
     $coupon = new Coupon($args);
     try {
         /**
          * Update [both]
          */
         if ($coupon->isPersisted() && $exists = $repository->get($coupon->srl)) { //
             /** @var $exists Coupon */
             $coupon->type = $exists->type;
             $out = $coupon->save();
             $repository->check($out);
             if ($coupon->isGroup()) {
                 $this->setMessage("Updated group <b>{$coupon->name}</b>");
             }
             elseif ($coupon->isSingle()) {
                 $this->setMessage("Updated coupon <b>{$coupon->code}</b>");
             }
         }
         /**
          * Group Insert
          */
         elseif (is_numeric($n = Context::get('codes_number')) && $n > 1) {
             $coupon->type = Coupon::TYPE_PARENT;
             $out = $coupon->save();
             $repository->check($out);
             $length = Context::get('code_length');
             $type = Context::get('code_type');
             $pattern = Context::get('code_pattern');
             if (!strstr($pattern, 'CODE')) throw new ShopException('Pattern must contain "CODE"');
             $pattern = str_replace('CODE', 'X', $pattern);
             $separateEvery = Context::get('separate_at');
             $coupons = $coupon->generateBulk($n, $length, $type, $pattern, $separateEvery);
             $this->setMessage('Generated ' . count($coupons) . ' (grouped) coupons');
         }
         /**
          * Single insert
          */
         else {
             $coupon->type = Coupon::TYPE_SINGLE;
             $out = $coupon->save();
             $repository->check($out);
             $this->setMessage("Generated single coupon with code <b>{$coupon->code}</b>");
         }
     }
     catch (Exception $e) {
         $msg = $e->getMessage();
         if (strstr($msg, 'unique_module_code')) {
             $msg = "Code '<b>{$coupon->code}</b>' is already in use";
         }
         return new Object(-1, $msg);
     }
     $this->setRedirectUrl(getNotEncodedUrl('', 'act', 'dispShopToolDiscountCodes', 'highlight', $coupon->srl));
 }
开发者ID:haegyung,项目名称:xe-module-shop,代码行数:64,代码来源:shop.controller.php

示例11: actionRestcreate

 /**
  * 新增优惠券信息
  * POST /api/activity/{activityId}/coupon
  */
 public function actionRestcreate()
 {
     $this->checkRestAuth();
     // check activity
     $activity = Activity::model()->findByPk($_GET['activityId']);
     if ($activity == null || $activity->archived == 0) {
         return $this->sendResponse(404, 'activity is not found');
     }
     if (!isset($_POST['batch']) || !isset($_POST['code'])) {
         return $this->sendResponse(400, "missed parameters");
     }
     // 判断code是否唯一
     if (!$this->checkCodeIsUnqinue($activity->id, $_POST['code'])) {
         return $this->sendResponse(400, 'code is not unique');
     }
     $coupon = new Coupon();
     $coupon->activity_id = $activity->id;
     $coupon->batch = $_POST['batch'];
     $coupon->code = $_POST['code'];
     if (isset($_POST['createdBy'])) {
         $coupon->created_by = $_POST['createdBy'];
     }
     if ($coupon->save()) {
         $this->sendResponse(201, $coupon->id);
     } else {
         $this->sendResponse(500, 'failed to create.');
     }
 }
开发者ID:aer123456,项目名称:yougou,代码行数:32,代码来源:CouponController.php

示例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');
             }
//.........这里部分代码省略.........
开发者ID:BGCX067,项目名称:facecom-svn-to-git,代码行数:101,代码来源:DiscountController.php

示例13: actionMakeCoupon

 /**
  * 生成优惠券
  */
 public function actionMakeCoupon()
 {
     if (empty($_POST)) {
         $info = CouponType::model()->findByPk($_REQUEST['id']);
         $viewData = array();
         $viewData['info'] = $info;
         $this->render('makecoupon', $viewData);
         exit;
     }
     $res = array('statusCode' => 200, 'message' => '生成成功!');
     try {
         $typeInfo = CouponType::model()->findByPk($_REQUEST['id']);
         if (empty($typeInfo)) {
             throw new exception('该优惠券类型不存在!');
         }
         $model = Coupon::model();
         $couponSns = array();
         $okNumber = 0;
         for ($i = 0; $i < $_REQUEST['send_num']; $i++) {
             $sn = $model->getCouponSn();
             if (in_array($sn, $couponSns)) {
                 continue;
             }
             $m = new Coupon();
             $m->coupon_sn = $sn;
             $m->coupon_type_id = $_REQUEST['id'];
             $m->coupon_amount = $typeInfo['coupon_amount'];
             $m->satisfied_amount = $typeInfo['satisfied_amount'];
             $m->start_time = $typeInfo['start_time'];
             $m->end_time = $typeInfo['end_time'];
             $m->add_time = time();
             $flag = $m->save();
             $okNumber += empty($flag) ? 0 : 1;
             array_push($couponSns, $sn);
         }
     } catch (Exception $e) {
         $res['statusCode'] = 300;
         $res['message'] = '失败【' . $e->getMessage() . '】';
     }
     $res['navTabId'] = 'couponTypeList';
     $res['callbackType'] = 'closeCurrent';
     $res['forwardUrl'] = '/manage/coupon/typeIndex';
     $this->ajaxDwzReturn($res);
 }
开发者ID:conghua1013,项目名称:yii,代码行数:47,代码来源:CouponController.php


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