Userintro.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. /*public function __construct(){
  13. parent::__construct();
  14. if($this->auth->group_id == 1){
  15. $this->error('无权进入');
  16. }
  17. }*/
  18. //生成我的视频海报
  19. //生成邀请码二维码图片
  20. public function introimage() {
  21. $params['text'] = config('h5register_url') .'?intro_no='. $this->auth->introcode;
  22. $qrcode_service = \addons\qrcode\library\Service::qrcode($params);
  23. $qrcodePath = ROOT_PATH . 'public/uploads/hbplayer/'.date('Ymd');
  24. if (!is_dir($qrcodePath)) {
  25. @mkdir($qrcodePath);
  26. }
  27. if (is_really_writable($qrcodePath)) {
  28. $filename = 'intro_'.$this->auth->introcode . '.png';
  29. $filePath = $qrcodePath .'/'. $filename;
  30. $qrcode_service->writeFile($filePath);
  31. }
  32. return '/uploads/hbplayer/'.date('Ymd') .'/'. $filename;
  33. }
  34. //生成视频分享海报
  35. public function shareposter() {
  36. $inviteimage = $this->introimage();
  37. $data = [
  38. [
  39. "left"=> "190px",
  40. "top"=> "320px",
  41. "type"=> "img",
  42. "width"=> "110px",
  43. "height"=> "110px",
  44. "src"=> httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  45. ],
  46. ];
  47. $data = json_encode($data, 320);
  48. $poster = [
  49. 'id' => $this->auth->id,
  50. 'title' => '珍友',
  51. 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
  52. 'bg_image' => '/assets/img/posteruserbg.png',
  53. 'data' => $data,
  54. 'status' => 'normal',
  55. 'weigh' => 0,
  56. 'createtime' => 1653993709,
  57. 'updatetime' => 1653994259,
  58. ];
  59. $image = new \addons\poster\library\Image();
  60. $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
  61. if (!$imgurl) {
  62. $this->error('生成海报出错');
  63. }
  64. $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
  65. //echo '<html><body><img src="'.$imgurl.'"></body></html>';
  66. $this->success('', $imgurl);
  67. }
  68. //申请绑定
  69. //申请绑定记录
  70. //日报
  71. public function ribao(){
  72. $authid = $this->auth->id;
  73. $result = [];
  74. //日期
  75. $today = date('Y-m-d');
  76. $startday = input('startday',$today);
  77. $starttime = strtotime($startday);
  78. $endtime = $starttime + 86399;
  79. //传入代理
  80. $down_all_id = input('down_all_id',0);
  81. //代理名
  82. $result['agentname'] = $this->auth->agentname ?: $this->auth->nickname;
  83. $result['yaoqingtime'] = $this->auth->yaoqingtime;
  84. $result['startday'] = $startday;
  85. //一级代理 下拉 可选二级代理
  86. $down_all = $this->select_agent();
  87. $result['down_all'] = $down_all;
  88. //dump($down_all);
  89. //确定收益统计范围
  90. if(!empty($down_all_id)){
  91. $downall_uid = Db::name('user')->where('intro_uid',$down_all_id)->column('id');//其下直推,A1下B0 或 B1下C1
  92. //$downall_uid[] = $down_all_id;
  93. }else{
  94. $down_uid = array_column($down_all,'id');
  95. //dump($down_uid);
  96. $downall_uid = Db::name('user')->where('intro_uid|agent_id','IN',$down_uid)->column('id');//其下直推+其下代理+代理下直推
  97. }
  98. //dump($downall_uid);
  99. //邀请奖励收益
  100. $recharge_sum = Db::name('user_agentjewel_log')->where('user_id','IN',$downall_uid)->where('log_type',51)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('change_value');
  101. $result['recharge_sum'] = $recharge_sum;
  102. //视频收益
  103. $video_sum = Db::name('user_match_video_log')->where('to_user_id','IN',$downall_uid)->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');
  104. $result['video_sum'] = $video_sum;
  105. //语音收益
  106. $audio_sum = Db::name('user_match_audio_log')->where('to_user_id','IN',$downall_uid)->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');
  107. $result['audio_sum'] = $audio_sum;
  108. //私信收益
  109. $typing_sum= Db::name('user_match_typing_log')->where('to_user_id','IN',$downall_uid)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('money');
  110. $result['typing_sum'] = $typing_sum;
  111. //礼物收益
  112. $gift_sum = Db::name('gift_user_typing')->where('user_to_id','IN',$downall_uid)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('getvalue');
  113. $result['gift_sum'] = $gift_sum;
  114. //总收益
  115. $result['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;
  116. //在线用户
  117. $active_num = Db::name('user_active')->where('user_id','IN',$downall_uid)->where('requesttime','BETWEEN',[$starttime,$endtime])->count();
  118. $result['active_num'] = $active_num;
  119. //收益用户
  120. $a = Db::name('user_agentjewel_log')->where('user_id','IN',$downall_uid)->where('log_type',51)->where('createtime','BETWEEN',[$starttime,$endtime])->distinct(true)->field('user_id')->select();
  121. $a1 = array_column($a,'user_id');
  122. $b = Db::name('user_match_video_log')->where('to_user_id','IN',$downall_uid)->where('updatetime','BETWEEN',[$starttime,$endtime])->distinct(true)->field('to_user_id')->select();
  123. $b1 = array_column($b,'to_user_id');
  124. $c = Db::name('user_match_audio_log')->where('to_user_id','IN',$downall_uid)->where('updatetime','BETWEEN',[$starttime,$endtime])->distinct(true)->field('to_user_id')->select();
  125. $c1 = array_column($c,'to_user_id');
  126. $d = Db::name('user_match_typing_log')->where('to_user_id','IN',$downall_uid)->where('createtime','BETWEEN',[$starttime,$endtime])->distinct(true)->field('to_user_id')->select();
  127. $d1 = array_column($d,'to_user_id');
  128. $e = Db::name('gift_user_typing')->where('user_to_id','IN',$downall_uid)->where('createtime','BETWEEN',[$starttime,$endtime])->distinct(true)->field('user_to_id')->select();
  129. $e1 = array_column($e,'user_to_id');
  130. // dump($a);
  131. // dump($a1);
  132. // dump($b);
  133. // dump($b1);
  134. // dump($c);
  135. // dump($c1);
  136. // dump($d);
  137. // dump($d1);
  138. // dump($e);
  139. // dump($e1);
  140. $abcde = array_merge(array_merge($a1,$b1,$c1),$d1,$e1);
  141. $shouyi_user = array_flip(array_flip($abcde));
  142. $result['shouyi_num'] = count($shouyi_user);
  143. $this->success(1,$result);
  144. }
  145. //下拉选择代理
  146. private function select_agent(){
  147. //一级代理下的二级代理
  148. $down_agent_users = [];
  149. if($this->auth->group_id == 3){
  150. $down_agent_users = Db::name('user')->field('id,nickname,agentname')->where('agent_id',$this->auth->id)->select();
  151. }
  152. //追加自己。二级代理的,就只有自己
  153. $self_agent = [['id'=>$this->auth->id,'nickname'=>$this->auth->nickname,'agentname'=>$this->auth->agentname]];
  154. $down_all = array_merge($self_agent,$down_agent_users);
  155. //没有代理名的用昵称
  156. foreach($down_all as $key => $val){
  157. $val['agentname'] = $val['agentname'] ?: $val['nickname'];
  158. unset($val['nickname']);
  159. $down_all[$key] = $val;
  160. }
  161. return $down_all;
  162. }
  163. //成员管理
  164. //成员收入
  165. //成员详情
  166. //邀请页
  167. //账户中心
  168. //账户明细
  169. //提现
  170. //提现记录
  171. //我邀请的人列表
  172. public function myintro_list(){
  173. $list = Db::name('user')->field('id,mobile,username,nickname,avatar,createtime')->where('intro_uid',$this->auth->id)->autopage()->select();
  174. $list = list_domain_image($list,['avatar']);
  175. $this->success('success',$list);
  176. }
  177. //邀请页多个信息
  178. public function introsite_info(){
  179. //本周
  180. $thisweek_start = strtotime(date('Y-m-d')) - ((date('w')==0?7:date('w'))-1)*86400;
  181. $thisweek_end = $thisweek_start + 604799;
  182. //上周
  183. $lastweek_start = $thisweek_start - 604800;
  184. $lastweek_end = $thisweek_end - 604800;
  185. //本周邀请人数
  186. $intro_num_thisweek = Db::name('user')->where('intro_uid',$this->auth->id)->where('createtime','BETWEEN',[$thisweek_start,$thisweek_end])->count();
  187. //上周邀请人数
  188. $intro_num_lastweek = Db::name('user')->where('intro_uid',$this->auth->id)->where('createtime','BETWEEN',[$lastweek_start,$lastweek_end])->count();
  189. //总邀请人数
  190. $intro_num_all = Db::name('user')->where('intro_uid',$this->auth->id)->count();
  191. //本周奖励
  192. $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');
  193. //上周奖励
  194. $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');
  195. //我邀请的人
  196. $user_list = Db::name('user')->field('id,username,nickname,mobile,avatar,createtime')->where('intro_uid',$this->auth->id)->limit(3)->select();
  197. $rs = [
  198. 'introcode' => $this->auth->introcode,
  199. 'user_list' => $user_list,
  200. 'money_sum_thisweek' => $money_sum_thisweek,
  201. 'money_sum_lastweek' => $money_sum_lastweek,
  202. 'intro_num_thisweek' => $intro_num_thisweek,
  203. 'intro_num_lastweek' => $intro_num_lastweek,
  204. 'intro_num_all' => $intro_num_all,
  205. ];
  206. $this->success('success',$rs);
  207. }
  208. }