Index.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 首页接口
  7. */
  8. class Index extends Api
  9. {
  10. protected $noNeedLogin = ['index'];
  11. protected $noNeedRight = ['*'];
  12. public function index(){
  13. echo 'apisuccess';
  14. exit;
  15. }
  16. public function fujin(){
  17. //是vip,且开启了隐身的,不能在内
  18. }
  19. public function tuijian(){}
  20. /**
  21. * 获取邀请图片
  22. */
  23. public function getInviteImg() {
  24. $plat = $this->request->request("plat",1); //平台:1=小程序,2=app
  25. if(!in_array($plat,[1,2])) $this->error("参数错误");
  26. // 获取用户的邀请码
  27. $invitecode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  28. // 文字图片合成
  29. $bigImgPath = $this->httpurlLocal('/assets/img/inviteimg.jpeg');
  30. $img = imagecreatefromstring(file_get_contents($bigImgPath));
  31. //字体文件
  32. $font = realpath('./assets/fonts/lato/lato-black.ttf');
  33. //字体颜色(RGB)
  34. $black = imagecolorallocate($img, 217, 76, 41);
  35. //字体大小
  36. $fontSize = 30;
  37. //旋转角度
  38. $circleSize = 0;
  39. //左边距
  40. $left = 275;
  41. //上边距
  42. $top = 540;
  43. imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $invitecode);
  44. $filename = date("YmdH").".jpeg";
  45. $path = "/uploads/qrcode/".$filename;
  46. $file = $_SERVER['DOCUMENT_ROOT'] . $path;//打开文件准备写入
  47. list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
  48. switch ($bgType) {
  49. case 1://gif
  50. header('Content-Type:image/gif');
  51. imagegif($img,$file);
  52. break;
  53. case 2://jpg
  54. header('Content-Type:image/jpg');
  55. imagejpeg($img,$file);
  56. break;
  57. case 3://jpg
  58. header('Content-Type:image/png');
  59. imagepng($img,$file);
  60. break;
  61. default:
  62. break;
  63. }
  64. //销毁照片
  65. imagedestroy($img);
  66. // 图片和二维码合成
  67. $qrcode = $plat == 1 ? config("site.miniqrcode"):config("site.qrcode");
  68. $background = $file;
  69. $target = $this->httpurl($qrcode);
  70. $background_iamge = imagecreatefromstring(file_get_contents($background));
  71. $target_image = imagecreatefromstring(file_get_contents($target));
  72. list($target_width, $target_height, $target_type) = getimagesize($target);
  73. imagecopymerge($background_iamge , $target_image , 250, 700, 0, 0, $target_width, $target_height, 100);
  74. list($background_width, $background_height, $background_type) = getimagesize($background);
  75. switch ($background_type) {
  76. case 1://gif
  77. header('Content-Type:image/gif');
  78. imagegif($background_iamge,$file);
  79. break;
  80. case 2://jpg
  81. header('Content-Type:image/jpg');
  82. imagejpeg($background_iamge,$file);
  83. break;
  84. case 3://jpg
  85. header('Content-Type:image/png');
  86. imagepng($background_iamge,$file);
  87. break;
  88. default:
  89. break;
  90. }
  91. $savepath = $this->httpurlLocal($path);
  92. $this->success("获取成功!",$savepath);
  93. }
  94. /**
  95. * 评论时间转换
  96. * @param null $time
  97. * @return false|string
  98. */
  99. private function get_last_time($time = NULL) {
  100. $text = '';
  101. $time = $time === NULL || $time > time() ? time() : intval($time);
  102. $t = time() - $time; //时间差 (秒)
  103. $y = date('Y', $time)-date('Y', time());//是否跨年
  104. switch($t){
  105. case $t == 0:
  106. $text = '刚刚';
  107. break;
  108. case $t < 60:
  109. $text = $t . '秒前'; // 一分钟内
  110. break;
  111. case $t < 60 * 60:
  112. $text = floor($t / 60) . '分钟前'; //一小时内
  113. break;
  114. case $t < 60 * 60 * 24:
  115. $text = floor($t / (60 * 60)) . '小时前'; // 一天内
  116. break;
  117. case $t < 60 * 60 * 24 * 3:
  118. $text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
  119. break;
  120. case $t < 60 * 60 * 24 * 30:
  121. $text = date('m月d日 H:i', $time); //一个月内
  122. break;
  123. case $t < 60 * 60 * 24 * 365&&$y==0:
  124. $text = date('m月d日', $time); //一年内
  125. break;
  126. default:
  127. $text = date('Y年m月d日', $time); //一年以前
  128. break;
  129. }
  130. return $text;
  131. }
  132. }