Beispiel #1
0
 public function save()
 {
     $invoice = Invoice::findOne(['id' => $this->id]);
     if (empty($invoice)) {
         $invoice = new Invoice();
         $invoice->user_id = $this->user_id;
         $invoice->status = $this->status;
         $invoice->data = json_encode($this->data);
         $invoice->payment_type = $this->payment_type;
         $invoice->currency = $this->currency;
         $invoice->total = $this->total;
         $invoice->delivery_address = $this->delivery_address;
         Yii::getLogger()->log('save:', YII_DEBUG);
         if ($invoice->save()) {
             $this->id = $invoice->id;
             return $invoice;
         } else {
             Yii::getLogger()->log('save error', YII_DEBUG);
         }
     } else {
         $invoice->user_id = $this->user_id;
         $invoice->status = $this->status;
         $invoice->data = json_encode($this->data);
         $invoice->payment_type = $this->payment_type;
         $invoice->currency = $this->currency;
         $invoice->total = $this->total;
         $invoice->delivery_address = $this->delivery_address;
         Yii::getLogger()->log('update:', YII_DEBUG);
         if ($invoice->update()) {
             return $invoice;
         } else {
             Yii::getLogger()->log('update error:' . print_r($invoice, true), YII_DEBUG);
         }
     }
     return null;
 }