【发布时间】:2021-10-26 05:46:26
【问题描述】:
我有一个交易表单,提交时会存储一个“total_value”。然后页面重新加载到相同的表单上,以便用户可以添加更多数据。我希望将输入的值添加到之前插入的“total_value”中。
示例: 如果第一次提交值 = 10,第二次提交值 = 5,则存储的 total_value 应为 15。
这是我在控制器中的代码:
$discount = Master::findOne(['id' => $usrM->master_id])->rate_discount;
$tempArray = Yii::$app->request->post('template');
$seat = Yii::$app->request->post('BookingDetails')['seats_count'];
$cost = [];
if ($model->load(Yii::$app->request->post())) {
$sp = Template::findOne(['id'=>$tempArray])->standard_price;
$seat_cost = $sp * $seat;
array_push($cost, $seat_cost);
$sum = array_sum($cost);
//this is the total cost of all templates with master center discount applied
$total = $sum - ($sum*($discount/100));
$model->save();
Yii::$app->db->createCommand('UPDATE ebs_booking_transaction SET total_value ='.$total.' WHERE id = '.$trans)->execute();
【问题讨论】:
-
SET total_value = total_value + ...