public function register_device()
 {
     $device = isset($_POST['device']) ? (int) htmlspecialchars($_POST['device']) : '';
     //1 android  2 ios
     $dev_id = isset($_POST['dev_id']) ? htmlspecialchars($_POST['dev_id']) : '';
     $session_id = $_POST['session_id'];
     $member_id = $this->session_handle->getsession_userid($session_id, 1);
     $systemid = CommonController::getSystemUserid($member_id['id'], $member_id['type']);
     if (empty($device) || $device != '1' || $device != '2') {
         $this->jsonUtils->echo_json_msg(4, '设备不正确');
         exit;
     }
     if (empty($dev_id)) {
         $this->jsonUtils->echo_json_msg(4, '设备号为空');
         exit;
     }
     $db = M('Device');
     //判断
     $data = $db->where(array('dev_id' => $dev_id, 'device' => $device))->getField('id');
     if ($data) {
     }
 }
 /**
  * 商家详情
  * 
  * @return [type] [description]
  */
 public function getMerchant()
 {
     $mer_session_id = isset($_POST['mer_session_id']) ? htmlspecialchars(trim($_POST['mer_session_id'])) : '';
     $merchant_id = isset($_POST['merchant_id']) ? htmlspecialchars($_POST['merchant_id']) : '';
     if (empty($merchant_id)) {
         if (!empty($mer_session_id)) {
             $merchant = $this->session_handle->getsession_userid($mer_session_id, 1);
             $merchant_id = $merchant['id'];
         } else {
             $this->jsonUtils->echo_json_msg(6, '商家id为空');
         }
     }
     $arr = $this->dao->field(" id as merchant_id,wifi_enable,merchant_name,header,manager,business_time,tel,intro,address,pics,collect_count,comment_count,business_time,mobile,area_id ")->where("id={$merchant_id}")->select();
     if ($arr) {
         $systemid = CommonController::getSystemUserid($merchant_id, 2);
         if ($arr[0]['pics']) {
             $json_obj = json_decode($arr[0]['pics'], true);
             $arr[0]['pics'] = imgUrl($json_obj);
         }
         $arr[0]['header'] = imgUrl($arr[0]['header']);
         $star = MerchantController::getMerCommentStar($merchant_id);
         $arr[0]['system_user_id'] = $systemid;
         $arr[0]['service_quality'] = $star['service_quality'];
         $arr[0]['service_attitude'] = $star['service_attitude'];
         $arr[0]['merchant_setting'] = $star['merchant_setting'];
         $this->jsonUtils->echo_json_data(0, "ok", $arr[0]);
         exit;
     } else {
         $this->jsonUtils->echo_json_msg(1, '获取商家信息错误!');
         exit;
     }
 }
 /**
  * 举报  system_user_id
  * type 1 色情 2暴力 3 发动 4 广告 5 骚扰信息 6资料不当 7 侵犯版权 8 其他
  * 
  * position 1 举报问题 2 举报问题回复 3举报问题评论 4举报遇见 5 举报遇见的评论 6举报个人 
  * obj_id  1 问题id 2 回复id 3评论id 4 遇见id 5遇见评论id 6 system_user_id
  */
 public function report()
 {
     $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']);
     $position = isset($_POST['position']) ? htmlspecialchars($_POST['position']) : '';
     $type = isset($_POST['type']) ? htmlspecialchars($_POST['type']) : '';
     //
     $obj_id = isset($_POST['obj_id']) ? htmlspecialchars($_POST['obj_id']) : '';
     if (empty($position)) {
         $this->jsonUtils->echo_json_msg(4, '举报来源为空...');
         exit;
     }
     if (empty($type)) {
         $this->jsonUtils->echo_json_msg(4, '举报分类为空...');
         exit;
     }
     if (empty($obj_id)) {
         $this->jsonUtils->echo_json_msg(4, '举报对象为空...');
         exit;
     }
     $db = M('Report');
     $unique = $db->where(array('reporter' => $systemid, 'position' => $position, 'obj_id' => $obj_id))->getField('id');
     if ($unique) {
         $this->jsonUtils->echo_json_msg(0, '你已举报过');
         exit;
     } else {
         $data = $db->add(array('reporter' => $systemid, 'position' => $position, 'obj_id' => $obj_id, 'type' => $type, 'addtime' => time()));
         if ($data) {
             $this->jsonUtils->echo_json_msg(0, '举报成功');
             exit;
         } else {
             $this->jsonUtils->echo_json_msg(1, '举报失败');
             exit;
         }
     }
 }
 public function jpush()
 {
     $jid = isset($_REQUEST['jid']) ? htmlspecialchars($_REQUEST['jid']) : '';
     $content = isset($_POST['content']) ? htmlspecialchars($_POST['content']) : '';
     $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']);
     $user = M('SystemUser')->where(array('id' => $jid))->field('type,name')->find();
     //jpush
     $jpush = new \App\Model\JpushModel();
     $jpush->user = $user['type'];
     $string = $content;
     $jpush->push(5, array($jid), array('content' => $string, 'jid' => $systemid, 'title' => $user['name']));
     $this->jsonUtils->echo_json_msg(0, 'ok');
     exit;
 }
 public function get_order()
 {
     $order_no = isset($_POST['order_no']) ? htmlspecialchars($_POST['order_no']) : '';
     $member_session_id = $_POST['member_session_id'];
     $member_id = $this->session_handle->getsession_userid($member_session_id);
     if (empty($order_no)) {
         $this->jsonUtils->echo_json_msg(4, '订单号为空...');
         exit;
     }
     $arr = $this->dao->table(C('DB_PREFIX') . "order as a")->field("a.order_no,a.addtime,b.id as merchant_id,b.header,b.merchant_name,a.reach_time,a.cart_data,a.member_remark,a.merchant_remark,a.total_price,a.total_time,a.type,a.sub_data,a.member_comment,a.merchant_comment,a.fail_content,a.status,b.tel")->join(C('DB_PREFIX') . 'merchant as b on a.merchant_id = b.id')->where("a.order_no={$order_no} and a.member_id = {$member_id} ")->find();
     if ($arr) {
         $cart = json_decode($arr['cart_data'], true);
         unset($arr['cart_data']);
         $arr['system_user_id'] = CommonController::getSystemUserid($arr['merchant_id'], 2);
         $arr['header'] = imgUrl($arr['header']);
         $arr['cart_model'] = $cart['cart_model'];
         $arr['reach_time'] = date('Y-m-d H:i:s', $arr['reach_time']);
         $arr['addtime'] = date('Y-m-d H:i:s', $arr['addtime']);
         // $arr ['header'] = imgUrl ( $arr ['header'] );
         $model = new Model();
         $sub_data = json_decode($arr['sub_data'], true);
         switch ($arr['type']) {
             // 0 预约 1需求 2活动
             case '0':
                 $arr['pics'] = imgUrl($sub_data['pics']);
                 //	$arr ['distance'] = '';
                 $arr['list'] = $sub_data['list'];
                 break;
             case '1' or '3':
                 // 需求
                 $arr['pics'] = imgUrl($sub_data['pics']);
                 //	$arr ['distance'] = $sub_data ['distance'];
                 $arr['list'] = $sub_data['list'];
                 break;
             case '2':
                 // 活动
                 //	$arr ['distance'] = '';
                 $arr['list'] = array();
                 break;
             default:
                 $this->jsonUtils->echo_json_msg(4, '数据异常');
                 exit;
                 break;
         }
         unset($arr['sub_data']);
         if ($arr['status'] != 0) {
             if ($arr['member_comment'] > 0) {
                 $sql = "select a.desc,c.header,c.nick_name,a.pics,from_unixtime(a.addtime,'%Y-%m-%d %H:%i:%s') as addtime,\r\n\t\t\t\t\ta.service_attitude,a.service_quality,a.merchant_setting\r\n\t\t\t\t\tfrom " . C('DB_PREFIX') . "comment as a  left join\r\n\t\t\t\t\t" . C('DB_PREFIX') . "member as c on a.member_id=c.id\r\n\t\t\t\t\twhere a.order_no={$arr['order_no']} and type=0 limit 1";
                 $arro = $this->dao->query($sql);
                 $arro[0]['header'] = imgUrl($arro[0]['header']);
                 $arro[0]['pics'] = imgUrl(json_decode($arro[0]['pics'], true));
                 $arr['member_comment'] = '1';
                 $arr['member_comment_info'] = empty($arro[0]) ? '' : $arro[0];
             } else {
                 $arr['member_comment'] = '0';
                 $arr['member_comment_info'] = '';
             }
             if ($arr['merchant_comment'] > 0) {
                 $sql = "select a.desc,c.header,a.pics,c.merchant_name as nick_name,a.service_attitude,from_unixtime(a.addtime,'%Y-%m-%d %H:%i:%s') as addtime \r\n\t\t\t\t\tfrom " . C('DB_PREFIX') . "comment as a  left join " . C('DB_PREFIX') . "merchant as c \r\n\t\t\t\t\ton a.merchant_id=c.id where a.order_no={$arr['order_no']} and type=2 limit 1";
                 $arro = $this->dao->query($sql);
                 $arro[0]['header'] = imgUrl($arro[0]['header']);
                 $arro[0]['pics'] = imgUrl(json_decode($arro[0]['pics'], true));
                 $arr['merchant_comment'] = '1';
                 $arr['merchant_comment_info'] = empty($arro[0]) ? '' : $arro[0];
             } else {
                 $arr['merchant_comment'] = '0';
                 $arr['merchant_comment_info'] = '';
             }
         } else {
             $arr['merchant_comment_info'] = '';
             $arr['member_comment_info'] = '';
         }
         $this->jsonUtils->echo_json_data(0, 'ok', $arr);
         exit;
     } else {
         $this->jsonUtils->echo_json_msg(1, '该订单不存在..');
         exit;
     }
 }
 /**
  * 收藏列表
  */
 public function collect_listV2()
 {
     $member_session_id = $_POST['session_id'];
     $page = isset($_POST['page']) ? htmlspecialchars($_POST['page']) : '1';
     $num = isset($_POST['num']) ? htmlspecialchars($_POST['num']) : '6';
     // 1 收藏商家 3用户收藏问答 4 商家收藏问答
     $type = isset($_POST['type']) ? htmlspecialchars($_POST['type']) : '1';
     $limit = ($page - 1) * $num . ',' . $num;
     if ($type == 1) {
         $member_id = $this->session_handle->getsession_userid($member_session_id);
         $model = new Model();
         $sql = "select b.id as merchant_id ,b.header,b.merchant_name,d.name as city_name,c.name as area_name,b.address\r\n\t\t\tfrom " . C('DB_PREFIX') . "collect as a  left join\r\n\t\t\t" . C('DB_PREFIX') . "merchant as b on a.obj_id=b.id\r\n\t\t\tleft join " . C('DB_PREFIX') . "city as c on c.id=b.area_id\r\n\t\t\tleft join " . C('DB_PREFIX') . "city as d on d.id=b.city_id\r\n\t\t\twhere a.member_id={$member_id} and a.type = 1 limit {$limit}";
         $arr = $model->query($sql);
         if ($arr) {
             foreach ($arr as $key => $value) {
                 $arr[$key]['header'] = imgUrl($value['header']);
             }
             $data['list'] = $arr;
             $this->jsonUtils->echo_json_data(0, 'ok', $data);
             exit;
         } else {
             $data['list'] = array();
             $this->jsonUtils->echo_json_msg(0, 'ok', $data);
             exit;
         }
     } elseif ($type == 3 || $type == 4) {
         $member_id = $this->session_handle->getsession_userid($member_session_id, 1);
         $systemid = CommonController::getSystemUserid($member_id['id'], $member_id['type']);
         $model = new Model();
         $sql = "select c.title,c.id as problem_id,d.name as category_name,e.header,b.id as reply_id,b.reply_content,b.laud_count,b.collect_count\r\n\t\t\tfrom " . C('DB_PREFIX') . "collect as a  left join\r\n\t\t\t" . C('DB_PREFIX') . "answer_reply as b on a.obj_id=b.id\r\n\t\t\tleft join " . C('DB_PREFIX') . "system_user as e on e.id=b.reply_id\r\n\t\t\tleft join " . C('DB_PREFIX') . "answer_problem as c on c.id=b.issue_id\r\n\t\t\tleft join " . C('DB_PREFIX') . "answer_category as d on d.id=c.pid\r\n\t\t\twhere a.member_id={$systemid} and a.type = {$type}  order by a.addtime desc limit {$limit}";
         $arr = $model->query($sql);
         if (!$arr) {
             $arr = array();
         } else {
             foreach ($arr as $key => $row) {
                 $arr[$key]['header'] = imgUrl($row['header']);
             }
         }
         $data['list'] = $arr;
         $this->jsonUtils->echo_json_data(0, 'ok', $data);
         exit;
     }
 }
 /**
  * 用户查看需求详情
  */
 public function get_demand()
 {
     $id = isset($_POST['id']) ? htmlspecialchars($_POST['id']) : '';
     $merchant_id = isset($_POST['merchant_id']) ? htmlspecialchars($_POST['merchant_id']) : '';
     $member_session_id = isset($_POST['member_session_id']) ? htmlspecialchars($_POST['member_session_id']) : '';
     //
     $member_id = $this->session_handle->getsession_userid($member_session_id);
     if (empty($id)) {
         $this->jsonUtils->echo_json_msg(4, '需求ID为空...');
         exit;
     }
     // 判断是否有改需求
     $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['is_bidding']) {
         $longitude = $_POST['longitude'];
         $latitude = $_POST['latitude'];
         if (empty($longitude) || empty($latitude)) {
             $this->jsonUtils->echo_json_msg(4, '经度或者纬度为空...');
             exit;
         }
         if (empty($merchant_id)) {
             $this->jsonUtils->echo_json_msg(4, '商家id为空...');
             exit;
         }
         // 需求项目列表信息
         // 查询某个商家对用户需求的所有报价
         $bidding = $this->getMerchantBiddingBy($id, $merchant_id, $bidding_arr['publish']);
         $total_price = 0;
         $total_time = 0;
         foreach ($bidding as $key => $row) {
             if ($row['price'] > 0) {
                 $total_price += $row['price'];
             }
             if ($row['time'] > 0) {
                 $total_time += $row['time'];
             }
         }
         $model = new Model();
         // 需求报价总价格和总服务时间
         $cart = json_decode($bidding_arr['cart_data'], true);
         $data['cart_model'] = $cart['cart_model'];
         $data['reach_time'] = date('Y-m-d H:i:s', $bidding_arr['reach_time']);
         $data['pics'] = imgUrl(json_decode($bidding_arr['pics'], true));
         $data['description'] = $bidding_arr['description'];
         $data['list'] = $bidding;
         $data["total_price"] = (string) $total_price;
         $data['total_time'] = (string) $total_time;
         $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';
                 //过期
             }
         }
         // 商家备注
         $remark_arr = $model->query("select remark from " . C('DB_PREFIX') . "merchant_bidding_remark  where demand_id={$id} and merchant_id = {$merchant_id}");
         $data['remark'] = $remark_arr[0]['remark'] == null ? '' : $remark_arr[0]['remark'];
         // 商家信息
         $merchant_arr = $model->query("select id,merchant_name,header,intro,longitude,latitude,tel from " . C('DB_PREFIX') . "merchant where id={$merchant_id}");
         $merchant_arr[0]['header'] = imgUrl($merchant_arr[0]['header']);
         $merchant_arr[0]['system_user_id'] = CommonController::getSystemUserid($merchant_arr[0]['id'], 2);
         $data['merchant_info'] = $merchant_arr[0];
         $distance = getDistance($latitude, $longitude, $merchant_arr[0]['latitude'], $merchant_arr[0]['longitude']);
         $data['merchant_info']['distance'] = $distance;
         $this->jsonUtils->echo_json_data(0, 'ok', $data);
         exit;
     } else {
         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;
     }
 }
 /**
  * 获取某人动态
  * 公共查看
  */
 public function getSomeoneRecentV2()
 {
     $session_id = isset($_POST['session_id']) ? htmlspecialchars($_POST['session_id']) : '';
     if (!empty($session_id)) {
         $member_id = $this->session_handle->getsession_userid($session_id, 1);
         $systemid = CommonController::getSystemUserid($member_id['id'], $member_id['type']);
     }
     $system_user_id = isset($_POST['system_user_id']) ? (int) htmlspecialchars($_POST['system_user_id']) : '';
     $longitude = isset($_POST['longitude']) ? htmlspecialchars($_POST['longitude']) : '';
     $latitude = isset($_POST['latitude']) ? htmlspecialchars($_POST['latitude']) : '';
     $page = isset($_POST['page']) ? htmlspecialchars($_POST['page']) : '1';
     $num = isset($_POST['num']) ? htmlspecialchars($_POST['num']) : '6';
     if (empty($system_user_id) && empty($systemid)) {
         $this->jsonUtils->echo_json_msg(4, '参数不全');
         exit;
     }
     if (empty($system_user_id) && !empty($systemid)) {
         $system_user_id = $systemid;
     }
     if (!empty($longitude) && !empty($latitude)) {
         $disable = true;
     } else {
         $disable = false;
     }
     $time = time();
     $db = M('AnswerUserRecent');
     $count = $db->where(array('system_user_id' => $system_user_id, 'status' => 0))->count();
     $data = $db->table(C('DB_PREFIX') . "answer_user_recent as a")->join(C('DB_PREFIX') . "system_user as b on b.id = a.system_user_id")->join(C('DB_PREFIX') . "member as c on (c.id = b.sub_id and b.type = 0)")->where(array('a.system_user_id' => $system_user_id, 'a.status' => 0))->field('a.id,a.system_user_id,a.content,a.pics,a.addtime,a.laud_count,a.comment_count,a.longitude,a.latitude,b.name,b.header,b.brand_icon,c.gender')->page($page)->order('addtime desc')->limit($num)->select();
     if ($data) {
         if ($disable) {
             foreach ($data as $key => $row) {
                 $data[$key]['addtime'] = dealtime($row['addtime']);
                 $data[$key]['header'] = imgUrl($row['header']);
                 $data[$key]['gender'] = !empty($row['gender']) ? $row['gender'] : '0';
                 $data[$key]['brand_icon'] = imgUrl($row['brand_icon']);
                 $data[$key]['pics'] = imgUrl(json_decode($row['pics'], true));
                 $data[$key]['distance'] = getDistance($longitude, $latitude, $row['longitude'], $row['latitude']);
                 unset($data[$key]['longitude']);
                 unset($data[$key]['latitude']);
             }
         } else {
             foreach ($data as $key => $row) {
                 $data[$key]['addtime'] = date('Y-m-d H:i:s', $row['addtime']);
                 $data[$key]['header'] = imgUrl($row['header']);
                 $data[$key]['gender'] = !empty($row['gender']) ? $row['gender'] : '0';
                 $data[$key]['brand_icon'] = imgUrl($row['brand_icon']);
                 $data[$key]['pics'] = imgUrl(json_decode($row['pics'], true));
             }
         }
     } else {
         $data = array();
     }
     $arr['count'] = empty($count) ? 0 : $count;
     $arr['list'] = $data;
     $this->jsonUtils->echo_json_data(0, 'ok', $arr);
     exit;
 }