Userwallet.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. //use app\common\model\wallet;
  6. /**
  7. * 用户钱包
  8. */
  9. class Userwallet extends Api
  10. {
  11. protected $noNeedLogin = [];
  12. protected $noNeedRight = ['*'];
  13. //我的钱包余额
  14. public function my_wallet(){
  15. $wallet = model('wallet')->getwallet($this->auth->id);
  16. $wallet['is_vip'] = $wallet['vip_endtime'] > time() ? 1 : 0;
  17. $this->success('success',$wallet);
  18. }
  19. public function ribao(){
  20. //日报数据
  21. $date = input('date',date('Y-m-d'));
  22. $starttime = strtotime($date);
  23. $endtime = $starttime + 86399;
  24. //当日收益
  25. // $log_type = [21,22,23,54,41,61,63];
  26. $log_type = [21,22,23,24,32,33,41,42];
  27. $change_value = Db::name('user_gold_log')
  28. ->where('createtime','IN',[$starttime,$endtime])
  29. ->where('user_id',$this->auth->id)
  30. ->where('money_type','jewel')
  31. ->where('log_type','IN',$log_type)
  32. ->sum('change_value');
  33. //通话
  34. $where = [
  35. 'to_user_id' => $this->auth->id,
  36. 'createtime' => ['BETWEEN',[$starttime,$endtime]],
  37. ];
  38. $audio_log = Db::name('user_match_audio_log')->where($where)->select();
  39. $audio_times = count($audio_log);//次数
  40. $audio_call_minutes = array_sum(array_column($audio_log,'call_minutes'));//通话时长
  41. $audio_userid = array_column($audio_log,'user_id');
  42. $video_log = Db::name('user_match_video_log')->where($where)->select();
  43. $video_times = count($video_log);//次数
  44. $video_call_minutes = array_sum(array_column($video_log,'call_minutes'));//通话时长
  45. $video_userid = array_column($video_log,'user_id');
  46. //通话时长
  47. $call_minutes = $audio_call_minutes + $video_call_minutes;
  48. //平均通话(分钟)
  49. $tonghua_times = $audio_times + $video_times;
  50. if($tonghua_times == 0){
  51. $pingjun_minutes = 0;
  52. }else{
  53. $pingjun_minutes = bcdiv($call_minutes,$tonghua_times,2);
  54. }
  55. //互动人数
  56. $call_usernum = count(array_flip(array_flip(array_merge($audio_userid,$video_userid))));
  57. $result = [
  58. 'change_value' => $change_value,
  59. 'call_minutes' => Minute2Time($call_minutes),
  60. 'pingjun_minutes' => $pingjun_minutes,
  61. 'call_usernum' => $call_usernum,
  62. 'online_times' => '00:02:47',
  63. ];
  64. $this->success('success',$result);
  65. }
  66. //金币日志
  67. public function my_gold_log(){
  68. $money_type = input('money_type',0);
  69. $map = [
  70. 'user_id' => $this->auth->id,
  71. ];
  72. if($money_type){
  73. $map['money_type'] = $money_type;
  74. }
  75. $list = Db::name('user_gold_log')
  76. ->field('id,log_type,money_type,before,change_value,remain,remark,createtime')
  77. ->where($map)->order('id desc')->autopage()->select();
  78. $list = $this->list_appen_logtext($list);
  79. $this->success('success',$list);
  80. }
  81. //追加log_text
  82. private function list_appen_logtext($list){
  83. if(!empty($list)){
  84. $conf = config('wallet.logtype');
  85. foreach($list as $key => $val){
  86. $list[$key]['log_text'] = isset($conf[$val['log_type']]) ? $conf[$val['log_type']] : '';
  87. }
  88. }
  89. return $list;
  90. }
  91. }