123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- namespace app\admin\controller\agent;
- use app\admin\model\AuthGroup;
- use app\admin\model\AuthGroupAccess;
- use app\common\controller\Backend;
- use fast\Random;
- use fast\Tree;
- use think\Db;
- use think\Validate;
- /**
- * 结算管理
- *
- * @icon fa fa-users
- * @remark 一个管理员可以有多个角色组,左侧的菜单根据管理员所拥有的权限进行生成
- */
- class Admin extends Backend
- {
- /**
- * @var \app\admin\model\Admin
- */
- protected $model = null;
- protected $selectpageFields = 'id,username,nickname,avatar';
- protected $searchFields = 'id,username,nickname';
- protected $childrenGroupIds = [];
- protected $childrenAdminIds = [];
- public function _initialize()
- {
- parent::_initialize();
- $this->model = model('Admin');
- $this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin());
- $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());
- $groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray();
- Tree::instance()->init($groupList);
- $groupdata = [];
- if ($this->auth->isSuperAdmin()) {
- $result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
- foreach ($result as $k => $v) {
- $groupdata[$v['id']] = $v['name'];
- }
- } else {
- $result = [];
- $groups = $this->auth->getGroups();
- foreach ($groups as $m => $n) {
- $childlist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['id']));
- $temp = [];
- foreach ($childlist as $k => $v) {
- $temp[$v['id']] = $v['name'];
- }
- $result[__($n['name'])] = $temp;
- }
- $groupdata = $result;
- }
- $this->view->assign('groupdata', $groupdata);
- //公会
- $gh = Db::name('gonghui')->order('id asc')->column('id,name');
- $this->assign('gh',$gh);
- //公会
- $this->assignconfig("admin", ['id' => $this->auth->id]);
- }
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- // $childrenGroupIds = $this->childrenGroupIds;
- // $groupName = AuthGroup::where('id', 'in', $childrenGroupIds)
- // ->column('id,name');
- // $authGroupList = AuthGroupAccess::where('group_id', 'in', $childrenGroupIds)
- // ->field('uid,group_id')
- // ->select();
- // $adminGroupName = [];
- // foreach ($authGroupList as $k => $v) {
- // if (isset($groupName[$v['group_id']])) {
- // $adminGroupName[$v['uid']][$v['group_id']] = $groupName[$v['group_id']];
- // }
- // }
- // $groups = $this->auth->getGroups();
- // foreach ($groups as $m => $n) {
- // $adminGroupName[$this->auth->id][$n['id']] = $n['name'];
- // }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $map['user_id'] = ['gt', 0];
- if ($this->auth->id != 1 && $this->auth->id != 11) {
- $map['id'] = $this->auth->id;
- }
- $list = $this->model
- // ->where($where)
- ->where($map)
- // ->where('id', 'in', $this->childrenAdminIds)
- ->field(['password', 'salt', 'token'], true)
- ->order($sort, $order)
- ->paginate($limit);
- //获取时间
- $searchwhere = $this->request->get("filter", '');
- $searchwhere = (array)json_decode($searchwhere, true);
- if (isset($searchwhere['time'])) {
- $starttime = strtotime(mb_substr($searchwhere['time'], 0, 19));
- $endtime = strtotime(mb_substr($searchwhere['time'], 23, 19));
- } else { //若没有 则显示本周
- $starttime = strtotime(date('Y-m-d')) - ((date('w')==0?7:date('w'))-1)*86400;
- $endtime = $starttime + 86400 * 7 - 1;
- }
- $money_map['log_type'] = ['in', [21, 22, 23, 54, 60, 82]];
- $money_map['createtime'] = ['between', [$starttime, $endtime]];
- $mt_user_money_log = Db::name('user_money_log');
- $mt_user = Db::name('user');
- $mt_extend_reward = Db::name('extend_reward');
- foreach ($list as $k => &$v) {
- // $groups = isset($adminGroupName[$v['id']]) ? $adminGroupName[$v['id']] : [];
- // $v['groups'] = implode(',', array_keys($groups));
- // $v['groups_text'] = implode(',', array_values($groups));
- $user_ids = $mt_user->where(['intro_uid' => $v['user_id']])->column('id');
- $user_ids = $user_ids ? : [];
- $money_map['user_id'] = ['in', $user_ids];
- //总收益
- $week_sum_money = $mt_user_money_log->where($money_map)->sum('change_value');
- $week_sum_money = $week_sum_money > 0 ? $week_sum_money : 0;
- $v['week_sum_money'] = $week_sum_money;
- //查询等级
- $extend_reward_info = $mt_extend_reward->where(['total_flow' => ['elt', $week_sum_money]])->order('id desc')->find();
- if ($extend_reward_info) {
- $v['extend_name'] = $extend_reward_info['name'];
- $v['extra_reward'] = $extend_reward_info['extra_reward'];
- $v['extra_moeny'] = number_format($week_sum_money * $extend_reward_info['extra_reward'] / 100, 2, '.', '');
- } else {
- $v['extend_name'] = '';
- $v['extra_reward'] = '';
- $v['extra_moeny'] = '';
- }
- }
- $result = array("total" => $list->total(), "rows" => $list->items());
- return json($result);
- }
- return $this->view->fetch();
- }
- /**
- * 批量更新
- * @internal
- */
- public function multi($ids = "")
- {
- // 管理员禁止批量操作
- $this->error();
- }
- /**
- * 下拉搜索
- */
- public function selectpage()
- {
- $this->dataLimit = 'auth';
- $this->dataLimitField = 'id';
- return parent::selectpage();
- }
- }
|