/**
  * 商家修改
  *
  * @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;
 }
 /**
  * 修改项目
  *
  * @return [type] [description]
  */
 public function mod_serviceV2()
 {
     $service_id = isset($_POST['service_id']) ? htmlspecialchars($_POST['service_id']) : '';
     $intro = isset($_POST['intro']) ? htmlspecialchars($_POST['intro']) : '';
     $price = isset($_POST['price']) ? htmlspecialchars($_POST['price']) : '';
     // $sub_id=isset($_POST['sub_id']) ?
     // htmlspecialchars($_POST['sub_id']):'';
     $timeout = isset($_POST['timeout']) ? htmlspecialchars($_POST['timeout']) : '';
     $mer_session_id = $_POST['mer_session_id'];
     $merchant_id = $this->session_handle->getsession_userid($mer_session_id);
     $pics = isset($_POST['pics']) ? trim($_POST['pics']) : '';
     if (!empty($price)) {
         if (!is_numeric($price)) {
             $this->jsonUtils->echo_json_msg(4, "项目价格不符合格式!");
             exit;
         } else {
             $data['price'] = $price;
         }
     }
     if ($intro) {
         $data['intro'] = $intro;
     }
     if ($timeout) {
         $data['timeout'] = $timeout;
     }
     $data['effect'] = 0;
     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={$service_id} and merchant_id = {$merchant_id}")->save($data);
     // 保存商家信息
     if ($result === false) {
         $this->jsonUtils->echo_json_msg(4, '修改失败!');
         exit;
     }
     $this->jsonUtils->echo_json_msg(0, '修改成功!');
     exit;
 }
 /**
  * 提交商家详情
  */
 function editMerchantInfo()
 {
     $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);
     // dump($salesman_id);
     if (empty($salesman_id)) {
         $this->jsonUtils->echo_json_msg(4, '会话id不能为空');
         exit;
     }
     $merchant_name = isset($_POST['merchant_name']) ? htmlspecialchars($_POST['merchant_name']) : '';
     $area_id = isset($_POST['area_id']) ? htmlspecialchars($_POST['area_id']) : '';
     $address = isset($_POST['address']) ? htmlspecialchars($_POST['address']) : '';
     $manager = isset($_POST['manager']) ? htmlspecialchars($_POST['manager']) : '';
     $tel = isset($_POST['tel']) ? htmlspecialchars($_POST['tel']) : '';
     $business_time = isset($_POST['business_time']) ? htmlspecialchars($_POST['business_time']) : '';
     $longitude = isset($_POST['longitude']) ? htmlspecialchars($_POST['longitude']) : '';
     $latitude = isset($_POST['latitude']) ? htmlspecialchars($_POST['latitude']) : '';
     // $auth =
     // $this->merchant->where(array('id'=>$id))->getField('check_by');
     // if($auth==0) {
     // $this->jsonUtils->echo_json_msg(4, '数据异常');exit();
     // }
     // if($auth==$salesman_id){
     if (empty($id)) {
         $this->jsonUtils->echo_json_msg(4, '商家id不能为空');
         exit;
     }
     if (empty($merchant_name)) {
         $this->jsonUtils->echo_json_msg(4, '商家名不能为空');
         exit;
     }
     if (empty($address)) {
         $this->jsonUtils->echo_json_msg(4, '商家地址不能为空');
         exit;
     }
     if (empty($manager)) {
         $this->jsonUtils->echo_json_msg(4, '负责人名字不能为空');
         exit;
     }
     if (empty($business_time)) {
         $this->jsonUtils->echo_json_msg(4, '营业时间为空');
         exit;
     }
     if (empty($longitude)) {
         $this->jsonUtils->echo_json_msg(4, '精度不能为空');
         exit;
     }
     if (empty($latitude)) {
         $this->jsonUtils->echo_json_msg(4, '维度不能空');
         exit;
     }
     if (empty($area_id)) {
         $this->jsonUtils->echo_json_msg(4, '区域id不能空');
         exit;
     }
     if ($_FILES) {
         $result = mul_upload('/Header/', 3);
         if ($result) {
             $save['header'] = $result[0];
         }
     }
     $area = CityController::getAreaIdPreId($area_id);
     $save['province_id'] = $area['province'];
     $save['city_id'] = $area['city'];
     $save['area_id'] = $area_id;
     $save['business_time'] = $business_time;
     $save['merchant_name'] = $merchant_name;
     $save['address'] = $address;
     $save['manager'] = $manager;
     $save['tel'] = $tel;
     $save['longitude'] = $longitude;
     $save['latitude'] = $latitude;
     $check = AuthController::addData($save, 0, 'save', array('salesman' => $salesman_id), $id);
     if ($check) {
         $this->jsonUtils->echo_json_msg(0, '已提交审核');
         exit;
     } else {
         $this->jsonUtils->echo_json_msg(4, '修改失败');
         exit;
     }
     // }else{
     // $this->jsonUtils->echo_json_msg(4, '无权限操作');exit();
     // }
 }
 /**
  * 上传图片,仅供图片修改删除 新增 使用,(未存储session,由js确定最终数据)
  */
 public function uploadPicByEdit()
 {
     $type = $_REQUEST['type'];
     $config = array('1' => array('/Answer/', 'pics_answer', 1), '2' => array('/Recent/', 'pics_recent', 2));
     if (empty($type) || empty($config[$type])) {
         die(json_encode(array("code" => 4, 'msg' => '请联系管理员')));
         exit;
     }
     if (!empty($_FILES)) {
         $arr = mul_upload($config[$type][0], $config[$type][2]);
         if ($arr) {
             $arr = imgUrl($arr);
             //$pic = $config[$type][1];
             //$_SESSION[$pic][]=$arr[0];
             die(json_encode(array("code" => 0, 'msg' => 'ok', 'data' => $arr[0])));
             exit;
         }
     } else {
         die(json_encode(array("code" => 4, 'msg' => '请选择上传图片')));
         exit;
     }
 }
 public function uploadQuestionPic()
 {
     $verifyToken = md5('seeyoulater' . $_POST['timestamp']);
     if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
         $arr = mul_upload('/Answer/', 1);
         if ($arr) {
             // 				 $arr = imgUrl($arr);
             die(json_encode(array("code" => 0, 'msg' => 'ok', 'data' => $arr[0])));
             exit;
         }
     } else {
         die(json_encode(array("code" => 4, 'msg' => '请选择上传图片')));
         exit;
     }
 }
 public function uploadPic()
 {
     if ($_FILES) {
         $f_arr = mul_upload('/ChatPic/', 3);
         if ($f_arr) {
             $f_arr[0] = imgUrl($f_arr[0]);
             $this->jsonUtils->echo_json_data(0, 'ok', $f_arr[0]);
             exit;
         }
     } else {
         $this->jsonUtils->echo_json_msg(404, '未上传图片');
         exit;
     }
 }
 /**
  * 修改会员信息
  */
 public function mod_member()
 {
     $member_session_id = $_POST['member_session_id'];
     $member_id = $this->session_handle->getsession_userid($member_session_id, 1);
     $nick_name = isset($_POST['nick_name']) ? htmlspecialchars($_POST['nick_name']) : '';
     $email = isset($_POST['email']) ? htmlspecialchars($_POST['email']) : '';
     $signature = isset($_POST['signature']) ? htmlspecialchars($_POST['signature']) : '';
     $driving_exp = isset($_POST['driving_exp']) ? htmlspecialchars($_POST['driving_exp']) : '';
     $gender = isset($_POST['gender']) ? htmlspecialchars($_POST['gender']) : '';
     if (empty($nick_name)) {
         $this->jsonUtils->echo_json_msg(4, '用户昵称为空...');
         exit;
     }
     /*
      * if(empty($email)){
      * $this->JsonUtils->echo_json_msg(4,'email为空...');exit(); }
      */
     $data['nick_name'] = $nick_name;
     if (!empty($email)) {
         $data['email'] = $email;
     }
     if (!empty($signature)) {
         $data['signature'] = $signature;
     }
     if (!empty($driving_exp)) {
         $data['driving_exp'] = $driving_exp;
     }
     if (isset($gender)) {
         $data['gender'] = (int) $gender;
     }
     if ($_FILES) {
         $img = mul_upload('/Header/', 3);
         if ($img) {
             $data['header'] = $img[0];
         }
     }
     $result = $this->dao->where("id={$member_id['id']}")->save($data);
     if ($result === false) {
         $this->jsonUtils->echo_json_msg(1, '修改失败');
         exit;
     } else {
         if (!empty($img[0])) {
             CommonController::saveHeader($member_id['id'], $member_id['type'], $img[0]);
         }
         CommonController::saveName($member_id['id'], $member_id['type'], $nick_name);
         $this->jsonUtils->echo_json_msg(0, '修改成功!');
         exit;
     }
 }
 public function submit_order()
 {
     $member_session_id = $_POST['member_session_id'];
     $member_id = $this->session_handle->getsession_userid($member_session_id);
     $merchant_id = isset($_POST['merchant_id']) ? htmlspecialchars($_POST['merchant_id']) : '';
     $order_time = isset($_POST['reach_time']) ? htmlspecialchars($_POST['reach_time']) : '';
     $cart_id = isset($_POST['cart_id']) ? htmlspecialchars($_POST['cart_id']) : '';
     $service_ids = isset($_POST['service_ids']) ? htmlspecialchars($_POST['service_ids']) : '';
     $member_remark = isset($_POST['remark']) ? htmlspecialchars($_POST['remark']) : '';
     if (empty($merchant_id)) {
         $this->jsonUtils->echo_json_msg(4, '商家ID为空...');
         exit;
     }
     if (empty($order_time)) {
         $this->jsonUtils->echo_json_msg(4, '到店时间为空...');
         exit;
     }
     if (empty($cart_id)) {
         $this->jsonUtils->echo_json_msg(4, '车id为空...');
         exit;
     }
     if (empty($service_ids)) {
         $this->jsonUtils->echo_json_msg(4, '请选择所需服务项目...');
         exit;
     }
     $unix_time = strtotime($order_time);
     if ($unix_time < time()) {
         $this->jsonUtils->echo_json_msg(4, '预约时间必须大于当前时间');
         exit;
     }
     $order = MemberOrderController::getOrderWithoutDone($member_id);
     if (!$order) {
         $this->jsonUtils->echo_json_msg(4, '您已有5个未完成的订单,请完成后在继续下单');
         exit;
     }
     $service = M("service");
     $order_no = time() . rand(1000, 9999);
     // 订单号
     $total_price = 0;
     $total_time = 0;
     $service_ids_arr = explode(',', $service_ids);
     if ($_FILES) {
         $f_arr = mul_upload('/UserService/', 1);
         if ($f_arr) {
             $d_data['pics'] = $f_arr;
         }
     } else {
         $d_data['pics'] = array();
     }
     foreach ($service_ids_arr as $key => $value) {
         $s_arr = $service->field("cat_id as id,price,name,timeout as time")->where("id={$value} and merchant_id = {$merchant_id}")->find();
         if ($s_arr) {
             $total_price = $total_price + $s_arr['price'];
             $total_time = $total_time + $s_arr['time'];
             $d_data['list'][$key] = $s_arr;
             $d_data['list'][$key]['is_server'] = 1;
             $service_name[] = $s_arr['name'];
         } else {
             $this->jsonUtils->echo_json_msg(4, '提交的服务项目有误');
             exit;
         }
     }
     $data['order_no'] = $order_no;
     $data['service_name'] = implode('、', $service_name);
     $data['status'] = 0;
     $data['merchant_id'] = $merchant_id;
     $data['member_id'] = $member_id;
     $data['type'] = 0;
     // 服务订单
     $data['goods_count'] = 1;
     $data['unit_price'] = $total_price;
     $data['total_price'] = $total_price;
     $data['total_time'] = $total_time;
     $data['sub_data'] = json_encode($d_data);
     $data['reach_time'] = $unix_time;
     $data['cart_id'] = $cart_id;
     $data['cart_data'] = MemberDemandController::getcart($cart_id);
     $data['addtime'] = time();
     $data['action_time'] = time();
     $data['member_remark'] = $member_remark;
     $data['merchant_remark'] = '';
     $result = $this->dao->add($data);
     if ($result) {
         $this->jsonUtils->echo_json_msg(0, '提交订单成功...');
         exit;
     } else {
         $this->jsonUtils->echo_json_msg(1, '提交订单失败...');
         exit;
     }
 }
 /**
  * chat聊天上图pic
  */
 public function uploadPic()
 {
     //跨域解决方法: 指定域名
     header('Access-Control-Allow-Origin:http://www.caryu.net');
     header('Access-Control-Allow-Credentials:true');
     if ($_FILES) {
         $f_arr = mul_upload('/ChatPic/', 3);
         if ($f_arr) {
             $f_arr[0] = imgUrl($f_arr[0]);
             $this->jsonUtils->echo_json_data(0, 'ok', $f_arr[0]);
             exit;
         }
     } else {
         $this->jsonUtils->echo_json_msg(404, '未上传图片');
         exit;
     }
 }
 /**
  * 用户发布需求
  */
 public function add_demand()
 {
     $publish = isset($_POST['publish']) ? (int) htmlspecialchars($_POST['publish']) : '0';
     // 发布需求方式默认0,0 项目发布需求 1保养发布需求
     $cart_id = isset($_POST['cart_id']) ? (int) htmlspecialchars($_POST['cart_id']) : '';
     $reach_time = isset($_POST['reach_time']) ? htmlspecialchars($_POST['reach_time']) : '';
     $desc = isset($_POST['desc']) ? htmlspecialchars($_POST['desc']) : '';
     // 		$range_km = isset ( $_POST ['range_km'] ) ? htmlspecialchars ( $_POST ['range_km'] ) : '';
     $category_ids = isset($_POST['category_ids']) ? htmlspecialchars($_POST['category_ids']) : '';
     $member_session_id = $_POST['member_session_id'];
     $member_id = $this->session_handle->getsession_userid($member_session_id);
     $longitude = $_POST['longitude'];
     $latitude = $_POST['latitude'];
     if (empty($longitude) || empty($latitude)) {
         $this->jsonUtils->echo_json_msg(4, '经度或者纬度为空...');
         exit;
     }
     // 		Log::write($cart_id,'ERR');
     if (empty($cart_id)) {
         $this->jsonUtils->echo_json_msg(4, '车辆为空...');
         exit;
     }
     if (empty($reach_time)) {
         $this->jsonUtils->echo_json_msg(4, '预约时间为空');
         exit;
     }
     $arr_ids = explode(",", $category_ids);
     $count = count($arr_ids);
     $name = $this->getDemandName($arr_ids, $publish);
     if (!$name) {
         $this->jsonUtils->echo_json_msg(4, '发布需求的项目存在错误');
         exit;
     }
     $reach_time = strtotime($reach_time);
     if ($reach_time < time()) {
         $this->jsonUtils->echo_json_msg(4, '发布到店时间要大于当前时间');
         exit;
     }
     $auth = $this->auth_add_demand($member_id);
     $ll_arr = rangekm(C('PUSH_RANGE_KM'), $longitude, $latitude);
     //获取最大最小经纬度
     $maxLng = $ll_arr['maxLng'];
     $minLng = $ll_arr['minLng'];
     $maxLat = $ll_arr['maxLat'];
     $minLat = $ll_arr['minLat'];
     $data['publish'] = $publish;
     if ($publish == 1) {
         $km = isset($_POST['km']) ? htmlspecialchars($_POST['km']) : '';
         if (empty($km)) {
             $this->jsonUtils->echo_json_msg(4, '用户公里数为空');
             exit;
         }
         $param = array('km' => $km, 'category_ids' => $category_ids);
         $data['param'] = json_encode($param);
     }
     $data['member_id'] = $member_id;
     $data['cart_id'] = $cart_id;
     $data['cart_data'] = $this->getcart($cart_id);
     $data['title'] = $name;
     // $data['city_id']=$area['city'];
     // $data['area_id']=$area_id;
     $data['reach_time'] = $reach_time;
     $data['description'] = $desc;
     $data['addtime'] = time();
     $data['expire_time'] = time() + 24 * 60 * 60;
     $data['range_km'] = C('PUSH_RANGE_KM');
     $data['longitude'] = $longitude;
     $data['latitude'] = $latitude;
     $data['pics'] = json_encode(array());
     if ($_FILES) {
         $f_arr = mul_upload('/Demand/', 1);
         if ($f_arr) {
             $data['pics'] = json_encode($f_arr);
             // 把多张图片数组格式转json保存数据库
         }
     }
     $result = $this->dao->add($data);
     if ($result) {
         $data['demand_id'] = $result;
         $subitems = M("member_demand_subitems");
         if (!empty($category_ids)) {
             $data1["member_id"] = $member_id;
             // 会员ID
             $data1["demand_id"] = $result;
             // 需求id
             foreach ($arr_ids as $key => $value) {
                 $data1['category_id'] = $value;
                 // 子项目ID
                 $subitems->add($data1);
             }
         }
         //查询出范围内的商家,给其调整需求配置
         $sql = "select a.business_time,a.id,b.id as jid from " . C('DB_PREFIX') . "merchant as a \r\n\t\t\tleft join " . C('DB_PREFIX') . "system_user as b on (a.id = b.sub_id and b.type =2)\r\n\t\t\twhere a.longitude <={$maxLng} and a.longitude>={$minLng} and a.latitude <={$maxLat} and a.latitude>={$minLat} and ( a.status = 0 or a.status = 1)";
         $ids = M('')->query($sql);
         //echo M('')->getLastSql();
         if ($ids) {
             foreach ($ids as $key => $row) {
                 $addAll[$key]['id'] = null;
                 $addAll[$key]['merchant_id'] = $row['id'];
                 $addAll[$key]['demand_id'] = $result;
                 if (timeCompare($row['business_time'])) {
                     $jid[] = $row['jid'];
                 }
             }
             M('DemandMerchantEnable')->addAll($addAll);
             $jpush = new \App\Model\JpushModel();
             $jpush->user = 2;
             $jpush->push(1, $jid, $data);
             $xmpp = new \App\Model\XmppApiModel();
             $xmpp->requestPush(1, $jid, $data);
             //云推送
         }
         $this->jsonUtils->echo_json_msg(0, '发布需求成功!');
         exit;
     } else {
         $this->jsonUtils->echo_json_msg(1, 'failed');
         exit;
     }
 }
 /**
  * 商家修改活动
  * 只有活动在进行中不能修改
  */
 public function mod_activity()
 {
     $id = isset($_POST['id']) ? htmlspecialchars($_POST['id']) : '';
     $sessionid = isset($_POST['mer_session_id']) ? htmlspecialchars($_POST['mer_session_id']) : '';
     $merchant_id = $this->session_handle->getsession_userid($sessionid);
     $name = isset($_POST['name']) ? htmlspecialchars($_POST['name']) : '';
     $categorys = isset($_POST['category_ids']) ? htmlspecialchars($_POST['category_ids']) : '';
     $cart_model = isset($_POST['cart_model']) ? htmlspecialchars($_POST['cart_model']) : '';
     $time = isset($_POST['time']) ? htmlspecialchars($_POST['time']) : '';
     $market_price = isset($_POST['market_price']) ? htmlspecialchars($_POST['market_price']) : '';
     $second_price = isset($_POST['second_price']) ? htmlspecialchars($_POST['second_price']) : '';
     $remain = isset($_POST['remain']) ? htmlspecialchars($_POST['remain']) : '';
     $start_time = isset($_POST['start_time']) ? htmlspecialchars($_POST['start_time']) : '';
     $end_time = isset($_POST['end_time']) ? htmlspecialchars($_POST['end_time']) : '';
     $valid_start_time = isset($_POST['valid_start_time']) ? htmlspecialchars($_POST['valid_start_time']) : '';
     $valid_end_time = isset($_POST['valid_end_time']) ? htmlspecialchars($_POST['valid_end_time']) : '';
     $date_limit = isset($_POST['date_limit']) ? htmlspecialchars($_POST['date_limit']) : '';
     // 日期限制
     $is_reserve = isset($_POST['reserve']) ? htmlspecialchars($_POST['reserve']) : '';
     // 是否需要预约
     $reserve_timeout = isset($_POST['reserve_timeout']) ? htmlspecialchars($_POST['reserve_timeout']) : '';
     // 逾期是否保留
     $enjoy_other_preferential = isset($_POST['enjoy_other_preferential']) ? htmlspecialchars($_POST['enjoy_other_preferential']) : '';
     // 是否享受其他优惠
     $detail = isset($_POST['detail']) ? htmlspecialchars($_POST['detail']) : '';
     if (empty($id)) {
         $this->jsonUtils->echo_json_msg(4, '活动id为空...');
         exit;
     }
     $rel = $this->activity_dao->where(array('id' => $id, 'merchant_id' => $merchant_id))->getField('id');
     if (!rel) {
         $this->jsonUtils->echo_json_msg(4, '错误操作');
     }
     if (!empty($name)) {
         $data['name'] = $name;
     }
     if (!empty($categorys)) {
         $data['category_ids'] = $categorys;
     }
     if (!empty($cart_model)) {
         $data['cart_model'] = $cart_model;
     }
     if (!empty($time)) {
         $data['time'] = $time;
     }
     if (!empty($market_price)) {
         $data['market_price'] = $market_price;
     }
     if (!empty($second_price)) {
         $data['second_price'] = $second_price;
     }
     if (!empty($remain)) {
         $data['remain'] = $remain;
     }
     if (!empty($start_time)) {
         $data['start_time'] = strtotime($start_time);
     }
     if (!empty($end_time)) {
         $data['end_time'] = strtotime($end_time);
     }
     if (!empty($valid_start_time)) {
         $data['valid_start_time'] = strtotime($valid_start_time);
     }
     if (!empty($valid_end_time)) {
         $data['valid_end_time'] = strtotime($valid_end_time);
     }
     if ($data['start_time'] >= $data['end_time']) {
         $this->jsonUtils->echo_json_msg(4, '活动开始结束时间无效');
         exit;
     }
     if ($data['valid_start_time'] >= $data['valid_end_time']) {
         $this->jsonUtils->echo_json_msg(4, '活动有效期开始结束时间无效');
         exit;
     }
     if (!empty($date_limit)) {
         $data['date_limit'] = $date_limit;
     }
     if (!empty($is_reserve)) {
         $data['reserve'] = $is_reserve;
     }
     if (!empty(${$reserve_timeout})) {
         $data['reserve_timeout'] = $reserve_timeout;
     }
     if (!empty($enjoy_other_preferential)) {
         $data['enjoy_other_preferential'] = $enjoy_other_preferential;
     }
     if (!empty($detail)) {
         $data['detail'] = $detail;
     }
     if (!empty($valid_end_time)) {
         $data['valid_end_time'] = strtotime($valid_end_time);
     }
     if (!empty($valid_end_time)) {
         $data['valid_end_time'] = strtotime($valid_end_time);
     }
     if (!empty($name)) {
         $data['valid_end_time'] = strtotime($valid_end_time);
     }
     $data['effect'] = 0;
     if ($_FILES) {
         $arr = mul_upload('/Activity/', 1);
         if ($arr) {
             $data['pics'] = json_encode($arr);
             // 把多张图片数组格式转json保存数据库
             // $this->service_dao->where("id=$id")->save($data1);
         }
     }
     $result = $this->activity_dao->where("id={$id}")->save($data);
     $this->jsonUtils->echo_json_msg(0, 'ok');
     exit;
 }
 /**
  * 修改个人资料
  */
 public function editUserInfoV2()
 {
     $session_id = isset($_POST['session_id']) ? htmlspecialchars($_POST['session_id']) : '';
     $member_id = $this->session_handle->getsession_userid($session_id, 1);
     //$systemid = CommonController::getSystemUserid($member_id['id'],$member_id['type']);
     $pics = isset($_POST['pics']) ? trim($_POST['pics']) : '';
     $signature = isset($_POST['signature']) ? htmlspecialchars($_POST['signature']) : '';
     $nick_name = isset($_POST['nick_name']) ? htmlspecialchars($_POST['nick_name']) : '';
     $gender = isset($_POST['gender']) ? htmlspecialchars($_POST['gender']) : '';
     $driving_exp = isset($_POST['driving_exp']) ? htmlspecialchars($_POST['driving_exp']) : '';
     $haunts = isset($_POST['haunts']) ? htmlspecialchars($_POST['haunts']) : '';
     $interests = isset($_POST['interests']) ? htmlspecialchars($_POST['interests']) : '';
     $personal_description = isset($_POST['personal_description']) ? htmlspecialchars($_POST['personal_description']) : '';
     if (empty($nick_name)) {
         $this->jsonUtils->echo_json_msg(5, '昵称为空');
         exit;
     }
     if (empty($gender) && !in_array($gender, array(1, 0))) {
         $this->jsonUtils->echo_json_msg(5, '性别为空');
         exit;
     }
     if (empty($driving_exp)) {
         $this->jsonUtils->echo_json_msg(5, '驾龄为空');
         exit;
     }
     $db = M('Member');
     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['albums'][] = $row;
             }
         } else {
             $data['albums'] = array();
         }
     } else {
         $data['albums'] = array();
     }
     if ($_FILES) {
         $f_arr = mul_upload('/Merchant/', 1);
         if ($f_arr) {
             $data['albums'] = array_merge($data['albums'], $f_arr);
             // 把多张图片数组格式转json保存数据库
         }
     }
     $data['albums'] = json_encode($data['albums']);
     $data['nick_name'] = $nick_name;
     CommonController::saveName($member_id['id'], 0, $nick_name);
     $data['gender'] = $gender;
     $data['driving_exp'] = $driving_exp;
     if (!empty($signature)) {
         $data['signature'] = $signature;
     }
     if (!empty($interests)) {
         $data['interests'] = $interests;
     }
     if (!empty($personal_description)) {
         $data['personal_description'] = $personal_description;
     }
     if (!empty($haunts)) {
         $data['haunts'] = $haunts;
     }
     $rel = $db->where(array('id' => $member_id['id']))->save($data);
     if ($rel === false) {
         $this->jsonUtils->echo_json_msg(6, '修改失败');
         exit;
     } else {
         $this->jsonUtils->echo_json_msg(0, 'ok');
         exit;
     }
 }
 /**
  * 会员评论
  */
 public function comment()
 {
     $session_id = isset($_POST['member_session_id']) ? htmlspecialchars($_POST['member_session_id']) : '';
     $member_id = $this->session_handle->getsession_userid($session_id);
     $order_no = isset($_POST['order_no']) ? htmlspecialchars($_POST['order_no']) : '';
     $content = isset($_POST['content']) ? htmlspecialchars($_POST['content']) : '';
     // 	Log::write($order_no);
     if (empty($order_no) || $order_no == null) {
         $this->jsonUtils->echo_json_msg(4, '订单id为空...');
         exit;
     }
     if (empty($content)) {
         $this->jsonUtils->echo_json_msg(4, '评论内容为空...');
         exit;
     }
     $db = M('Order');
     $dat = $db->where(array('order_no' => $order_no, 'member_id' => $member_id))->find();
     if ($dat == false) {
         $this->jsonUtils->echo_json_msg(4, '无权操作');
     } else {
         if ($dat['member_comment'] == 1) {
             $this->jsonUtils->echo_json_msg(4, '你已经评价过该订单');
         }
     }
     $data['service_quality'] = (int) $_POST['service_quality'];
     $data['service_attitude'] = (int) $_POST['service_attitude'];
     $data['merchant_setting'] = (int) $_POST['merchant_setting'];
     $data['merchant_id'] = $dat['merchant_id'];
     $data['member_id'] = $member_id;
     $data['order_no'] = $order_no;
     $data['desc'] = $content;
     $data['addtime'] = time();
     if ($_FILES) {
         //            	Log::write(json_encode($_FILES));
         $arr = mul_upload('/Comment/', 2);
         if ($arr) {
             $data['pics'] = json_encode($arr);
             //把多张图片数组格式转json保存数据库
         }
     } else {
         $data['pics'] = "[]";
     }
     $result = $this->dao->add($data);
     if ($result) {
         $rel = M('Merchant')->where(array('id' => $dat['merchant_id']))->find();
         $save['service_attitude'] = number_format(($rel['service_attitude'] + $data['service_attitude']) / ($rel['comment_count'] + 1), 1);
         $save['service_quality'] = number_format(($rel['service_quality'] + $data['service_quality']) / ($rel['comment_count'] + 1), 1);
         $save['merchant_setting'] = number_format(($rel['merchant_setting'] + $data['merchant_setting']) / ($rel['comment_count'] + 1), 1);
         $save['comment_count'] = $rel['comment_count'] + 1;
         M('Merchant')->where(array('id' => $dat['merchant_id']))->save($save);
         $db->where(array('id' => $dat['id']))->save(array('member_comment' => 1));
         $this->jsonUtils->echo_json_msg(0, '评论成功!');
         exit;
     } else {
         $this->jsonUtils->echo_json_msg(1, '评论失败...');
         exit;
     }
 }
 public function comment()
 {
     $mer_session_id = $_POST['mer_session_id'];
     $merchant_id = $this->session_handle->getsession_userid($mer_session_id);
     //$service_attitude = isset ( $_POST ['service_attitude'] ) ? htmlspecialchars ( $_POST ['service_attitude'] ) : '';
     if (empty($merchant_id)) {
         $this->jsonUtils->echo_json_msg(4, '商家ID为空...');
         exit;
     }
     $order_no = isset($_POST['order_no']) ? htmlspecialchars($_POST['order_no']) : '';
     $content = isset($_POST['content']) ? htmlspecialchars($_POST['content']) : '';
     if (empty($order_no)) {
         $this->jsonUtils->echo_json_msg(4, '订单id为空...');
         exit;
     }
     if (empty($content)) {
         $this->jsonUtils->echo_json_msg(4, '评论内容为空...');
         exit;
     }
     $db = M('Order');
     $dat = $db->where(array('order_no' => $order_no, 'merchant_id' => $merchant_id))->find();
     if ($dat === false) {
         $this->jsonUtils->echo_json_msg(4, '无权操作');
     } else {
         if ($dat['merchant_comment'] == 1) {
             $this->jsonUtils->echo_json_msg(4, '你已经评价过该订单');
         }
     }
     $data['service_quality'] = 0;
     $data['service_attitude'] = 0;
     $data['merchant_setting'] = 0;
     $data['merchant_id'] = $merchant_id;
     $data['member_id'] = $dat['member_id'];
     $data['type'] = 2;
     // 商户评论
     $data['order_no'] = $order_no;
     $data['desc'] = $content;
     $data['addtime'] = time();
     $data['pics'] = "[]";
     $result = $this->dao->add($data);
     if ($result) {
         if ($_FILES) {
             $arr = mul_upload('/Comment/', 2);
             if ($arr) {
                 $data1['pics'] = json_encode($arr);
                 // 把多张图片数组格式转json保存数据库
                 $this->service_dao->where("id={$result}")->save($data1);
             }
         }
         $db->where(array('id' => $dat['id']))->save(array('merchant_comment' => '1'));
         $this->jsonUtils->echo_json_msg(0, '评论成功!');
         exit;
     } else {
         $this->jsonUtils->echo_json_msg(1, '评论失败...');
         exit;
     }
 }