Userintro.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. private function mini_code($scene, $page_url, $introcode)
  14. {
  15. $value = config('wxMiniProgram');
  16. $appid = $value['appid'];
  17. $secret = $value['secret'];
  18. $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $secret;
  19. $res = file_get_contents($url);
  20. $token = json_decode($res, true)['access_token'];
  21. $URL = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=' . $token;
  22. $data = [
  23. 'scene' => 'introcode='.$introcode, //二维码传入参数
  24. 'page' => $page_url, //扫码后进入页面
  25. 'env_version' => 'trial', //要打开的小程序版本。正式版为 "release",体验版为 "trial",开发版为 "develop"。默认是正式版。
  26. 'width' => 280, //二维码的宽度,单位 px,最小 280px,最大 1280px
  27. 'auto_color' => false, //自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调,默认 false
  28. 'is_hyaline' => false, //是否需要透明底色,为 true 时,生成透明底色的小程序
  29. 'check_path' => false,
  30. ];
  31. $json = json_encode($data); //数组加密
  32. //$result = $this->api_notice_increment($URL, $json); //用CURL 进行POST请求
  33. $result = curl_post($URL,$json);
  34. $path = ROOT_PATH . 'public/uploads/minicode'; //ROOT_PATH 我使用的是TP5框架
  35. $path2 = '/uploads/minicode';
  36. if (!file_exists($path)) { //判断目录是否存在
  37. mkdir($path, 0777, true);
  38. }
  39. $path = $path . '/' . $scene . '.png'; //最后要写入的目录及文件名
  40. $path2 = $path2 . '/' . $scene . '.png'; //最后要写入的目录及文件名
  41. file_put_contents($path, $result);
  42. return $path2;
  43. }
  44. //生成视频分享海报
  45. public function shareposter() {
  46. if($this->auth->group_id != 2){$this->error('你是不是来错地方了?');}
  47. $inviteimage = $this->mini_code($this->auth->id,'pages/index/index',$this->auth->username);
  48. $data = [
  49. [
  50. "left"=> "170px",
  51. "top"=> "500px",
  52. "type"=> "nickname",
  53. "width"=> "166px",
  54. "height"=> "38px",
  55. "size"=> "11px",
  56. "color"=> "#FFFFFF",
  57. "content" => '识别微信小程序',
  58. ],
  59. [
  60. "left"=> "170px",
  61. "top"=> "525px",
  62. "type"=> "nickname",
  63. "width"=> "166px",
  64. "height"=> "38px",
  65. "size"=> "11px",
  66. "color"=> "#FFFFFF",
  67. "content" => '更多游艇等你来~',
  68. ],
  69. [
  70. "left"=> "30px",
  71. "top"=> "460px",
  72. "type"=> "img",
  73. "width"=> "120px",
  74. "height"=> "120px",
  75. "src"=> httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  76. ],
  77. ];
  78. $data = json_encode($data, 320);
  79. $poster = [
  80. 'id' => 1,
  81. 'title' => '测试',
  82. 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
  83. 'bg_image' => '/assets/img/posteruserbg.png',
  84. 'data' => $data,
  85. 'status' => 'normal',
  86. 'weigh' => 0,
  87. 'createtime' => 1653993709,
  88. 'updatetime' => 1653994259,
  89. ];
  90. $image = new \addons\poster\library\Image();
  91. $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
  92. if (!$imgurl) {
  93. $this->error('生成海报出错');
  94. }
  95. $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
  96. //echo '<html><body><img src="'.$imgurl.'"></body></html>';
  97. $this->success('', $imgurl);
  98. }
  99. //我邀请的人列表
  100. public function myintro_list(){
  101. if($this->auth->group_id != 2){$this->error('你是不是来错地方了?');}
  102. $list = Db::name('user')->field('id,nickname,avatar,createtime')->where('intro_uid',$this->auth->id)->autopage()->select();
  103. $list = list_domain_image($list,['avatar']);
  104. $this->success('success',$list);
  105. }
  106. //////////////////////////////////////////////////////////////////////
  107. //邀请页多个信息
  108. public function introsite_info(){
  109. //本周
  110. $thisweek_start = strtotime(date('Y-m-d')) - ((date('w')==0?7:date('w'))-1)*86400;
  111. $thisweek_end = $thisweek_start + 604799;
  112. //上周
  113. $lastweek_start = $thisweek_start - 604800;
  114. $lastweek_end = $thisweek_end - 604800;
  115. //本周邀请人数
  116. $intro_num_thisweek = Db::name('user')->where('intro_uid',$this->auth->id)->where('createtime','BETWEEN',[$thisweek_start,$thisweek_end])->count();
  117. //上周邀请人数
  118. $intro_num_lastweek = Db::name('user')->where('intro_uid',$this->auth->id)->where('createtime','BETWEEN',[$lastweek_start,$lastweek_end])->count();
  119. //总邀请人数
  120. $intro_num_all = Db::name('user')->where('intro_uid',$this->auth->id)->count();
  121. //本周奖励
  122. $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');
  123. //上周奖励
  124. $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');
  125. //我邀请的人
  126. $user_list = Db::name('user')->field('id,username,nickname,mobile,avatar,createtime')->where('intro_uid',$this->auth->id)->limit(3)->select();
  127. $rs = [
  128. 'introsite_activeinfo' => config('site.introsite_activeinfo'),
  129. 'introsite_introrule' => config('site.introsite_introrule'),
  130. 'introcode' => $this->auth->introcode,
  131. 'user_list' => $user_list,
  132. 'money_sum_thisweek' => $money_sum_thisweek,
  133. 'money_sum_lastweek' => $money_sum_lastweek,
  134. 'intro_num_thisweek' => $intro_num_thisweek,
  135. 'intro_num_lastweek' => $intro_num_lastweek,
  136. 'intro_num_all' => $intro_num_all,
  137. ];
  138. $this->success('success',$rs);
  139. }
  140. }