|
|
@ -2,8 +2,7 @@ |
|
|
|
|
|
|
|
namespace backend\modules\shop\controllers; |
|
|
|
|
|
|
|
use backend\modules\shop\models\ars\City; |
|
|
|
use backend\modules\shop\models\ars\Province; |
|
|
|
use backend\modules\shop\logic\ShopManager; |
|
|
|
use backend\modules\shop\models\searchs\ExpressAreaSearch; |
|
|
|
use Yii; |
|
|
|
use backend\modules\shop\models\ars\ExpressTemplate; |
|
|
@ -15,6 +14,7 @@ use yii\web\Response; |
|
|
|
use yii\widgets\ActiveForm; |
|
|
|
use backend\modules\shop\models\ars\ExpressArea; |
|
|
|
use backend\modules\goods\models\ars\Goods; |
|
|
|
use backend\modules\shop\logic\CommonManager; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
@ -207,42 +207,13 @@ class ExpressTemplateController extends Controller |
|
|
|
$cityIds = array_keys(Yii::$app->request->post('area')); |
|
|
|
$data['city'] = implode(',', $cityIds); |
|
|
|
$model->load($data, ''); |
|
|
|
$model->basic_price *= 100; |
|
|
|
$model->extra_price *= 100; |
|
|
|
if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { |
|
|
|
$model->basic_count *= 1000; |
|
|
|
$model->extra_count *= 1000; |
|
|
|
} else { |
|
|
|
$model->basic_count *= 1; |
|
|
|
$model->extra_count *= 1; |
|
|
|
} |
|
|
|
ShopManager::expressAreaScaleDate($model, $expressTemplateModel); //按比例转换数据
|
|
|
|
$model->save(); |
|
|
|
return $this->redirect('express-area-list?id='.$model->express_template); |
|
|
|
} |
|
|
|
$data = []; |
|
|
|
$expressAreas = ExpressArea::find()->select(['city'])->where(['express_template' => $expressTemplateModel->id])->all(); |
|
|
|
$expressAresCityIdArr = []; |
|
|
|
if ($expressAreas) { |
|
|
|
foreach ($expressAreas as $expressAreaCity) { |
|
|
|
$cityIdArr = explode(',', $expressAreaCity->city); |
|
|
|
$expressAresCityIdArr = array_unique(array_merge($cityIdArr, $expressAresCityIdArr)); |
|
|
|
} |
|
|
|
} |
|
|
|
$provinces = Province::find()->cache(0)->all(); |
|
|
|
$j = 0; |
|
|
|
foreach ($provinces as $k => $v) { |
|
|
|
$cities = City::find() |
|
|
|
->where(['province_id' => $v->province_id]) |
|
|
|
->andWhere(['not in', 'city_id', $expressAresCityIdArr]) |
|
|
|
->all(); |
|
|
|
if ($cities) { |
|
|
|
$data[$j]['province'] = $v->name; |
|
|
|
foreach ($cities as $city) { |
|
|
|
$data[$j]['city'][] = ['id' => $city->city_id, 'name' => $city->name]; |
|
|
|
} |
|
|
|
$j++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$data = ShopManager::filterCity($model); //获取筛选的城市数据
|
|
|
|
|
|
|
|
if (empty($data)) { |
|
|
|
Yii::$app->session->setFlash('error', '已无地区选择'); |
|
|
|
return $this->redirect('express-area-list?id='.$expressTemplateModel->id); |
|
|
@ -261,13 +232,16 @@ class ExpressTemplateController extends Controller |
|
|
|
public function actionExpressAreaUpdate($id) |
|
|
|
{ |
|
|
|
$model = ExpressArea::findOne($id); |
|
|
|
|
|
|
|
//数据按比例转换
|
|
|
|
$expressTemplateModel = ExpressTemplate::findOne($model->express_template); |
|
|
|
$model->basic_price /= 100; |
|
|
|
$model->extra_price /= 100; |
|
|
|
$model->basic_price /= ShopManager::proportionalConversion(ShopManager::UNIT_TYPE_MONEY); |
|
|
|
$model->extra_price /= ShopManager::proportionalConversion(ShopManager::UNIT_TYPE_MONEY); |
|
|
|
if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { |
|
|
|
$model->basic_count /= 1000; |
|
|
|
$model->extra_count /= 1000; |
|
|
|
$model->basic_count /= ShopManager::proportionalConversion(ShopManager::UNIT_TYPE_WEIGHT); |
|
|
|
$model->extra_count /= ShopManager::proportionalConversion(ShopManager::UNIT_TYPE_WEIGHT); |
|
|
|
} |
|
|
|
|
|
|
|
$data = Yii::$app->request->post('ExpressArea'); |
|
|
|
if ($data) { |
|
|
|
if (Yii::$app->request->post('area') == null) { |
|
|
@ -276,42 +250,12 @@ class ExpressTemplateController extends Controller |
|
|
|
$cityIds = array_keys(Yii::$app->request->post('area')); |
|
|
|
$data['city'] = implode(',', $cityIds); |
|
|
|
$model->load($data, ''); |
|
|
|
$model->basic_price *= 100; |
|
|
|
$model->extra_price *= 100; |
|
|
|
if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { |
|
|
|
$model->basic_count *= 1000; |
|
|
|
$model->extra_count *= 1000; |
|
|
|
} else { |
|
|
|
$model->basic_count *= 1; |
|
|
|
$model->extra_count *= 1; |
|
|
|
} |
|
|
|
ShopManager::expressAreaScaleDate($model, $expressTemplateModel); //按比例转换数据
|
|
|
|
$model->save(); |
|
|
|
return $this->redirect('express-area-list?id='.$model->express_template); |
|
|
|
} |
|
|
|
$data = []; |
|
|
|
$expressAreas = ExpressArea::find()->select(['city'])->where(['express_template' => $expressTemplateModel->id])->andWhere(['!=', 'id', $id])->all(); |
|
|
|
$expressAresCityIdArr = []; |
|
|
|
if ($expressAreas) { |
|
|
|
foreach ($expressAreas as $expressAreaCity) { |
|
|
|
$cityIdArr = explode(',', $expressAreaCity->city); |
|
|
|
$expressAresCityIdArr = array_unique(array_merge($cityIdArr, $expressAresCityIdArr)); |
|
|
|
} |
|
|
|
} |
|
|
|
$provinces = Province::find()->cache(0)->all(); |
|
|
|
$j = 0; |
|
|
|
foreach ($provinces as $k => $v) { |
|
|
|
$cities = City::find() |
|
|
|
->where(['province_id' => $v->province_id]) |
|
|
|
->andWhere(['not in', 'city_id', $expressAresCityIdArr]) |
|
|
|
->all(); |
|
|
|
if ($cities) { |
|
|
|
$data[$j]['province'] = $v->name; |
|
|
|
foreach ($cities as $city) { |
|
|
|
$data[$j]['city'][] = ['id' => $city->city_id, 'name' => $city->name]; |
|
|
|
} |
|
|
|
$j++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$data = ShopManager::filterCity($model); //获取筛选的城市数据
|
|
|
|
|
|
|
|
return $this->render('express_area_update', [ |
|
|
|
'model' => $model, 'data' => $data, 'cities' => explode(',', $model->city), 'expressTemplateModel' => $expressTemplateModel |
|
|
|