| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use think\Db;
- /**
- *
- *
- * @icon fa fa-circle-o
- */
- class Rfiduser extends Backend
- {
- /**
- * Rfiduser模型对象
- * @var \app\admin\model\Rfiduser
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\Rfiduser;
- }
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
- * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- /**
- 新增
- */
- public function add()
- {
- if ($this->request->isPost()) {
- $param = input('');
- // 当前时间和 token 过期时间
- $now = time();
- $todayEnd = strtotime(date('Y-m-d 23:59:59'));
- // 生成初始 token
- $token = md5($param['row']['username'] . $now . uniqid());
- $arr = [
- 'nickname' => $param['row']['nickname'],
- 'username' => $param['row']['username'],
- 'password' => md5($param['row']['password']),
- 'token' => $token, // 初始 token
- 'token_expire_time' => date('Y-m-d H:i:s', $todayEnd), // 当天结束时间
- 'building' => '', // 栋
- 'room' => '', // 房间
- 'pen' => '', // 栏位
- 'sys_rq' => date('Y-m-d H:i:s') // 系统创建时间
- ];
- $add_result = Db::name("rfid_user")->insert($arr);
- if ($add_result) {
- $this->success('新增成功');
- } else {
- $this->error('新增失败');
- }
- } else {
- return $this->view->fetch();
- }
- }
- /**
- 修改
- */
- public function edit($ids = null)
- {
- if ($this->request->isPost()) {
- $param = input('');
- $arr = [
- 'nickname' => $param['row']['nickname'],
- 'username' => $param['row']['username'],
- 'password' => md5($param['row']['password'])
- ];
- $res = Db::name("rfid_user")->where('id',$ids)->update($arr);
- if ($res == 0) {
- $this->success('修改成功');
- } else {
- $this->error('修改失败');
- }
- }else{
- $row = Db::name("rfid_user")->where('id', $ids)->find();
- if (!$row) {
- $this->error("记录未找到");
- }
- $this->assign("row", $row);
- return $this->view->fetch();
- }
- }
- }
|