c

来源:互联网 发布:安卓淘宝秒杀器 编辑:程序博客网 时间:2024/06/05 12:47
<?phperror_reporting(0);abstract class Controller {    protected $registry;    protected $user_db = 1;     //人    protected $case_db = 2;     //店铺    protected $say_db = 5;      //说说    protected $hshs_db = 7;     //绘声绘色    protected $live_db = 6;     //直播    protected $user_key = 'usergeo';    protected $case_key = 'casegeo';    protected $say_key = 'saysomegeo';    protected $hshs_key = 'hshsgeo';    protected $live_key = 'livegeo';    protected $userCustomer = 'userCustomer';    protected $caseCustomer = 'caseCustomer';    protected $sayCustomer = 'sayCustomer';    protected $hshsCustomer = 'hshsCustomer';    protected $liveCustomer = 'liveCustomer';    public function __construct($registry)    {        $this->registry = $registry;        $this->load->model('json/account');        // 傲视 写入请求日志        $this->load->model('log/access');        $this->load->model('log/myerror');        $request_url = $_SERVER['REQUEST_URI'];        $str = http_build_query($_REQUEST);        if(!$_REQUEST['customer_id'] && !$_REQUEST['telephone']) {            $_REQUEST['customer_id'] = $_SERVER['REMOTE_ADDR'];        } else if(!$_REQUEST['customer_id'] && $_REQUEST['telephone']) {            $_REQUEST['customer_id'] = $_REQUEST['telephone'];        }        $this->model_log_access->add($_REQUEST['customer_id'], $_REQUEST['token'],$request_url,$str);    }    public function __get($key) {        return $this->registry->get($key);    }    public function __set($key, $value) {        $this->registry->set($key, $value);    }    public function exit( $json ) {        $this->response->addHeader('Content-Type: application/json');        $this->response->setOutput(json_encode($json));    }    /*     * aoshi 检测必填参数*/    public function must_params($data) {        $return = true;        foreach($data as $val) {            if(empty($this->request->post[$val])) {         //必填参数不能为空                $return = false;                break;            }        }        return $return;    }    /*     * aoshi  需要登录的构造函数*/    public function _construct($data) {        foreach($data as $val) {            if(empty($this->request->post[$val])) {         //必填参数不能为空                return array('code'=>206,'message'=>'参数错误!');                break;            }        }        //验证token        if(!$this->customer->checkExpire()) {           //token有效期            return array('code'=>201,'message'=>'未登录!');        }        //token 是否正确        $customerId = $this->model_json_account->getIdByToken($this->request->post['token']);        if($customerId != $this->request->post['customer_id']){            return array('code'=>206,'message'=>'参数错误!');        }        return true;    }    /*     * aoshi  不需要登录的构造函数*/    public function _constructNoLogin($data) {        $this->load->model('json/account');        foreach($data as $val) {            if(empty($this->request->post[$val])) {         //必填参数不能为空                return array('code'=>206,'message'=>'参数错误!');                break;            }        }        return true;    }    /*     * 输出返回数据*/    public function return_output($data,$type = 'JSON') {        /*$this->response->addHeader('Content-Type: application/json');        $this->response->setOutput(json_encode($data));*/        if(empty($type)) $type =  'JSON';        if(strtoupper($type)=='JSON') {            // 返回JSON数据格式到客户端 包含状态信息//            header('Content-Type:text/html; charset=utf-8');            header('Content-Type: application/json');            exit(json_encode($data));        }elseif(strtoupper($type)=='XML'){            // 返回xml格式数据            header('Content-Type:text/xml; charset=utf-8');            exit(xml_encode($data));        }elseif(strtoupper($type)=='EVAL'){            // 返回可执行的js脚本            header('Content-Type:text/html; charset=utf-8');            exit($data);        }else{            // TODO 增加其它格式        }    }    /*     * 格式化人     * param    array   $rVal     * param    array   req_post     * param    int     customerId     * */    protected function formatCustomerNew($rVal,$req_post,$customerId) {        //昵称 头像        $user_info = $this->model_json_account->getCustomerInfoAs($rVal['customer_id']);        $rVal['nick_name'] = $user_info['nick_name'];        $rVal['head_pic'] = $user_info['head_pic'];        $rVal['online_status'] = $user_info['online_status'];        $rVal['sex'] = $user_info['sex'];        $rVal['heartbeat'] = $user_info['heartbeat'];        //羽毛        $rVal['in_level'] = '1';              //升级标识  羽毛            //在线状态        //行业图标        $rVal['cate_icon'] = $this->model_json_account->getCateIcon($rVal['customer_id']);        //角色帽子        $role_icons = $this->model_json_account->getRoleIcon($rVal['customer_id']);        $rVal = array_merge($rVal,$role_icons);        //是否关注        $whe = array('type'=>3,'item_id'=>$rVal['customer_id'],'customer_id'=>$customerId);        $is_attention = $this->model_attention_attention->checkIsAttention($whe);        $rVal['is_attention'] = $is_attention ? '1' : '0';        //是否约起        $customer_ids = array($rVal['customer_id'],$customerId);        $whe = array('type'=>3,'customer_ids'=>$customer_ids);        $is_about = $this->model_appointment_appointment->checkIsAppointmentCustomer($whe);        $rVal['is_about'] = $is_about ? '1' : '0';        //约起数量        $rVal['about_num'] = $this->model_appointment_appointment->appointmentCou($rVal['customer_id']);        //收藏        $is_collect = $this->model_json_collect->isCollect($customerId,$rVal['customer_id'],1);        $rVal['is_collect'] = $is_collect ? '1' : '0';        /*//是否看好        $rVal['is_wish'] = $this->model_wishcheck_wishcheck->isWish($rVal['customer_id'],$customerId,3);        //是否观察        $rVal['is_check'] = $this->model_wishcheck_wishcheck->isCheck($rVal['customer_id'],$customerId,3);*/        $isWishCheckPointWill = $this->model_wishcheck_wishcheck->isWishCheckPointWill($rVal['customer_id'],$customerId,3);        $wishCheckPointWillNum = $this->model_wishcheck_wishcheck->wishCheckPointWillNum($customerId);        $rVal = array_merge($rVal,$isWishCheckPointWill,$wishCheckPointWillNum);        //名片一句话简介        $data = $this->model_subject_sayshow->get($rVal['customer_id'],5);        if($data) {            $rVal['remark'] = $data['abstract'];        } else {            $rVal['remark'] = '';        }        //发布时间 名片发布时间        $ctime = time() - rand(86400,8640000);        $rVal['ctime'] = date('Y.m.d',$ctime);        //角色上一级        $rVal['upcatname'] = '容通人';        //角色        $rVal['role_str'] = '咖啡园技能人';        //行业标识        $rVal['cate_name'] = '云南保山梯田咖啡园';        $rVal['position'] = '咖啡园种植匠人';        //影响力        $rVal['affect_num'] = (string)rand(5550,6000);        //经常出现坐标        $lnglat = $this->model_map_lnglat->getOften($rVal['customer_id']);        //获取距离        if($req_post['lng'] && $req_post['lat'] && $lnglat['lng'] && $lnglat['lat']) {            $member_name1 = 'c_' . $customerId;            $member_name2 = 'co_' . $rVal['customer_id'];            $member1 = array('member_name'=>$member_name1,'lng'=>$req_post['lng'],'lat'=>$req_post['lat']);            $member2 = array('member_name'=>$member_name2,'lng'=>$lnglat['lng'],'lat'=>$lnglat['lat']);            $distance_num = $this->redisMemberDistNew($this->userCustomer,$member1,$member2);        } else {            $distance_num = '';        }        $rVal['often_lng_lat'] = array('lng'=>$lnglat['lng'],'lat'=>$lnglat['lat'],'address'=>$lnglat['address'],'distance_num'=>$distance_num);        //在线时间        $online_time = formatOnlineTime($rVal['heartbeat']);        $rVal = array_merge($rVal,$online_time);        //$rVal['online_time'] = say_time_stream_format1($rVal['heartbeat'],1);        //当前位置数据        $lnglat = $this->model_map_lnglat->getLocal($rVal['customer_id']);        //获取距离        if($req_post['lng'] && $req_post['lat'] && $lnglat['lng'] && $lnglat['lat']) {            $member_name1 = 'c_' . $customerId;            $member_name2 = 'cl_' . $rVal['customer_id'];            $member1 = array('member_name'=>$member_name1,'lng'=>$req_post['lng'],'lat'=>$req_post['lat']);            $member2 = array('member_name'=>$member_name2,'lng'=>$lnglat['lng'],'lat'=>$lnglat['lat']);            $distance_num = $this->redisMemberDistNew($this->userCustomer,$member1,$member2);        } else {            $distance_num = '';        }        //当前位置        $rVal['local_lng_lat'] = array('lng'=>$lnglat['lng'],'lat'=>$lnglat['lat'],'address'=>$lnglat['address'],'distance_num'=>$distance_num);        //距离        if($rVal['dist']) {            $rVal['distance_num'] = $rVal['dist'];        } else {            $rVal['distance_num'] = $distance_num;        }        //经度        $rVal['lng'] = $lnglat['lng'];        //维度        $rVal['lat'] = $lnglat['lat'];        //地址        $rVal['address'] = $lnglat['address'];        //直播ID        $rVal['id'] = $rVal['customer_id'];        unset($rVal['heartbeat']);        return $rVal;    }    /*     * 格式化店铺     * param    array   $rVal     * param    array   req_post     * param    int     customerId     * @return  array     * */    protected function formatCaseNew($rVal,$req_post,$customerId) {        //昵称 头像        $user_info = $this->model_json_account->getCustomerInfoAs($rVal['customer_id']);        if(!$user_info['customer_id']) {            return '';        }        $rVal['nick_name'] = $user_info['nick_name'];        $rVal['head_pic'] = $user_info['head_pic'];        $rVal['online_status'] = $user_info['online_status'];        $rVal['sex'] = $user_info['sex'];        $rVal['heartbeat'] = $user_info['heartbeat'];        //羽毛        $rVal['in_level'] = '1';              //升级标识  羽毛            //在线状态        //行业图标        $rVal['cate_icon'] = $this->model_json_account->getCateIcon($rVal['customer_id']);        //角色帽子        $role_icons = $this->model_json_account->getRoleIcon($rVal['customer_id']);        $rVal = array_merge($rVal,$role_icons);        //是否关注        $whe = array('type'=>4,'item_id'=>$rVal['id'],'customer_id'=>$customerId);        $is_attention = $this->model_attention_attention->checkIsAttention($whe);        $rVal['is_attention'] = $is_attention ? '1' : '0';        //是否约起        $customer_ids = array($rVal['id'],$customerId);        $whe = array('type'=>5,'customer_ids'=>$customer_ids);        $is_about = $this->model_appointment_appointment->checkIsAppointmentCustomer($whe);        $rVal['is_about'] = $is_about ? '1' : '0';        //约起数量        $rVal['about_num'] = $this->model_appointment_appointment->appointmentCou($rVal['customer_id']);        //收藏        $is_collect = $this->model_json_collect->isCollect($customerId,$rVal['id'],7);        $rVal['is_collect'] = $is_collect ? '1' : '0';//        //是否看好//        $rVal['is_wish'] = $this->model_wishcheck_wishcheck->isWish($rVal['live_id'],$customerId,5);////        //是否观察//        $rVal['is_check'] = $this->model_wishcheck_wishcheck->isCheck($rVal['live_id'],$customerId,5);        $isWishCheckPointWill = $this->model_wishcheck_wishcheck->isWishCheckPointWill($rVal['id'],$customerId,5);        $wishCheckPointWillNum = $this->model_wishcheck_wishcheck->wishCheckPointWillNum($customerId);        $rVal = array_merge($rVal,$isWishCheckPointWill,$wishCheckPointWillNum);        //店铺一句话简介        $data = $this->model_subject_sayshow->get($rVal['customer_id'],4);        if($data) {            $rVal['remark'] = $data['abstract'];        } else {            $rVal['remark'] = '';        }        //发布时间 名片发布时间        $rVal['timestring'] = date('Y.m.d',$rVal['ctime']);        //经常出现坐标        $lnglat = $this->model_map_lnglat->getOften($rVal['customer_id']);        //获取距离        if($req_post['lng'] && $req_post['lat'] && $lnglat['lng'] && $lnglat['lat']) {            $member_name1 = 'c_' . $customerId;            $member_name2 = 'co_' . $rVal['customer_id'];            $member1 = array('member_name'=>$member_name1,'lng'=>$req_post['lng'],'lat'=>$req_post['lat']);            $member2 = array('member_name'=>$member_name2,'lng'=>$lnglat['lng'],'lat'=>$lnglat['lat']);            $distance_num = $this->redisMemberDistNew($this->caseCustomer,$member1,$member2);        } else {            $distance_num = '';        }        $rVal['often_lng_lat'] = array('lng'=>$lnglat['lng'],'lat'=>$lnglat['lat'],'address'=>$lnglat['address'],'distance_num'=>$distance_num);        //在线时间        $online_time = formatOnlineTime($rVal['heartbeat']);        $rVal = array_merge($rVal,$online_time);//        $rVal['online_time'] = say_time_stream_format1($rVal['heartbeat'],1);        //当前位置数据        $lnglat = $this->model_map_lnglat->getLocal($rVal['customer_id']);        //获取距离        if($req_post['lng'] && $req_post['lat'] && $lnglat['lng'] && $lnglat['lat']) {            $member_name1 = 'c_' . $customerId;            $member_name2 = 'cl_' . $rVal['customer_id'];            $member1 = array('member_name'=>$member_name1,'lng'=>$req_post['lng'],'lat'=>$req_post['lat']);            $member2 = array('member_name'=>$member_name2,'lng'=>$lnglat['lng'],'lat'=>$lnglat['lat']);            $distance_num = $this->redisMemberDistNew($this->caseCustomer,$member1,$member2);        } else {            $distance_num = '';        }        //当前位置        $rVal['local_lng_lat'] = array('lng'=>$lnglat['lng'],'lat'=>$lnglat['lat'],'address'=>$lnglat['address'],'distance_num'=>$distance_num);        //距离        if($rVal['dist']) {            $rVal['distance_num'] = $rVal['dist'];        } else {            $rVal['distance_num'] = $distance_num;        }        //经度        $rVal['lng'] = $lnglat['lng'];        //维度        $rVal['lat'] = $lnglat['lat'];        //地址        $rVal['address'] = $lnglat['address'];        //获取说说        $sayInfo = $this->model_subject_say->getCaseSay($rVal['customer_id']);        if(is_array($sayInfo)) {            $sayInfo['type'] = '5';        }        $rVal['say_info'] = $sayInfo;        //获取绘声绘色        $hshsInfo = $this->model_subject_hshs->getCaseHshs($rVal['customer_id']);        if(is_array($hshsInfo)) {           //绘声绘色是否有视频            $hshsInfo['has_video'] = $this->model_subject_hshs->hasVideo($hshsInfo['id']);            $hshsInfo['type'] = '7';        }        $rVal['hshs_info'] = $hshsInfo;        //获取直播        $liveInfo = $this->model_qcloud_live->getCaseLive($rVal['customer_id']);        if(is_array($liveInfo)) {            $liveInfo['id'] = $liveInfo['live_id'];            $liveInfo['type'] = '6';        }        $rVal['live_info'] = $liveInfo;        unset($rVal['heartbeat']);        return $rVal;    }    /*     * 格式化绘声绘色     * param    array   $rVal               //数据主体     * param    array   req_post            //请求参数     * param    int     customerId          //访问者ID     * */    protected function formatHshsNew($rVal,$req_post,$customerId) {        $user_info = $this->model_json_account->getCustomerInfoAs($rVal['customer_id']);        $rVal['head_pic'] = $user_info['head_pic'];        $rVal['nick_name'] = $user_info['nick_name'];        $rVal['sex'] = $user_info['sex'];        $rVal['heartbeat'] = $user_info['heartbeat'];        $rVal['timestring'] = date('Y-m-d H:i',$rVal['add_time']);        $rVal['content_desc'] = $this->model_subject_hshs->hshsContentString($rVal['id']);        //店铺名称        if($rVal['case_id']) {            $rVal['case_name'] = $this->model_case_case->getNameByCaseId($rVal['case_id']);        } else {            $rVal['case_name'] = '';        }        //绘声绘色类型        $rVal['have_type_name'] = $rVal['have_type'] == 1 ? '特色篇' : '商业篇';        //获取五行分类        if($rVal['cate_id']) {            $rVal['cate_name'] = $this->model_category_category->getFieldById($rVal['cate_id'],'name');        } else {            $rVal['cate_name'] = '';        }        //八类资本类型        $rVal['investment_name'] = $this->model_subject_hshs->investmentTypename($rVal['investment']);        //羽毛        $rVal['in_level'] = '1';              //升级标识  羽毛        //在线状态      1|在线  2|隐身  3|离开        $rVal['online_status'] = $user_info['online_status'];              //在线状态        //行业图标        $rVal['cate_icon'] = $this->model_json_account->getCateIcon($rVal['customer_id']);        //角色帽子        $role_icons = $this->model_json_account->getRoleIcon($rVal['customer_id']);        $rVal = array_merge($rVal,$role_icons);        //约起数量        $rVal['about_num'] = $this->model_appointment_appointment->appointmentCou($rVal['customer_id']);        //是否约起        $whe = array('type'=>2,'from_id'=>$rVal['id'],'customer_id'=>$customerId);        $is_about = $this->model_appointment_appointment->checkIsAppointment($whe);        $rVal['is_about'] = $is_about ? '1' : '0';        //是否关注        $whe = array('type'=>2,'item_id'=>$rVal['id'],'customer_id'=>$customerId);        $is_attention = $this->model_attention_attention->checkIsAttention($whe);        $rVal['is_attention'] = $is_attention ? '1' : '0';        //是否收藏        $is_collect = $this->model_json_collect->isCollect($customerId,$rVal['id'],3);        $rVal['is_collect'] = $is_collect ? '1' : '0';        //是否点赞        $rVal['is_zan'] = $this->model_zan_hshs->checkIsZan($rVal['id'],$customerId);        //是否谴责        $rVal['is_condemn'] = $this->model_comment_hshs->isCondemn($customerId,$rVal['id']);        //是否颂扬        $rVal['is_praise'] = $this->model_comment_hshs->isPraise($customerId,$rVal['id']);        //是否中立        $rVal['is_neutral'] = $this->model_comment_hshs->isNeutral($customerId,$rVal['id']);        //是否拥有视频元素        $rVal['has_video'] = $this->model_subject_hshs->hasVideo($rVal['id']);        //是否看好//        $rVal['is_wish'] = $this->model_wishcheck_wishcheck->isWish($rVal['id'],$customerId,2);        //是否观察//        $rVal['is_check'] = $this->model_wishcheck_wishcheck->isCheck($rVal['id'],$customerId,2);        $isWishCheckPointWill = $this->model_wishcheck_wishcheck->isWishCheckPointWill($rVal['customer_id'],$customerId,2);        $wishCheckPointWillNum = $this->model_wishcheck_wishcheck->wishCheckPointWillNum($customerId);        $rVal = array_merge($rVal,$isWishCheckPointWill,$wishCheckPointWillNum);        //经常出现坐标        $lnglat = $this->model_map_lnglat->getOften($rVal['customer_id']);        //获取距离        if($req_post['lng'] && $req_post['lat'] && $lnglat['lng'] && $lnglat['lat']) {            $member_name1 = 'c_' . $customerId;            $member_name2 = 'co_' . $rVal['customer_id'];            $member1 = array('member_name'=>$member_name1,'lng'=>$req_post['lng'],'lat'=>$req_post['lat']);            $member2 = array('member_name'=>$member_name2,'lng'=>$lnglat['lng'],'lat'=>$lnglat['lat']);            $distance_num = $this->redisMemberDIST($this->hshsCustomer,$member1,$member2);        } else {            $distance_num = '';        }        $rVal['often_lng_lat'] = array('lng'=>$lnglat['lng'],'lat'=>$lnglat['lat'],'address'=>$lnglat['address'],'distance_num'=>$distance_num);        //在线时间        $online_time = formatOnlineTime($rVal['heartbeat']);        $rVal = array_merge($rVal,$online_time);//        $rVal['online_time'] = say_time_stream_format1($user_info['heartbeat'],0);        //当前位置        $lnglat = $this->model_map_lnglat->getLocal($rVal['customer_id']);        //获取距离        if($req_post['lng'] && $req_post['lat'] && $lnglat['lng'] && $lnglat['lat']) {            $member_name1 = 'c_' . $customerId;            $member_name2 = 'hc_' . $rVal['customer_id'];            $member1 = array('member_name'=>$member_name1,'lng'=>$req_post['lng'],'lat'=>$req_post['lat']);            $member2 = array('member_name'=>$member_name2,'lng'=>$lnglat['lng'],'lat'=>$lnglat['lat']);            $distance_num = $this->redisMemberDistNew($this->hshsCustomer,$member1,$member2);        } else {            $distance_num = '';        }        $rVal['local_lng_lat'] = array('lng'=>$lnglat['lng'],'lat'=>$lnglat['lat'],'address'=>$lnglat['address'],'distance_num'=>$distance_num);        if($rVal['dist']) {            $rVal['distance_num'] = $rVal['dist'];        } else {            $rVal['distance_num'] = $distance_num;        }        return $rVal;    }    /*     * 格式化说说* param    array   $rVal               //数据主体     * param    array   req_post            //请求参数     * param    int     customerId          //访问者ID     *     * */    protected function formatSaysomeNew($rVal,$req_post,$customerId) {        $user_info = $this->model_json_account->getCustomerInfoAs($rVal['customer_id']);        $rVal['head_pic'] = $user_info['head_pic'];        $rVal['nick_name'] = $user_info['nick_name'];        $rVal['sex'] = $user_info['sex'];        $rVal['heartbeat'] = $user_info['heartbeat'];        $rVal['timestring'] = date('Y-m-d H:i',$rVal['addtime']);        //羽毛        $rVal['in_level'] = '1';              //升级标识  羽毛        //在线状态      1|在线  2|隐身  3|离开        $rVal['online_status'] = $user_info['online_status'];              //在线状态        //行业图标        $rVal['cate_icon'] = $this->model_json_account->getCateIcon($rVal['customer_id']);        //角色帽子        $role_icons = $this->model_json_account->getRoleIcon($rVal['customer_id']);        $rVal = array_merge($rVal,$role_icons);        //约起数量        $rVal['about_num'] = $this->model_appointment_appointment->appointmentCou($rVal['customer_id']);        //是否约起        $whe = array('type'=>1,'from_id'=>$rVal['id'],'customer_id'=>$customerId);        $is_about = $this->model_appointment_appointment->checkIsAppointment($whe);        $rVal['is_about'] = $is_about ? '1' : '0';        //是否关注        $whe = array('type'=>1,'item_id'=>$rVal['id'],'customer_id'=>$customerId);        $is_attention = $this->model_attention_attention->checkIsAttention($whe);        $rVal['is_attention'] = $is_attention ? '1' : '0';        //是否收藏        $is_collect = $this->model_json_collect->isCollect($customerId,$rVal['id'],4);        $rVal['is_collect'] = $is_collect ? '1' : '0';        //是否点赞        $rVal['is_zan'] = $this->model_zan_say->checkIsZan($rVal['id'],$customerId);        //是否看好//        $rVal['is_wish'] = $this->model_wishcheck_wishcheck->isWish($rVal['id'],$customerId,1);        //是否观察//        $rVal['is_check'] = $this->model_wishcheck_wishcheck->isCheck($rVal['id'],$customerId,1);        $isWishCheckPointWill = $this->model_wishcheck_wishcheck->isWishCheckPointWill($rVal['customer_id'],$customerId,1);        $wishCheckPointWillNum = $this->model_wishcheck_wishcheck->wishCheckPointWillNum($customerId);        $rVal = array_merge($rVal,$isWishCheckPointWill,$wishCheckPointWillNum);        //经常出现坐标        $lnglat = $this->model_map_lnglat->getOften($rVal['customer_id']);        if($req_post['lng'] && $req_post['lat'] && $lnglat['lng'] && $lnglat['lat']) {            $member_name1 = 'c_' . $customerId;            $member_name2 = 'co_' . $rVal['customer_id'];            $member1 = array('member_name'=>$member_name1,'lng'=>$req_post['lng'],'lat'=>$req_post['lat']);            $member2 = array('member_name'=>$member_name2,'lng'=>$lnglat['lng'],'lat'=>$lnglat['lat']);            $distance_num = $this->redisMemberDistNew($this->sayCustomer,$member1,$member2);        } else {            $distance_num = '';        }        $rVal['often_lng_lat'] = array('lng'=>$lnglat['lng'],'lat'=>$lnglat['lat'],'address'=>$lnglat['address'],'distance_num'=>$distance_num);        //在线时间        $online_time = formatOnlineTime($rVal['heartbeat']);        $rVal = array_merge($rVal,$online_time);//        $rVal['online_time'] = say_time_stream_format1($user_info['heartbeat'],1);        //当前位置        $lnglat = $this->model_map_lnglat->getLocal($rVal['customer_id']);        //获取距离        if($req_post['lng'] && $req_post['lat'] && $lnglat['lng'] && $lnglat['lat']) {            $member_name1 = 'c_' . $customerId;            $member_name2 = 'sc_' . $rVal['customer_id'];            $member1 = array('member_name'=>$member_name1,'lng'=>$req_post['lng'],'lat'=>$req_post['lat']);            $member2 = array('member_name'=>$member_name2,'lng'=>$lnglat['lng'],'lat'=>$lnglat['lat']);            $distance_num = $this->redisMemberDistNew($this->sayCustomer,$member1,$member2);        } else {            $distance_num = '';        }        $rVal['local_lng_lat'] = array('lng'=>$lnglat['lng'],'lat'=>$lnglat['lat'],'address'=>$lnglat['address'],'distance_num'=>$distance_num);        if($rVal['dist']) {            $rVal['distance_num'] = $rVal['dist'];        } else {            $rVal['distance_num'] = $distance_num;        }        return $rVal;    }    /*     * 格式化直播     * param    array   $rVal               //数据主体     * param    array   req_post            //请求参数     * param    int     customerId          //访问者ID     * */    protected function formatLiveNew($rVal,$req_post,$customerId) {        $user_info = $this->model_json_account->getCustomerInfoAs($rVal['customer_id']);        $rVal['head_pic'] = $user_info['head_pic'];        $rVal['nick_name'] = $user_info['nick_name'];        $rVal['sex'] = $user_info['sex'];        $rVal['heartbeat'] = $user_info['heartbeat'];        switch($rVal['status']) {            case 0:                $rVal['status_name'] = '未开始';                $diff_time = $rVal['play_time'] - time();                $rVal['diff_time'] = (string)$diff_time;                break;            case 1:                $rVal['status_name'] = '直播中';                $rVal['diff_time'] = '';                break;            default:                $rVal['status_name'] = '看录播';                $rVal['diff_time'] = '';                break;        }        $rVal['timestring'] = date('Y-m-d H:i',$rVal['create_time']);        //五行分类        $rVal['cate_name'] = $this->model_category_category->getFieldById($rVal['cate_id'],'name');        //直播属性        $rVal['type_name'] = $this->model_category_category->getFieldById($rVal['type_id'],'name');        //粉丝多少人        $rVal['fans_num'] = $this->model_attention_attention->getNum($rVal['customer_id'],$rVal['live_id']);        //羽毛        $rVal['in_level'] = '1';              //升级标识  羽毛        //在线状态      1|在线  2|隐身  3|离开        $rVal['online_status'] = $user_info['online_status'];              //在线状态        //行业图标        $rVal['cate_icon'] = $this->model_json_account->getCateIcon($rVal['customer_id']);        //角色帽子        $role_icons = $this->model_json_account->getRoleIcon($rVal['customer_id']);        $rVal = array_merge($rVal,$role_icons);        //约起数量        $rVal['about_num'] = $this->model_appointment_appointment->appointmentCou($rVal['customer_id']);        //是否约起        $whe = array('type'=>4,'from_id'=>$rVal['live_id'],'customer_id'=>$customerId);        $is_about = $this->model_appointment_appointment->checkIsAppointment($whe);        $rVal['is_about'] = $is_about ? '1' : '0';        //是否关注        $whe = array('type'=>5,'item_id'=>$rVal['live_id'],'customer_id'=>$customerId);        $is_attention = $this->model_attention_attention->checkIsAttention($whe);        $rVal['is_attention'] = $is_attention ? '1' : '0';        //是否收藏        $is_collect = $this->model_json_collect->isCollect($customerId,$rVal['live_id'],6);        $rVal['is_collect'] = $is_collect ? '1' : '0';        //是否点赞        $rVal['is_zan'] = $this->model_zan_live->checkIsZan($rVal['live_id'],$customerId);        //是否看好//        $rVal['is_wish'] = $this->model_wishcheck_wishcheck->isWish($rVal['live_id'],$customerId,4);        //是否观察//        $rVal['is_check'] = $this->model_wishcheck_wishcheck->isCheck($rVal['live_id'],$customerId,4);        $isWishCheckPointWill = $this->model_wishcheck_wishcheck->isWishCheckPointWill($rVal['customer_id'],$customerId,3);        $wishCheckPointWillNum = $this->model_wishcheck_wishcheck->wishCheckPointWillNum($customerId);        $rVal = array_merge($rVal,$isWishCheckPointWill,$wishCheckPointWillNum);        //经常出现坐标        $lnglat = $this->model_map_lnglat->getOften($rVal['customer_id']);        if($req_post['lng'] && $req_post['lat'] && $lnglat['lng'] && $lnglat['lat']) {            $member_name1 = 'c_' . $customerId;            $member_name2 = 'co_' . $rVal['customer_id'];            $member1 = array('member_name'=>$member_name1,'lng'=>$req_post['lng'],'lat'=>$req_post['lat']);            $member2 = array('member_name'=>$member_name2,'lng'=>$lnglat['lng'],'lat'=>$lnglat['lat']);            $distance_num = $this->redisMemberDistNew($this->liveCustomer,$member1,$member2);        } else {            $distance_num = '';        }        $rVal['often_lng_lat'] = array('lng'=>$lnglat['lng'],'lat'=>$lnglat['lat'],'address'=>$lnglat['address'],'distance_num'=>$distance_num);        //在线时间        $online_time = formatOnlineTime($rVal['heartbeat']);        $rVal = array_merge($rVal,$online_time);//        $rVal['online_time'] = say_time_stream_format1($user_info['heartbeat'],1);        $rVal['trades'] = array();        //当前位置        $lnglat = $this->model_map_lnglat->getLocal($rVal['customer_id']);        $rVal['local_lng_lat'] = array('lng'=>$lnglat['lng'],'lat'=>$lnglat['lat'],'address'=>$lnglat['address']);        //获取距离        if($req_post['lng'] && $req_post['lat'] && $lnglat['lng'] && $lnglat['lat']) {            $member_name1 = 'c_' . $customerId;            $member_name2 = 'lc_' . $rVal['customer_id'];            $member1 = array('member_name'=>$member_name1,'lng'=>$req_post['lng'],'lat'=>$req_post['lat']);            $member2 = array('member_name'=>$member_name2,'lng'=>$lnglat['lng'],'lat'=>$lnglat['lat']);            $distance_num = $this->redisMemberDistNew($this->liveCustomer,$member1,$member2);        } else {            $distance_num = '';        }        $rVal['often_lng_lat'] = array('lng'=>$lnglat['lng'],'lat'=>$lnglat['lat'],'address'=>$lnglat['address'],'distance_num'=>$distance_num);        if($rVal['dist']) {            $rVal['distance_num'] = $rVal['dist'];        } else {            $rVal['distance_num'] = $distance_num;        }        $rVal['id'] = $rVal['live_id'];        unset($rVal['create_time']);        unset($rVal['trade_id']);        unset($rVal['type_id']);        unset($rVal['cate_id']);        return $rVal;    }    /*     * 获取两点距离     * */    protected function redisMemberDistNew($distKey,$mem1,$mem2) {        $members = array($mem1,$mem2);        $this->redis->geozadd($distKey,$members);        $dist = $this->redis->get_geomemberdist($distKey,$mem1['member_name'],$mem2['member_name']);        return format_dist($dist);    }}
原创粉丝点击