Userintro.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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/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 myprofit(){
  97. //今日
  98. $start = strtotime(date('Y-m-d'));
  99. $end = $start + 86399;
  100. //收益type
  101. $profit_type = [21,22,23,52,54,56];
  102. //今日收益
  103. $map = [
  104. 'log_type' => ['IN',$profit_type],
  105. 'user_id' => $this->auth->id,
  106. 'createtime' => ['between',[$start,$end]],
  107. ];
  108. $today_profit = Db::name('user_money_log')->where($map)->sum('change_value');
  109. //今日视频时长
  110. $map = [
  111. 'user_id|to_user_id' => $this->auth->id,
  112. 'createtime' => ['between',[$start,$end]],
  113. ];
  114. $today_video_min = Db::name('user_match_video_log')->where($map)->count();
  115. //今日语音时长
  116. $map = [
  117. 'user_id|to_user_id' => $this->auth->id,
  118. 'createtime' => ['between',[$start,$end]],
  119. ];
  120. $today_audio_min = Db::name('user_match_audio_log')->where($map)->count();
  121. //本周收益
  122. $week_start = strtotime(date('Y-m-d')) - ((date('w')==0?7:date('w'))-1)*86400;
  123. $week_end = $week_start + 604799;
  124. $map = [
  125. 'log_type' => ['IN',$profit_type],
  126. 'user_id' => $this->auth->id,
  127. 'createtime' => ['between',[$week_start,$week_end]],
  128. ];
  129. $week_profit = Db::name('user_money_log')->where($map)->sum('change_value');
  130. //我的累计收益
  131. $map = [
  132. 'log_type' => ['IN',$profit_type],
  133. 'user_id' => $this->auth->id,
  134. ];
  135. $all_profit = Db::name('user_money_log')->where($map)->sum('change_value');
  136. //我的邀请
  137. $my_intro_number = Db::name('user')->where('intro_uid',$this->auth->id)->count('id');
  138. $result = [
  139. 'avatar' => $this->auth->avatar,
  140. 'nickname' => $this->auth->nickname,
  141. 'username' => $this->auth->username,
  142. 'today_profit' => $today_profit,
  143. 'today_video_min' => $today_video_min,
  144. 'today_audio_min' => $today_audio_min,
  145. 'week_profit' => $week_profit,
  146. 'all_profit' => $all_profit,
  147. 'my_intro_number' => $my_intro_number,
  148. ];
  149. $this->success('success',$result);
  150. }
  151. //我邀请的,成员今日收益
  152. public function myintro(){
  153. $map = [
  154. 'intro_uid' => $this->auth->id,
  155. ];
  156. $list = Db::name('user')->field('id,nickname,username,avatar')->where($map)->page($this->page,$this->listrow)->select();
  157. $rs = [];
  158. foreach($list as $key => $user){
  159. $rs[] = $this->profit($user);
  160. }
  161. //dump($rs);
  162. $this->success('success',$rs);
  163. }
  164. //收益数据
  165. private function profit($userinfo){
  166. $uid = $userinfo['id'];
  167. //今日
  168. $start = strtotime(date('Y-m-d'));
  169. $end = $start + 86399;
  170. //收益type
  171. $profit_type = [21,22,23,52,54,56];
  172. //今日收益
  173. $map = [
  174. 'log_type' => ['IN',$profit_type],
  175. 'user_id' => $uid,
  176. 'createtime' => ['between',[$start,$end]],
  177. ];
  178. $today_profit = Db::name('user_money_log')->where($map)->sum('change_value');
  179. //今日视频时长
  180. $map = [
  181. 'user_id|to_user_id' => $uid,
  182. 'createtime' => ['between',[$start,$end]],
  183. ];
  184. $today_video_min = Db::name('user_match_video_log')->where($map)->count('id');
  185. //今日语音时长
  186. $map = [
  187. 'user_id|to_user_id' => $uid,
  188. 'createtime' => ['between',[$start,$end]],
  189. ];
  190. $today_audio_min = Db::name('user_match_audio_log')->where($map)->count('id');
  191. //本周收益
  192. $week_start = strtotime(date('Y-m-d')) - ((date('w')==0?7:date('w'))-1)*86400;
  193. $week_end = $week_start + 604799;
  194. $map = [
  195. 'log_type' => ['IN',$profit_type],
  196. 'user_id' => $uid,
  197. 'createtime' => ['between',[$week_start,$week_end]],
  198. ];
  199. $week_profit = Db::name('user_money_log')->where($map)->sum('change_value');
  200. $result = [
  201. 'today_profit' => $today_profit,
  202. 'today_video_min' => $today_video_min,
  203. 'today_audio_min' => $today_audio_min,
  204. 'week_profit' => $week_profit,
  205. ];
  206. $result = array_merge($result,$userinfo);
  207. return $result;
  208. }
  209. }