如何在yii2中添加最小计算
How to add a minimum calculation in yii2
1 .for example like this picture, I put in 30 kg of mass 2. result 123000, because 30 x 4100 = 123000 3. When entering 4 kg mass 4. the result is 123000 . because min mass 30 kg. even though 4 x 4100 = 16400. I want to be like that如何添加最小值计算。例如,质量为 1 千克的货物的价格 = 1000,最小质量为 100 千克的货物的价格 = 100000。所以当我想添加 45 千克或小于 100 千克时,结果仍然是 100,000,因为最小质量为 100公斤。如果我输入大于 100 的质量,例如 101,则 101 x 1000 = 101000。我只能指望此源代码,但没有最低使用量 100 公斤。谢谢
[
'label' => 'Tarif',
'format' => 'Currency',
'value' => function ($model) {
$volume = $model->rate * Yii::$app->request->get('TarifCargoSearch')['panjang'] * Yii::$app->request->get('TarifCargoSearch')['lebar'] * Yii::$app->request->get('TarifCargoSearch')['tinggi'] /4000 + $model->admin_fee;
$mass = $model->rate * Yii::$app->request->get('TarifCargoSearch')['massa'];
return $mass > $volume? $mass : $volume;
}
],
我认为您必须将其解析为变量以便于使用
[
'label' => 'Tarif',
'format' => 'Currency',
'value' => function ($model) {
$panjang = Yii::$app->request->get('TarifCargoSearch')['panjang'];
$lebar = Yii::$app->request->get('TarifCargoSearch')['lebar'];
$tinggi = Yii::$app->request->get('TarifCargoSearch')['tinggi'];
$volume = ($panjang * $lebar * $tinggi) / 4000;
$rate = $model->rate;
$rate_total = ($rate * $volume) + $model->admin_fee;
$mass = Yii::$app->request->get('TarifCargoSearch')['massa'];
$mass_min = 100;
if ($mass_min < $mass)
{
return $rate_total * $mass;
}
else
{
return $rate_total * $mass_min;
}
}
],
1 .for example like this picture, I put in 30 kg of mass 2. result 123000, because 30 x 4100 = 123000 3. When entering 4 kg mass 4. the result is 123000 . because min mass 30 kg. even though 4 x 4100 = 16400. I want to be like that如何添加最小值计算。例如,质量为 1 千克的货物的价格 = 1000,最小质量为 100 千克的货物的价格 = 100000。所以当我想添加 45 千克或小于 100 千克时,结果仍然是 100,000,因为最小质量为 100公斤。如果我输入大于 100 的质量,例如 101,则 101 x 1000 = 101000。我只能指望此源代码,但没有最低使用量 100 公斤。谢谢
[
'label' => 'Tarif',
'format' => 'Currency',
'value' => function ($model) {
$volume = $model->rate * Yii::$app->request->get('TarifCargoSearch')['panjang'] * Yii::$app->request->get('TarifCargoSearch')['lebar'] * Yii::$app->request->get('TarifCargoSearch')['tinggi'] /4000 + $model->admin_fee;
$mass = $model->rate * Yii::$app->request->get('TarifCargoSearch')['massa'];
return $mass > $volume? $mass : $volume;
}
],
我认为您必须将其解析为变量以便于使用
[
'label' => 'Tarif',
'format' => 'Currency',
'value' => function ($model) {
$panjang = Yii::$app->request->get('TarifCargoSearch')['panjang'];
$lebar = Yii::$app->request->get('TarifCargoSearch')['lebar'];
$tinggi = Yii::$app->request->get('TarifCargoSearch')['tinggi'];
$volume = ($panjang * $lebar * $tinggi) / 4000;
$rate = $model->rate;
$rate_total = ($rate * $volume) + $model->admin_fee;
$mass = Yii::$app->request->get('TarifCargoSearch')['massa'];
$mass_min = 100;
if ($mass_min < $mass)
{
return $rate_total * $mass;
}
else
{
return $rate_total * $mass_min;
}
}
],