deffyc 2016-06-06 22:59:09 3203次浏览 1条回复 0 0 0

Booksear::findOne(['useflag' => $useflag]);没有返回记录,事务报错,我应该怎么写?

$model=Booksear::findOne(['userid' => Yii::$app->user->id,'useflag' => $useflag]);//用户书籍
if(!$model){
    $connection->transaction(function() {
        //抽取一个书籍
        $model=Booksear::findOne(['useflag' => $useflag]);
        if($model){
            
                //书籍存在,分配给用户
                $model->userid=Yii::$app->user->id;
                $model->save();
        }else{
            //书籍审核完毕,抽取待定书籍
            $useflag=3;
            $model=Booksear::findOne(['useflag' => $useflag]);//用户书籍
            if($model){	
                
                $connection->transaction(function() {
                   //书籍存在,分配给用户
                    if($model->userid!=Yii::$app->user->id){
                        $model->userid=Yii::$app->user->id;
                        $model->save();
                    }
                },Transaction::SERIALIZABLE);
                
            }else{
                //待定书籍审核完毕,返回列表页
                 return $this->redirect(['index']);
            }
        }
    },Transaction::SERIALIZABLE);
}
return $this->redirect(['inview', 'id' => $model->id]);
  • 回复于 2016-06-07 08:36 举报
    $connection->transaction //$connection is null, try debug here.
    
    1 条回复
    回复于 2016-06-07 17:34 回复

    thank you,i really ignore this problem.i just think the model is non object.

您需要登录后才可以回复。登录 | 立即注册