如何为yii2中的单独计算计算gridview

时间:2018-10-29 09:57:51

标签: php yii yii2 yii2-advanced-app

我想在gridview上将陆路货物的计算与空运货物分开。例如,service_id陆运货物= D2D,service_id空运货物= P2P。计算陆运货物P x P x P / 4000和空运货物P x P x P /6000。我想找到发往目的地的城市,它将根据计算结果在gridview上显示陆运价格和空运价格在GridView中。我不知道怎么。谢谢

    [
    '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; //$model->service_id=>['D2D']
        $volume = $model->rate * Yii::$app->request->get('TarifCargoSearch')['panjang'] * Yii::$app->request->get('TarifCargoSearch')['lebar'] * Yii::$app->request->get('TarifCargoSearch')['tinggi'] /6000 + $model->admin_fee; //$model->service_id=>['P2P']
        $mass = $model->rate * Yii::$app->request->get('TarifCargoSearch')['massa'] + $model->admin_fee;

        return $mass > $volume? $mass : $volume;
        }
    ],

1 个答案:

答案 0 :(得分:0)

[
    'label' => 'Tarif',
    'format' => 'Currency',
    'value' => function ($model) {
       $volume = 0;
       if($model->service_id == 'D2D') {
           $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;
        } else if($model->service_id == 'P2P')
           $volume = $model->rate * Yii::$app->request->get('TarifCargoSearch')['panjang'] * Yii::$app->request->get('TarifCargoSearch')['lebar'] * Yii::$app->request->get('TarifCargoSearch')['tinggi'] /6000 + $model->admin_fee;
        }
       $mass = $model->rate * Yii::$app->request->get('TarifCargoSearch')['massa'] + $model->admin_fee;

       return $mass > $volume? $mass : $volume;
       }
],