User.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <?php
  2. // +—————————————————————————————————————————————————————————————————————
  3. // | Created by Yunbao
  4. // +—————————————————————————————————————————————————————————————————————
  5. // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
  6. // +—————————————————————————————————————————————————————————————————————
  7. // | Author: https://gitee.com/yunbaokeji
  8. // +—————————————————————————————————————————————————————————————————————
  9. // | Date: 2022-04-30
  10. // +—————————————————————————————————————————————————————————————————————
  11. class Model_User extends PhalApi_Model_NotORM {
  12. /* 用户全部信息 */
  13. public function getBaseInfo($uid) {
  14. $info=DI()->notorm->user
  15. ->select("id,user_nicename,avatar,avatar_thumb,sex,signature,province,city,area,birthday,age,mobile,bg_img")
  16. ->where('id=? and user_type="2"',$uid)
  17. ->fetchOne();
  18. if($info){
  19. if($info['age']==-1){
  20. $info['age']="年龄未填写";
  21. }else{
  22. $info['age'].="岁";
  23. }
  24. if($info['city']==""){
  25. $info['city']="城市未填写";
  26. $info['hometown']="";
  27. }else{
  28. $info['hometown']=$info['province'].$info['city'].$info['area'];
  29. }
  30. $info['avatar']=get_upload_path($info['avatar']);
  31. $info['avatar_thumb']=get_upload_path($info['avatar_thumb']);
  32. $info['follows']=getFollows($uid);
  33. $info['fans']=getFans($uid);
  34. $info['praise']=getPraises($uid);
  35. $info['workVideos']=getWorks($uid);
  36. $info['likeVideos']=getLikes($uid);
  37. $info['bg_img']=get_upload_path($info['bg_img']);
  38. $info['signature']=ReplaceSensitiveWords($info['signature']); //个性签名过滤敏感词
  39. $info['user_nicename']=ReplaceSensitiveWords($info['user_nicename']); //昵称过滤敏感词
  40. }
  41. return $info;
  42. }
  43. /* 判断昵称是否重复 */
  44. public function checkName($uid,$name){
  45. $isexist=DI()->notorm->user
  46. ->select('id')
  47. ->where('id!=? and user_nicename=?',$uid,$name)
  48. ->fetchOne();
  49. if($isexist){
  50. return 0;
  51. }else{
  52. return 1;
  53. }
  54. }
  55. /* 判断手机号码是否重复 */
  56. public function checkMobile($uid,$mobile){
  57. $isexist=DI()->notorm->user
  58. ->select('id')
  59. ->where('id!=? and mobile=?',$uid,$mobile)
  60. ->fetchOne();
  61. if($isexist){
  62. return 0;
  63. }else{
  64. return 1;
  65. }
  66. }
  67. /* 修改信息 */
  68. public function userUpdate($uid,$fields){
  69. /* 清除缓存 */
  70. delCache("userinfo_".$uid);
  71. return DI()->notorm->user
  72. ->where('id=?',$uid)
  73. ->update($fields);
  74. }
  75. /* 关注 */
  76. public function setAttent($uid,$touid){
  77. //判断关注列表情况
  78. $isexist=DI()->notorm->user_attention
  79. ->select("*")
  80. ->where('uid=? and touid=?',$uid,$touid)
  81. ->fetchOne();
  82. if($isexist){
  83. DI()->notorm->user_attention
  84. ->where('uid=? and touid=?',$uid,$touid)
  85. ->delete();
  86. return 0;
  87. }else{
  88. DI()->notorm->user_attention
  89. ->insert(array("uid"=>$uid,"touid"=>$touid,"addtime"=>time()));
  90. return 1;
  91. }
  92. }
  93. /* 关注列表 */
  94. public function getFollowsList($uid,$touid,$p,$key){
  95. $pnum=50;
  96. $start=($p-1)*$pnum;
  97. if($key!=0 &&!$key){
  98. $touids=DI()->notorm->user_attention
  99. ->select("touid")
  100. ->where('uid=?',$touid)
  101. ->order("addtime desc")
  102. ->limit($start,$pnum)
  103. ->fetchAll();
  104. }else{
  105. $where="a.uid='{$touid}' and u.user_nicename like '%".$key."%'";
  106. $prefix= DI()->config->get('dbs.tables.__default__.prefix');
  107. $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}");
  108. }
  109. //敏感词树
  110. $tree=trieTreeBasic();
  111. foreach($touids as $k=>$v){
  112. $userinfo=getUserInfo($v['touid'],$tree);
  113. if($userinfo){
  114. if($uid==$touid){
  115. $isattent=1;
  116. }else{
  117. $isattent=isAttention($uid,$v['touid']);
  118. }
  119. $userinfo['isattention']=$isattent;
  120. $touids[$k]=$userinfo;
  121. }else{
  122. DI()->notorm->user_attention->where('uid=? or touid=?',$v['touid'],$v['touid'])->delete();
  123. unset($touids[$k]);
  124. }
  125. }
  126. $touids=array_values($touids);
  127. return $touids;
  128. }
  129. /* 粉丝列表 */
  130. public function getFansList($uid,$touid,$p){
  131. $pnum=50;
  132. $start=($p-1)*$pnum;
  133. $touids=DI()->notorm->user_attention
  134. ->select("uid,addtime")
  135. ->where('touid=?',$touid)
  136. ->limit($start,$pnum)
  137. ->fetchAll();
  138. //敏感词树
  139. $tree=trieTreeBasic();
  140. foreach($touids as $k=>$v){
  141. $userinfo=getUserInfo($v['uid'],$tree);
  142. if($userinfo){
  143. $userinfo['isattention']=isAttention($uid,$v['uid']);
  144. $touids[$k]=$userinfo;
  145. $touids[$k]['attentiontime']=datetime($v['addtime']);
  146. }else{
  147. DI()->notorm->user_attention->where('uid=? or touid=?',$v['uid'],$v['uid'])->delete();
  148. unset($touids[$k]);
  149. }
  150. }
  151. $touids=array_values($touids);
  152. return $touids;
  153. }
  154. /* 个人主页 */
  155. public function getUserHome($uid,$touid){
  156. $info=getUserInfo($touid);
  157. $info['follows']=NumberFormat(getFollows($touid));
  158. $info['fans']=NumberFormat(getFans($touid));
  159. $info['isattention']=(string)isAttention($uid,$touid);
  160. return $info;
  161. }
  162. /*获取用户喜欢的视频列表*/
  163. public function getLikeVideos($uid,$touid,$p){
  164. $pnum=18; //数字必须为18
  165. $start=($p-1)*$pnum;
  166. //获取用户喜欢的视频列表
  167. $list=DI()->notorm->user_video_like->where("uid=? and status=1 ",$touid)->order("addtime desc")->limit($start,$pnum)->fetchAll();
  168. if(!$list){
  169. return 1001;
  170. }
  171. //敏感词树
  172. $tree=trieTreeBasic();
  173. foreach ($list as $k => $v) {
  174. $videoinfo=DI()->notorm->user_video->where("id=? and status=1 and isdel=0 ",$v['videoid'])->fetchOne();
  175. if(!$videoinfo){
  176. //DI()->notorm->user_video_like->where("videoid=?",$v['videoid'])->delete();
  177. unset($list[$k]);
  178. continue;
  179. }
  180. $video=handleVideo($uid,$videoinfo,$tree);
  181. $video['addtime']=date('Y-m-d H:i:s', $v['addtime']);
  182. $video['datetime']=datetime($v['addtime']);
  183. $video['isdel']='0'; //暂时跟getAttentionVideo统一(包含下面的)
  184. $video['isdialect']='0';
  185. $lista[]=$video; //因为unset掉某个数组后,k值连不起来了,所以重新赋值给新数组
  186. }
  187. if(empty($lista)){
  188. $lista=array();
  189. }
  190. return $lista;
  191. }
  192. /* 充值规则 */
  193. public function getChargeRules(){
  194. $rules= DI()->notorm->charge_rules
  195. ->select('id,coin,coin_ios,money,product_id,give')
  196. ->order('orderno asc')
  197. ->fetchAll();
  198. return $rules;
  199. }
  200. /* 我的钻石 */
  201. public function getBalance($uid){
  202. return DI()->notorm->user
  203. ->select("coin")
  204. ->where('id=?',$uid)
  205. ->fetchOne();
  206. }
  207. //获取用户是否可开播、是否可上传视频
  208. public function checkLiveVipStatus($uid){
  209. $configpri=getConfigPri();
  210. $auth_islimit=$configpri['auth_islimit'];
  211. $result['video_status']='1';
  212. //判断后台是否开启发布视频需要身份认证状态
  213. $isauth=isAuth($uid);
  214. if($auth_islimit && !$isauth){ //认证开启 且用户未认证
  215. return 1001;
  216. }
  217. return $result;
  218. }
  219. //更换背景图
  220. public function updateBgImg($uid,$img){
  221. $result=DI()->notorm->user
  222. ->where(['id'=>$uid])
  223. ->update(['bg_img'=>$img]);
  224. if(!$result){
  225. return 1001;
  226. }
  227. return 1;
  228. }
  229. }