Browse Source

feat:开发在创建修改运费区域中的处理区域信息方法,修改优化代码

antshop
linyaostalker 5 years ago
parent
commit
1dfc08be94
  1. 21
      backend/modules/shop/controllers/ExpressTemplateController.php
  2. 17
      backend/modules/shop/logic/ShopManager.php

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

@ -4,6 +4,7 @@ namespace backend\modules\shop\controllers;
use backend\modules\shop\logic\ShopManager; use backend\modules\shop\logic\ShopManager;
use backend\modules\shop\models\searchs\ExpressAreaSearch; use backend\modules\shop\models\searchs\ExpressAreaSearch;
use http\Url;
use Throwable; use Throwable;
use Yii; use Yii;
use backend\modules\shop\models\ars\ExpressTemplate; use backend\modules\shop\models\ars\ExpressTemplate;
@ -205,14 +206,11 @@ class ExpressTemplateController extends Controller
$data['status'] = 2; $data['status'] = 2;
return $data; return $data;
} }
if (Yii::$app->request->post('area') == null) {
return $this->redirect(Yii::$app->request->referrer . '?status=1');
$area = Yii::$app->request->post('area');
if ($area == null) {
return $this->redirect(Yii::$app->request->referrer . '&status=1');
} }
$cityIds = array_keys(Yii::$app->request->post('area'));
$data['city'] = implode(',', $cityIds);
$model->load($data, '');
ShopManager::expressAreaScaleDate($model, $expressTemplateModel); //按比例转换数据
$model->save();
ShopManager::dealAreaInExpressArea($area, $model, $expressTemplateModel);
return $this->redirect('express-area-list?id='.$model->express_template); return $this->redirect('express-area-list?id='.$model->express_template);
} }
@ -247,14 +245,11 @@ class ExpressTemplateController extends Controller
$data = Yii::$app->request->post('ExpressArea'); $data = Yii::$app->request->post('ExpressArea');
if ($data) { if ($data) {
if (Yii::$app->request->post('area') == null) {
$area = Yii::$app->request->post('area');
if ($area == null) {
return $this->redirect(Yii::$app->request->referrer . '&status=1'); return $this->redirect(Yii::$app->request->referrer . '&status=1');
} }
$cityIds = array_keys(Yii::$app->request->post('area'));
$data['city'] = implode(',', $cityIds);
$model->load($data, '');
ShopManager::expressAreaScaleDate($model, $expressTemplateModel); //按比例转换数据
$model->save();
ShopManager::dealAreaInExpressArea($area, $model, $expressTemplateModel);
return $this->redirect('express-area-list?id='.$model->express_template); return $this->redirect('express-area-list?id='.$model->express_template);
} }

17
backend/modules/shop/logic/ShopManager.php

@ -119,4 +119,21 @@ class ShopManager
} }
return array_values($data); return array_values($data);
} }
/**
* 处理所选区域数据
* @param $area
* @param ExpressArea|$expressAreaModel
* @param ExpressTemplate|$expressTemplateModel
* @return bool
*/
public static function dealAreaInExpressArea($area, $expressAreaModel, $expressTemplateModel)
{
$cityIds = array_keys($area);
$data['city'] = implode(',', $cityIds);
$expressAreaModel->load($data, '');
self::expressAreaScaleDate($expressAreaModel, $expressTemplateModel); //按比例转换数据
$expressAreaModel->save();
return true;
}
} }
Loading…
Cancel
Save