public function edit()
 {
     $id = intval(I('param.id'));
     $d_ask = D('Ask');
     if (IS_POST) {
         $data = $d_ask->create();
         if ($id) {
             $data['id'] = $id;
             //编辑一个房源
             if (!($this->mid == $this->d_ask->where(array('id' => $data['id']))->getField('uid')) && !is_administrator()) {
                 $this->error('对不起,您的权限不足');
             }
             $data['uptime'] = time();
             $data['status'] = 1;
             if ($this->d_ask->save($data)) {
                 $this->ajaxReturnHandle(1, '编辑需求成功', U('home/object/index', array('uid' => $this->mid)));
             } else {
                 $this->ajaxReturnHandle(0, '编辑需求失败');
             }
         } else {
             //新增一个房源
             $data['uid'] = $this->mid;
             $data['createtime'] = $data['uptime'] = time();
             $data['status'] = 1;
             if ($id = $this->d_ask->add($data)) {
                 $this->ajaxReturnHandle(1, '新增需求成功', U('home/object/index', array('uid' => $this->mid)));
             } else {
                 $this->ajaxReturnHandle(0, '新增需求失败');
             }
         }
     } else {
         if ($id) {
             $data = $d_ask->getDetail($id);
             $data['cbd'] = get_whole_address($data['bid']);
             //根据cbd,找到其父菜单
             $data['cbd']['property'] = $data['fid'];
             $this->assign('data', $data);
             $this->display();
         } else {
             $this->display();
         }
     }
 }
 public function edit($id = 0, $fid = 0, $floor = 0, $style = 0, $lname = '', $address = '', $area = 0, $shi = 0, $ting = 0, $wei = 0, $originalprice = 0, $totalprice = 0, $charge = 0, $description = '', $deal_description = '', $pics = '', $kanfang_charge = 0, $files = '', $province = 0, $city = 0, $district = 0, $bid = 0, $nei_tel = '', $nei_name = '', $gong_name = '', $gong_tel = '', $ifspecial = 0, $ifershou = 0, $ifdingzhang = 0, $type_span = 0, $type = 0, $huxing = 0)
 {
     $id = intval($id);
     if (IS_POST) {
         $data['fid'] = intval($fid);
         //个人房源没有所属楼盘
         $data['style'] = intval($style);
         $data['floor'] = intval($floor);
         $data['lname'] = text($lname);
         $data['address'] = text($address);
         $data['area'] = $area;
         $data['shi'] = intval($shi);
         $data['ting'] = intval($ting);
         $data['wei'] = intval($wei);
         $data['totalprice'] = floatval($totalprice);
         $data['originalprice'] = floatval($originalprice);
         $data['charge'] = intval($charge);
         $data['kanfang_charge'] = intval($kanfang_charge);
         $data['description'] = text($description);
         $data['deal_description'] = text($deal_description);
         $data['uid'] = $this->mid;
         $data['status'] = 1;
         $data['pics'] = $pics;
         $data['pic_num'] = count(explode(',', $pics));
         $data['province'] = $province;
         $data['city'] = $city ? $city : session('user_city.city_id');
         $data['district'] = $district;
         $data['files'] = $files;
         $data['type'] = intval($type);
         $data['ifspecial'] = intval($ifspecial);
         $data['ifershou'] = intval($ifershou);
         $data['ifdingzhang'] = intval($ifdingzhang);
         $data['type_span'] = intval($type_span);
         $data['huxing'] = intval($huxing);
         $data['nei_tel'] = text($nei_tel);
         $data['nei_name'] = text($nei_name);
         $data['gong_name'] = text($gong_name);
         $data['gong_tel'] = text($gong_tel);
         $data['bid'] = $bid;
         //CBD, 归属为哪个商圈
         //为了优化搜索,此处添加title冗余,并添加索引
         $data['title'] = $data['lname'] . ' ' . $data['floor'] . '楼 ' . $data['area'] . '平 ' . $data['shi'] . '室 ' . $data['totalprice'] . '万';
         if ($id) {
             $data['id'] = $id;
             //编辑一个房源
             if (!($this->mid == $this->d_object->where(array('id' => $data['id']))->getField('uid')) && !is_administrator()) {
                 $this->error('对不起,您的权限不足');
             }
             $data['uptime'] = time();
             if ($this->d_object->savePic($id, $data['pics']) || $this->d_object->save($data)) {
                 //D('shuo')->where(array('uid'=>is_login()))->save(array('uptime'=>NOW_TIME));//更新说说时间,也就是更新主页信息
                 D('property')->where(array('id' => $data['fid']))->save(array('uptime' => NOW_TIME));
                 //更新说说时间,也就是更新主页信息
                 $this->ajaxReturnHandle(1, '编辑房源成功', U('home/object/index', array('uid' => $this->mid)));
             } else {
                 $this->ajaxReturnHandle(0, '编辑房源失败');
             }
         } else {
             //新增一个房源
             $data['createtime'] = $data['uptime'] = time();
             if ($id = $this->d_object->add($data)) {
                 $this->d_object->savePic($id, $data['pics']);
                 //更新说说数据
                 D('shuo')->where(array('uid' => is_login()))->setInc('count', 1);
                 D('shuo')->where(array('uid' => is_login()))->save(array('uptime' => NOW_TIME));
                 //更新说说时间,也就是更新主页信息
                 //更新楼盘表数据
                 D('property')->where(array('id' => $data['fid']))->setInc('objectcount', 1);
                 D('property')->where(array('id' => $data['fid']))->save(array('uptime' => NOW_TIME));
                 //更新说说时间,也就是更新主页信息
                 $this->ajaxReturnHandle(1, '新增房源成功', U('home/object/index', array('uid' => $this->mid)));
             } else {
                 $this->ajaxReturnHandle(0, '新增房源失败');
             }
         }
     } else {
         if ($id) {
             $data = $this->d_object->alias('a')->where(array('id' => $id, 'uid' => $this->mid))->field('a.*,group_concat(b.pid) as pics')->join('__OBJECT_PIC__  b on a.id = b.oid', 'left')->find();
             if (!$data) {
                 $this->error('错误');
             }
             $data['cbd'] = get_whole_address($data['bid']);
             //根据cbd,找到其父菜单
             $data['cbd']['property'] = $data['fid'];
             $this->assign('data', $data);
             $this->display();
         } else {
             //认证楼盘穿一个他的楼盘id 地址集过去,默认显示他的楼盘地址
             //先判断身份,再取值
             $user_info = $this->user_info;
             $auth_role = $user_info['auth_role'];
             if ($auth_role == 4) {
                 //更具property表中的uid找到id,再利用get_whole_address
                 $data['cbd'] = get_whole_address_by_uid(is_login());
             }
             $this->assign('data', $data);
             $this->display();
         }
     }
 }