<?php
namespace Uapp\Controller;
class AddressController extends BaseController {
    /**
     *编辑收货地址页面渲染
     */
    public function edit_address()
    {
        $id =I('param.id');
        $order_ids = I('param.order_ids');
        if ($id > 0) {
            $address = D('Common/Member')->address_cont($id);
            $data['consignee']=$address['consignee'];
            $data['province'] =$address['province'];
            $data['city_id'] =$address['city'];
            $data['district'] =$address['district'];
            $data['address'] =$address['address'];
            $data['house_no'] =$address['house_no'];
            $data['mobile'] =$address['mobile'];
            $data['status'] = $address['status'];
            $data['xpoint'] = $address['xpoint'];
            $data['ypoint'] =$address['ypoint'];
            $data['region'] =$address['region'];
            $return['data']=$data;
            $return['status']=1;
        }else{
            $return['status']=3;
            $return['msg']="未获取到数据";
        }
        $this->ajaxReturn($return);
    }
    /**
     *添加或修改地址
     */
    public function update_address()
    {
        $postdata = I('param.');
        if($postdata['info']){
            $post=json_decode(htmlspecialchars_decode($postdata['info']),true);
            $param['consignee']=$post['consignee'];
            $param['mobile']=$post['mobile'];
            $param['province']=$post["province"];
            $param['city_id']=$post["city_id"];
            $param['district']=$post["district"];
            $param['address']=$post["address"];
            $param['house_no']=$post["house_no"];
            $param['status']=$post['status'];
            $param['xpoint']=$post["xpoint"];
            $param['ypoint']=$post["ypoint"];
            $param['uid']=$postdata['uid'];
            $param['token']=$postdata['token'];
            if($postdata['id']) $param['id']=$postdata['id'];
            $data = D('Common/Member')->modify_address($param);
        }else{
            $data = D('Common/Member')->modify_address($postdata);
        }
        if($data){
            $return['status']=1;
        }else{
            $return['status']=3;
        }
        $return['msg']=$data['msg'];
        $this->ajaxReturn($return);
    }

    public function address_list(){
        $address_list = D('Common/Member')->get_address_list();
        // print_r($address_list);
        if($address_list['list']){
            foreach ($address_list['list'] as $k => $v) {
                $address_list['list'][$k]['address_region']=$v['address'].$v['region'];
            }
            $return['data']=$address_list['list'];
            $return['status']=1;
        }else{
            $return['status']=2;
            $return['msg']="没有获取到数据";
        }
        $this->ajaxReturn($return);
    }
    /**
     *删除收货地址
     */
    public function del_address()
    {
        $id=I('param.id');
        $data = D('Common/Member')->delete_address($id);
        if($data){
            $return['status']=1;
        }else{
            $return['status']=3;
        }
        $return['msg']=$data;
        $this->ajaxReturn($data);
    }


}
?>