示例#1
0
 public function addVoucherNew()
 {
     $functionsk = new FunctionsK();
     $merchant_id = Yii::app()->functions->getMerchantID();
     $params = array('voucher_name' => $this->data['voucher_name'], 'voucher_type' => $this->data['voucher_type'], 'amount' => $this->data['amount'], 'expiration' => $this->data['expiration'], 'status' => $this->data['status'], 'date_created' => date('c'), 'ip_address' => $_SERVER['REMOTE_ADDR'], 'merchant_id' => $merchant_id);
     /*dump($this->data);
     		dump($params);
     		die();*/
     if (isset($this->data['voucher_owner'])) {
         unset($params['merchant_id']);
         $params['voucher_owner'] = $this->data['voucher_owner'];
     }
     if (isset($this->data['joining_merchant'])) {
         $params['joining_merchant'] = json_encode($this->data['joining_merchant']);
     }
     if (isset($this->data['used_once'])) {
         $params['used_once'] = $this->data['used_once'];
     }
     if (!empty($this->data['id'])) {
         if ($functionsk->checkIFVoucherCodeExisting($this->data['voucher_name'], $this->data['id'])) {
             $this->msg = t("Sorry but voucher name already exist!");
             return;
         }
         $params['date_modified'] = date('c');
         unset($params['date_created']);
         if ($this->updateData("{{voucher_new}}", $params, 'voucher_id', $this->data['id'])) {
             $this->code = 1;
             $this->msg = t("Successful");
         } else {
             $this->msg = t("Failed cannot update records");
         }
     } else {
         if ($functionsk->checkIFVoucherCodeExists($this->data['voucher_name'])) {
             $this->msg = t("Sorry but voucher name already exist!");
             return;
         }
         if ($this->insertData('{{voucher_new}}', $params)) {
             $this->details = Yii::app()->db->getLastInsertID();
             $this->code = 1;
             $this->msg = Yii::t("default", "Successful");
         } else {
             $this->msg = t("ERROR: Something went wrong");
         }
     }
 }