123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- <?php
- // +—————————————————————————————————————————————————————————————————————
- // | Created by Yunbao
- // +—————————————————————————————————————————————————————————————————————
- // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
- // +—————————————————————————————————————————————————————————————————————
- // | Author: https://gitee.com/yunbaokeji
- // +—————————————————————————————————————————————————————————————————————
- // | Date: 2022-04-30
- // +—————————————————————————————————————————————————————————————————————
- class Model_User extends PhalApi_Model_NotORM {
- /* 用户全部信息 */
- public function getBaseInfo($uid) {
-
- $info=DI()->notorm->user
- ->select("id,user_nicename,avatar,avatar_thumb,sex,signature,province,city,area,birthday,age,mobile,bg_img")
- ->where('id=? and user_type="2"',$uid)
- ->fetchOne();
- if($info){
- if($info['age']==-1){
- $info['age']="年龄未填写";
- }else{
- $info['age'].="岁";
- }
- if($info['city']==""){
- $info['city']="城市未填写";
- $info['hometown']="";
- }else{
- $info['hometown']=$info['province'].$info['city'].$info['area'];
- }
- $info['avatar']=get_upload_path($info['avatar']);
- $info['avatar_thumb']=get_upload_path($info['avatar_thumb']);
- $info['follows']=getFollows($uid);
- $info['fans']=getFans($uid);
- $info['praise']=getPraises($uid);
- $info['workVideos']=getWorks($uid);
- $info['likeVideos']=getLikes($uid);
- $info['bg_img']=get_upload_path($info['bg_img']);
- $info['signature']=ReplaceSensitiveWords($info['signature']); //个性签名过滤敏感词
- $info['user_nicename']=ReplaceSensitiveWords($info['user_nicename']); //昵称过滤敏感词
- }
-
-
-
- return $info;
- }
-
- /* 判断昵称是否重复 */
- public function checkName($uid,$name){
- $isexist=DI()->notorm->user
- ->select('id')
- ->where('id!=? and user_nicename=?',$uid,$name)
- ->fetchOne();
- if($isexist){
- return 0;
- }else{
- return 1;
- }
- }
- /* 判断手机号码是否重复 */
- public function checkMobile($uid,$mobile){
- $isexist=DI()->notorm->user
- ->select('id')
- ->where('id!=? and mobile=?',$uid,$mobile)
- ->fetchOne();
- if($isexist){
- return 0;
- }else{
- return 1;
- }
- }
- /* 修改信息 */
- public function userUpdate($uid,$fields){
- /* 清除缓存 */
- delCache("userinfo_".$uid);
-
- return DI()->notorm->user
- ->where('id=?',$uid)
- ->update($fields);
- }
-
- /* 关注 */
- public function setAttent($uid,$touid){
- //判断关注列表情况
-
- $isexist=DI()->notorm->user_attention
- ->select("*")
- ->where('uid=? and touid=?',$uid,$touid)
- ->fetchOne();
- if($isexist){
- DI()->notorm->user_attention
- ->where('uid=? and touid=?',$uid,$touid)
- ->delete();
- return 0;
- }else{
- DI()->notorm->user_attention
- ->insert(array("uid"=>$uid,"touid"=>$touid,"addtime"=>time()));
-
- return 1;
- }
- }
-
- /* 关注列表 */
- public function getFollowsList($uid,$touid,$p,$key){
- $pnum=50;
- $start=($p-1)*$pnum;
- if($key!=0 &&!$key){
- $touids=DI()->notorm->user_attention
- ->select("touid")
- ->where('uid=?',$touid)
- ->order("addtime desc")
- ->limit($start,$pnum)
- ->fetchAll();
- }else{
- $where="a.uid='{$touid}' and u.user_nicename like '%".$key."%'";
-
- $prefix= DI()->config->get('dbs.tables.__default__.prefix');
- $touids=DI()->notorm->user_attention->queryAll("select a.touid,u.user_nicename from {$prefix}user_attention as a left join {$prefix}user as u on a.touid=u.id where ".$where." order by addtime desc limit {$start},{$pnum}");
- }
- //敏感词树
- $tree=trieTreeBasic();
- foreach($touids as $k=>$v){
- $userinfo=getUserInfo($v['touid'],$tree);
- if($userinfo){
- if($uid==$touid){
- $isattent=1;
- }else{
- $isattent=isAttention($uid,$v['touid']);
- }
- $userinfo['isattention']=$isattent;
- $touids[$k]=$userinfo;
- }else{
- DI()->notorm->user_attention->where('uid=? or touid=?',$v['touid'],$v['touid'])->delete();
- unset($touids[$k]);
- }
- }
- $touids=array_values($touids);
- return $touids;
- }
-
- /* 粉丝列表 */
- public function getFansList($uid,$touid,$p){
- $pnum=50;
- $start=($p-1)*$pnum;
- $touids=DI()->notorm->user_attention
- ->select("uid,addtime")
- ->where('touid=?',$touid)
- ->limit($start,$pnum)
- ->fetchAll();
- //敏感词树
- $tree=trieTreeBasic();
-
- foreach($touids as $k=>$v){
- $userinfo=getUserInfo($v['uid'],$tree);
- if($userinfo){
- $userinfo['isattention']=isAttention($uid,$v['uid']);
- $touids[$k]=$userinfo;
- $touids[$k]['attentiontime']=datetime($v['addtime']);
- }else{
- DI()->notorm->user_attention->where('uid=? or touid=?',$v['uid'],$v['uid'])->delete();
- unset($touids[$k]);
- }
-
- }
- $touids=array_values($touids);
- return $touids;
- }
-
- /* 个人主页 */
- public function getUserHome($uid,$touid){
- $info=getUserInfo($touid);
- $info['follows']=NumberFormat(getFollows($touid));
- $info['fans']=NumberFormat(getFans($touid));
- $info['isattention']=(string)isAttention($uid,$touid);
-
- return $info;
- }
-
- /*获取用户喜欢的视频列表*/
- public function getLikeVideos($uid,$touid,$p){
- $pnum=18; //数字必须为18
- $start=($p-1)*$pnum;
- //获取用户喜欢的视频列表
- $list=DI()->notorm->user_video_like->where("uid=? and status=1 ",$touid)->order("addtime desc")->limit($start,$pnum)->fetchAll();
- if(!$list){
- return 1001;
- }
- //敏感词树
- $tree=trieTreeBasic();
- foreach ($list as $k => $v) {
-
- $videoinfo=DI()->notorm->user_video->where("id=? and status=1 and isdel=0 ",$v['videoid'])->fetchOne();
- if(!$videoinfo){
- //DI()->notorm->user_video_like->where("videoid=?",$v['videoid'])->delete();
- unset($list[$k]);
- continue;
- }
- $video=handleVideo($uid,$videoinfo,$tree);
- $video['addtime']=date('Y-m-d H:i:s', $v['addtime']);
- $video['datetime']=datetime($v['addtime']);
- $video['isdel']='0'; //暂时跟getAttentionVideo统一(包含下面的)
- $video['isdialect']='0';
- $lista[]=$video; //因为unset掉某个数组后,k值连不起来了,所以重新赋值给新数组
- }
- if(empty($lista)){
- $lista=array();
- }
- return $lista;
- }
- /* 充值规则 */
- public function getChargeRules(){
- $rules= DI()->notorm->charge_rules
- ->select('id,coin,coin_ios,money,product_id,give')
- ->order('orderno asc')
- ->fetchAll();
- return $rules;
- }
- /* 我的钻石 */
- public function getBalance($uid){
- return DI()->notorm->user
- ->select("coin")
- ->where('id=?',$uid)
- ->fetchOne();
- }
- //获取用户是否可开播、是否可上传视频
- public function checkLiveVipStatus($uid){
- $configpri=getConfigPri();
- $auth_islimit=$configpri['auth_islimit'];
- $result['video_status']='1';
- //判断后台是否开启发布视频需要身份认证状态
- $isauth=isAuth($uid);
- if($auth_islimit && !$isauth){ //认证开启 且用户未认证
- return 1001;
- }
- return $result;
- }
-
-
- //更换背景图
- public function updateBgImg($uid,$img){
- $result=DI()->notorm->user
- ->where(['id'=>$uid])
- ->update(['bg_img'=>$img]);
- if(!$result){
- return 1001;
- }
- return 1;
- }
-
- }
|