我在codeigniter中有一个观点。当我在一个或两个字段中输入时,值来自数据库中的2个表。我在此视图中尝试了定价计算逻辑,其中每月,每周,每天的费率均来自台式计算机。定价计算后,它在一个字段中给出总费率。但是,所有每月,每周和每天的费率都需要插入另一个表中。我该怎么做?
我的控制器功能:
public function pricing()
{
$hire_mode = $this->input->post('hire_mode');
$com_sno = $this->input->post('com_sno');
$diff = $this->input->post('diff');
$this->load->model('autocomplete_model');
$result = $this->autocomplete_model->getRates($com_sno);
$data = array();
switch($hire_mode) {
case 0:
$rate = $result->mohr/30;
$total = $diff * $rate;
$data['rate'] = $result->mohr;
$data['total'] = $total;
break;
case 1:
$rate = $result->wehr/7;
$total = $diff * $rate;
$data['rate'] = $result->mohr;
$data['total'] = $total;
break;
case 2:
$rate = $result->dahr;
$total = $diff * $rate;
$data['rate'] = $result->mohr;
$data['total'] = $total;
break;
}
echo json_encode($data);
}
在我看来json jquery:
<script>
$('#diff').change(function () {
var hireMode = $('input[name=hire_mode]:checked').val();
var diff = $(this).text();
var com_sno = $('#com_sno').val();
console.log(hireMode+'---'+diff+'---'+com_sno)
$.ajax({
url: "<?php echo base_url();?>autocomplete/pricing",
method: "POST",
data: {hire_mode:hireMode, com_sno:com_sno, diff:diff},
dataType: 'JSON',
success: function(res) {
$('#rate').val(res.rate);
$('#total').val(res.total);
console.log(res);
}
});
});