2017-05-24 6 views
0

データベースクエリに問題があります。
最初にTHISのような2つのエントリをインポートし、データが正しく挿入されました。データが存在する場合に更新する方法、存在しない場合は作成しない方法、Laravel 5

卸売業者ID |ターゲット|週| total_transaction |リベート|

11223344  | 100.000| 1.2017| 50.000   | 2,25 | 0 
11223344  | 100.000| 2.2017| 120.000   | 2,25 | 2700 
11223344  | 100.000| 3.2017| 185.000   | 2,25 | 1462,5 
11223344  | 100.000| 4.2017| 248.000   | 2,25 | 1417,5 

total_voucher しかし、私は追加の行enter image description hereで再びインポートする場合、以下のように、結果は次のとおりです。

wholesaler_id

|ターゲット|週| total_transaction |リベート|私が欲しい結果は以下の通りである。total_voucher

11223344  | 100.000| 1.2017| 50.000   | 2,25 | 0 
11223344  | 100.000| 2.2017| 120.000   | 2,25 | 2700 
11223344  | 100.000| 3.2017| 185.000   | 2,25 | 1462,5 
11223344  | 100.000| 4.2017| 248.000   | 2,25 | 1417,5 
11223344  | 100.000| 1.2017| 63.100   | 2,25 | 0 
11223344  | 100.000| 2.2017| 142.700   | 2,25 | 2700 
11223344  | 100.000| 3.2017| 205.000   | 2,25 | 1462,5 
11223344  | 100.000| 4.2017| 279.400   | 2,25 | 1417,5 

 
wholesaler_id | target | week | total_transaction | rebate | total_voucher 

11223344  | 100.000| 1.2017| 63.100   | 2,25 | 0 
11223344  | 100.000| 2.2017| 155.800   | 2,25 | 2700 
11223344  | 100.000| 3.2017| 240.800   | 2,25 | 1462,5 
11223344  | 100.000| 4.2017| 332.200   | 2,25 | 1417,5

リベートと総バウチャー列が問題ではありませんが、主な問題はtotal_transactionです。
これは私のコントローラの関数のコードであるimportCsv

 


    $voucher = Voucher::firstOrCreate(array(
    'wholesaler_id' => $wholesaler_id, 
    'target' => $target, 
    'week' => $week . '.' . date("Y"), 
    'total_transaction' => $sum, 
    'rebate' => $wholesaler_type->rebate_percentage, 
    'total_voucher' => $total_voucher 
    )); 

答えて

0

それは次のように行われる必要があります。..

$voucher = Voucher::firstOrCreate(['wholesaler_id'=>$wholesaler_id], 
    [ 
     'target' => $target, 
     'week' => $week . '.' . date("Y"), 
     'total_transaction' => $sum, 
     'rebate' => $wholesaler_type->rebate_percentage, 
     'total_voucher' => $total_voucher 
    ] 
); 
関連する問題