Home.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. <?php
  2. namespace App\Model;
  3. use PhalApi\Model\NotORMModel as NotORM;
  4. use think\facade\Db;
  5. session_start();
  6. class Home extends NotORM{
  7. /* 搜索 */
  8. public function search($uid,$key,$city,$p) {
  9. $pnum=50;
  10. $start=($p-1)*$pnum;
  11. $where=' user_type="2" and user_status=1 and ( id=? or user_nickname like ?) and id!=?';
  12. if($p!=1){
  13. $id=$_SESSION['search'];
  14. $where.=" and id < {$id}";
  15. }
  16. if($city!=''){
  17. $where.=" and city like '%{$city}%'";
  18. }
  19. $result=\PhalApi\DI()->notorm->user
  20. ->select("id,user_nickname,avatar,avatar_thumb,sex,signature,province,city,birthday,age")
  21. ->where($where,$key,'%'.$key.'%',$uid)
  22. ->order("id desc")
  23. ->limit($start,$pnum)
  24. ->fetchAll();
  25. foreach($result as $k=>$v){
  26. $result[$k]['isattention']=(string)\App\isAttention($uid,$v['id']);
  27. $result[$k]['avatar']=\App\get_upload_path($v['avatar']);
  28. $result[$k]['avatar_thumb']=\App\get_upload_path($v['avatar_thumb']);
  29. if($v['age']<0){
  30. $result[$k]['age']=\PhalApi\T("年龄未填写");
  31. }else{
  32. $result[$k]['age'].=\PhalApi\T("岁");
  33. }
  34. if($v['city']==""){
  35. $result[$k]['city']=\PhalApi\T("城市未填写");
  36. }
  37. $result[$k]['praise']=\App\getPraises($v['id']);
  38. $result[$k]['fans']=\App\getFans($v['id']);
  39. $result[$k]['follows']=\App\getFollows($v['id']);
  40. $result[$k]['coin']="0";
  41. unset($result[$k]['consumption']);
  42. }
  43. if($result){
  44. $last=array_slice($result,-1,1);
  45. $_SESSION['search']=$last[0]['id'];
  46. }
  47. return $result;
  48. }
  49. public function videoSearch($uid,$key,$lng,$lat,$city,$p) {
  50. $pnum=50;
  51. $start=($p-1)*$pnum;
  52. $where="v.isdel=0 and v.status=1 and v.is_ad=0";
  53. $where.=' and (v.title like "%'.$key.'%" or u.user_nickname like "%'.$key.'%")';
  54. if($lng!='' && $lat!='' && $city!=''){
  55. $where.=" and v.city like '%{$city}%'";
  56. }
  57. /*if($p!=1){
  58. $id=$_SESSION['videosearch'];
  59. $where.=" and v.id < {$id}";
  60. }*/
  61. $prefix= \PhalApi\DI()->config->get('dbs.tables.__default__.prefix');
  62. $result=\PhalApi\DI()->notorm->user_video
  63. ->queryAll("select v.*,u.user_nickname,u.avatar from {$prefix}user_video v left join {$prefix}user u on v.uid=u.id where {$where} order by v.addtime desc limit {$start},{$pnum}");
  64. /*if($result){
  65. $last=array_slice($result,-1,1);
  66. $_SESSION['videosearch']=$last['id'];
  67. }*/
  68. //敏感词树
  69. $tree=\App\trieTreeBasic();
  70. foreach ($result as $k => $v) {
  71. $v=\App\handleVideo($uid,$v,$tree);
  72. $result[$k]=$v;
  73. }
  74. return $result;
  75. }
  76. /* 轮播 */
  77. public function getSlide($where){
  78. $rs=\PhalApi\DI()->notorm->slide_item
  79. ->select("image as slide_pic,url as slide_url")
  80. ->where($where)
  81. ->order("list_order asc")
  82. ->fetchAll();
  83. foreach($rs as $k=>$v){
  84. $rs[$k]['slide_pic']=\App\get_upload_path($v['slide_pic']);
  85. }
  86. return $rs;
  87. }
  88. /*商城-商品列表*/
  89. public function getShopList($p){
  90. $order="isrecom desc,sale_nums desc,id desc";
  91. $where=[];
  92. $where['status']=1;
  93. $list=\App\handleGoodsList($where,$p,$order);
  94. foreach ($list as $k => $v) {
  95. unset($list[$k]['specs']);
  96. }
  97. return $list;
  98. }
  99. /* 获取新闻列表*/
  100. public function getNewsList($p){
  101. $where='status=1';
  102. $list=\App\getNewsList($where,$p);
  103. return $list;
  104. }
  105. public function getNewsDetail($id){
  106. $where=['id'=>$id];
  107. $info=\App\getNewsDetail($where);
  108. return $info;
  109. }
  110. public function getClassidShopLists($type,$province,$name,$p){
  111. // $where=['type'=>$type];
  112. $where['type'] = $type;
  113. //
  114. // $where="type={$type} ";
  115. if(!empty($province)){
  116. $where['province'] = $province;
  117. }
  118. if(!empty($name)){
  119. // $where['province'] = $province;
  120. // $where .= " and name like '%{$name}%' " ;
  121. }
  122. $info=\App\getClassidShopLists($where,$name,$p);
  123. return $info;
  124. }
  125. public function getShopAddressList(){
  126. $info=\App\getShopAddressList();
  127. return $info;
  128. }
  129. /*商城-一级分类商品列表*/
  130. public function getShopGoodsList($p,$shopclassid){
  131. $order="isrecom desc,sale_nums desc,id desc";
  132. $where=[];
  133. $where['status']=1;
  134. $list=\App\handleGoodsList($where,$p,$order,$shopclassid);
  135. foreach ($list as $k => $v) {
  136. unset($list[$k]['specs']);
  137. }
  138. return $list;
  139. }
  140. /*商城-获取普通 助农 特价等商品列表*/
  141. public function getShopClassGoodsList($p,$type){
  142. $order="isrecom desc,sale_nums desc,id desc";
  143. $where=[];
  144. $where['status']=1;
  145. $list=\App\handleGoodsList($where,$p,$order,'',$type);
  146. foreach ($list as $k => $v) {
  147. unset($list[$k]['specs']);
  148. }
  149. return $list;
  150. }
  151. /*商城-推荐商品*/
  152. public function getRecomGoodsList(){
  153. $order="isrecom desc,sale_nums desc,id desc";
  154. $where=[];
  155. $where['status']=1;
  156. $list=\App\handleGoodsList($where,1,$order,'',1,1);
  157. foreach ($list as $k => $v) {
  158. unset($list[$k]['specs']);
  159. }
  160. return $list;
  161. }
  162. /*商城-获取分类下的商品*/
  163. public function getShopClassList($shopclassid,$sell,$price,$isnew,$p){
  164. $order=""; //排序
  165. $where="status=1 and three_classid={$shopclassid} ";
  166. if($isnew){
  167. //获取今天开始结束时间
  168. $dayStart=strtotime(date('Y-m-d',strtotime('-2 day')));
  169. $dayEnd=strtotime(date("Y-m-d 23:59:59"));
  170. $where.="and addtime >={$dayStart} and addtime<={$dayEnd}";
  171. }
  172. if($sell!=''){
  173. $order.="sale_nums {$sell},";
  174. }else if($price!=''){
  175. $order.="low_price {$price},";
  176. }
  177. $order.="id desc";
  178. $list=\App\handleGoodsList($where,$p,$order,'',4,0);
  179. foreach ($list as $k => $v) {
  180. unset($list[$k]['specs']);
  181. }
  182. return $list;
  183. }
  184. /*商城-获取分类下的商品*/
  185. public function getShopOneClassGoodsList($shopclassid,$sell,$price,$isnew,$p){
  186. $order=""; //排序
  187. $where="status=1 and one_classid={$shopclassid} ";
  188. if($isnew){
  189. //获取今天开始结束时间
  190. $dayStart=strtotime(date('Y-m-d',strtotime('-2 day')));
  191. $dayEnd=strtotime(date("Y-m-d 23:59:59"));
  192. $where.="and addtime >={$dayStart} and addtime<={$dayEnd}";
  193. }
  194. if($sell!=''){
  195. $order.="sale_nums {$sell},";
  196. }else if($price!=''){
  197. $order.="low_price {$price},";
  198. }
  199. $order.="id desc";
  200. $list=\App\handleGoodsList($where,$p,$order);
  201. foreach ($list as $k => $v) {
  202. unset($list[$k]['specs']);
  203. }
  204. return $list;
  205. }
  206. public function searchShop($key,$sell,$price,$isnew,$p) {
  207. $order=""; //排序
  208. $where="status=1 and name like '%{$key}%' ";
  209. if($isnew){
  210. //获取今天开始结束时间
  211. $dayStart=strtotime(date('Y-m-d',strtotime('-2 day')));
  212. $dayEnd=strtotime(date("Y-m-d 23:59:59"));
  213. $where.="and addtime >={$dayStart} and addtime<={$dayEnd}";
  214. }
  215. if($sell!=''){
  216. $order.="sale_nums {$sell},";
  217. }else if($price!=''){
  218. $order.="low_price {$price},";
  219. }
  220. $order.="id desc";
  221. $list=\App\handleGoodsList($where,$p,$order);
  222. foreach ($list as $k => $v) {
  223. unset($list[$k]['specs']);
  224. }
  225. return $list;
  226. }
  227. //获取本周内累计观众人数前20名的主播榜单
  228. public function getWeekShowLists(){
  229. $nowtime=time();
  230. $w=date('w',$nowtime);
  231. //获取本周开始日期,如果$w是0,则表示周日,减去 6 天
  232. $first=1;
  233. //周一
  234. $week=date('Y-m-d H:i:s',strtotime( date("Ymd")."-".($w ? $w - $first : 6).' days'));
  235. $week_start=strtotime( date("Ymd")."-".($w ? $w - $first : 6).' days');
  236. //本周结束日期
  237. //周天
  238. $week_end=strtotime("{$week} +1 week");
  239. $list_week=\PhalApi\DI()->notorm->user_liverecord
  240. ->select("uid,sum(nums) as total")
  241. ->where("starttime >={$week_start} and starttime < {$week_end} ")
  242. ->group("uid")
  243. ->order("total desc,uid asc")
  244. ->limit(20)
  245. ->fetchAll();
  246. foreach ($list_week as $k => $v) {
  247. $userinfo=\App\getUserInfo($v['uid']);
  248. $v['user_nickname']=$userinfo['user_nickname'];
  249. $v['avatar']=$userinfo['avatar'];
  250. $v['total']=\App\NumberFormat($v['total']);
  251. //判断用户是否在直播
  252. $live_info=\App\getLiveInfo($v['uid']);
  253. $v['stream']=$live_info['stream'];
  254. $v['islive']=$live_info['islive'];
  255. $list_week[$k]=$v;
  256. }
  257. return $list_week;
  258. }
  259. }