Userintro.php 5.8 KB

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