Index.php 14 KB

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