store\controllers\ApplyController::actionCancel PHP Метод

actionCancel() публичный Метод

public actionCancel ( $id )
    public function actionCancel($id)
    {
        $model = Apply::findOne(['id' => $id, 'status' => Apply::STATUS_REJECTED, 'store_id' => Yii::$app->user->identity->store_id]);
        if (!$model) {
            throw new BadRequestHttpException('参数错误!');
        }
        $transaction = Yii::$app->db->beginTransaction();
        try {
            $model->status = Apply::STATUS_CANCELLED;
            if (!$model->save(false)) {
                throw new \Exception('操作失败!');
            }
            $modelApplyLog = new ApplyLog();
            $modelApplyLog->apply_id = $id;
            $modelApplyLog->remark = '取消申请。';
            if (!$modelApplyLog->save(false)) {
                throw new \Exception('申请日志记录失败!');
            }
            $transaction->commit();
            Yii::$app->session->setFlash('success', '操作成功!');
        } catch (\Exception $e) {
            $transaction->rollBack();
            Yii::$app->session->setFlash('danger', $e->getMessage());
        }
        return $this->redirect(['view', 'id' => $id]);
    }