Index.php 5.1 KB

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