| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519 |
- <?php
- namespace app\admin\controller\user;
- use app\admin\logic\GreenScoreLogLogic;
- use app\admin\logic\MoneyLogLogic;
- use app\admin\logic\ScoreLogLogic;
- use app\admin\logic\UserLogic;
- use app\common\model\User as UserModel;
- use app\admin\traits\Curd;
- use app\common\controller\AdminController;
- use app\common\model\UserMoneyModel;
- use app\Request;
- use app\validate\admin\user\user\ModifyGreenScore;
- use app\validate\admin\user\user\ModifyMoney;
- use app\validate\admin\user\user\ModifyScore;
- use app\validate\admin\user\user\ModifyPid;
- use app\validate\admin\user\user\PhoneSet;
- use jianyan\excel\Excel;
- use think\App;
- use think\exception\ValidateException;
- use think\facade\Cache;
- use app\admin\model\dao\User as UserDao;
- class User extends AdminController
- {
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->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 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 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();
- }
- /**
- * 余额明细
- * @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();
- }
- /**
- * 积分明细
- * @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 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();
- }
- /*
- * 修改余额
- * @return mixed
- */
- public function modifygreenscore()
- {
- if ($this->request->isPost()) {
- $post = $this->request->post();
- try {
- validate(ModifyGreenScore::class)->check($post);
- } catch (ValidateException $e) {
- $this->error($e->getMessage());
- }
- $userLogic = new UserLogic();
- $result = $userLogic->ModifyGreenScore($post);
- if ($result !== true) {
- $this->error($result);
- }
- $this->success('成功');
- }
- $user = UserDao::getUserOrEmptyById($this->request['id']);
- $user['type_map'] = GreenScoreLogLogic::getTypeMap();
- $user['state_map'] = GreenScoreLogLogic::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('删除失败');
- }
- }
- }
|