Userwallet.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. //日报数据
  18. $date = input('date',date('Y-m-d'));
  19. $starttime = strtotime($date);
  20. $endtime = $starttime + 86399;
  21. //当日收益
  22. $log_type = [];
  23. Db::name('user_gold_log')
  24. ->where('createtime','IN',[$starttime,$endtime])
  25. ->where('user_id',$this->auth->id)
  26. ->where('money_type','jewel')
  27. ->where('log_type','IN',$log_type)
  28. ->sum('change_value');
  29. //通话时长
  30. $where = [
  31. 'to_user_id' => $this->auth->id,
  32. 'createtime' => ['BETWEEN',[$starttime,$endtime]],
  33. ];
  34. $audio_log = Db::name('user_match_audio_log')->where($where)->select();
  35. $audio_times = count($audio_log);//次数
  36. $audio_call_minutes = array_sum(array_column($audio_log,'call_minutes'));//通话时长
  37. $video_log = Db::name('user_match_video_log')->where($where)->select();
  38. $video_times = count($video_log);//次数
  39. $video_call_minutes = array_sum(array_column($video_log,'call_minutes'));//通话时长
  40. //平均通话(分钟)
  41. //互动个人数
  42. $this->success('success',$wallet);
  43. }
  44. //金币日志
  45. public function my_gold_log(){
  46. $money_type = input('money_type',0);
  47. $map = [
  48. 'user_id' => $this->auth->id,
  49. ];
  50. if($money_type){
  51. $map['money_type'] = $money_type;
  52. }
  53. $list = Db::name('user_gold_log')
  54. ->field('id,log_type,money_type,before,change_value,remain,remark,createtime')
  55. ->where($map)->order('id desc')->autopage()->select();
  56. $list = $this->list_appen_logtext($list);
  57. $this->success('success',$list);
  58. }
  59. //追加log_text
  60. private function list_appen_logtext($list){
  61. if(!empty($list)){
  62. $conf = config('wallet.logtype');
  63. foreach($list as $key => $val){
  64. $list[$key]['log_text'] = isset($conf[$val['log_type']]) ? $conf[$val['log_type']] : '';
  65. }
  66. }
  67. return $list;
  68. }
  69. }