TP5 事務操作


 // 啟動事務
            Db::startTrans();
            try {
                $save = [
                    'wx'=>$data['wx'],
                    'nickname'=>$data['nickname'],
                    'sex'=>$data['sex'],
                    'birth_date'=>$data['birth_date'],
                    'email'=>$data['email'],
                    'address'=>$data['address']
                ];
                $ok = Db::name('User')->where(['id'=>$user_id])->update($save);
                if($ok!==false){
                    //自定義字段保存
                    $field_save = model('api/v1/User')->field_list_save($data,$user_id);
                    if($field_save['code']!=200){
                        throw new \Exception($field_save['msg']);
                    }
                    //獲取職位所屬分類id
                    $category = explode('/',$job['category']);
                    $tid = $category?end($category):'';
                    $message_data = [
                        'tid'=>$tid,
                        'pid'=>$data['id'],
                        'add_user_id'=>$user_id
                    ];
                    $insert = Db::name('JobMessage')->insert($message_data);
                    if($insert){
                        $json = ['code'=>200,'msg'=>'申請成功,請等待后台審核'];
                    }else{
                        throw new \Exception('申請失敗,請聯系管理員');
                    }
                }
                // 提交事務
                Db::commit();
            } catch (\Exception $e) {
                // 回滾事務
                Db::rollback();
                $json = ['code'=>-200,'msg'=>$e->getMessage()];
            }
            return $json;
 

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM