Userintro.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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('createtime','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. if($down_uid == $this->auth->id){
  121. $this->error('不能绑定自己');
  122. }
  123. $where = [
  124. 'user_id' => $this->auth->id,
  125. 'down_uid' => $down_uid,
  126. 'status' => 0,
  127. ];
  128. $check = Db::name('user_intro_apply')->where($where)->find();
  129. if($check){
  130. $this->error('您上次的申请还在审核中');
  131. }
  132. $data = [
  133. 'user_id' => $this->auth->id,
  134. 'down_uid' => $down_uid,
  135. 'images' => $images,
  136. 'remark' => $remark,
  137. 'createtime'=> time(),
  138. ];
  139. Db::name('user_intro_apply')->insertGetId($data);
  140. $this->success('申请成功');
  141. }
  142. //申请绑定记录
  143. public function apply_intro_log(){
  144. $where = [
  145. 'user_id' => $this->auth->id,
  146. ];
  147. $list = Db::name('user_intro_apply')->alias('log')
  148. ->field('log.*,user.username,user.nickname,user.avatar')
  149. ->join('user','log.down_uid = user.id','LEFT')
  150. ->where($where)->autopage()->select();
  151. $list = list_domain_image($list,['avatar']);
  152. $this->success(1,$list);
  153. }
  154. //日报
  155. public function ribao(){
  156. $result = [];
  157. //日期
  158. $today = date('Y-m-d');
  159. $startday = input('startday',$today);
  160. $starttime = strtotime($startday);
  161. $endtime = $starttime + 86399;
  162. //传入代理
  163. $down_all_id = input('down_all_id',0);
  164. //代理名
  165. $result['agentname'] = $this->auth->agentname ?: $this->auth->nickname;
  166. $result['yaoqingtime'] = $this->auth->yaoqingtime;
  167. $result['startday'] = $startday;
  168. //一级代理 下拉 可选二级代理
  169. $down_all = $this->select_agent();
  170. $result['down_all'] = $down_all;
  171. //dump($down_all);
  172. //确定收益统计范围
  173. if(!empty($down_all_id)){
  174. $downall_uid = Db::name('user')->where('intro_uid',$down_all_id)->column('id');//其下直推,A1下B0+B1 或 B1下C1
  175. //$downall_uid[] = $down_all_id;
  176. }else{
  177. $down_uid = array_column($down_all,'id');
  178. //dump($down_uid);
  179. $downall_uid = Db::name('user')->where('intro_uid','IN',$down_uid)->column('id');//其下直推B0+代理下直推C1 或 C1
  180. }
  181. //dump($downall_uid);
  182. //邀请奖励收益
  183. $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');
  184. $result['recharge_sum'] = $recharge_sum;
  185. //视频收益
  186. $video_sum = Db::name('user_match_video_log')->where('to_user_id','IN',$downall_uid)->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');
  187. $result['video_sum'] = $video_sum;
  188. //语音收益
  189. $audio_sum = Db::name('user_match_audio_log')->where('to_user_id','IN',$downall_uid)->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');
  190. $result['audio_sum'] = $audio_sum;
  191. //私信收益
  192. $typing_sum= Db::name('user_match_typing_log')->where('to_user_id','IN',$downall_uid)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('money');
  193. $result['typing_sum'] = $typing_sum;
  194. //礼物收益
  195. $gift_sum = Db::name('gift_user_typing')->where('user_to_id','IN',$downall_uid)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('getvalue');
  196. $result['gift_sum'] = $gift_sum;
  197. //总收益
  198. $result['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;
  199. $result['total'] = bcadd($result['total'],0,2);
  200. //在线用户
  201. $active_num = Db::name('user_active')->where('user_id','IN',$downall_uid)->where('requesttime','BETWEEN',[$starttime,$endtime])->count();
  202. $result['active_num'] = $active_num;
  203. //收益用户
  204. $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();
  205. $a1 = array_column($a,'user_id');
  206. $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();
  207. $b1 = array_column($b,'to_user_id');
  208. $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();
  209. $c1 = array_column($c,'to_user_id');
  210. $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();
  211. $d1 = array_column($d,'to_user_id');
  212. $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();
  213. $e1 = array_column($e,'user_to_id');
  214. // dump($a);
  215. // dump($a1);
  216. // dump($b);
  217. // dump($b1);
  218. // dump($c);
  219. // dump($c1);
  220. // dump($d);
  221. // dump($d1);
  222. // dump($e);
  223. // dump($e1);
  224. $abcde = array_merge(array_merge($a1,$b1,$c1),$d1,$e1);
  225. $shouyi_user = array_flip(array_flip($abcde));
  226. $result['shouyi_num'] = count($shouyi_user);
  227. $this->success(1,$result);
  228. }
  229. //下拉选择代理
  230. private function select_agent(){
  231. //一级代理下的二级代理
  232. $down_agent_users = [];
  233. if($this->auth->group_id == 3){
  234. $down_agent_users = Db::name('user')->field('id,nickname,agentname')->where('agent_id',$this->auth->id)->select();
  235. }
  236. //追加自己。二级代理的,就只有自己
  237. $self_agent = [['id'=>$this->auth->id,'nickname'=>$this->auth->nickname,'agentname'=>$this->auth->agentname]];
  238. $down_all = array_merge($self_agent,$down_agent_users);
  239. //没有代理名的用昵称
  240. foreach($down_all as $key => $val){
  241. $val['agentname'] = $val['agentname'] ?: $val['nickname'];
  242. unset($val['nickname']);
  243. $down_all[$key] = $val;
  244. }
  245. return $down_all;
  246. }
  247. //成员管理
  248. public function all_user(){
  249. $result = [];
  250. //传入代理
  251. $down_all_id = input('down_all_id',0);
  252. //传入用户id
  253. $get_username = input('get_username',0);
  254. //一级代理 下拉 可选二级代理
  255. $down_all = $this->select_agent();
  256. $result['down_all'] = $down_all;
  257. //dump($down_all);
  258. //确定收益统计范围
  259. if(!empty($down_all_id)){
  260. $where = ['intro_uid' => $down_all_id];
  261. if($get_username){
  262. $where['username']= $get_username;
  263. }
  264. $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
  265. //$downall_uid[] = $down_all_id;
  266. }else{
  267. $down_uid = array_column($down_all,'id');
  268. $where = ['intro_uid' => ['IN',$down_uid]];
  269. if($get_username){
  270. $where['username']= $get_username;
  271. }
  272. //dump($down_uid);
  273. $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
  274. }
  275. //dump($downall_uid);
  276. foreach($downall_uid as $key => &$user){
  277. $user['avatar'] = one_domain_image($user['avatar']);
  278. $user['agentname'] = Db::name('user')->where('id',$user['intro_uid'])->value('agentname');
  279. //邀请奖励收益
  280. $recharge_sum = Db::name('user_agentjewel_log')->where('user_id',$user['id'])->where('log_type',51)->sum('change_value');
  281. $user['recharge_sum'] = $recharge_sum;
  282. //视频收益
  283. $video_sum = Db::name('user_match_video_log')->where('to_user_id',$user['id'])->sum('money');
  284. $user['video_sum'] = $video_sum;
  285. //语音收益
  286. $audio_sum = Db::name('user_match_audio_log')->where('to_user_id',$user['id'])->sum('money');
  287. $user['audio_sum'] = $audio_sum;
  288. //私信收益
  289. $typing_sum= Db::name('user_match_typing_log')->where('to_user_id',$user['id'])->sum('money');
  290. $user['typing_sum'] = $typing_sum;
  291. //礼物收益
  292. $gift_sum = Db::name('gift_user_typing')->where('user_to_id',$user['id'])->sum('getvalue');
  293. $user['gift_sum'] = $gift_sum;
  294. //总收益
  295. $user['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;
  296. $user['total'] = bcadd($user['total'],0,2);
  297. }
  298. //用户列表的排序
  299. if(!empty($downall_uid)){
  300. $column_total = array_column($downall_uid,'total');
  301. array_multisort($column_total, SORT_DESC, $downall_uid);
  302. }
  303. //用户列表的排序
  304. $result['user_list'] = $downall_uid;
  305. $this->success(1,$result);
  306. }
  307. //成员收入
  308. public function user_shouyi(){
  309. $result = [];
  310. //日期
  311. $today = date('Y-m-d');
  312. $startday = input('startday',$today);
  313. $starttime = strtotime($startday);
  314. $endtime = $starttime + 86399;
  315. //传入代理
  316. $down_all_id = input('down_all_id',0);
  317. //传入用户id
  318. $get_username = input('get_username',0);
  319. $result['startday'] = $startday;
  320. //一级代理 下拉 可选二级代理
  321. $down_all = $this->select_agent();
  322. $result['down_all'] = $down_all;
  323. //dump($down_all);
  324. //确定收益统计范围
  325. if(!empty($down_all_id)){
  326. $where = ['intro_uid' => $down_all_id];
  327. if($get_username){
  328. $where['username']= $get_username;
  329. }
  330. $downall_uid = Db::name('user')->where($where)->field('id,username,avatar,nickname,intro_uid')->order('yaoqingtime desc')->autopage()->select();//其下直推,A1下B0 或 B1下C1
  331. //$downall_uid[] = $down_all_id;
  332. }else{
  333. $down_uid = array_column($down_all,'id');
  334. $where = ['intro_uid' => ['IN',$down_uid]];
  335. if($get_username){
  336. $where['username']= $get_username;
  337. }
  338. //dump($down_uid);
  339. $downall_uid = Db::name('user')->where($where)->field('id,username,avatar,nickname,intro_uid')->order('yaoqingtime desc')->autopage()->select();//其下直推B0+代理下直推C1 或 C1
  340. }
  341. //dump($downall_uid);
  342. foreach($downall_uid as $key => &$user){
  343. $user['agentname'] = Db::name('user')->where('id',$user['intro_uid'])->value('agentname');
  344. //邀请奖励收益
  345. $recharge_sum = Db::name('user_agentjewel_log')->where('user_id',$user['id'])->where('log_type',51)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('change_value');
  346. // $user['recharge_sum'] = $recharge_sum;
  347. //视频收益
  348. $video_sum = Db::name('user_match_video_log')->where('to_user_id',$user['id'])->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');
  349. // $user['video_sum'] = $video_sum;
  350. //语音收益
  351. $audio_sum = Db::name('user_match_audio_log')->where('to_user_id',$user['id'])->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');
  352. // $user['audio_sum'] = $audio_sum;
  353. //私信收益
  354. $typing_sum= Db::name('user_match_typing_log')->where('to_user_id',$user['id'])->where('createtime','BETWEEN',[$starttime,$endtime])->sum('money');
  355. // $user['typing_sum'] = $typing_sum;
  356. //礼物收益
  357. $gift_sum = Db::name('gift_user_typing')->where('user_to_id',$user['id'])->where('createtime','BETWEEN',[$starttime,$endtime])->sum('getvalue');
  358. // $user['gift_sum'] = $gift_sum;
  359. //总收益
  360. $user['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;
  361. $user['total'] = bcadd($user['total'],0,2);
  362. }
  363. //用户列表的排序
  364. if(!empty($downall_uid)){
  365. $column_total = array_column($downall_uid,'total');
  366. array_multisort($column_total, SORT_DESC, $downall_uid);
  367. }
  368. //用户列表的排序
  369. $result['user_list'] = $downall_uid;
  370. $this->success(1,$result);
  371. }
  372. //成员详情
  373. public function user_info(){
  374. $user_id = input('user_id',0);
  375. $user_info = Db::name('user')->where('id',$user_id)->field('id,username,avatar,nickname,intro_uid,yaoqingtime')->find();
  376. //邀请奖励收益
  377. $recharge_sum = Db::name('user_agentjewel_log')->where('user_id',$user_id)->where('log_type',51)->sum('change_value');
  378. $user_info['recharge_sum'] = $recharge_sum;
  379. //视频收益
  380. $video_sum = Db::name('user_match_video_log')->where('to_user_id',$user_id)->sum('money');
  381. $user_info['video_sum'] = $video_sum;
  382. //语音收益
  383. $audio_sum = Db::name('user_match_audio_log')->where('to_user_id',$user_id)->sum('money');
  384. $user_info['audio_sum'] = $audio_sum;
  385. //私信收益
  386. $typing_sum= Db::name('user_match_typing_log')->where('to_user_id',$user_id)->sum('money');
  387. $user_info['typing_sum'] = $typing_sum;
  388. //礼物收益
  389. $gift_sum = Db::name('gift_user_typing')->where('user_to_id',$user_id)->sum('getvalue');
  390. $user_info['gift_sum'] = $gift_sum;
  391. //总收益
  392. $user_info['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;
  393. $user_info['total'] = bcadd($user_info['total'],0,2);
  394. $this->success(1,$user_info);
  395. }
  396. //成员详情-日历数据
  397. public function user_info_date(){
  398. $user_id = input('user_id',0);
  399. $user_info = Db::name('user')->where('id',$user_id)->field('yaoqingtime')->find();
  400. //日期
  401. $todaytime = strtotime(date('Y-m-d'));//今天凌晨
  402. $page = input('page',1);
  403. //
  404. $datelist = [];
  405. if(empty($user_info['yaoqingtime'])){
  406. $this->success(1,$datelist);
  407. }
  408. //总共查几天,页数
  409. $days = ceil((time() - strtotime(date('Y-m-d',$user_info['yaoqingtime']))) / 86400);
  410. $pagemax = ceil($days/10);
  411. if($page > $pagemax){
  412. $this->success(1,$datelist);
  413. }
  414. $datelist = [];
  415. for($i=0;$i<10;$i++){ //循环10次
  416. $day = ($page-1)*10 + $i;//往前推的天数
  417. $starttime = $todaytime - $day*86400;
  418. $endtime = $starttime + 86399;
  419. if($endtime <= $user_info['yaoqingtime']){
  420. break;
  421. }
  422. $thisday = [
  423. 'date' => date('m-d',$starttime),
  424. ];
  425. //邀请奖励收益
  426. $recharge_sum = Db::name('user_agentjewel_log')->where('user_id',$user_id)->where('log_type',51)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('change_value');
  427. $thisday['recharge_sum'] = $recharge_sum;
  428. //视频收益
  429. $video_sum = Db::name('user_match_video_log')->where('to_user_id',$user_id)->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');
  430. $thisday['video_sum'] = $video_sum;
  431. //语音收益
  432. $audio_sum = Db::name('user_match_audio_log')->where('to_user_id',$user_id)->where('updatetime','BETWEEN',[$starttime,$endtime])->sum('money');
  433. $thisday['audio_sum'] = $audio_sum;
  434. //私信收益
  435. $typing_sum= Db::name('user_match_typing_log')->where('to_user_id',$user_id)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('money');
  436. $thisday['typing_sum'] = $typing_sum;
  437. //礼物收益
  438. $gift_sum = Db::name('gift_user_typing')->where('user_to_id',$user_id)->where('createtime','BETWEEN',[$starttime,$endtime])->sum('getvalue');
  439. $thisday['gift_sum'] = $gift_sum;
  440. //总收益
  441. $thisday['total'] = $recharge_sum + $video_sum + $audio_sum + $typing_sum + $gift_sum;
  442. $thisday['total'] = bcadd($thisday['total'],0,2);
  443. //
  444. $datelist[] = $thisday;
  445. }
  446. $this->success(1,$datelist);
  447. }
  448. }