thinkphp中try catch的运用

 1 public function doedit_set(){
 2     $info=$this->_post("info");  
 3     $id=$this->_post("id");//dump($info);exit();
 4     $user=DD("Order.OrderPackage")->deal_account($info[‘accounts‘]); 
 5     try{
 6         $result=DD(‘Set.UserSet‘)->doedit_setinfo($id,$info,$user);
 7         if($result){
 8            $this->success("编辑成功",U("Userset/index"));
 9         }
10         $this->error("编辑失败"); 
11     }catch(Exception $e){    
12        $this->error($e->getMessage());
13     }    
14 }
15 
16 
17 
18 public function doedit_setinfo($id,$edit_info,$user_id)
19 {
20    if($id && $edit_info)
21    {     
22         $res=M(‘user_set‘)->where(array(‘op_name‘=>$edit_info[‘op_name‘],‘id‘=>$id))->find();
23 
24         if(!$res)
25         {
26             E("非法数据");
27         }
28 
29         $md=new Model();
30         $md->startTrans(); 
31         $user_info=DD("User.AdminUser")->get_info();
32         $edit_info[‘start_time‘]=strtotime($edit_info[‘time1‘]);
33         $edit_info[‘end_time‘]=strtotime($edit_info[‘time2‘]);
34         foreach ($user_id as $key => $value) {
35 
36             $op=M(‘user_set‘)->where(array(‘op_name‘=>$edit_info[‘op_name‘],‘uid‘=>$value))->find();
37             if($op[‘id‘]!=$id && $op )
38             {
39                E("此用户配置已存在");
40             }
41 
42             if(M(‘user_set‘)->where(‘uid=%d‘,$value)->find())
43             {   
44                 $edit_info[‘uid‘]=$value;
45                 $result=M(‘user_set‘)->where("id=%d",$id)->save($edit_info);
46                 $content="id:".$id."修改前的|op_name:".$res[‘op_name‘]."|op_value:".$res[‘op_value‘]."|op_des:".$res[‘op_des‘]."|start_time:".$res[‘start_time‘]."|end_time:".$res[‘end_time‘]."|is_del:".$res[‘is_del‘]."|uid:".$res[‘uid‘]."|修改后:op_name".$edit_info[‘op_name‘]."|op_value".$edit_info[‘op_value‘]."|op_des:".$edit_info[‘op_des‘]."|start_time:".$edit_info[‘start_time‘]."|end_time:".$edit_info[‘end_time‘]."|uid:".$value; 
47                 $type="修改";
48                 $obj="用户配置";
49                 $log_result=DD("Logs.UserOp")->handle_logs($user_info[‘userId‘],$user_info[‘account‘] ,$content,$type,$obj); 
50             }
51             else
52             {  
53                $edit_info[‘uid‘]=$value;     
54                $result=M(‘user_set‘)->add($edit_info); 
55                $content="新增用户配置|id:".$result."|op_name:".$edit_info[‘op_name‘]."|op_value:".$edit_info[‘op_value‘]."|op_des:".$edit_info[‘op_des‘]."|start_time:".$edit_info[‘start_time‘]."|end_time:".$edit_info[‘end_time‘]."|uid:".$edit_info[‘uid‘]."|is_del:".$edit_info[‘is_del‘]; 
56                $type="新增";
57                $obj="用户配置";
58                $log_result=DD("Logs.UserOp")->handle_logs($user_info[‘userId‘],$user_info[‘account‘] ,$content,$type,$obj);    
59             }
60         }
61  
62         if($result!==false && $log_result )
63         {  
64             $md->commit(); 
65             return true;
66         }
67         else
68         {   
69             $md->rollback();
70             return false;
71         }
72    }
73    else
74    {
75        E("参数错误");
76    }
77 }

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。