model = new UserModel(); } use Curd; /** * 会员列表 * @return mixed|\think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function index() { if ($this->request->isAjax()) { if (input('selectFields')) { return $this->selectList(); } list($page, $limit, $where) = $this->buildTableParames(); Cache::set("USER_EXPORT", ['page' => $page, 'limit' => $limit, 'where' => $where]); if (($pid = $this->request->param('pid')) !== false && $pid) $where[] = ['pid', '=', $this->request->param('pid', '')]; $userLogic = new UserLogic(); $data = $userLogic->getList($page, $limit, $where, $this->sort, $this->user_map); return $data; } return $this->fetch(); } /** * 禁用用户 * @param $id */ public function forbid($id) { list($result, $msg) = UserLogic::forbid($id); if ($result !== true) { $this->error($msg); } $this->success($msg); } /** * 启用用户 * @param $id */ public function enable($id) { list($result, $msg) = UserLogic::enable($id); if ($result !== true) { $this->error($msg); } $this->success($msg); } /** * 会员详情 * @param Request $request * @return mixed */ public function details(Request $request) { $id = $request->param('id'); $info = UserLogic::getUserDetail($id); $this->assign('info', $info); return $this->fetch(); } /** * 添加用户(功能不存在) * @return mixed */ /*public function add() { if ($this->request->isAjax()) { $post = $this->request->post(); $mobile = $this->model->where('mobile', $post['mobile'])->value('id'); $mobile && $this->error('该手机号码已被注册'); $invite = $this->model->where('code|px_code', $post['code'])->value('id'); !$invite && $this->error('邀请人不存在'); $this->model->startTrans(); try { $insert['mobile'] = $post['mobile']; $insert['reg_ip'] = $this->request->ip(); $insert['avatar'] = 'http://images.yxj.hongyun63.com/user/default_avatar.jpg'; $insert['code'] = create_invite_code(); $insert['px_code'] = create_invite_code(); $insert['user_type'] = 2; $rz_money = 1.5 + rand(0, 30) / 100; $this->model->save($insert); $uid = $this->model->id; $user_data = new UserData(); $user_data->save(['uid' => $uid, 'rz_money' => $rz_money]); // 保存用户关联信息 $this->bindRelation($post['code'], $uid); // 绑定关系 $this->model->commit(); } catch (\Exception $e) { $this->model->rollback(); $this->error('添加用户失败'); } $this->success('添加成功'); } return $this->fetch(); }*/ /** * 邀请页面 * @return mixed */ public function invite() { $admin = session('admin'); !$admin['user_id'] && $this->error('没有该权限'); $user = UserDao::getUserOrEmptyById($admin['user_id']); empty($user) && $this->error('用户信息不存在'); $this->assign('user_id', encode($admin['user_id'])); return $this->fetch(); } /** * 兜底 * @return mixed */ public function doudi() { return 22; if ($this->request->isAjax()) { $post = $this->request->post(); $user = $this->model->findOrEmpty(['id' => $post['uid']]); empty($user) && $this->error('用户不存在'); $post['active'] <= 0 && $this->error('参数错误'); $path = trim_string($user['path'] . ',' . $user['id']); $path_explode = explode(',', $path); $insert = []; foreach ($path_explode as $value) { $insert[] = [ 'active' => $post['active'], 'uid' => $value, 'ip' => $this->request->ip(), 'user_admin' => session('?admin.username') ? session('admin.username') : '', 'from_uid' => $post['uid'], 'failure_at' => date('Y-m-d H:i:s', time() + 86400 * 30), ]; } $this->model->startTrans(); try { $this->model->whereIn('id', $path)->save(['active_set' => ['inc', $post['active']], 'total_number' => ['inc', $post['active']], 'total_number_real' => ['inc', $post['active']], 'total_active' => ['inc', $post['active']]]); ActiveSet::insertAll($insert); $this->model->commit(); } catch (\Exception $e) { $this->model->rollback(); $this->error('失败'); } $this->success('成功'); } return $this->fetch(); } /** * 增加余额(功能已屏蔽) * @return mixed */ /*public function editmoney() { if ($this->request->isPost()) { $post = $this->request->post(); $user = $this->model->findOrEmpty(['id' => $post['uid']]); $money = $post['money']; $type = $post['type']; empty($user) && $this->error('用户不存在'); $this->model->startTrans(); try { if ($type == 'more') { edit_user_money(7, $post['uid'], $money); } else { edit_user_money(8, $post['uid'], $money); } $this->model->commit(); } catch (\Exception $e) { $this->model->rollback(); $this->error('失败' . $e->getMessage()); } $this->success('成功'); } return $this->fetch(); }*/ /** * 修改手机号码 * @return mixed */ public function phoneset() { if ($this->request->isPost()) { $post = $this->request->post(); try { validate(PhoneSet::class)->check($post); } catch (ValidateException $e) { $this->error($e->getMessage()); } $userLogic = new UserLogic(); $result = $userLogic->modifyPhone($post['id'], $post['phone']); if ($result !== true) { $this->error($result); } $this->success('成功'); } $user = UserDao::getUserOrEmptyById($this->request['id']); $this->assign('info', $user); return $this->fetch('phoneset'); } /* * 修改所属上级 * @return mixed */ public function modifypid() { if ($this->request->isPost()) { $post = $this->request->post(); try { validate(ModifyPid::class)->check($post); } catch (ValidateException $e) { $this->error($e->getMessage()); } $userLogic = new UserLogic(); $result = $userLogic->modifypid($post['id'], $post['pid']); if ($result !== true) { $this->error($result); } $this->success('成功'); } $user = UserDao::getUserOrEmptyById($this->request['id']); $this->assign('info', $user); return $this->fetch(); } /** * 等级设置 * @return mixed */ public function levelset() { if ($this->request->isPost()) { $post = $this->request->post(); $result = UserLogic::levelset($post); if ($result !== true) { $this->error($result); } $this->success('成功'); } $user = UserDao::getUserOrEmptyById($this->request['id']); $this->assign('info', $user); return $this->fetch(); } /** * 回收卡设置 * @return mixed */ public function recyclecountset() { if ($this->request->isPost()) { $post = $this->request->post(); $result = UserLogic::recycleCountSet($post); if ($result !== true) { $this->error($result); } $this->success('成功'); } $user = UserDao::getUserOrEmptyById($this->request['id']); $this->assign('info', $user); return $this->fetch(); } /** * 末尾奖励(功能已注释) * @return mixed */ /*public function moweiscore() { if ($this->request->isPost()) { $post = $this->request->post(); $user = $this->model->findOrEmpty(['id' => $post['uid']]); $money = $post['money']; empty($user) && $this->error('用户不存在'); $this->model->startTrans(); try { edit_user_score(8, $post['uid'], $money); $this->model->commit(); } catch (\Exception $e) { $this->model->rollback(); $this->error('失败' . $e->getMessage()); } $this->success('成功'); } return $this->fetch(); }*/ /** * 余额明细 * @param UserMoneyModel $model * @return mixed|\think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function moneyLog() { if ($this->request->isAjax()) { if (input('selectFields')) { return $this->selectList(); } list($page, $limit, $where) = $this->buildTableParames(); $where[] = ['uid', '=', $this->request->param('id', '')]; list($count, $list) = MoneyLogLogic::getMoneyLog($page, $limit, $where, $this->sort); $data = [ 'code' => 0, 'msg' => '', 'count' => $count, 'data' => $list, ]; return json($data); } return $this->fetch(); } /** * 查看上级 * @return mixed|\think\response\Json */ public function lookpidlevel() { if ($this->request->isAjax()) { $id = $this->request->param('id'); list($count, $list) = UserLogic::lookpidlevel($id); $data = [ 'code' => 0, 'msg' => '成功', 'count' => $count, 'data' => $list, ]; return json($data); } return $this->fetch(); } /** * 元宝明细(功能已失效) * @param CoinLog $model * @return mixed|\think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ /*public function coinLog(CoinLog $model) { if ($this->request->isAjax()) { if (input('selectFields')) { return $this->selectList(); } list($page, $limit, $where) = $this->buildTableParames(); $where[] = ['uid', '=', $this->request->param('id', '')]; $count = $model ->where($where) ->count(); $type_conf = config('type.coin'); $list = $model ->where($where) ->withAttr('type', function ($value, $data) use ($type_conf) { return $type_conf[$value]; }) ->withAttr('coin', function ($value, $data) { if ($data['state'] == 2) $value = '-' . $value; return $value; }) ->page($page, $limit) ->order($this->sort) ->select(); $data = [ 'code' => 0, 'msg' => '', 'count' => $count, 'data' => $list, ]; return json($data); } return $this->fetch(); }*/ /** * 积分明细 * @return mixed|\think\response\Json */ public function scoreLog() { if ($this->request->isAjax()) { if (input('selectFields')) { return $this->selectList(); } list($page, $limit, $where) = $this->buildTableParames(); $where[] = ['uid', '=', $this->request->param('id', '')]; list($count, $list) = ScoreLogLogic::scoreLog($page, $limit, $where, $this->sort); $data = [ 'code' => 0, 'msg' => '', 'count' => $count, 'data' => $list, ]; return json($data); } return $this->fetch(); } /** * 活跃明细(功能已失效) * @param ActiveLog $model * @return mixed|\think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ /*public function activeLog(ActiveLogModel $model) { if ($this->request->isAjax()) { if (input('selectFields')) { return $this->selectList(); } list($page, $limit, $where) = $this->buildTableParames(); $where[] = ['uid', '=', $this->request->param('id', '')]; $count = $model ->where($where) ->count(); $type_conf = config('type.active'); $list = $model ->where($where) ->withAttr('type', function ($value, $data) use ($type_conf) { return $type_conf[$value]; }) ->withAttr('active', function ($value, $data) { if ($data['state'] == 2) $value = '-' . $value; return $value; }) ->page($page, $limit) ->order($this->sort) ->select(); $data = [ 'code' => 0, 'msg' => '', 'count' => $count, 'data' => $list, ]; return json($data); } return $this->fetch(); }*/ /** * @NodeAnotation(title="导出") */ public function export() { list($page, $limit, $where) = $this->buildTableParames(); if (empty($where)) { $search = Cache::get("USER_EXPORT"); $page = $search['page']; $limit = $search['limit']; $where = $search['where']; } $header = getExportHeader($this->model->getName(), $this->noExportFields); $list = UserLogic::getExportList($where, $page, $limit); $fileName = time(); return Excel::exportData($list, $header, $fileName, 'xlsx'); } /** * 团队充值(已失效) * @return mixed */ /*public function teamincome(Request $request) { if ($this->request->isAjax()) { // if (($pid = $this->request->param('pid')) !== false && $pid) // $where[] = ['pid', '=', $this->request->param('pid', '')]; $id = $this->request->param('id'); // $path = Db::name('user')->where('id', $id)->value('path'); $where = array(); $where[] = ['team_id', '=', $id]; $where[] = ['type', '=', 5]; $count = Db::name('userteam_log') // ->withJoin('user', 'INNER') ->where($where) ->count(); $list = Db::name('userteam_log') // ->withJoin('user', 'INNER') ->where($where) ->order($this->sort) ->select(); $data = [ 'code' => 0, 'msg' => '成功', 'count' => $count, 'data' => $list, ]; return json($data); } return $this->fetch(); }*/ /* * 修改积分 * @return mixed */ public function modifyscore() { if ($this->request->isPost()) { $post = $this->request->post(); try { validate(ModifyScore::class)->check($post); } catch (ValidateException $e) { $this->error($e->getMessage()); } $userLogic = new UserLogic(); $result = $userLogic->ModifyScore($post); if ($result !== true) { $this->error($result); } $this->success('成功'); } $user = UserDao::getUserOrEmptyById($this->request['id']); $user['type_map'] = ScoreLogLogic::getTypeMap(); $user['state_map'] = ScoreLogLogic::getStateMap(); $this->assign('info', $user); return $this->fetch(); } /* * 修改余额 * @return mixed */ public function modifymoney() { if ($this->request->isPost()) { $post = $this->request->post(); try { validate(ModifyMoney::class)->check($post); } catch (ValidateException $e) { $this->error($e->getMessage()); } $userLogic = new UserLogic(); $result = $userLogic->ModifyMoney($post); if ($result !== true) { $this->error($result); } $this->success('成功'); } $user = UserDao::getUserOrEmptyById($this->request['id']); $user['type_map'] = MoneyLogLogic::getTypeMap(); $user['state_map'] = MoneyLogLogic::getStateMap(); $this->assign('info', $user); return $this->fetch(); } /** * 注销用户 * @param $id */ public function deluser($id) { if ($this->request->isAjax()) { $userLogic = new UserLogic(); $flag = $userLogic->delUser($id); $flag === true ? $this->success('删除成功') : $this->success('删除失败'); } } }