Public function xiaohao(){
$user=M('jiedan');
$jd=M('jingdong');
$ujd=M('user');
$data['uid']=$_SESSION['uid'];
$data['rw_id']=I('rw_id');
$list=$jd->where("id=$data[rw_id]")->find();
$ulist=$ujd->where("uid=$data[uid]")->field("uid,qq")->find();
$data['sj_username']=$list['username'];
$data['sj_qq']=$list['qq'];
$data['sj_uid']=$list['uid'];
$data['rw_dan']=$list['rw_dan'];
$data['qq']=$ulist['qq'];
$data['username']=$_SESSION['username'];
$data['utype']=$_SESSION['utype'];
$data['rw_type']=I('rw_type');
$data['dan_type']=I('dan_type');
$date['rw_xh']=I('rw_xh');
$data['addtime']=time();
$this->assign('list',$list);
$this->display();
if($_SERVER["SERVER_NAME"]=="localhost" ){
$map['_string'] = "(uid=$data[uid] AND rw_state=1) || (uid=$data[uid] AND rw_state=0)";
$danshu=$user->where($map)->count();
//$this->display();
if($danshu>0){
$this->error( '您还有未完成的任务不能接单,请完成未完成的任务再接新任务。');
}
if($user->add($data)){
$nums=$jd->where("id=$data[rw_id] AND status=0")->find();
$up['id']=$data['rw_id'];
$up['rw_nums']=$nums['rw_nums']-1;
if($up['rw_nums']==0){
$up['status']=1;
}
$up['uptime']=time();
if($nums['rw_nums']<=0){
$this->error('任务已结束或者已没有剩余单请返回刷新页面后选择任务。');
}
if($jd->save($up)){
$this->success('接单成功!','/index.php?s=/Taobao/tao_jieshou');
}else{
$this->error('接单失败!');
}
}else{
$this->error('接单失败!');
}
}else{
$this->error('不明请求,请登录本站后接单');
}
}