/** * Updates an existing Goods model. * If update is successful, the browser will be redirected to the 'view' page. * @param string $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $oldPrice = $model->price; if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($oldPrice !== $model->price) { //价格不同 就增加 价格修改日志 $goodspricelog = new GoodsPriceLog(); $goodspricelog->goods_id = $model->id; $goodspricelog->price = $model->price; $time = time(); $goodspricelog->year = date('Y', $time); $goodspricelog->month = date('m', $time); $goodspricelog->day = date('d', $time); $x = $goodspricelog->save(); if (!$x) { var_dump($goodspricelog); die; } } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model]); } }
/** * Creates a new GoodsPriceLog model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new GoodsPriceLog(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }