2016-03-21 54 views
0

如何存儲唯一$payment->transaction_id = Input::get('transact'); 沒有更多transaction_id應與相同數量的存儲商店獨特的價值到數據庫laravel 4.2

請給我建議。

public function ddclback() 
    { 

     if(Input::get('statuscode') == 2){ 
      //Save data into the Database 
      $payment      = new Payment; 
      $payment->order_id   = Input::get('orderid'); 
      $payment->amount    = (Input::get('base_amount', 0))?Input::get('base_amount'):Input::get('amount'); 
      $payment->amount    = $payment->amount/100; 
      $payment->cc_fee    = Input::get('processing_fee', 0); 
      $payment->payment_type  = 'CCD-'.Input::get('currency'); 
      $payment->currency   = Input::get('currency'); 
      $payment->exchange_rate  = $this->getExchangeRate(Input::get('currency')); 
      $payment->gateway   = 'DIBS'; 
      $payment->payment_date  = date('Y-m-d'); //\Carbon\Carbon::today()->toDateString(); 
      $payment->card_type   = Input::get('paytype'); 
      $payment->transaction_id  = Input::get('transact'); 
      $payment->customer_ip  = $_SERVER['REMOTE_ADDR']; 
      $payment->save(); 

      Order::ccid(Input::get('orderid')); 
      Order::upord(Input::get('orderid')); 
     } 

    } 

回答

1

在將記錄插入到數據庫之前,您應該檢查where子句。

試試下面的代碼:

public function ddclback() { 

    if (Input::get('statuscode') == 2) { 
     $exist = $this->checkExist(Input::get('orderid'), Input::get('transact')); // check if exist it will return true/ false 
     if (!$exist) { 

      //Save data into the Database if not exist 
      $payment = new Payment; 
      $payment->order_id = Input::get('orderid'); 
      $payment->amount = (Input::get('base_amount', 0)) ? Input::get('base_amount') : Input::get('amount'); 
      $payment->amount = $payment->amount/100; 
      $payment->cc_fee = Input::get('processing_fee', 0); 
      $payment->payment_type = 'CCD-' . Input::get('currency'); 
      $payment->currency = Input::get('currency'); 
      $payment->exchange_rate = $this->getExchangeRate(Input::get('currency')); 
      $payment->gateway = 'DIBS'; 
      $payment->payment_date = date('Y-m-d'); //\Carbon\Carbon::today()->toDateString(); 
      $payment->card_type = Input::get('paytype'); 
      $payment->transaction_id = Input::get('transact'); 
      $payment->customer_ip = $_SERVER['REMOTE_ADDR']; 
      $payment->save(); 

      Order::ccid(Input::get('orderid')); 
      Order::upord(Input::get('orderid')); 
     } 
    } 
} 
public function checkExist($orderId, $transactionId) { 
    $existRecord = Payment::where('order_id', $orderId)->where('transaction_id', $transactionId)->get()->toArray(); 
    if ($existRecord) { 
     return true; 
    } else { 
     return false; 
    } 
} 
+0

Dhaval什麼,我猜測這$費付款> TRANSACTION_ID =輸入::獲得( '辦理');是通過dibs後端它應該來獨特的Bt有時它是調用5次相同的事務ID不知道爲什麼有任何想法 – Jimmy

+0

你應該檢查從這個函數被調用的位置的代碼。 –

+0

如何檢查數據庫中是否存在order_id,並且transaction_id是否存在,它將只保存同一代碼中的一個數據 – Jimmy