Browse Source

处理城市列表显示问题

antshop
linyaostalker 5 years ago
parent
commit
7560af34f1
  1. 1
      backend/modules/shop/controllers/ExpressTemplateController.php
  2. 22
      backend/modules/shop/models/searchs/ExpressAreaSearch.php
  3. 2
      backend/modules/shop/views/express-template/express_area_update.php

1
backend/modules/shop/controllers/ExpressTemplateController.php

@ -359,6 +359,7 @@ class ExpressTemplateController extends Controller
$j++; $j++;
} }
} }
return $this->render('express_area_update', [ return $this->render('express_area_update', [
'model' => $model, 'data' => $data, 'cities' => explode(',', $model->city), 'expressTemplateModel' => $expressTemplateModel 'model' => $model, 'data' => $data, 'cities' => explode(',', $model->city), 'expressTemplateModel' => $expressTemplateModel
]); ]);

22
backend/modules/shop/models/searchs/ExpressAreaSearch.php

@ -2,6 +2,8 @@
namespace backend\modules\shop\models\searchs; namespace backend\modules\shop\models\searchs;
use backend\modules\shop\models\ars\City;
use backend\modules\shop\models\ars\Province;
use yii\base\Model; use yii\base\Model;
use yii\data\ActiveDataProvider; use yii\data\ActiveDataProvider;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
@ -57,12 +59,24 @@ class ExpressAreaSearch extends ExpressArea
'id', 'id',
['attribute' => 'city', ['attribute' => 'city',
'value' => function ($model) { 'value' => function ($model) {
$array = explode(',', $model->city);
$expressAreas = ExpressArea::findOne($model->id);
$expressAresCityIdArr = explode(',', $expressAreas->city);
$cities = []; $cities = [];
foreach (\backend\modules\shop\models\ars\City::find()->andWhere(['in', 'city_id', $array])->all() as $city) {
$cities[] = $city->name;
$provinces = Province::find()->cache(0)->all();
foreach ($provinces as $k => $v) {
$cityId = City::find()
->select(['city_id'])
->where(['province_id' => $v->province_id])
->column();
if (empty(array_diff($cityId, $expressAresCityIdArr))) {
$cities[] = $v->name;
}else{
foreach (\backend\modules\shop\models\ars\City::find()->andWhere(['in', 'city_id', array_diff($cityId, array_diff($cityId, $expressAresCityIdArr))])->all() as $city) {
$cities[] = $city->name;
}
}
} }
return implode(' // ', $cities);
return implode(' , ', $cities);
}, },
], ],
[ [

2
backend/modules/shop/views/express-template/express_area_update.php

@ -43,7 +43,7 @@ Yii::$app->params['bsVersion'] = '4.x';
<div class="form-group"> <div class="form-group">
<?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?> <?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
<?= Html::a('返回', ['index'], ['class' => 'btn btn-info']) ?>
<?= Html::a('返回', ['express-area-list', 'id' => $expressTemplateModel->id], ['class' => 'btn btn-info']) ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>

Loading…
Cancel
Save