Index.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use fast\Random;
  5. use \think\Log;
  6. use Redis;
  7. use app\common\library\Sms as Smslib;
  8. /**
  9. * 首页接口
  10. */
  11. class Index extends Api
  12. {
  13. protected $noNeedLogin = ['index','contactus','tcpTest','getAppShare','getWebsiteInfo','getUserCharmRankList',
  14. 'getPartyHotList','searchUsers','getInviteCode','getEdition','getInviteImg','getWebsiteInfoForMini','getBankList',
  15. 'getSwitch','ageList','starList','bannerList'];
  16. protected $noNeedRight = ['*'];
  17. /**
  18. * 首页
  19. *
  20. */
  21. public function index()
  22. {
  23. // 强制关闭需要退出正在房间的用户
  24. $tenim = new \app\api\controller\Tenim();
  25. $tenim->outMemberFromRoom(4);
  26. $this->success('请求成功');
  27. }
  28. // /**
  29. // * 生成不重复的随机数字字母组合
  30. // */
  31. // function getUinqueNo($length = 8) {
  32. // $newid = Random::build("alnum",$length);
  33. //// if(in_array($newid,$nos)) {
  34. //// $this->getUinqueNo(8);
  35. //// }
  36. // return $newid;
  37. // }
  38. /**
  39. * 获取用户协议等
  40. */
  41. public function getWebsiteInfo() {
  42. $params = $this->request->request("params"); //内容
  43. if($params == "boxGiftLogo") {
  44. echo $this->success("获取成功!",$this->httpurl(config("site.".$params)));
  45. exit;
  46. }
  47. echo "<html><body>";
  48. echo config("site.".$params);
  49. echo "</body></html>";exit;
  50. }
  51. /**
  52. * 获取用户协议等 小程序
  53. */
  54. public function getWebsiteInfoForMini() {
  55. $params = $this->request->request("params"); //内容
  56. $res = config("site.".$params);
  57. if($params == "boxGiftLogo") $res = $this->httpurl(config("site.".$params));
  58. $this->success("获取成功!",$res);
  59. }
  60. /**
  61. * 联系我们
  62. */
  63. public function contactus() {
  64. $list = \app\common\model\Config::where(["group"=>"basic","name"=>["in",["email","mobile"]]])->select();
  65. $data = [];
  66. foreach($list as $k => $v) {
  67. $v["name"] == "email" && $data["email"] = $v["value"];
  68. $v["name"] == "mobile" && $data["mobile"] = $v["value"];
  69. }
  70. $this->success("获取成功!",$data);
  71. }
  72. /*
  73. * 获取系统消息列表
  74. */
  75. public function getMessage() {
  76. $page = $this->request->request('page',1); // 分页
  77. $pageNum = $this->request->request('pageNum',10); // 分页
  78. // 分页搜索构建
  79. $pageStart = ($page-1)*$pageNum;
  80. $flag = $this->request->request("flag",1,"intval"); //标识:1=只取一条,0=全部
  81. $user_id = $this->auth->id;
  82. $obj = \app\common\model\Message::where(["user_id"=>$user_id])->order("createtime","desc")->limit($pageStart,$pageNum);
  83. if($flag == 1) {
  84. $list = $obj->find();
  85. $list || $list = [];
  86. $list && $list["createtime"] = $this->get_last_time($list["createtime"]);
  87. } else {
  88. $list = $obj->select();
  89. if($list) foreach($list as $k => &$v) {
  90. $v["createtime"] = $this->get_last_time($v["createtime"]);
  91. }
  92. }
  93. $this->success("获取成功!",$list);
  94. }
  95. /**
  96. * 删除系统消息
  97. */
  98. public function delMessage() {
  99. $id = $this->request->request("id",0,"intval"); //消息ID
  100. if($id <= 0) {
  101. $this->error("参数传入错误!");
  102. }
  103. $res = \app\common\model\Message::where(["id"=>$id,"user_id"=>$this->auth->id])->delete();
  104. if($res) {
  105. $this->success("删除成功!");
  106. } else {
  107. $this->error("删除失败!");
  108. }
  109. }
  110. /**
  111. * 获取主播魅力值排行
  112. */
  113. public function getUserCharmRankList() {
  114. $time = $this->request->request("time",0,"intval"); //时间筛选 1=小时榜,2=今日榜,3=本周榜,4=月榜
  115. if(!in_array($time,[1,2,3,4])) {
  116. $this->error("参数传入错误!");
  117. }
  118. $hour = strtotime(date("Y-m-d H:00:00"));
  119. $today = strtotime(date("Y-m-d 00:00:00"));
  120. $weekend = strtotime('monday this week');
  121. // $weekend = mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"));
  122. $month = strtotime(date("Y-m-01 00:00:00"));
  123. // 剩余时间
  124. $thistime = time();
  125. switch ($time) {
  126. case 1:
  127. $redtime = 3600-($thistime - $hour);
  128. break;
  129. case 2:
  130. $redtime = 3600*24-($thistime - $today);
  131. break;
  132. case 3:
  133. $redtime = 3600*24*7-($thistime - $weekend);
  134. break;
  135. case 4:
  136. $monthend = mktime(23,59,59,date("m"),date("t"),date("Y"));
  137. $redtime = ($monthend - $month)-($thistime - $month);
  138. break;
  139. }
  140. $timeArr = [1=>$hour,2=>$today,3=>$weekend,4=>$month];
  141. $where = [];
  142. $where["a.createtime"] = ["gt",$timeArr[$time]];
  143. $list = \app\common\model\UserCharmRank::alias("a")
  144. ->field("p.id,sum(a.charm) as charm,u.avatar,u.nickname,u.gender,u.level,u.is_live")
  145. ->where($where)
  146. ->join("hx_user u","u.id = a.user_id")
  147. ->join("hx_party p","p.user_id = a.user_id")
  148. ->group("a.user_id")
  149. ->order("charm","desc")
  150. ->limit(100)
  151. ->select();
  152. $data = [];
  153. $data["redtime"] = $redtime;
  154. $data["data"] = $list;
  155. $this->success("获取成功!",$data);
  156. }
  157. /**
  158. * 获取派对热度排序
  159. */
  160. public function getPartyHotList() {
  161. // 剩余时间
  162. $thistime = time();
  163. $hour = strtotime(date("Y-m-d H:00:00"));
  164. $redtime = 3600-($thistime - $hour);
  165. $where = [];
  166. $where["a.createtime"] = ["gt",$hour];
  167. $where["p.room_type"] = 1;
  168. $list = \app\common\model\PartyHot::alias("a")
  169. ->field("sum(a.hot) as hot,p.id,u.avatar,p.party_name,p.party_logo")
  170. ->where($where)
  171. ->join("hx_party p","p.id = a.party_id")
  172. ->join("hx_user u","u.id = p.user_id")
  173. ->group("a.party_id")
  174. ->order("hot","desc")
  175. ->limit(100)
  176. ->select();
  177. $data = [];
  178. $data["redtime"] = $redtime;
  179. $data["data"] = $list;
  180. $this->success("获取成功!",$data);
  181. }
  182. /**
  183. * 首页搜索
  184. */
  185. public function searchUsers() {
  186. $search = $this->request->request("search"); //关键词筛选
  187. if(!$search) {
  188. $this->error("请输入搜索内容!");
  189. }
  190. // 搜索派对
  191. global $whereOr;
  192. $where = [];
  193. $whereOr["party_id"] = $search;
  194. $whereOr["party_name"] = ["like","%$search%"];
  195. $where["room_type"] = 1;
  196. $partyList = \app\common\model\Party::field("id,party_logo,party_id,party_name")
  197. ->where($where)
  198. ->where(function ($query) {
  199. global $whereOr;
  200. $query->whereOr($whereOr);
  201. })->order("party_hot","desc")->select();
  202. // 搜索直播间
  203. global $whereOrlive;
  204. $where = [];
  205. $whereOrlive["party_id"] = $search;
  206. $whereOrlive["party_name"] = ["like","%$search%"];
  207. $where["room_type"] = 2;
  208. $liveList = \app\common\model\Party::field("id,party_logo,party_id,party_name")
  209. ->where($where)
  210. ->where(function ($query) {
  211. global $whereOrlive;
  212. $query->whereOr($whereOrlive);
  213. })
  214. ->order("party_hot","desc")->select();
  215. // 相关用户
  216. $where = [];
  217. $where["a.nickname"] = ["like","%$search%"];
  218. $where["a.u_id"] = $search;
  219. $userList = \app\common\model\User::alias("a")->field("id,avatar,nickname,u_id,f.fans")
  220. ->join("hx_view_fans f","f.user_id = a.id","left")
  221. ->order("a.is_online,a.noble,a.level")
  222. ->whereOr($where)->select();
  223. $res = [];
  224. $res["partylist"] = $partyList;
  225. $res["livelist"] = $liveList;
  226. $res["userlist"] = $userList;
  227. $this->success("获取成功!",$res);
  228. }
  229. /**
  230. * 获取下载二维码和邀请码
  231. */
  232. public function getInviteCode() {
  233. // 获取二维码
  234. $host = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"];
  235. $qrcode = $this->httpurl($host.config("site.qrcode"));
  236. $miniqrcode = $this->httpurl($host.config("site.miniqrcode"));
  237. // 获取用户邀请码
  238. $inviteCode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  239. $downlowdLink = $host."/index/index/appJump?t=wlt".rand(10,999).Random::alpha(8);
  240. $this->success("获取成功!",["qrcode"=>$qrcode,"miniqrcode"=>$miniqrcode,"inviteCode"=>$inviteCode,"downlowdLink"=>$downlowdLink]);
  241. }
  242. /**
  243. * 获取app分享海报
  244. */
  245. public function getAppShare() {
  246. $this->success("获取成功!",["url"=>$this->httpurl(config("site.appShare"))]);
  247. }
  248. /**
  249. * 获取版本更新信息
  250. */
  251. public function getEdition() {
  252. // 获取二维码
  253. $is_force = config("site.is_force");
  254. $apkUrl = config("site.apkUrl");
  255. $apkName = config("site.apkName");
  256. $desc = config("site.desc");
  257. $versionCode = config("site.versionCode");
  258. $this->success("获取成功!",["versionCode"=>$versionCode,"isForceUpdate"=>$is_force,"apkUrl"=>$apkUrl,"apkName"=>$apkName,"desc"=>$desc]);
  259. }
  260. /**
  261. * 获取邀请图片
  262. */
  263. public function getInviteImg() {
  264. $plat = $this->request->request("plat",1); //平台:1=小程序,2=app
  265. if(!in_array($plat,[1,2])) $this->error("参数错误");
  266. // 获取用户的邀请码
  267. $invitecode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  268. // 文字图片合成
  269. $bigImgPath = $this->httpurlLocal('/assets/img/inviteimg.jpeg');
  270. $img = imagecreatefromstring(file_get_contents($bigImgPath));
  271. //字体文件
  272. $font = realpath('./assets/fonts/lato/lato-black.ttf');
  273. //字体颜色(RGB)
  274. $black = imagecolorallocate($img, 217, 76, 41);
  275. //字体大小
  276. $fontSize = 30;
  277. //旋转角度
  278. $circleSize = 0;
  279. //左边距
  280. $left = 275;
  281. //上边距
  282. $top = 540;
  283. imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $invitecode);
  284. $filename = date("YmdH").".jpeg";
  285. $path = "/uploads/qrcode/".$filename;
  286. $file = $_SERVER['DOCUMENT_ROOT'] . $path;//打开文件准备写入
  287. list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
  288. switch ($bgType) {
  289. case 1://gif
  290. header('Content-Type:image/gif');
  291. imagegif($img,$file);
  292. break;
  293. case 2://jpg
  294. header('Content-Type:image/jpg');
  295. imagejpeg($img,$file);
  296. break;
  297. case 3://jpg
  298. header('Content-Type:image/png');
  299. imagepng($img,$file);
  300. break;
  301. default:
  302. break;
  303. }
  304. //销毁照片
  305. imagedestroy($img);
  306. // 图片和二维码合成
  307. $qrcode = $plat == 1 ? config("site.miniqrcode"):config("site.qrcode");
  308. $background = $file;
  309. $target = $this->httpurl($qrcode);
  310. $background_iamge = imagecreatefromstring(file_get_contents($background));
  311. $target_image = imagecreatefromstring(file_get_contents($target));
  312. list($target_width, $target_height, $target_type) = getimagesize($target);
  313. imagecopymerge($background_iamge , $target_image , 250, 700, 0, 0, $target_width, $target_height, 100);
  314. list($background_width, $background_height, $background_type) = getimagesize($background);
  315. switch ($background_type) {
  316. case 1://gif
  317. header('Content-Type:image/gif');
  318. imagegif($background_iamge,$file);
  319. break;
  320. case 2://jpg
  321. header('Content-Type:image/jpg');
  322. imagejpeg($background_iamge,$file);
  323. break;
  324. case 3://jpg
  325. header('Content-Type:image/png');
  326. imagepng($background_iamge,$file);
  327. break;
  328. default:
  329. break;
  330. }
  331. $savepath = $this->httpurlLocal($path);
  332. $this->success("获取成功!",$savepath);
  333. }
  334. /**
  335. * 获取银行列表
  336. */
  337. public function getBankList() {
  338. $this->success("获取成功!",["banklist"=>\app\common\model\Bank::select()]);
  339. }
  340. /**
  341. * 获取开关配置
  342. */
  343. public function getSwitch() {
  344. $this->success("获取成功!",["switch"=>config("site.switch")]);
  345. }
  346. /**
  347. * 评论时间转换
  348. * @param null $time
  349. * @return false|string
  350. */
  351. private function get_last_time($time = NULL) {
  352. $text = '';
  353. $time = $time === NULL || $time > time() ? time() : intval($time);
  354. $t = time() - $time; //时间差 (秒)
  355. $y = date('Y', $time)-date('Y', time());//是否跨年
  356. switch($t){
  357. case $t == 0:
  358. $text = '刚刚';
  359. break;
  360. case $t < 60:
  361. $text = $t . '秒前'; // 一分钟内
  362. break;
  363. case $t < 60 * 60:
  364. $text = floor($t / 60) . '分钟前'; //一小时内
  365. break;
  366. case $t < 60 * 60 * 24:
  367. $text = floor($t / (60 * 60)) . '小时前'; // 一天内
  368. break;
  369. case $t < 60 * 60 * 24 * 3:
  370. $text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
  371. break;
  372. case $t < 60 * 60 * 24 * 30:
  373. $text = date('m月d日 H:i', $time); //一个月内
  374. break;
  375. case $t < 60 * 60 * 24 * 365&&$y==0:
  376. $text = date('m月d日', $time); //一年内
  377. break;
  378. default:
  379. $text = date('Y年m月d日', $time); //一年以前
  380. break;
  381. }
  382. return $text;
  383. }
  384. /**
  385. * 年龄段列表
  386. * @return void
  387. */
  388. public function ageList()
  389. {
  390. try {
  391. $field = 'id,name';
  392. $where['status'] = 1;
  393. $result = model('Age')->field($field)->where($where)->order('weigh asc')->select();
  394. $this->success('获取成功',$result);
  395. } catch (Exception $e) {
  396. $this->error($e->getMessage());
  397. }
  398. }
  399. /**
  400. * 星座列表
  401. * @return void
  402. */
  403. public function starList()
  404. {
  405. try {
  406. $field = 'id,name,image';
  407. $where['status'] = 1;
  408. $result = model('Constellation')->field($field)->where($where)->order('weigh asc')->select();
  409. if (!$result) {
  410. $result = list_domain_image($result,['image']);
  411. }
  412. $this->success('获取成功',$result);
  413. } catch (Exception $e) {
  414. $this->error($e->getMessage());
  415. }
  416. }
  417. /**
  418. * 星座列表
  419. * @return void
  420. */
  421. public function bannerList()
  422. {
  423. try {
  424. $field = 'id,title,image';
  425. $where['status'] = 1;
  426. $result = model('Banner')->field($field)->where($where)->order('weigh asc')->select();
  427. if (!$result) {
  428. $result = list_domain_image($result,['image']);
  429. }
  430. $this->success('获取成功',$result);
  431. } catch (Exception $e) {
  432. $this->error($e->getMessage());
  433. }
  434. }
  435. }