backend\controllers\ApplyController::actionPass PHP Method

actionPass() public method

public actionPass ( $id )
    public function actionPass($id)
    {
        $model = Apply::findOne(['id' => $id, 'status' => Apply::STATUS_PENDING]);
        if (!$model) {
            throw new BadRequestHttpException('参数错误!');
        }
        $transaction = Yii::$app->db->beginTransaction();
        try {
            $model->status = Apply::STATUS_PASSED;
            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();
            if (!empty($model->store->cellphone)) {
                Yii::$app->smser->send($model->store->cellphone, "亲爱的店长,恭喜您的采购订单{$model->apply_sn}申请成功,我们的工作人员很快会与您取得联系。");
            }
            Yii::$app->session->setFlash('success', '操作成功!');
        } catch (\Exception $e) {
            $transaction->rollBack();
            Yii::$app->session->setFlash('danger', $e->getMessage());
        }
        return $this->redirect(['view', 'id' => $id]);
    }