Userintro.php 5.9 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. //生成邀请码二维码图片
  14. public function inviteimage($introcode) {
  15. // $params['text'] = config('app_download_url') . '/index/index/appdownload';
  16. $params['text'] = config('app_download_url') . '/?code='.$introcode;
  17. $qrcode_service = \addons\qrcode\library\Service::qrcode($params);
  18. // $mimetype = 'image/png';
  19. // $response = Response::create()->header("Content-Type", $mimetype);
  20. // 直接显示二维码
  21. // header('Content-Type: ' . $qrcode_service->getContentType());
  22. // $response->content($qrcode_service->writeString());
  23. $qrcodePath = ROOT_PATH . 'public/uploads/qrcode/';
  24. if (!is_dir($qrcodePath)) {
  25. @mkdir($qrcodePath);
  26. }
  27. if (is_really_writable($qrcodePath)) {
  28. $filename = md5(implode('', $params)) . '.png';
  29. $filePath = $qrcodePath . $filename;
  30. $qrcode_service->writeFile($filePath);
  31. }
  32. return '/uploads/qrcode/' . $filename;
  33. }
  34. //生成视频分享海报
  35. public function shareposter() {
  36. $inviteimage = $this->inviteimage($this->auth->introcode);
  37. $data = [
  38. [
  39. "left"=> "140px",
  40. "top"=> "120px",
  41. "type"=> "img",
  42. "width"=> "50px",
  43. "height"=> "50px",
  44. "src"=> localpath_to_netpath($this->auth->avatar)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  45. ],
  46. [
  47. "left"=> "95px",
  48. "top"=> "190px",
  49. "type"=> "nickname",
  50. "width"=> "166px",
  51. "height"=> "38px",
  52. "size"=> "11px",
  53. "color"=> "#FFFFFF",
  54. "content" => '这里真心不错,推荐你来',
  55. ],
  56. [
  57. "left"=> "105px",
  58. "top"=> "400px",
  59. "type"=> "nickname",
  60. "width"=> "166px",
  61. "height"=> "38px",
  62. "size"=> "11px",
  63. "color"=> "#333333",
  64. "content" => '邀请码:'.$this->auth->introcode,
  65. ],
  66. [
  67. "left"=> "100px",
  68. "top"=> "265px",
  69. "type"=> "img",
  70. "width"=> "130px",
  71. "height"=> "130px",
  72. "src"=> httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  73. ],
  74. ];
  75. $data = json_encode($data, 320);
  76. $poster = [
  77. 'id' => 1,
  78. 'title' => '测试',
  79. 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
  80. 'bg_image' => '/assets/img/posteruserbg.png',
  81. 'data' => $data,
  82. 'status' => 'normal',
  83. 'weigh' => 0,
  84. 'createtime' => 1653993709,
  85. 'updatetime' => 1653994259,
  86. ];
  87. $image = new \addons\poster\library\Image();
  88. $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
  89. if (!$imgurl) {
  90. $this->error('生成海报出错');
  91. }
  92. $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
  93. //echo '<html><body><img src="'.$imgurl.'"></body></html>';
  94. $this->success('', $imgurl);
  95. }
  96. //我邀请的人列表
  97. public function myintro_list(){
  98. $list = Db::name('user')->field('id,mobile,username,nickname,avatar,createtime')->where('intro_uid',$this->auth->id)->autopage()->select();
  99. $list = list_domain_image($list,['avatar']);
  100. $this->success('success',$list);
  101. }
  102. //邀请页多个信息
  103. public function introsite_info(){
  104. //本周
  105. $thisweek_start = strtotime(date('Y-m-d')) - ((date('w')==0?7:date('w'))-1)*86400;
  106. $thisweek_end = $thisweek_start + 604799;
  107. //上周
  108. $lastweek_start = $thisweek_start - 604800;
  109. $lastweek_end = $thisweek_end - 604800;
  110. //本周邀请人数
  111. $intro_num_thisweek = Db::name('user')->where('intro_uid',$this->auth->id)->where('createtime','BETWEEN',[$thisweek_start,$thisweek_end])->count();
  112. //上周邀请人数
  113. $intro_num_lastweek = Db::name('user')->where('intro_uid',$this->auth->id)->where('createtime','BETWEEN',[$lastweek_start,$lastweek_end])->count();
  114. //总邀请人数
  115. $intro_num_all = Db::name('user')->where('intro_uid',$this->auth->id)->count();
  116. //本周奖励
  117. $money_sum_thisweek = Db::name('user_money_log')->where(['user_id'=>$this->auth->id,'log_type'=>63,'createtime'=>['BETWEEN',[$thisweek_start,$thisweek_end]]])->sum('change_value');
  118. //上周奖励
  119. $money_sum_lastweek = Db::name('user_money_log')->where(['user_id'=>$this->auth->id,'log_type'=>63,'createtime'=>['BETWEEN',[$lastweek_start,$lastweek_end]]])->sum('change_value');
  120. //我邀请的人
  121. $user_list = Db::name('user')->field('id,username,nickname,mobile,avatar,createtime')->where('intro_uid',$this->auth->id)->limit(3)->select();
  122. $rs = [
  123. 'introsite_activeinfo' => config('site.introsite_activeinfo'),
  124. 'introsite_introrule' => config('site.introsite_introrule'),
  125. 'introcode' => $this->auth->introcode,
  126. 'user_list' => $user_list,
  127. 'money_sum_thisweek' => $money_sum_thisweek,
  128. 'money_sum_lastweek' => $money_sum_lastweek,
  129. 'intro_num_thisweek' => $intro_num_thisweek,
  130. 'intro_num_lastweek' => $intro_num_lastweek,
  131. 'intro_num_all' => $intro_num_all,
  132. ];
  133. $this->success('success',$rs);
  134. }
  135. }