/** * Creates a new Collection model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Collection(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Collection model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Collection(); if ($model->load(Yii::$app->request->post())) { // set the time if ($model->time) { date_default_timezone_set("Asia/ShangHai"); $model->time .= " " . date("H:i:s"); } $model->save(); // add the money to customer $customer = $model->customer; $customer->payed += $model->money; $customer->unpay -= $model->money; $customer->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }