User.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. namespace app\admin\controller\agent;
  3. use app\common\controller\Backend;
  4. use app\common\library\Auth;
  5. use Think\Db;
  6. /**
  7. * 主播管理
  8. *
  9. * @icon fa fa-user
  10. */
  11. class User extends Backend
  12. {
  13. protected $searchFields = 'id,username,nickname';
  14. protected $selectpageFields = 'id,username,nickname,mobile';
  15. /**
  16. * User模型对象
  17. * @var \app\admin\model\User
  18. */
  19. protected $model = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\User;
  24. $this->view->assign("realStatusList", $this->model->getRealStatusList());
  25. $this->view->assign("genderList", $this->model->getGenderList());
  26. $this->view->assign("idcardStatusList", $this->model->getIdcardStatusList());
  27. $this->view->assign("statusList", $this->model->getStatusList());
  28. $this->view->assign("isKefuList", $this->model->getIsKefuList());
  29. $this->view->assign("openMatchVideoList", $this->model->getOpenMatchVideoList());
  30. $this->view->assign("openMatchAudioList", $this->model->getOpenMatchAudioList());
  31. $this->view->assign("openMatchTypingList", $this->model->getOpenMatchTypingList());
  32. $this->view->assign("freeVideoList", $this->model->getFreeVideoList());
  33. $this->view->assign("freeAudioList", $this->model->getFreeAudioList());
  34. $this->view->assign("freeTypingList", $this->model->getFreeTypingList());
  35. }
  36. public function import()
  37. {
  38. parent::import();
  39. }
  40. /**
  41. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  42. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  43. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  44. */
  45. /**
  46. * 查看
  47. */
  48. public function index()
  49. {
  50. //当前是否为关联查询
  51. $this->relationSearch = true;
  52. //设置过滤方法
  53. $this->request->filter(['strip_tags', 'trim']);
  54. if ($this->request->isAjax()) {
  55. //如果发送的来源是Selectpage,则转发到Selectpage
  56. if ($this->request->request('keyField')) {
  57. return $this->selectpage();
  58. }
  59. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  60. $map = [];
  61. if ($this->auth->id != 1 && $this->auth->id != 11) {
  62. if ($this->auth->user_id > 0) {
  63. $map['intro_uid'] = $this->auth->user_id;
  64. } else {
  65. $map['intro_uid'] = -100;
  66. }
  67. }
  68. $list = $this->model
  69. ->with([/*'gonghui',*/ 'userwallet'])
  70. ->where($where)
  71. ->where($map)
  72. ->order($sort, $order)
  73. ->paginate($limit);
  74. $mt_admin = Db::name('admin');
  75. if ($this->auth->id == 1 || $this->auth->id == 11) {
  76. $is_show = 1;
  77. } else {
  78. $is_show = 0;
  79. }
  80. foreach ($list as &$row) {
  81. // $row->getRelation('gonghui')->visible(['id','name']);
  82. $row->getRelation('userwallet')->visible(['money', 'pay_money', 'get_money']);
  83. $row['sharing_ratio'] = $mt_admin->where(['user_id' => $row['intro_uid']])->value('sharing_ratio');
  84. $row['sharing_ratio'] = $row['sharing_ratio'] ? : 0;
  85. $row['is_show'] = $is_show;
  86. }
  87. $result = array("total" => $list->total(), "rows" => $list->items());
  88. return json($result);
  89. }
  90. $this->assignConfig('sharing_ratio', $this->auth->sharing_ratio);
  91. return $this->view->fetch();
  92. }
  93. /**
  94. * 统计详情
  95. * @return void
  96. */
  97. public function detail()
  98. {
  99. $ids = $this->request->param('ids','');
  100. $result = [];
  101. if (!empty($ids)) {
  102. //21='视频通话收益',22='语音通话收益',23='文字聊天收益',52='语聊间获得礼物',54='聊天获得礼物',56='直播获得礼物',58='打招呼获得礼物'
  103. //60='动态获得礼物',65='邀请人充值奖励',67='女性完成个人任务',68='邀请人收益奖励',82='被守护收益',91='额外提成奖励'
  104. //总收益:今天、昨天、上周、近30天、总收益(收益+充值奖励)
  105. $revenueWhere['user_id'] = $ids;
  106. //$revenueWhere['log_type'] = ['in',[60,65,67,91]];
  107. $revenueWhere['log_type'] = ['in',[21,22,23,52,54,56,58,60,67,82,91]];
  108. /*$revenueWhereOr['other_user_id'] = $ids;
  109. $revenueWhereOr['log_type'] = ['in',[21,22,23,52,54,56,58,68,82]];*///other_user_id
  110. $today = day_now();
  111. $yesterday = day_yesterday();
  112. $nowweek = week_now();
  113. $lastweek = last_week();
  114. $month = now_month();
  115. //今日总收益
  116. $revenueWhereToday['createtime'] = [['egt',$today[0]],['lt',$today[1]+1],'and'];
  117. $revenueToday = Db::name('user_money_log')->where($revenueWhere)->where($revenueWhereToday)->sum('change_value');
  118. //昨日总收益
  119. $revenueWhereYesterday['createtime'] = [['egt',$yesterday[0]],['lt',$yesterday[1]+1],'and'];
  120. $revenueYesterday = Db::name('user_money_log')->where($revenueWhere)->where($revenueWhereYesterday)->sum('change_value');
  121. //上周总收益
  122. $revenueWhereLastweek['createtime'] = [['egt',$lastweek[0]],['lt',$lastweek[1]+1],'and'];
  123. $revenueLastweek = Db::name('user_money_log')->where($revenueWhere)->where($revenueWhereLastweek)->sum('change_value');
  124. //本周总收益
  125. $revenueWhereNowweek['createtime'] = [['egt',$nowweek[0]],['lt',$nowweek[1]+1],'and'];
  126. $revenueNowweek = Db::name('user_money_log')->where($revenueWhere)->where($revenueWhereNowweek)->sum('change_value');
  127. //近30天总收益
  128. $revenueWhereMonth['createtime'] = [['egt',$month[0]],['lt',$month[1]+1],'and'];
  129. $revenueMonth = Db::name('user_money_log')->where($revenueWhere)->where($revenueWhereMonth)->sum('change_value');
  130. //总收益
  131. $revenueTotal = Db::name('user_money_log')->where($revenueWhere)->sum('change_value');
  132. $result['revenue_today'] = !empty($revenueToday) ? $revenueToday : 0;
  133. $result['revenue_yesterday'] = !empty($revenueYesterday) ? $revenueYesterday : 0;
  134. $result['revenue_now_week'] = !empty($revenueNowweek) ? $revenueNowweek : 0;
  135. $result['revenue_last_week'] = !empty($revenueLastweek) ? $revenueLastweek : 0;
  136. $result['revenue_month'] = !empty($revenueMonth) ? $revenueMonth : 0;
  137. $result['revenue_taotal'] = !empty($revenueTotal) ? $revenueTotal : 0;
  138. //邀请充值奖励:本周、上周
  139. $inviteRechargeWhere['user_id'] = $ids;
  140. $inviteRechargeWhere['log_type'] = 65;
  141. //本周
  142. $inviteWhereNowweek['createtime'] = [['egt',$nowweek[0]],['lt',$nowweek[1]+1],'and'];
  143. $inviteNowweek = Db::name('user_money_log')->where($inviteRechargeWhere)->where($inviteWhereNowweek)->sum('change_value');
  144. //上周
  145. $inviteWhereLastweek['createtime'] = [['egt',$lastweek[0]],['lt',$lastweek[1]+1],'and'];
  146. $inviteLastweek = Db::name('user_money_log')->where($inviteRechargeWhere)->where($inviteWhereLastweek)->sum('change_value');
  147. $result['invite_recharge_week'] = $inviteNowweek;
  148. $result['invite_recharge_last_week'] = $inviteLastweek;
  149. //邀请奖励:今日、昨日
  150. $inviteWhere['user_id'] = $ids;
  151. $inviteWhere['log_type'] = ['in',[65,68]];
  152. //今日
  153. $inviteWhereToday['createtime'] = [['egt',$today[0]],['lt',$today[1]+1],'and'];
  154. $inviteToday = Db::name('user_money_log')->where($inviteWhere)->where($inviteWhereToday)->sum('change_value');
  155. //昨日
  156. $inviteWhereYesterday['createtime'] = [['egt',$yesterday[0]],['lt',$yesterday[1]+1],'and'];
  157. $inviteLastweek = Db::name('user_money_log')->where($inviteWhere)->where($inviteWhereYesterday)->sum('change_value');
  158. $result['invite_today'] = $inviteToday;
  159. $result['invite_yesterday'] = $inviteLastweek;
  160. }
  161. $res['row'] = $result;
  162. $user = $this->model->find($ids);
  163. $res['user'] = [
  164. 'id' => $user['id'],
  165. 'nickname' => $user['nickname'],
  166. ];
  167. $this->view->assign($res);
  168. return $this->view->fetch();
  169. }
  170. }