Index.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Log;
  6. /**
  7. * 首页接口
  8. */
  9. class Index extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 获取视频第一针
  15. */
  16. public function getVideo() {
  17. $video = $this->request->request('video'); // 视频文件
  18. if(!$video) {
  19. $this->error(__('视频文件缺失!'));
  20. }
  21. $cover = 'uploads/video_cover/'.date('Ymd').date('His').rand(1000,9999).'.png';
  22. getVideoCover($video,0.1,$cover);
  23. $full_cover = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].'/'.$cover;
  24. if($full_cover) {
  25. $this->success("获取成功",$full_cover);
  26. } else {
  27. $this->error("网络错误,请稍后重试");
  28. }
  29. }
  30. /**
  31. * 首页
  32. *
  33. */
  34. public function index()
  35. {
  36. getVideoCover('/www/wwwroot/yanyuan.lanmaonet.com/public/assets/123.mp4',3,'uploads/ffmpeg_test.png');
  37. $this->success('请求成功');
  38. }
  39. /**
  40. * 获取版本更新信息
  41. */
  42. public function getEdition() {
  43. // 获取二维码
  44. $is_force = config("site.is_force");
  45. $apkUrl = config("site.apkUrl");
  46. $apkName = config("site.apkName");
  47. $desc = config("site.desc");
  48. $versionCode = config("site.versionCode");
  49. $this->success("获取成功!",["versionCode"=>$versionCode,"isForceUpdate"=>$is_force,"apkUrl"=>$apkUrl,"apkName"=>$apkName,"desc"=>$desc]);
  50. }
  51. /**
  52. * 获取网站配置信息
  53. */
  54. public function getWebsiteInfo() {
  55. $params = $this->request->request("params"); //内容
  56. $this->success("获取成功!",config("site.".$params));
  57. }
  58. /**
  59. * 获取省数据
  60. */
  61. public function getProvince() {
  62. $res = \app\common\model\Area::field("id,pid,name,level")->where(["pid"=>0])->select();
  63. $this->success('请求成功',$res);
  64. }
  65. /**
  66. * 获取市数据
  67. */
  68. public function getCity() {
  69. $province = $this->request->request('province'); // 省
  70. if (!$province) $this->error('参数缺失!');
  71. $res = \app\common\model\Area::field("id,pid,name,level")->where(["pid"=>$province])->select();
  72. $this->success('请求成功',$res);
  73. }
  74. /**
  75. * 获取区数据
  76. */
  77. public function getArea() {
  78. $city = $this->request->request('city'); // 市
  79. if (!$city) $this->error('参数缺失!');
  80. $res = \app\common\model\Area::field("id,pid,name,level")->where(["pid"=>$city])->select();
  81. $this->success('请求成功',$res);
  82. }
  83. /**
  84. * 根据生日获取年龄和星座
  85. */
  86. public function getAgeByBirthday() {
  87. $birthday = $this->request->request('birthday'); // 生日 格式:2011-04-31
  88. $signs = array( array('20' => '水瓶座'), array('19' => '双鱼座'), array('21' => '白羊座'), array('20' => '金牛座'), array('21' => '双子座'), array('22' => '巨蟹座'), array('23' => '狮子座'), array('23' => '处女座'), array('23' => '天秤座'), array('24' => '天蝎座'), array('22' => '射手座'), array('22' => '摩羯座'));
  89. if (!empty($birthday)) {
  90. $age = strtotime($birthday);
  91. if ($age === false) {
  92. $this->error("参数缺失!");
  93. }
  94. list($y1, $m1, $d1) = explode("-", date("Y-m-d", $age));
  95. list($y2, $m2, $d2) = explode("-", date("Y-m-d"), time());
  96. $age = $y2 - $y1;
  97. //下面是判断月份大小,如果只是逄年份的可以去掉,如果算上月份的话,比如:2000年4月1日,那算出来是16算,要到了4月,算出来才是17岁
  98. if ((int)($m2 . $d2) < (int)($m1 . $d1)) {
  99. $age -= 1;
  100. }
  101. //星座
  102. $key = (int)$m1 - 1;
  103. $startSign = array_keys($signs[$key]);
  104. $signName = array_values($signs[$key])[0];
  105. if ($d1 < $startSign) {
  106. $key = $m1 - 2 < 0 ? $m1 = 11 : $m1 -= 2;
  107. $startSign = array_keys($signs[$key]);
  108. $signName = array_values($signs[$key])[0];
  109. }
  110. if($age < 0) {
  111. $this->error("出生日期不能大于当前时间!");
  112. }
  113. $data = [];
  114. $data['age'] = $age;
  115. $data['signName'] = $signName;
  116. $this->success("获取成功!",$data);
  117. } else {
  118. $this->error("参数缺失!");
  119. }
  120. }
  121. /**
  122. * 获取期望对象列表
  123. */
  124. public function getExpect() {
  125. $this->success("获取成功!",\app\admin\model\website\Expect::order("weight","desc")->select());
  126. }
  127. /**
  128. * 获取爱好列表
  129. */
  130. public function getHobby() {
  131. $this->success("获取成功!",\app\admin\model\website\Hobby::order("weight","desc")->select());
  132. }
  133. /**
  134. * 获取职业列表
  135. */
  136. public function getProfession() {
  137. $this->success("获取成功!",\app\admin\model\website\Profession::order("weight","desc")->select());
  138. }
  139. /**
  140. * 获取收入列表
  141. */
  142. public function getIncome() {
  143. $this->success("获取成功!",\app\admin\model\website\Income::order("weight","desc")->select());
  144. }
  145. /**
  146. * 获取会员举报类型
  147. */
  148. public function getReportType() {
  149. $this->success("获取成功!",\app\admin\model\website\ReportType::order("weight","desc")->select());
  150. }
  151. /**
  152. * 获取音乐列表信息
  153. */
  154. public function getMusicInfo() {
  155. $this->success("获取成功!",\app\admin\model\website\Music::order("weight","desc")->select());
  156. }
  157. /**
  158. * 获取标签列表信息
  159. */
  160. public function getTagInfo() {
  161. $this->success("获取成功!",\app\admin\model\website\Tag::order("weight","desc")->select());
  162. }
  163. /**
  164. * 获取客服列表
  165. */
  166. public function getCsList() {
  167. $this->success("获取成功!",\app\admin\model\website\Kefu::order("weight","desc")->select());
  168. }
  169. /**
  170. * 获取邀请图片
  171. */
  172. public function getInviteImg() {
  173. // 获取用户的邀请码
  174. $invitecode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  175. // 文字图片合成
  176. $bigImgPath = httpurllocal('/assets/img/inviteimg.png');
  177. $img = imagecreatefrompng($bigImgPath);
  178. imagesavealpha($img, true);
  179. //字体文件
  180. $font = realpath('./assets/fonts/lato/lato-black.ttf');
  181. //字体颜色(RGB)
  182. $black = imagecolorallocate($img, 217, 76, 41);
  183. //字体大小
  184. $fontSize = 30;
  185. //旋转角度
  186. $circleSize = 0;
  187. //左边距
  188. $left = 383;
  189. //上边距
  190. $top = 680;
  191. imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $invitecode);
  192. $filename = date("YmdH").".jpeg";
  193. $path = "/uploads/qrcode/".$filename;
  194. $file = $_SERVER['DOCUMENT_ROOT'] . $path;//打开文件准备写入
  195. list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
  196. switch ($bgType) {
  197. case 1://gif
  198. header('Content-Type:image/gif');
  199. imagegif($img,$file);
  200. break;
  201. case 2://jpg
  202. header('Content-Type:image/jpg');
  203. imagejpeg($img,$file);
  204. break;
  205. case 3://jpg
  206. header('Content-Type:image/png');
  207. imagepng($img,$file);
  208. break;
  209. default:
  210. break;
  211. }
  212. //销毁照片
  213. imagedestroy($img);
  214. // 图片和二维码合成
  215. $qrcode = config("site.qrcode");
  216. $background = $file;
  217. $target = httpurl($qrcode);
  218. // $background_iamge = imagecreatefromstring(file_get_contents($background)); // 无透明度
  219. $background_iamge = imagecreatefrompng($background); // 保留背景的透明度
  220. imagesavealpha($background_iamge, true);
  221. $target_image = imagecreatefromstring(file_get_contents($target));
  222. list($target_width, $target_height, $target_type) = getimagesize($target);
  223. imagecopy($background_iamge , $target_image , 350, 850, 0, 0, $target_width, $target_height);
  224. list($background_width, $background_height, $background_type) = getimagesize($background);
  225. switch ($background_type) {
  226. case 1://gif
  227. header('Content-Type:image/gif');
  228. imagegif($background_iamge,$file);
  229. break;
  230. case 2://jpg
  231. header('Content-Type:image/jpg');
  232. imagejpeg($background_iamge,$file);
  233. break;
  234. case 3://jpg
  235. header('Content-Type:image/png');
  236. imagepng($background_iamge,$file);
  237. break;
  238. default:
  239. break;
  240. }
  241. // header("Content-type: image/png");
  242. // imagepng($background_iamge);exit;
  243. $savepath = httpurllocal($path);
  244. $this->success("获取成功!",$savepath);
  245. }
  246. /**
  247. * 获取邀请的用户
  248. */
  249. public function getInviteusers() {
  250. $user_list = \app\common\model\User::field('id,nickname,invite_time')->where(['pre_user_id'=>$this->auth->id])->select();
  251. if($user_list) foreach($user_list as $k => $v) {
  252. $user_list[$k]['invite_time'] = date('Y-m-d H:i:s',$v['invite_time']);
  253. }
  254. $this->success("获取成功!",$user_list);
  255. }
  256. /**
  257. * 获取累计邀请/邀请码等
  258. */
  259. public function getInviteCount() {
  260. $user_count = \app\common\model\User::where(['pre_user_id'=>$this->auth->id])->count("id");
  261. $invite_no = \app\common\model\User::where(['id'=>$this->auth->id])->value('invite_no');
  262. $this->success("获取成功!",['user_count'=>$user_count,'invite_no'=>$invite_no]);
  263. }
  264. }