Index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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'];
  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. $host = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"];
  233. $qrcode = $this->httpurl($host.config("site.qrcode"));
  234. $miniqrcode = $this->httpurl($host.config("site.miniqrcode"));
  235. // 获取用户邀请码
  236. $inviteCode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  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. public function getEdition() {
  250. // 获取二维码
  251. $is_force = config("site.is_force");
  252. $apkUrl = config("site.apkUrl");
  253. $apkName = config("site.apkName");
  254. $desc = config("site.desc");
  255. $versionCode = config("site.versionCode");
  256. $this->success("获取成功!",["versionCode"=>$versionCode,"isForceUpdate"=>$is_force,"apkUrl"=>$apkUrl,"apkName"=>$apkName,"desc"=>$desc]);
  257. }
  258. /**
  259. * 获取邀请图片
  260. */
  261. public function getInviteImg() {
  262. $plat = $this->request->request("plat",1); //平台:1=小程序,2=app
  263. if(!in_array($plat,[1,2])) $this->error("参数错误");
  264. // 获取用户的邀请码
  265. $invitecode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  266. // 文字图片合成
  267. $bigImgPath = $this->httpurlLocal('/assets/img/inviteimg.jpeg');
  268. $img = imagecreatefromstring(file_get_contents($bigImgPath));
  269. //字体文件
  270. $font = realpath('./assets/fonts/lato/lato-black.ttf');
  271. //字体颜色(RGB)
  272. $black = imagecolorallocate($img, 217, 76, 41);
  273. //字体大小
  274. $fontSize = 30;
  275. //旋转角度
  276. $circleSize = 0;
  277. //左边距
  278. $left = 275;
  279. //上边距
  280. $top = 540;
  281. imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $invitecode);
  282. $filename = date("YmdH").".jpeg";
  283. $path = "/uploads/qrcode/".$filename;
  284. $file = $_SERVER['DOCUMENT_ROOT'] . $path;//打开文件准备写入
  285. list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
  286. switch ($bgType) {
  287. case 1://gif
  288. header('Content-Type:image/gif');
  289. imagegif($img,$file);
  290. break;
  291. case 2://jpg
  292. header('Content-Type:image/jpg');
  293. imagejpeg($img,$file);
  294. break;
  295. case 3://jpg
  296. header('Content-Type:image/png');
  297. imagepng($img,$file);
  298. break;
  299. default:
  300. break;
  301. }
  302. //销毁照片
  303. imagedestroy($img);
  304. // 图片和二维码合成
  305. $qrcode = $plat == 1 ? config("site.miniqrcode"):config("site.qrcode");
  306. $background = $file;
  307. $target = $this->httpurl($qrcode);
  308. $background_iamge = imagecreatefromstring(file_get_contents($background));
  309. $target_image = imagecreatefromstring(file_get_contents($target));
  310. list($target_width, $target_height, $target_type) = getimagesize($target);
  311. imagecopymerge($background_iamge , $target_image , 250, 700, 0, 0, $target_width, $target_height, 100);
  312. list($background_width, $background_height, $background_type) = getimagesize($background);
  313. switch ($background_type) {
  314. case 1://gif
  315. header('Content-Type:image/gif');
  316. imagegif($background_iamge,$file);
  317. break;
  318. case 2://jpg
  319. header('Content-Type:image/jpg');
  320. imagejpeg($background_iamge,$file);
  321. break;
  322. case 3://jpg
  323. header('Content-Type:image/png');
  324. imagepng($background_iamge,$file);
  325. break;
  326. default:
  327. break;
  328. }
  329. $savepath = $this->httpurlLocal($path);
  330. $this->success("获取成功!",$savepath);
  331. }
  332. /**
  333. * 获取银行列表
  334. */
  335. public function getBankList() {
  336. $this->success("获取成功!",["banklist"=>\app\common\model\Bank::select()]);
  337. }
  338. /**
  339. * 获取开关配置
  340. */
  341. public function getSwitch() {
  342. $this->success("获取成功!",["switch"=>config("site.switch")]);
  343. }
  344. /**
  345. * 评论时间转换
  346. * @param null $time
  347. * @return false|string
  348. */
  349. private function get_last_time($time = NULL) {
  350. $text = '';
  351. $time = $time === NULL || $time > time() ? time() : intval($time);
  352. $t = time() - $time; //时间差 (秒)
  353. $y = date('Y', $time)-date('Y', time());//是否跨年
  354. switch($t){
  355. case $t == 0:
  356. $text = '刚刚';
  357. break;
  358. case $t < 60:
  359. $text = $t . '秒前'; // 一分钟内
  360. break;
  361. case $t < 60 * 60:
  362. $text = floor($t / 60) . '分钟前'; //一小时内
  363. break;
  364. case $t < 60 * 60 * 24:
  365. $text = floor($t / (60 * 60)) . '小时前'; // 一天内
  366. break;
  367. case $t < 60 * 60 * 24 * 3:
  368. $text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
  369. break;
  370. case $t < 60 * 60 * 24 * 30:
  371. $text = date('m月d日 H:i', $time); //一个月内
  372. break;
  373. case $t < 60 * 60 * 24 * 365&&$y==0:
  374. $text = date('m月d日', $time); //一年内
  375. break;
  376. default:
  377. $text = date('Y年m月d日', $time); //一年以前
  378. break;
  379. }
  380. return $text;
  381. }
  382. }