用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2566|回复: 1
收起左侧

[库 Library] 朋友圈好友关系类,给新手参考,不用谢

[复制链接]
发表于 2015-12-22 16:15:51 | 显示全部楼层 |阅读模式
PHP复制代码
<?php
/**
 *  @ 获取职业圈全局规则
 *  @class-return NULL
 *  @class-construct-param NULL
 *  @author CrazyCodes
 *  @time 2015/12/11
 */

class Firclass{
    private static $_id;
    private static $_firid;
    private static $object;
    public function __construct(array $id){
        self::$_id = $id;
        self::$object =& get_instance();
        self::$object->load->database();
        self::$object->config->load('model');
 
    }
    private static function __GetFriend(){
        self::$object->db->select('ApplyUnMemberId as firid,ApplyMemberId');
        self::$object->db->or_where(['ApplyMemberId'=>self::$_id[0]]);
        self::$object->db->or_where(['ApplyUnMemberId'=>self::$_id[0]]);
        self::$object->db->where(['ApplyState'=>1]);
        return self::__GetFirId(self::$object->db->get(self::$object->config->item('FirendsApply','table'))->result_array());
    }
    private static function __GetFirId(array $data){
        $firid = array();
        foreach($data as $key=>$val){
            $firid[] = (int)$val['firid'];
            $firid[] = (int)$val['ApplyMemberId'];
        }
        $firid = array_unique($firid);
        return $firid;
    }
    private static function __GetOther(array $data){
        for($i=0;$i<count($data);$i++){
            $data[$i]['WorkImg'] = self::__GetWorkImg($data[$i]['WorkImg']);
            unset($data[$i]['WorkImg']['add']);
 
            $data[$i]['UserData'] = self::__GetMember($data[$i]['WorkBindMemberId']);
            $data[$i]['News'] = self::__PetternImg(self::_GetNewsMatter($data[$i]['NewsId']));
 
            $WorkPraise = self::_GetWorkPraiseNum($data[$i]['WorkId']);
            $data[$i]['WorkPraise'] = $WorkPraise == null ? [] : $WorkPraise;
            $data[$i]['WorkPraiseNum'] = count($data[$i]['WorkPraise']);
        }
        return $data;
    }
    protected static function _GetWorkPraiseNum($WorkId){
 
        self::$object->db->where(['WorkBindId'=>$WorkId]);
        self::$object->db->limit(0,5);
        self::$object->db->order_by('WorkPraiseId','desc');
        $data = self::$object->db->get(self::$object->config->item('WorkPraise','table'))->result_array();
 
        for($i=0;$i<count($data);$i++){
            self::$object->db->select('*');
            self::$object->db->where(["MemberId"=>trim($data[$i]['WorkBindMemberId'])]);
            $UserData = self::$object->db->get(self::$object->config->item('Member','table'))->row_array();
 
            self::$object->db->select('MemberName,MemberImg');
            self::$object->db->where(["MemberDataId"=>trim($UserData['MemberBindDataId'])]);
            $result[] = self::$object->db->get(self::$object->config->item('MemberData','table'))->row_array();
            $result[$i]['MemberId'] = $data[$i]['WorkBindMemberId'];
        }
 
        return $result;
    }
    private static function __GetWorkImg($data){
        return unserialize($data);
    }
    private static function __GetMember($data){
        self::$object->db->select('*');
        self::$object->db->where(["MemberId"=>trim($data)]);
        $User = self::$object->db->get(self::$object->config->item('Member','table'))->row_array();
 
        self::$object->db->select('MemberName,MemberPostition,MemberImg');
        self::$object->db->where(["MemberDataId"=>trim($User['MemberBindDataId'])]);
        $WorkData = self::$object->db->get(self::$object->config->item('MemberData','table'))->row_array();
        $WorkData['Tag'] = self::_GetMemberTag($data);
        $WorkData['SkillTag'] = self::_GetMemberSkills($data);
        return $WorkData;
    }
    protected static function _GetMemberTag($MemberId){
        self::$object->db->select('MemberTagId,MemberTagName');
        self::$object->db->where(['MemberBindId'=>$MemberId]);
        self::$object->db->limit(2);
        self::$object->db->order_by('MemberTagId','DESC');
        $data = self::$object->db->get(self::$object->config->item('MemberTag','table'))->result_array();
        return $data;
    }
    protected static function _GetMemberSkills($MemberId){
        self::$object->db->select('SkillsTagName,SkillsTagId');
        self::$object->db->from(self::$object->config->item('SkillsTag','table'));
        self::$object->db->where(['MemberBindId'=>$MemberId]);
        self::$object->db->limit(1);
        self::$object->db->order_by('SkillsTagId','DESC');
        self::$object->db->join(self::$object->config->item('MemberSkill','table'),self::$object->config->item('MemberSkill','table').".MemberTagName = ".self::$object->config->item('SkillsTag','table').".SkillsTagId");
        $data = self::$object->db->get()->result_array();
        return $data;
    }
    protected static function _GetNewsMatter($NewId){
        self::$object->db->select('*');
        self::$object->db->where(['NewsId'=>$NewId]);
        return self::$object->db->get(self::$object->config->item('News','table'))->row_array();
    }
    protected static function __Shield($MemberId){
        self::$object->db->where(['ShieldBindMemberId'=>$MemberId]);
        return self::$object->db->get(self::$object->config->item('MemberShield','table'))->result_array();
    }
    private static function __PetternImg($data){
 
        $pattern="/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i";
            if($data['NewsImg']){
                unset($data['NewsMatter']);
                $data['NewsImg'] = explode(',', $data['NewsImg']);
 
                $data['NewsImg'] = self::$object->db->select('path,content')->where_in('id',$data['NewsImg'])->get(self::$object->config->item('PublicUpload','table'))->result_array();
           }else{
                preg_match_all($pattern,$data['NewsMatter'],$match);
                $data['NewsMatter'] = $match[1];
                $data['NewsImg'] = [];
           }
           return $data;
    }
    private static function __GetMemberTag($Member){
        self::$object->db->where(['MemberBindId'=>$Member]);
        return self::$object->db->get(self::$object->config->item('MemberTag','table'))->result_array();
    }
    private static function __GetMemberCity($Member){
        self::$object->db->select('MemberCityId');
        self::$object->db->where(['MemberId'=>$Member]);
        self::$object->db->from(self::$object->config->item('Member','table'));
        self::$object->db->join(self::$object->config->item('MemberData','table'),self::$object->config->item('Member','table').".MemberBindDataId = ".self::$object->config->item('MemberData','table').".MemberDataId");
        return self::$object->db->get()->row_array();
    }
    private static function __GetShield($data){
        for($i=0;$i<count($data);$i++){
           $Shield[]  = $data[$i]['ShieldBindUnMemberId'];
        }
        return $Shield;
    }
    private static function __GetWorkList(array $data){
        $MemberTag = self::__GetMemberTag(self::$_id[0]);
        $MemberCity = self::__GetMemberCity(self::$_id[0]);
        $MemberShield = self::__GetShield(self::__Shield(self::$_id[0]));
 
        self::$object->db->select('WorkId,WorkMatter,WorkImg,WorkRadio,WorkAddtime,WorkBindMemberId,NewsId');
        self::$object->db->from(self::$object->config->item('WorkRing','table'));
        //self:object->db->join(self:object->config->item('MemberTag','table'),self:object->config->item('WorkRing','table').".WorkBindMemberId = ".self:object->config->item('MemberTag','table').".MemberBindId");
        self::$object->db->join(self::$object->config->item('Member','table'),self::$object->config->item('WorkRing','table').".WorkBindMemberId = ".self::$object->config->item('Member','table').".MemberId");
        self::$object->db->join(self::$object->config->item('MemberData','table'),self::$object->config->item('Member','table').".MemberBindDataId = ".self::$object->config->item('MemberData','table').".MemberDataId");
        foreach($MemberTag as $key=>$val){
          //  self:object->db->or_like('MemberTagName',$val['MemberTagName']);
        }
        //self:object->db->or_where(['MemberCityId'=>$MemberCity['MemberCityId']]);
 
        //$data == null ? '' : self:object->db->or_where_in('WorkBindMemberId',$data);
        self::$object->db->where_not_in('WorkBindMemberId',$MemberShield);
        self::$object->db->order_by('WorkAddtime','DESC');
 
        self::$object->db->limit(self::$_id[2],self::$_id[1]);
        return self::__GetOther(self::$object->db->get()->result_array());
    }
    public function GetWorkList(){
        return self::__GetWorkList(self::__GetFriend());
    }
 
}
复制代码


发表于 2016-1-2 23:07:36 | 显示全部楼层
支持一下,不错。

本版积分规则