Userintro.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 mini_code($scene, $page_url)
  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' => $scene, //二维码传入参数
  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. ];
  30. $json = json_encode($data); //数组加密
  31. //$result = $this->api_notice_increment($URL, $json); //用CURL 进行POST请求
  32. $result = curl_post($URL,$json);
  33. $path = ROOT_PATH . 'public/uploads/minicode'; //ROOT_PATH 我使用的是TP5框架
  34. $path2 = '/uploads/minicode';
  35. if (!file_exists($path)) { //判断目录是否存在
  36. mkdir($path, 0777, true);
  37. }
  38. $path = $path . '/' . $scene . '.png'; //最后要写入的目录及文件名
  39. $path2 = $path2 . '/' . $scene . '.png'; //最后要写入的目录及文件名
  40. file_put_contents($path, $result);
  41. return $path2;
  42. }
  43. //生成视频分享海报
  44. public function shareposter() {
  45. $inviteimage = $this->mini_code($this->auth->id,'');
  46. $data = [
  47. [
  48. "left"=> "170px",
  49. "top"=> "500px",
  50. "type"=> "nickname",
  51. "width"=> "166px",
  52. "height"=> "38px",
  53. "size"=> "11px",
  54. "color"=> "#FFFFFF",
  55. "content" => '识别微信小程序',
  56. ],
  57. [
  58. "left"=> "170px",
  59. "top"=> "525px",
  60. "type"=> "nickname",
  61. "width"=> "166px",
  62. "height"=> "38px",
  63. "size"=> "11px",
  64. "color"=> "#FFFFFF",
  65. "content" => '更多游艇等你来~',
  66. ],
  67. [
  68. "left"=> "30px",
  69. "top"=> "460px",
  70. "type"=> "img",
  71. "width"=> "120px",
  72. "height"=> "120px",
  73. "src"=> httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  74. ],
  75. ];
  76. $data = json_encode($data, 320);
  77. $poster = [
  78. 'id' => 1,
  79. 'title' => '测试',
  80. 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
  81. 'bg_image' => '/assets/img/posteruserbg.png',
  82. 'data' => $data,
  83. 'status' => 'normal',
  84. 'weigh' => 0,
  85. 'createtime' => 1653993709,
  86. 'updatetime' => 1653994259,
  87. ];
  88. $image = new \addons\poster\library\Image();
  89. $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
  90. if (!$imgurl) {
  91. $this->error('生成海报出错');
  92. }
  93. $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
  94. //echo '<html><body><img src="'.$imgurl.'"></body></html>';
  95. $this->success('', $imgurl);
  96. }
  97. //我邀请的人列表
  98. public function myintro_list(){
  99. $list = Db::name('user')->field('id,mobile,username,nickname,avatar,createtime')->where('intro_uid',$this->auth->id)->autopage()->select();
  100. $list = list_domain_image($list,['avatar']);
  101. $this->success('success',$list);
  102. }
  103. //////////////////////////////////////////////////////////////////////
  104. //邀请页多个信息
  105. public function introsite_info(){
  106. //本周
  107. $thisweek_start = strtotime(date('Y-m-d')) - ((date('w')==0?7:date('w'))-1)*86400;
  108. $thisweek_end = $thisweek_start + 604799;
  109. //上周
  110. $lastweek_start = $thisweek_start - 604800;
  111. $lastweek_end = $thisweek_end - 604800;
  112. //本周邀请人数
  113. $intro_num_thisweek = Db::name('user')->where('intro_uid',$this->auth->id)->where('createtime','BETWEEN',[$thisweek_start,$thisweek_end])->count();
  114. //上周邀请人数
  115. $intro_num_lastweek = Db::name('user')->where('intro_uid',$this->auth->id)->where('createtime','BETWEEN',[$lastweek_start,$lastweek_end])->count();
  116. //总邀请人数
  117. $intro_num_all = Db::name('user')->where('intro_uid',$this->auth->id)->count();
  118. //本周奖励
  119. $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');
  120. //上周奖励
  121. $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');
  122. //我邀请的人
  123. $user_list = Db::name('user')->field('id,username,nickname,mobile,avatar,createtime')->where('intro_uid',$this->auth->id)->limit(3)->select();
  124. $rs = [
  125. 'introsite_activeinfo' => config('site.introsite_activeinfo'),
  126. 'introsite_introrule' => config('site.introsite_introrule'),
  127. 'introcode' => $this->auth->introcode,
  128. 'user_list' => $user_list,
  129. 'money_sum_thisweek' => $money_sum_thisweek,
  130. 'money_sum_lastweek' => $money_sum_lastweek,
  131. 'intro_num_thisweek' => $intro_num_thisweek,
  132. 'intro_num_lastweek' => $intro_num_lastweek,
  133. 'intro_num_all' => $intro_num_all,
  134. ];
  135. $this->success('success',$rs);
  136. }
  137. }