Ejemplo n.º 1
0
 /**
  * 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]);
     }
 }
Ejemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = GoodsPriceLog::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'goods_id' => $this->goods_id, 'year' => $this->year, 'month' => $this->month, 'day' => $this->day, 'price' => $this->price, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     return $dataProvider;
 }
 /**
  * Finds the GoodsPriceLog model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return GoodsPriceLog the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = GoodsPriceLog::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }