| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666 |
- <?php
- namespace app\admin\controller\user;
- //use app\admin\model\ActiveLog;
- //use app\admin\model\ActiveSet;
- //use app\admin\model\CoinLog;
- use app\admin\logic\UserLogic;
- use app\common\model\MoneyLog;
- use app\common\model\ScoreLog;
- //use app\admin\model\UpgradeLog;
- use app\common\model\ScoreLogModel;
- use app\common\model\User as UserModel;
- use app\common\model\UserData;
- use app\admin\traits\Curd;
- use app\common\constants\AdminConstant;
- use app\common\controller\AdminController;
- use app\common\model\UserMoneyModel;
- use app\common\model\UserteamLogModel;
- use app\Request;
- use app\validate\admin\mall\shopOrder\EditStatus;
- use app\validate\admin\user\user\ModifyScore;
- use app\validate\admin\user\user\PhoneSet;
- use EasyAdmin\tool\CommonTool;
- use jianyan\excel\Excel;
- use think\App;
- use think\exception\ValidateException;
- use think\facade\Db;
- 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();
- 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)
- {
- $user = $this->model->findOrEmpty($id);
- empty($user) && $this->error('数据不存在');
- $user['status'] == 0 && $this->error('该用户已被禁用');
- if ($this->model->where('id', $id)->save(['status' => 0]))
- $this->success('禁用成功');
- else
- $this->error('禁用失败');
- }
- /**
- * 启用用户
- * @param $id
- */
- public function enable($id)
- {
- $user = $this->model->findOrEmpty($id);
- empty($user) && $this->error('数据不存在');
- $user['status'] == 1 && $this->error('该用户已启用');
- if ($this->model->where('id', $id)->save(['status' => 1]))
- $this->success('启用成功');
- else
- $this->error('启用失败');
- }
- /**
- * 会员详情
- * @param Request $request
- * @param UpgradeLog $upgradeLog
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function details(Request $request)
- {
- $id = $request->param('id');
- $info = $this->model
- ->withJoin('userData', 'INNER')
- ->where('id', $id)
- ->find()
- ->toArray();
- // $upgrade_log = $upgradeLog->where('uid', $id)->order('create_at', 'desc')->select();
- // $this->assign('upgrade_log', $upgrade_log);
- $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 = $this->model->findOrEmpty(['id' => $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());
- }
- $user = $this->model->findOrEmpty(['id' => $post['id']]);
- $phone = $post['phone'];
- empty($user) && $this->error('用户不存在');
- $userLogic = new UserLogic();
- $result = $userLogic->modifyPhone($post['id'], $phone);
- if ($result !== true) {
- $this->error($result);
- }
- $this->success('成功');
- }
- $user = $this->model->findOrEmpty(['id' => $this->request['id']]);
- $this->assign('info', $user);
- return $this->fetch('phoneset');
- }
- /**
- * 增加余额
- * @return mixed
- */
- public function modifymoney()
- {
- 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->modifyMoney($post['uid'], $post);
- if ($result !== true) {
- $this->error($result);
- }
- $this->success('成功');
- }
- $user = $this->model->findOrEmpty(['id' => $this->request['id']]);
- $this->assign('info', $user);
- return $this->fetch('phoneset');
- }
- /**
- * 等级设置
- * @return mixed
- */
- public function levelset()
- {
- if ($this->request->isPost()) {
- $post = $this->request->post();
- $level = $post['level'];
- if ($level > 4) {
- $this->error('最高等级4级');
- }
- $user = $this->model->findOrEmpty(['id' => $post['id']]);
- empty($user) && $this->error('用户不存在');
- $level_type = 1;
- if ($level > $user['level']) {
- $level_type = 2;
- }
- $this->model->startTrans();
- try {
- $this->model->where('id', $post['id'])->save(['level' => $level, 'level_type' => $level_type]);
- $this->model->commit();
- } catch (\Exception $e) {
- $this->model->rollback();
- $this->error('失败' . $e->getMessage());
- }
- $this->success('成功');
- }
- $user = $this->model->findOrEmpty(['id' => $this->request['id']]);
- // $user_info = Db::name('user', $id)->find();
- $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 MoneyLog $model
- * @return mixed|\think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function moneyLog(UserMoneyModel $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.money');
- $list = $model
- ->where($where)
- ->withAttr('type', function ($value, $data) use ($type_conf) {
- return $type_conf[$value];
- })
- ->withAttr('money', 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();
- }
- /**
- * 查看上级
- * @param Request $request
- * @param UpgradeLog $upgradeLog
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function lookpidlevel(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');
- $arr = explode(',', $path);
- $ids = $arr;
- $ids = implode(',', $ids);
- $order = 'field(id,' . $ids . ')';
- // return User::whereIn('id',$ids)->order(Db::raw($order))->select();
- $where = array();
- $where[] = ['uid', 'in', $arr];
- sr_log($where);
- $count = $this->model
- ->withJoin('userData', 'INNER')
- ->where($where)
- ->count();
- $list = $this->model
- ->withJoin('userData', 'INNER')
- ->where($where)
- ->order(Db::raw($order))
- ->select();
- $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();
- }
- /**
- * 积分明细
- * @param ScoreLog $model
- * @return mixed|\think\response\Json
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function scoreLog(ScoreLogModel $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.score');
- $list = $model
- ->where($where)
- ->withAttr('type', function ($value, $data) use ($type_conf) {
- return $type_conf[$value];
- })
- ->withAttr('score', 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();
- }
- /**
- * 积分明细
- * @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(ActiveLog $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();
- $tableName = $this->model->getName();
- $tableName = CommonTool::humpToLine(lcfirst($tableName));
- $prefix = config('database.connections.mysql.prefix');
- $dbList = Db::query("show full columns from {$prefix}{$tableName}");
- $header = [];
- foreach ($dbList as $vo) {
- $comment = !empty($vo['Comment']) ? $vo['Comment'] : $vo['Field'];
- if (!in_array($vo['Field'], $this->noExportFields)) {
- $header[] = [$comment, $vo['Field']];
- }
- }
- $list = $this->model
- ->where($where)
- ->withJoin('userData', 'INNER')
- ->where($where)
- ->limit(100000)
- ->order('id', 'desc')
- ->select()
- ->toArray();
- $fileName = time();
- return Excel::exportData($list, $header, $fileName, 'xlsx');
- }
- 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();
- }
- }
|