Browse Source

修改运费模板创建和更新方法因删除字段导致的逻辑变更

antshop
linyaostalker 5 years ago
parent
commit
f6dc5c426e
  1. 74
      backend/modules/shop/controllers/ExpressTemplateController.php

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

@ -73,52 +73,13 @@ class ExpressTemplateController extends Controller
public function actionCreate() public function actionCreate()
{ {
$model = new ExpressTemplate(); $model = new ExpressTemplate();
$model->calculation_type = ExpressTemplate::CALCULATION_TYPE_NUMBER;
$model->basic_count = 1;
$model->basic_price = '0.00';
if (Yii::$app->request->isPost) {
$data = Yii::$app->request->post('ExpressTemplate');
if (Yii::$app->request->isAjax) {
$model->load($data, '');
Yii::$app->response->format = Response::FORMAT_JSON;
$data = ActiveForm::validate($model);
$data['status'] = 2;
return $data;
}
if (Yii::$app->request->post('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, '');
$model->basic_price *= 100;
$model->extra_price *= 100;
if ($model->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) {
$model->basic_count *= 10;
$model->extra_count *= 10;
} else {
$model->basic_count *= 1;
$model->extra_count *= 1;
}
$model->save();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect('index'); return $this->redirect('index');
} }
$data = [];
$provinces = Province::find()->cache(0)->all();
foreach ($provinces as $k => $v) {
$data[$k]['province'] = $v->name;
$cities = City::find()
->where(['province_id' => $v->province_id])
->all();
foreach ($cities as $city) {
$data[$k]['city'][] = ['id' => $city->city_id, 'name' => $city->name];
}
}
return $this->render('create', [ return $this->render('create', [
'model' => $model, 'model' => $model,
'data' => $data
]); ]);
} }
@ -132,36 +93,13 @@ class ExpressTemplateController extends Controller
public function actionUpdate($id) public function actionUpdate($id)
{ {
$model = $this->findModel($id); $model = $this->findModel($id);
$model->basic_price /= 100;
$model->extra_price /= 100;
if ($model->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) {
$model->basic_count /= 10;
$model->extra_count /= 10;
}
$data = Yii::$app->request->post('ExpressTemplate');
if ($data) {
if (Yii::$app->request->post('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, '');
$model->save();
return $this->render('view', ['model' => ExpressTemplate::findOne($model->id)]);
}
$data = [];
$provinces = Province::find()->cache(0)->all();
foreach ($provinces as $k => $v) {
$data[$k]['province'] = $v->name;
$cities = City::find()
->where(['province_id' => $v->province_id])
->all();
foreach ($cities as $city) {
$data[$k]['city'][] = ['id' => $city->city_id, 'name' => $city->name];
}
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect('index');
} }
return $this->render('update', [ return $this->render('update', [
'model' => $model, 'data' => $data, 'cities' => explode(',', $model->city)
'model' => $model,
]); ]);
} }

Loading…
Cancel
Save