Admin.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace app\admin\controller\agent;
  3. use app\admin\model\AuthGroup;
  4. use app\admin\model\AuthGroupAccess;
  5. use app\common\controller\Backend;
  6. use fast\Random;
  7. use fast\Tree;
  8. use think\Db;
  9. use think\Validate;
  10. /**
  11. * 结算管理
  12. *
  13. * @icon fa fa-users
  14. * @remark 一个管理员可以有多个角色组,左侧的菜单根据管理员所拥有的权限进行生成
  15. */
  16. class Admin extends Backend
  17. {
  18. /**
  19. * @var \app\admin\model\Admin
  20. */
  21. protected $model = null;
  22. protected $selectpageFields = 'id,username,nickname,avatar';
  23. protected $searchFields = 'id,username,nickname';
  24. protected $childrenGroupIds = [];
  25. protected $childrenAdminIds = [];
  26. public function _initialize()
  27. {
  28. parent::_initialize();
  29. $this->model = model('Admin');
  30. $this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin());
  31. $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());
  32. $groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray();
  33. Tree::instance()->init($groupList);
  34. $groupdata = [];
  35. if ($this->auth->isSuperAdmin()) {
  36. $result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
  37. foreach ($result as $k => $v) {
  38. $groupdata[$v['id']] = $v['name'];
  39. }
  40. } else {
  41. $result = [];
  42. $groups = $this->auth->getGroups();
  43. foreach ($groups as $m => $n) {
  44. $childlist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['id']));
  45. $temp = [];
  46. foreach ($childlist as $k => $v) {
  47. $temp[$v['id']] = $v['name'];
  48. }
  49. $result[__($n['name'])] = $temp;
  50. }
  51. $groupdata = $result;
  52. }
  53. $this->view->assign('groupdata', $groupdata);
  54. //公会
  55. $gh = Db::name('gonghui')->order('id asc')->column('id,name');
  56. $this->assign('gh',$gh);
  57. //公会
  58. $this->assignconfig("admin", ['id' => $this->auth->id]);
  59. }
  60. /**
  61. * 查看
  62. */
  63. public function index()
  64. {
  65. //设置过滤方法
  66. $this->request->filter(['strip_tags', 'trim']);
  67. if ($this->request->isAjax()) {
  68. //如果发送的来源是Selectpage,则转发到Selectpage
  69. if ($this->request->request('keyField')) {
  70. return $this->selectpage();
  71. }
  72. // $childrenGroupIds = $this->childrenGroupIds;
  73. // $groupName = AuthGroup::where('id', 'in', $childrenGroupIds)
  74. // ->column('id,name');
  75. // $authGroupList = AuthGroupAccess::where('group_id', 'in', $childrenGroupIds)
  76. // ->field('uid,group_id')
  77. // ->select();
  78. // $adminGroupName = [];
  79. // foreach ($authGroupList as $k => $v) {
  80. // if (isset($groupName[$v['group_id']])) {
  81. // $adminGroupName[$v['uid']][$v['group_id']] = $groupName[$v['group_id']];
  82. // }
  83. // }
  84. // $groups = $this->auth->getGroups();
  85. // foreach ($groups as $m => $n) {
  86. // $adminGroupName[$this->auth->id][$n['id']] = $n['name'];
  87. // }
  88. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  89. $map['user_id'] = ['gt', 0];
  90. if ($this->auth->id != 1 && $this->auth->id != 11) {
  91. $map['id'] = $this->auth->id;
  92. }
  93. $list = $this->model
  94. // ->where($where)
  95. ->where($map)
  96. // ->where('id', 'in', $this->childrenAdminIds)
  97. ->field(['password', 'salt', 'token'], true)
  98. ->order($sort, $order)
  99. ->paginate($limit);
  100. //获取时间
  101. $searchwhere = $this->request->get("filter", '');
  102. $searchwhere = (array)json_decode($searchwhere, true);
  103. if (isset($searchwhere['time'])) {
  104. $starttime = strtotime(mb_substr($searchwhere['time'], 0, 19));
  105. $endtime = strtotime(mb_substr($searchwhere['time'], 23, 19));
  106. } else { //若没有 则显示本周
  107. $starttime = strtotime(date('Y-m-d')) - ((date('w')==0?7:date('w'))-1)*86400;
  108. $endtime = $starttime + 86400 * 7 - 1;
  109. }
  110. $money_map['log_type'] = ['in', [21, 22, 23, 54, 60, 82]];
  111. $money_map['createtime'] = ['between', [$starttime, $endtime]];
  112. $mt_user_money_log = Db::name('user_money_log');
  113. $mt_user = Db::name('user');
  114. $mt_extend_reward = Db::name('extend_reward');
  115. foreach ($list as $k => &$v) {
  116. // $groups = isset($adminGroupName[$v['id']]) ? $adminGroupName[$v['id']] : [];
  117. // $v['groups'] = implode(',', array_keys($groups));
  118. // $v['groups_text'] = implode(',', array_values($groups));
  119. $user_ids = $mt_user->where(['intro_uid' => $v['user_id']])->column('id');
  120. $user_ids = $user_ids ? : [];
  121. $money_map['user_id'] = ['in', $user_ids];
  122. //总收益
  123. $week_sum_money = $mt_user_money_log->where($money_map)->sum('change_value');
  124. $week_sum_money = $week_sum_money > 0 ? $week_sum_money : 0;
  125. $v['week_sum_money'] = $week_sum_money;
  126. //查询等级
  127. $extend_reward_info = $mt_extend_reward->where(['total_flow' => ['elt', $week_sum_money]])->order('id desc')->find();
  128. if ($extend_reward_info) {
  129. $v['extend_name'] = $extend_reward_info['name'];
  130. $v['extra_reward'] = $extend_reward_info['extra_reward'];
  131. $v['extra_moeny'] = number_format($week_sum_money * $extend_reward_info['extra_reward'] / 100, 2, '.', '');
  132. } else {
  133. $v['extend_name'] = '';
  134. $v['extra_reward'] = '';
  135. $v['extra_moeny'] = '';
  136. }
  137. }
  138. $result = array("total" => $list->total(), "rows" => $list->items());
  139. return json($result);
  140. }
  141. return $this->view->fetch();
  142. }
  143. /**
  144. * 批量更新
  145. * @internal
  146. */
  147. public function multi($ids = "")
  148. {
  149. // 管理员禁止批量操作
  150. $this->error();
  151. }
  152. /**
  153. * 下拉搜索
  154. */
  155. public function selectpage()
  156. {
  157. $this->dataLimit = 'auth';
  158. $this->dataLimitField = 'id';
  159. return parent::selectpage();
  160. }
  161. }