会员中心—2—收货地址管理

控制器:

    //地址
    public function address(){
    	if(IS_POST){
    		$m = M("Address");
    		$m->create();
    		$uid = trim($_POST['uid']);
    		$res = $m->where(array('uid'=>$uid))->select();
    		if(count($res)>10){
    			$this->error("收货地址最多只能添加10条,您的收货地址已经达到限度!");
    		}elseif(count($res)==0){
                $m->isdefault = 1;
    		}else{
    			$isdefault= trim($_POST['isdefault']);
	            if($isdefault=="on"){
	            	$m->isdefault = 1;
	            	$addid = $m->where(array('uid'=>$uid,'isdefault'=>1))->getField("id");
	            }   			
    		}
            
    		$m->addtime = time();
    		if($m->add()){
    			$data[isdefault]=0;
    			M("Address")->where(array('id'=>$addid))->limit(1)->save($data);
	         	$this->success("添加成功",U("Member/address"));
	        }else{
	        	$this->error("添加失败");
	        }

    	}else{
            $uid = ($_SESSION['qtuid']);
            $data=M("Address")->where(array('uid'=>$uid))->select();

            $this->assign("data",$data);
            $this->assign("count",count($data));
            $this->assign("num",10-count($data));

    		$this->display();
    	}
    	
    }
    //删除地址
	public function addrdelete(){
		$id = I("get.id");
		if($id>0){
			$m = M("Address");
			$del = $m->where(array('id'=>$id))->limit(1)->delete();
			if($del){
				$this->success("删除成功",U("Member/address"));
			}else{
				$this->error("删除失败");
			}
		}
	
	}

address.php:

		

收货地址

已保存<{$count}>条地址,还能保存<{$num}>条
  • 收货人:<{$vo.receiver}> 电话:<{$vo.tel}> 地址:<{$vo.province}><{$vo.city}><{$vo.area}><{$vo.address}> $vo['id']))}>">删除 默认|
----------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------

数据表:

CREATE TABLE IF NOT EXISTS `tp_address` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `uid` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '用户id',
  `province` varchar(255) DEFAULT '' COMMENT '省份',
  `city` varchar(255) DEFAULT '' COMMENT '城市',
  `area` varchar(255) DEFAULT '' COMMENT '地区',
  `address` varchar(255) DEFAULT '' COMMENT '详细地址',
  `receiver` varchar(30) DEFAULT NULL COMMENT '收货人',
  `tel` varchar(16) DEFAULT NULL COMMENT '收货人电话',
  `addtime` varchar(30) DEFAULT NULL COMMENT '添加时间',
  `updatetime` varchar(30) DEFAULT NULL COMMENT '修改时间',
  `isdefault` int(1) DEFAULT '0' COMMENT '是否设为默认地址',
  PRIMARY KEY (`id`),
  KEY `OrderID` (`uid`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='地址管理' AUTO_INCREMENT=3 ;
jquery.citys.js: 点击打开链接

你可能感兴趣的:(会员中心,thinkphp)