Index.php 14 KB

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