Userintro.php 5.8 KB

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