我的数据库查询有问题 我首先导入了两个条目,如,并且数据插入正确。
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
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
。
这是我的Controller函数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 :(得分: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
]
);