public function actionUpdate($id)
{
/* @var $model Goods */
$model = Goods::findOne(['id' => $id, 'store_id' => Yii::$app->user->identity->store_id]);
if (!$model) {
throw new NotFoundHttpException('未找到该商品。');
}
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if (floatval($model->price_original) < 0.01) {
$model->price_original = null;
}
if ($model->save(false)) {
Yii::$app->session->setFlash('success', '成功更新商品“' . $model->name . '”。');
return $this->redirect(['index']);
} else {
Yii::$app->session->setFlash('danger', $e->getMessage());
}
}
return $this->render('form', ['model' => $model]);
}