/**
  * 商家修改
  *
  * @return [type] [description]
  */
 public function modMerchantV2()
 {
     $style = isset($_POST['style']) ? htmlspecialchars(trim($_POST['style'])) : '0';
     //为了web能修改资料
     $mer_session_id = isset($_POST['mer_session_id']) ? htmlspecialchars(trim($_POST['mer_session_id'])) : '';
     if ($style == 0) {
         $merchant_id = $this->session_handle->getsession_userid($mer_session_id);
     } else {
         $mobile = isset($_POST['moblie']) ? htmlspecialchars($_POST['moblie']) : '';
         //根据 手机号 session_id 验证是否能编辑商户
         $ver = M('Verifycode')->where(array('mobile' => $mobile, 'session_id' => $mer_session_id))->getField('expire');
         if ($ver >= time()) {
             $merchant_id = $this->dao->where(array('mobile' => $mobile))->getField('id');
         } else {
             $this->jsonUtils->echo_json_msg(4, '注册后半小时,无法在编辑资料');
             exit;
         }
     }
     $wifi_enable = isset($_POST['wifi_enable']) ? htmlspecialchars(trim($_POST['wifi_enable'])) : '0';
     $tel = isset($_POST['tel']) ? htmlspecialchars(trim($_POST['tel'])) : '';
     $area_id = isset($_POST['area_id']) ? htmlspecialchars(trim($_POST['area_id'])) : '';
     $device = isset($_POST['device']) ? htmlspecialchars(trim($_POST['device'])) : '';
     $intro = isset($_POST['intro']) ? htmlspecialchars(trim($_POST['intro'])) : '';
     $address = isset($_POST['address']) ? htmlspecialchars(trim($_POST['address'])) : '';
     $business_time = isset($_POST['business_time']) ? htmlspecialchars(trim($_POST['business_time'])) : '';
     $pics = isset($_POST['pics']) ? trim($_POST['pics']) : '';
     if (!empty($tel)) {
         $data['tel'] = $tel;
     }
     if (!empty($intro)) {
         $data['intro'] = $intro;
     }
     if (!empty($address)) {
         $data['address'] = $address;
     }
     if (!empty($business_time)) {
         $data['business_time'] = $business_time;
     }
     if (isset($wifi_enable)) {
         $data['wifi_enable'] = $wifi_enable;
     }
     if (!empty($area_id) && $device == 'web') {
         $area = CityController::getAreaIdPreId($area_id);
         $data['province_id'] = $area['province'];
         $data['city_id'] = $area['city'];
         $data['area_id'] = $area_id;
     }
     Log::write($pics, 'ERR');
     if (!empty($pics)) {
         $arr_decode = json_decode($pics, true);
         if (!empty($arr_decode)) {
             foreach ($arr_decode as $key => $row) {
                 if (!empty($row)) {
                     $temp[$key]['hs'] = str_replace(C('ROOT_UPLOADS'), '', $row['hs']);
                     $temp[$key]['hb'] = str_replace(C('ROOT_UPLOADS'), '', $row['hb']);
                 }
             }
             foreach ($temp as $row) {
                 $data['pics'][] = $row;
             }
         } else {
             $data['pics'] = array();
         }
     } else {
         $data['pics'] = array();
     }
     if ($_FILES) {
         $f_arr = mul_upload('/Merchant/', 1);
         if ($f_arr) {
             $data['pics'] = array_merge($data['pics'], $f_arr);
             // 把多张图片数组格式转json保存数据库
         }
     }
     $data['pics'] = json_encode($data['pics']);
     $result = $this->dao->where("id={$merchant_id}")->save($data);
     $this->jsonUtils->echo_json_msg(0, '修改成功!');
     exit;
 }
 /**
  * 附近商家(未启用)
  */
 public function around_merchant()
 {
     $longitude = $_POST['longitude'];
     $latitude = $_POST['latitude'];
     $classid = isset($_POST['cat_id']) ? htmlspecialchars($_POST['cat_id']) : '';
     $sort = isset($_POST['sort']) ? htmlspecialchars($_POST['sort']) : '1';
     $page = isset($_POST['page']) ? htmlspecialchars($_POST['page']) : '1';
     $num = isset($_POST['num']) ? htmlspecialchars($_POST['num']) : '6';
     // $km=isset($_POST['km'])?htmlspecialchars($_POST['km']):'3';
     if (empty($longitude) || empty($latitude)) {
         $this->jsonUtils->echo_json_msg(4, '经纬度参数为空...');
         exit;
     }
     // $ll_arr=rangekm($km, $longitude,$latitude);//获取最大最小经纬度
     // $maxLng=$ll_arr['maxLng'];
     // $minLng=$ll_arr['minLng'];
     // $maxLat=$ll_arr['maxLat'];
     // $minLat=$ll_arr['minLat'];
     $where = " 1=1 and is_salesman =0 ";
     // $where .= "and b.longitude <$maxLng and b.longitude>$minLng and
     // b.latitude <$maxLat and b.latitude>$minLat";
     // $sql="select
     // a.id,a.longitude,a.latitude,a.intro,a.pics,a.header,a.merchant_name
     // ,a.pcat_id ,b.name as area_name from ". C('DB_PREFIX')."merchant as a
     // left join ".C('DB_PREFIX')."city as b on a.area_id=b.id where
     // a.collecter=0 and a.longitude <$maxLng and a.longitude>$minLng and
     // a.latitude <$maxLat and a.latitude>$minLat ";
     if (!empty($classid)) {
         $sql = $where . " and a.pcat_id ={$classid} ";
         $arr = $this->dao->table(C('DB_PREFIX') . "service as a")->join(C('DB_PREFIX') . 'merchant as b on a.merchant_id = b.id')->field('b.id,b.merchant_name,b.header,b.intro,b.tel,b.address,b.mobile,b.longitude,b.latitude,b.area_id')->where($where)->group('a.merchant_id')->page($page)->limit($num)->select();
     } else {
         $arr = $this->dao->table(C('DB_PREFIX') . "merchant as b")->field('b.id,b.merchant_name,b.header,b.intro,b.tel,b.address,b.mobile,b.longitude,b.latitude,b.area_id')->where($where)->page($page)->limit($num)->select();
     }
     // $sql=$sql." limit $pagenum,20";
     // $arr=$this->dao->query($sql);
     if ($arr) {
         foreach ($arr as $key => $value) {
             if ($arr[$key]['pics']) {
                 // 取json数组图片第一张作为图片
                 $json_arr = json_decode($arr[$key]['pics']);
                 $arr[$key]['pics'] = imgUrl($json_arr[0]);
             }
             $arr[$key]['header'] = imgUrl($value['header']);
             $arr[$key]['area_name'] = CityController::getName($value['area_id']);
             $arr[$key]['service_name'] = CommonController::getMerchantServerListName($value['id']);
             $arr[$key]['distance'] = getDistance($latitude, $longitude, $arr[$key]['latitude'], $arr[$key]['longitude']);
             // 计算两点距离
         }
         if ($sort == 1) {
             // 按距离升序和降序
             $arr1 = sort_asc($arr);
         }
         if ($sort == 2) {
             $arr1 = sort_desc($arr);
         }
         $data['list'] = $arr1;
         $this->jsonUtils->echo_json_data(0, 'ok', $data);
         exit;
     } else {
         $this->jsonUtils->echo_json_msg(1, '该附近没有商家信息...');
     }
 }
 /**
  * 获取商家编辑信息
  */
 function getMerchantInfo()
 {
     $id = isset($_POST['id']) ? htmlspecialchars($_POST['id']) : '';
     // 商家id
     $salesman_session_id = isset($_POST['salesman_session_id']) ? htmlspecialchars($_POST['salesman_session_id']) : '';
     $salesman_id = $this->session_handle->getsession_userid($salesman_session_id);
     if (empty($salesman_id)) {
         $this->jsonUtils->echo_json_msg(4, '会话id不能为空');
         exit;
     }
     $db = M('Auth');
     $auth = $db->where(array('mark_id' => $id, 'status' => 0))->find();
     if ($auth == false) {
         $data = $this->merchant->where(array('id' => $id))->field('province_id,city_id,area_id,business_time,merchant_name,address,manager,tel,longitude,latitude,header')->find();
         $data['status'] = '0';
     } else {
         $data = json_decode($auth['check_data'], true);
         $data['status'] = '1';
     }
     if ($data) {
         $data['header'] = imgUrl($data['header']);
         $data['province_name'] = CityController::getName($data['province_id']);
         $data['city_name'] = CityController::getName($data['city_id']);
         $data['area_name'] = CityController::getName($data['area_id']);
         $this->jsonUtils->echo_json_data(0, 'ok', $data);
         exit;
     } else {
         $this->jsonUtils->echo_json_msg(4, '该商家不存在');
         exit;
     }
 }
 public function get_demand_info()
 {
     $id = isset($_POST['id']) ? htmlspecialchars($_POST['id']) : '';
     $member_session_id = isset($_POST['member_session_id']) ? htmlspecialchars($_POST['member_session_id']) : '';
     $member_id = $this->session_handle->getsession_userid($member_session_id);
     $bidding_arr = $this->dao->where("id={$id} and member_id = {$member_id} and member_del = 0")->find();
     if ($bidding_arr === false) {
         $this->jsonUtils->echo_json_msg(1, '该需求不存在...');
         exit;
     }
     if ($bidding_arr['pics']) {
         $data['pics'] = imgUrl(json_decode($bidding_arr['pics'], true));
     }
     $cart = json_decode($bidding_arr['cart_data'], true);
     $data['id'] = $bidding_arr['id'];
     $data['title'] = $bidding_arr['title'];
     $data['reach_time'] = date('Y-m-d H:i:s', $bidding_arr['reach_time']);
     $data['cart_model'] = $cart['cart_model'];
     $data['description'] = $bidding_arr['description'];
     $data['province_id'] = CityController::getName($bidding_arr['province_id']);
     $data['city_id'] = CityController::getName($bidding_arr['city_id']);
     $data['area_id'] = CityController::getName($bidding_arr['area_id']);
     $data['demand_status'] = $bidding_arr['status'];
     // 1 已过期 0 未过期
     $is_expire = time() - $bidding_arr['expire_time'] > 0 ? '1' : '0';
     if ($is_expire) {
         if ($bidding_arr['status'] == 0) {
             $data['demand_status'] = '3';
             //过期
         }
     }
     $this->jsonUtils->echo_json_data(0, 'ok', $data);
     exit;
 }