Userintro.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 用户推荐
  7. */
  8. class Userintro extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //生成海报
  13. public function createposter() {
  14. // $image = input('image', '', 'trim');
  15. // if (!$image) {
  16. // $this->error('您的网络开小差啦~');
  17. // }
  18. $image = config('site.intro_imges');
  19. $haibao = $this->haibao($this->auth->id,['invite_no'=>$this->auth->invite_no, 'background' => $image]);
  20. return $haibao;
  21. // $this->success('success', $haibao);
  22. }
  23. //海报
  24. public function haibao($player_id,$data){
  25. //下载页二维码,没必要保留
  26. $httpStr = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];
  27. $params = [
  28. 'text' => $httpStr.'/index/index/appdownload?code=' . $data['invite_no'],
  29. ];
  30. $qrCode = \addons\qrcode\library\Service::qrcode($params);
  31. $qrcode_path = 'uploads/hbplayer/'.date('Ymd');
  32. mk_dir($qrcode_path);
  33. $download_qrcode = $qrcode_path.'/download'.$player_id.'.png';
  34. $qrCode->writeFile($download_qrcode);
  35. //海报
  36. $result['url'] = $this->createhaibao($download_qrcode,$player_id,$data);
  37. $this->success('获取成功',$result);
  38. }
  39. public function createhaibao($download_qrcode,$player_id,$sub_data){
  40. //二维码
  41. $httpStr = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'];
  42. $download_qrcode= $httpStr.'/'.$download_qrcode;
  43. $data = [
  44. [
  45. "left" => "18px",
  46. "top" => "410px",
  47. "type" => "text",
  48. "width" => "80px",
  49. "height" => "24px",
  50. "size" => "16px",
  51. "color" => "#123354",
  52. "content" => 'K歌社交'
  53. ],
  54. [
  55. "left" => "18px",
  56. "top" => "445px",
  57. "type" => "text",
  58. "width" => "80px",
  59. "height" => "24px",
  60. "size" => "10px",
  61. "color" => "#123354",
  62. "content" => '更多金币奖励等你来拿'
  63. ],
  64. [
  65. "left" => "210px",
  66. "top" => "385px",
  67. "type" => "img",
  68. "width" => "95px",
  69. "height" => "95px",
  70. "src" => $download_qrcode//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  71. ]
  72. ];
  73. $data = json_encode($data, 320);
  74. $poster = [
  75. 'id' => $player_id,
  76. 'title' => 'K歌',
  77. 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
  78. 'bg_image' => $sub_data['background'] ? cdnurl($sub_data['background']) : '/assets/img/inviteposter.png',
  79. 'data' => $data,
  80. 'status' => 'normal',
  81. 'weigh' => 0,
  82. 'createtime' => 1653993709,
  83. 'updatetime' => 1653994259,
  84. ];
  85. $image = new \addons\poster\library\Image();
  86. $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
  87. if (!$imgurl) {
  88. $this->error('生成海报出错');
  89. }
  90. // $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
  91. return $httpStr.'/' . $imgurl;
  92. }
  93. //我邀请的人列表
  94. public function myintro_list(){
  95. $list = Db::name('user')->field('id,u_id,mobile,username,nickname,avatar,createtime')->where('pre_userid',$this->auth->id)->autopage()->select();
  96. $list = list_domain_image($list,['avatar']);
  97. $this->success('success',$list);
  98. }
  99. //邀请页多个信息
  100. public function introsite_info(){
  101. //本周
  102. $thisweek_start = strtotime(date('Y-m-d')) - ((date('w')==0?7:date('w'))-1)*86400;
  103. $thisweek_end = $thisweek_start + 604799;
  104. //上周
  105. $lastweek_start = $thisweek_start - 604800;
  106. $lastweek_end = $thisweek_end - 604800;
  107. //本周邀请人数
  108. $intro_num_thisweek = Db::name('user')->where('pre_userid',$this->auth->id)->where('createtime','BETWEEN',[$thisweek_start,$thisweek_end])->count();
  109. //上周邀请人数
  110. $intro_num_lastweek = Db::name('user')->where('pre_userid',$this->auth->id)->where('createtime','BETWEEN',[$lastweek_start,$lastweek_end])->count();
  111. //总邀请人数
  112. $intro_num_all = Db::name('user')->where('pre_userid',$this->auth->id)->count();
  113. //本周奖励
  114. $money_sum_thisweek = Db::name('user_money_log')->where(['user_id'=>$this->auth->id,'type'=>103,'createtime'=>['BETWEEN',[$thisweek_start,$thisweek_end]]])->sum('value');
  115. //上周奖励
  116. $money_sum_lastweek = Db::name('user_money_log')->where(['user_id'=>$this->auth->id,'type'=>103,'createtime'=>['BETWEEN',[$lastweek_start,$lastweek_end]]])->sum('value');
  117. //我邀请的人
  118. $user_list = Db::name('user')->field('id,u_id,username,nickname,mobile,avatar,createtime')->where('pre_userid',$this->auth->id)->limit(3)->select();
  119. $rs = [
  120. 'introsite_activeinfo' => config('site.introsite_activeinfo'),
  121. 'introsite_introrule' => config('site.introsite_introrule'),
  122. 'invite_no' => $this->auth->invite_no,
  123. 'user_list' => $user_list,
  124. 'money_sum_thisweek' => $money_sum_thisweek,
  125. 'money_sum_lastweek' => $money_sum_lastweek,
  126. 'intro_num_thisweek' => $intro_num_thisweek,
  127. 'intro_num_lastweek' => $intro_num_lastweek,
  128. 'intro_num_all' => $intro_num_all,
  129. ];
  130. $this->success('success',$rs);
  131. }
  132. }