model = model('User'); $user_id = $this->request->param('ids/d', 0); $this->assignconfig('user_id', $user_id); $this->view->assign("typeList", UsersPath::where('parent_id', $user_id)->order('distance', 'asc')->column('distance')); } /** * 查看 * @return string|Json * @throws \think\Exception * @throws DbException */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if (false === $this->request->isAjax()) { return $this->view->fetch(); } //如果发送的来源是 Selectpage,则转发到 Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } [, $sort, $order, $offset, $limit] = $this->buildparams(); $where = self::_where(json_decode($this->request->get("filter"), true)); $mapType = []; $type = $this->request->param('distance/d'); if($type > 0) $mapType['distance'] = $type; $user_id = $this->request->param('user_id/d'); $list = $this->model->alias('a') ->join('users b','a.parent_id = b.id', 'LEFT') ->join('users_path c','a.id = c.user_id and c.parent_id ='. $user_id, 'LEFT') ->where('a.id','IN',function($query) use($user_id){ $query->table('ta_users_path')->where('parent_id', $user_id)->order('distance', 'desc')->field('user_id'); }) ->where($where)->where($mapType)->where('a.is_delete', 0) ->field('a.id,a.is_lock,a.mobile,a.balance,a.bonus_sum,a.create_time,b.mobile as parent_name,c.distance') ->order($sort, $order) ->paginate($limit); if($list->total() > 0){ $in = model('Mongyin'); $out = model('Mongyout'); foreach ($list as &$item) { $item->recharge = $in::where('status', 1)->where('user_id', $item->id)->sum('amount'); $item->withdraw = $out::where('status', 1)->where('user_id', $item->id)->sum('amount'); } } $result = ['total' => $list->total(), 'rows' => $list->items()]; return json($result); } /** * 封禁 * @param $ids * @return string * @throws DbException * @throws \think\Exception */ public function lock($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } $result = false; try { $result = $row->allowField(true)->save(['is_lock'=>1]); } catch (ValidateException|PDOException|Exception $e) { $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } /** * 封禁团队 * @param $ids * @return string * @throws DbException * @throws \think\Exception */ public function lockAll($ids = null) { $rows = UsersPath::where('parent_id', $ids)->column('distance'); if (!$rows) { $this->error(__('No Results were found')); } $result = false; try { $result = $this->model->where('id', 'in', $rows)->update(['is_lock'=>1]); } catch (ValidateException|PDOException|Exception $e) { $this->error($e->getMessage()); } if (false === $result) { $this->error(__('No rows were updated')); } $this->success(); } //搜索条件 private static function _where($filter = array()): array { $where = []; if(isset($filter['mobile'])) $where['a.mobile'] = $filter['mobile']; if(isset($filter['create_time'])) { $arr = explode(' - ', $filter['create_time']); $where['a.create_time']= ['between', [strtotime($arr[0]), strtotime($arr[1])]]; } return $where; } }