HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/cs.wgegeghx.com/application/member/controller/Member.php
<?php
// | 会员管理

namespace app\member\controller;

use app\common\controller\Adminbase;
use app\member\model\Member as Member_Model;
use app\member\service\User;

class Member extends Adminbase
{
    //初始化
    protected function initialize()
    {
        parent::initialize();
        $this->modelClass  = new Member_Model;
        $this->UserService = User::instance();
        $this->groupCache  = cache("Member_Group"); //会员模型
    }

    /**
     * 会员列表
     */
    public function manage()
    {
        if ($this->request->isAjax()) {
            list($page, $limit, $where) = $this->buildTableParames();
            $_list                      = $this->modelClass->where($where)->where('status', 1)->page($page, $limit)->withAttr('last_login_time', function ($value, $data) {
                return time_format($value);
            })->select();
            $total  = $this->modelClass->where($where)->where('status', 1)->count();
            $result = array("code" => 0, "count" => $total, "data" => $_list);
            return json($result);
        }
        return $this->fetch();
    }

    /**
     * 会员增加
     */
    public function add()
    {
        if ($this->request->isPost()) {
            $data   = $this->request->post();
            $result = $this->validate($data, 'member');
            if (true !== $result) {
                return $this->error($result);
            }
            $userid = $this->UserService->userRegister($data['username'], $data['password'], $data['email'], $data['mobile'], $data);
            if ($userid) {
                unset($data['username'], $data['password'], $data['email']);
                $data['overduedate'] = strtotime($data['overduedate']);
                if (false !== $this->modelClass->save($data, ['id' => $userid])) {
                    $this->success("添加会员成功!", url("member/manage"));
                } else {
                    //service("Passport")->userDelete($memberinfo['userid']);
                    $this->error("添加会员失败!");
                }
            } else {
                $this->error($this->UserService->getError() ?: '帐号注册失败!');
            }
        } else {
            foreach ($this->groupCache as $_key => $_value) {
                $groupCache[$_key] = $_value['name'];
            }
            $this->assign('groupCache', $groupCache);
            return $this->fetch();
        }
    }

    /**
     * 会员编辑
     */
    public function edit()
    {
        if ($this->request->isPost()) {
            $userid = $this->request->param('id/d', 0);
            $data   = $this->request->post();
            $result = $this->validate($data, 'member.edit');
            if (true !== $result) {
                return $this->error($result);
            }
            //获取用户信息
            $userinfo = Member_Model::get($userid);
            if (empty($userinfo)) {
                $this->error('该会员不存在!');
            }
            //修改基本资料
            if ($userinfo['username'] != $data['username'] || !empty($data['password']) || $userinfo['email'] != $data['email']) {
                $res = $this->modelClass->userEdit($userinfo['username'], '', $data['password'], $data['email'], 1);
                if (!$res) {
                    $this->error($this->modelClass->getError());
                }
            }
            unset($data['username'], $data['password'], $data['email']);
            $data['overduedate'] = strtotime($data['overduedate']);
            //更新除基本资料外的其他信息
            if (false === $this->modelClass->allowField(true)->save($data, ['id' => $userid])) {
                $this->error('更新失败!');
            }
            $this->success("更新成功!", url("member/manage"));

        } else {
            $userid = $this->request->param('id/d', 0);
            $data   = $this->modelClass->where(["id" => $userid])->withAttr('overduedate', function ($value, $data) {
                return date('Y-m-d H:i:s', $value);
            })->find();
            if (empty($data)) {
                $this->error("该会员不存在!");
            }
            foreach ($this->groupCache as $_key => $_value) {
                $groupCache[$_key] = $_value['name'];
            }
            $this->assign('groupCache', $groupCache);
            $this->assign("data", $data);
            return $this->fetch();
        }
    }

    /**
     * 会员删除
     */
    public function del()
    {
        $ids = $this->request->param('ids/a', null);
        if (empty($ids)) {
            $this->error('请选择需要删除的会员!');
        }
        if (!is_array($ids)) {
            $ids = array(0 => $ids);
        }
        foreach ($ids as $uid) {
            $info = $this->modelClass->find($uid);
            if (!empty($info)) {
                $this->modelClass->userDelete($uid);
            }
        }
        $this->success("删除成功!");

    }

    /**
     * 审核会员
     */
    public function userverify()
    {
        if ($this->request->isAjax()) {
            list($page, $limit, $where) = $this->buildTableParames();
            $_list                      = $this->modelClass->where($where)->where('status', '<>', 1)->page($page, $limit)->withAttr('last_login_time', function ($value, $data) {
                return time_format($value);
            })->select();
            $total  = $this->modelClass->where($where)->where('status', '<>', 1)->count();
            $result = array("code" => 0, "count" => $total, "data" => $_list);
            return json($result);

        }
        return $this->fetch();
    }

    /**
     * 审核会员
     */
    public function pass()
    {
        $ids = $this->request->param('ids/a', null);
        if (empty($ids)) {
            $this->error('请选择需要审核的会员!');
        }
        if (!is_array($ids)) {
            $ids = array(0 => $ids);
        }
        foreach ($ids as $uid) {
            $info = Member_Model::where('id', $uid)->update(['status' => 1]);
        }
        $this->success("审核成功!");
    }

}