Userintro.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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. public function introinfo(){
  20. $today = date('Y-m-d');
  21. $starttime = strtotime($today) - 86400;
  22. $endtime = $starttime + 86399;
  23. $zuori_count = Db::name('user')->where('intro_uid',$this->auth->id)->where('yaoqingtime','BETWEEN',[$starttime,$endtime])->count();
  24. $total_count = Db::name('user')->where('intro_uid',$this->auth->id)->count();
  25. $register_url = config('h5register_url') .'?intro_no='. $this->auth->introcode;
  26. $result = [
  27. 'zuori_count' => $zuori_count,
  28. 'total_count' => $total_count,
  29. 'register_url' => $register_url,
  30. ];
  31. $this->success(1,$result);
  32. }
  33. //生成视频分享海报
  34. public function shareposter() {
  35. $inviteimage = $this->introimage();
  36. $data = [
  37. [
  38. "left"=> "190px",
  39. "top"=> "320px",
  40. "type"=> "img",
  41. "width"=> "110px",
  42. "height"=> "110px",
  43. "src"=> httpurllocal($inviteimage)//"https://metavision.oss-cn-hongkong.aliyuncs.com/uploads/20220615/f00cb545deb4c4e7296f444239d83e84.jpg"
  44. ],
  45. ];
  46. $data = json_encode($data, 320);
  47. $poster = [
  48. 'id' => $this->auth->id,
  49. 'title' => '珍友',
  50. 'waittext' => '您的专属海报正在拼命生成中,请等待片刻...',
  51. 'bg_image' => '/assets/img/posteruserbg.png',
  52. 'data' => $data,
  53. 'status' => 'normal',
  54. 'weigh' => 0,
  55. 'createtime' => 1653993709,
  56. 'updatetime' => 1653994259,
  57. ];
  58. $image = new \addons\poster\library\Image();
  59. $imgurl = $image->createPosterImage($poster, $this->auth->getUser());
  60. if (!$imgurl) {
  61. $this->error('生成海报出错');
  62. }
  63. $imgurl = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"] . '/' . $imgurl;
  64. //echo '<html><body><img src="'.$imgurl.'"></body></html>';
  65. $this->success('', $imgurl);
  66. }
  67. //生成邀请码二维码图片
  68. private function introimage() {
  69. $params['text'] = config('h5register_url') .'?intro_no='. $this->auth->introcode;
  70. $qrcode_service = \addons\qrcode\library\Service::qrcode($params);
  71. $qrcodePath = ROOT_PATH . 'public/uploads/hbplayer/'.date('Ymd');
  72. if (!is_dir($qrcodePath)) {
  73. @mkdir($qrcodePath);
  74. }
  75. if (is_really_writable($qrcodePath)) {
  76. $filename = 'intro_'.$this->auth->introcode . '.png';
  77. $filePath = $qrcodePath .'/'. $filename;
  78. $qrcode_service->writeFile($filePath);
  79. }
  80. return '/uploads/hbplayer/'.date('Ymd') .'/'. $filename;
  81. }
  82. //账户中心 api/withdraw/config
  83. //提现 api/withdraw/withdraw
  84. //账户明细
  85. public function agentjewel_log(){
  86. $map = [
  87. 'user_id' => $this->auth->id,
  88. ];
  89. $list = Db::name('user_agentjewel_log')
  90. ->field('id,log_type,before,change_value,remain,remark,createtime')
  91. ->where($map)->order('id desc')->autopage()->select();
  92. $list = $this->list_appen_logtext($list);
  93. $this->success('success',$list);
  94. }
  95. //追加log_text
  96. private function list_appen_logtext($list){
  97. if(!empty($list)){
  98. $conf = config('wallet.logtype');
  99. foreach($list as $key => $val){
  100. $list[$key]['log_text'] = isset($conf[$val['log_type']]) ? $conf[$val['log_type']] : '';
  101. }
  102. }
  103. return $list;
  104. }
  105. //申请绑定查询
  106. public function intro_search(){
  107. $username = input('username',0);
  108. $user_info = Db::name('user')->field('id,username,group_id,nickname,avatar')->where('username',$username)->find();
  109. if(empty($user_info)){
  110. $this->error('不存在的用户');
  111. }
  112. $user_info = info_domain_image($user_info,['avatar']);
  113. $this->success(1,$user_info);
  114. }
  115. //申请绑定
  116. public function apply_intro(){
  117. $down_uid = input('search_uid',0);
  118. $images = input('images','');
  119. $remark = input('remark','');
  120. $where = [
  121. 'user_id' => $this->auth->id,
  122. 'down_uid' => $down_uid,
  123. 'status' => 0,
  124. ];
  125. $check = Db::name('user_intro_apply')->where($where)->find();
  126. if($check){
  127. $this->error('您上次的申请还在审核中');
  128. }
  129. $data = [
  130. 'user_id' => $this->auth->id,
  131. 'down_uid' => $down_uid,
  132. 'images' => $images,
  133. 'remark' => $remark,
  134. 'createtime'=> time(),
  135. ];
  136. Db::name('user_intro_apply')->insertGetId($data);
  137. $this->success('申请成功');
  138. }
  139. //申请绑定记录
  140. public function apply_intro_log(){
  141. $where = [
  142. 'user_id' => $this->auth->id,
  143. ];
  144. $list = Db::name('user_intro_apply')->alias('log')
  145. ->field('log.*,user.username,user.nickname,user.avatar')
  146. ->join('user','log.down_uid = user.id','LEFT')
  147. ->where($where)->autopage()->select();
  148. $list = list_domain_image($list,['avatar']);
  149. $this->success(1,$list);
  150. }
  151. //日报
  152. public function ribao(){
  153. $result = [];
  154. //日期
  155. $today = date('Y-m-d');
  156. $startday = input('startday',$today);
  157. $starttime = strtotime($startday);
  158. $endtime = $starttime + 86399;
  159. //传入代理
  160. $down_all_id = input('down_all_id',0);
  161. //代理名
  162. $result['agentname'] = $this->auth->agentname ?: $this->auth->nickname;
  163. $result['yaoqingtime'] = $this->auth->yaoqingtime;
  164. $result['startday'] = $startday;
  165. //一级代理 下拉 可选二级代理
  166. $down_all = $this->select_agent();
  167. $result['down_all'] = $down_all;
  168. //dump($down_all);
  169. //确定收益统计范围
  170. if(!empty($down_all_id)){
  171. $downall_uid = Db::name('user')->where('intro_uid',$down_all_id)->column('id');//其下直推,A1下B0+B1 或 B1下C1
  172. //$downall_uid[] = $down_all_id;
  173. }else{
  174. $down_uid = array_column($down_all,'id');
  175. //dump($down_uid);
  176. $downall_uid = Db::name('user')->where('intro_uid','IN',$down_uid)->column('id');//其下直推B0+代理下直推C1 或 C1
  177. }
  178. //dump($downall_uid);
  179. //邀请奖励收益
  180. $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');
  181. $result['recharge_sum'] = $recharge_sum;
  182. //视频收益
  183. $video_sum = Db::name('user_match_video_log')->where('to_user_id','IN',$downall_uid)->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');
  184. $result['video_sum'] = $video_sum;
  185. //语音收益
  186. $audio_sum = Db::name('user_match_audio_log')->where('to_user_id','IN',$downall_uid)->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');
  187. $result['audio_sum'] = $audio_sum;
  188. //私信收益
  189. $typing_sum= Db::name('user_match_typing_log')->where('to_user_id','IN',$downall_uid)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('money');
  190. $result['typing_sum'] = $typing_sum;
  191. //礼物收益
  192. $gift_sum = Db::name('gift_user_typing')->where('user_to_id','IN',$downall_uid)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('getvalue');
  193. $result['gift_sum'] = $gift_sum;
  194. //总收益
  195. $result['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;
  196. //在线用户
  197. $active_num = Db::name('user_active')->where('user_id','IN',$downall_uid)->where('requesttime','BETWEEN',[$starttime,$endtime])->count();
  198. $result['active_num'] = $active_num;
  199. //收益用户
  200. $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();
  201. $a1 = array_column($a,'user_id');
  202. $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();
  203. $b1 = array_column($b,'to_user_id');
  204. $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();
  205. $c1 = array_column($c,'to_user_id');
  206. $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();
  207. $d1 = array_column($d,'to_user_id');
  208. $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();
  209. $e1 = array_column($e,'user_to_id');
  210. // dump($a);
  211. // dump($a1);
  212. // dump($b);
  213. // dump($b1);
  214. // dump($c);
  215. // dump($c1);
  216. // dump($d);
  217. // dump($d1);
  218. // dump($e);
  219. // dump($e1);
  220. $abcde = array_merge(array_merge($a1,$b1,$c1),$d1,$e1);
  221. $shouyi_user = array_flip(array_flip($abcde));
  222. $result['shouyi_num'] = count($shouyi_user);
  223. $this->success(1,$result);
  224. }
  225. //下拉选择代理
  226. private function select_agent(){
  227. //一级代理下的二级代理
  228. $down_agent_users = [];
  229. if($this->auth->group_id == 3){
  230. $down_agent_users = Db::name('user')->field('id,nickname,agentname')->where('agent_id',$this->auth->id)->select();
  231. }
  232. //追加自己。二级代理的,就只有自己
  233. $self_agent = [['id'=>$this->auth->id,'nickname'=>$this->auth->nickname,'agentname'=>$this->auth->agentname]];
  234. $down_all = array_merge($self_agent,$down_agent_users);
  235. //没有代理名的用昵称
  236. foreach($down_all as $key => $val){
  237. $val['agentname'] = $val['agentname'] ?: $val['nickname'];
  238. unset($val['nickname']);
  239. $down_all[$key] = $val;
  240. }
  241. return $down_all;
  242. }
  243. //成员管理
  244. public function all_user(){
  245. $result = [];
  246. //传入代理
  247. $down_all_id = input('down_all_id',0);
  248. //传入用户id
  249. $get_username = input('get_username',0);
  250. //一级代理 下拉 可选二级代理
  251. $down_all = $this->select_agent();
  252. $result['down_all'] = $down_all;
  253. //dump($down_all);
  254. //确定收益统计范围
  255. if(!empty($down_all_id)){
  256. $where = ['intro_uid' => $down_all_id];
  257. if($get_username){
  258. $where['username']= $get_username;
  259. }
  260. $downall_uid = Db::name('user')->where($where)->field('id,username,avatar,nickname,is_active,intro_uid,yaoqingtime')->order('yaoqingtime desc')->autopage()->select();//其下直推,A1下B0 或 B1下C1
  261. //$downall_uid[] = $down_all_id;
  262. }else{
  263. $down_uid = array_column($down_all,'id');
  264. $where = ['intro_uid' => ['IN',$down_uid]];
  265. if($get_username){
  266. $where['username']= $get_username;
  267. }
  268. //dump($down_uid);
  269. $downall_uid = Db::name('user')->where($where)->field('id,username,avatar,nickname,is_active,intro_uid,yaoqingtime')->order('yaoqingtime desc')->autopage()->select();//其下直推B0+代理下直推C1 或 C1
  270. }
  271. //dump($downall_uid);
  272. foreach($downall_uid as $key => &$user){
  273. $user['avatar'] = one_domain_image($user['avatar']);
  274. $user['agentname'] = Db::name('user')->where('id',$user['intro_uid'])->value('agentname');
  275. //邀请奖励收益
  276. $recharge_sum = Db::name('user_agentjewel_log')->where('user_id',$user['id'])->where('log_type',51)->sum('change_value');
  277. $user['recharge_sum'] = $recharge_sum;
  278. //视频收益
  279. $video_sum = Db::name('user_match_video_log')->where('to_user_id',$user['id'])->sum('money');
  280. $user['video_sum'] = $video_sum;
  281. //语音收益
  282. $audio_sum = Db::name('user_match_audio_log')->where('to_user_id',$user['id'])->sum('money');
  283. $user['audio_sum'] = $audio_sum;
  284. //私信收益
  285. $typing_sum= Db::name('user_match_typing_log')->where('to_user_id',$user['id'])->sum('money');
  286. $user['typing_sum'] = $typing_sum;
  287. //礼物收益
  288. $gift_sum = Db::name('gift_user_typing')->where('user_to_id',$user['id'])->sum('getvalue');
  289. $user['gift_sum'] = $gift_sum;
  290. //总收益
  291. $user['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;
  292. }
  293. $result['user_list'] = $downall_uid;
  294. $this->success(1,$result);
  295. }
  296. //成员收入
  297. public function user_shouyi(){
  298. $result = [];
  299. //日期
  300. $today = date('Y-m-d');
  301. $startday = input('startday',$today);
  302. $starttime = strtotime($startday);
  303. $endtime = $starttime + 86399;
  304. //传入代理
  305. $down_all_id = input('down_all_id',0);
  306. //传入用户id
  307. $get_username = input('get_username',0);
  308. $result['startday'] = $startday;
  309. //一级代理 下拉 可选二级代理
  310. $down_all = $this->select_agent();
  311. $result['down_all'] = $down_all;
  312. //dump($down_all);
  313. //确定收益统计范围
  314. if(!empty($down_all_id)){
  315. $where = ['intro_uid' => $down_all_id];
  316. if($get_username){
  317. $where['username']= $get_username;
  318. }
  319. $downall_uid = Db::name('user')->where($where)->field('id,username,avatar,nickname,intro_uid')->order('yaoqingtime desc')->autopage()->select();//其下直推,A1下B0 或 B1下C1
  320. //$downall_uid[] = $down_all_id;
  321. }else{
  322. $down_uid = array_column($down_all,'id');
  323. $where = ['intro_uid' => ['IN',$down_uid]];
  324. if($get_username){
  325. $where['username']= $get_username;
  326. }
  327. //dump($down_uid);
  328. $downall_uid = Db::name('user')->where($where)->field('id,username,avatar,nickname,intro_uid')->order('yaoqingtime desc')->autopage()->select();//其下直推B0+代理下直推C1 或 C1
  329. }
  330. //dump($downall_uid);
  331. foreach($downall_uid as $key => &$user){
  332. $user['agentname'] = Db::name('user')->where('id',$user['intro_uid'])->value('agentname');
  333. //邀请奖励收益
  334. $recharge_sum = Db::name('user_agentjewel_log')->where('user_id',$user['id'])->where('log_type',51)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('change_value');
  335. // $user['recharge_sum'] = $recharge_sum;
  336. //视频收益
  337. $video_sum = Db::name('user_match_video_log')->where('to_user_id',$user['id'])->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');
  338. // $user['video_sum'] = $video_sum;
  339. //语音收益
  340. $audio_sum = Db::name('user_match_audio_log')->where('to_user_id',$user['id'])->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');
  341. // $user['audio_sum'] = $audio_sum;
  342. //私信收益
  343. $typing_sum= Db::name('user_match_typing_log')->where('to_user_id',$user['id'])->where('createtime','BETWEEN',[$starttime,$endtime])->sum('money');
  344. // $user['typing_sum'] = $typing_sum;
  345. //礼物收益
  346. $gift_sum = Db::name('gift_user_typing')->where('user_to_id',$user['id'])->where('createtime','BETWEEN',[$starttime,$endtime])->sum('getvalue');
  347. // $user['gift_sum'] = $gift_sum;
  348. //总收益
  349. $user['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;
  350. }
  351. $result['user_list'] = $downall_uid;
  352. $this->success(1,$result);
  353. }
  354. //成员详情
  355. public function user_info(){
  356. $user_id = input('user_id',0);
  357. $user_info = Db::name('user')->where('id',$user_id)->field('id,username,avatar,nickname,intro_uid,yaoqingtime')->find();
  358. //邀请奖励收益
  359. $recharge_sum = Db::name('user_agentjewel_log')->where('user_id',$user_id)->where('log_type',51)->sum('change_value');
  360. $user_info['recharge_sum'] = $recharge_sum;
  361. //视频收益
  362. $video_sum = Db::name('user_match_video_log')->where('to_user_id',$user_id)->sum('money');
  363. $user_info['video_sum'] = $video_sum;
  364. //语音收益
  365. $audio_sum = Db::name('user_match_audio_log')->where('to_user_id',$user_id)->sum('money');
  366. $user_info['audio_sum'] = $audio_sum;
  367. //私信收益
  368. $typing_sum= Db::name('user_match_typing_log')->where('to_user_id',$user_id)->sum('money');
  369. $user_info['typing_sum'] = $typing_sum;
  370. //礼物收益
  371. $gift_sum = Db::name('gift_user_typing')->where('user_to_id',$user_id)->sum('getvalue');
  372. $user_info['gift_sum'] = $gift_sum;
  373. //总收益
  374. $user_info['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;
  375. $this->success(1,$user_info);
  376. }
  377. //成员详情-日历数据
  378. public function user_info_date(){
  379. $user_id = input('user_id',0);
  380. $user_info = Db::name('user')->where('id',$user_id)->field('yaoqingtime')->find();
  381. //日期
  382. $todaytime = strtotime(date('Y-m-d'));//今天凌晨
  383. $page = input('page',1);
  384. //
  385. $datelist = [];
  386. //总共查几天,页数
  387. $days = ceil((time() - strtotime(date('Y-m-d',$user_info['yaoqingtime']))) / 86400);
  388. $pagemax = ceil($days/10);
  389. if($page > $pagemax){
  390. $this->success($datelist);
  391. }
  392. $datelist = [];
  393. for($i=0;$i<10;$i++){ //循环10次
  394. $day = ($page-1)*10 + $i;//往前推的天数
  395. $starttime = $todaytime - $day*86400;
  396. $endtime = $starttime + 86399;
  397. if($endtime <= $user_info['yaoqingtime']){
  398. break;
  399. }
  400. $thisday = [
  401. 'date' => date('m-d',$starttime),
  402. ];
  403. //邀请奖励收益
  404. $recharge_sum = Db::name('user_agentjewel_log')->where('user_id',$user_id)->where('log_type',51)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('change_value');
  405. $thisday['recharge_sum'] = $recharge_sum;
  406. //视频收益
  407. $video_sum = Db::name('user_match_video_log')->where('to_user_id',$user_id)->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');
  408. $thisday['video_sum'] = $video_sum;
  409. //语音收益
  410. $audio_sum = Db::name('user_match_audio_log')->where('to_user_id',$user_id)->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');
  411. $thisday['audio_sum'] = $audio_sum;
  412. //私信收益
  413. $typing_sum= Db::name('user_match_typing_log')->where('to_user_id',$user_id)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('money');
  414. $thisday['typing_sum'] = $typing_sum;
  415. //礼物收益
  416. $gift_sum = Db::name('gift_user_typing')->where('user_to_id',$user_id)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('getvalue');
  417. $thisday['gift_sum'] = $gift_sum;
  418. //总收益
  419. $thisday['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;
  420. //
  421. $datelist[] = $thisday;
  422. }
  423. $this->success(1,$datelist);
  424. }
  425. }