Rule.php 961 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace app\user\model;
  3. use think\Model;
  4. use think\Db;
  5. use think\Request;
  6. /**
  7. * 权限管理
  8. * @author Superbee
  9. *
  10. */
  11. class Rule extends Model{
  12. protected $updateTime = 'update_time'; // 每次更新时间
  13. protected $autoWriteTimestamp = 'datetime'; // 开启自动写入时间戳字段
  14. public function initialize() {
  15. parent::initialize();
  16. }
  17. public function getInfo(){
  18. return $this->db()->getTreeData('tree', 'id', 'title');
  19. }
  20. /**
  21. * 根据id找到对象
  22. * @param int $id
  23. */
  24. public function getRuleById($id){
  25. return $this->db()->where(['id'=>$id])->find();
  26. }
  27. public function addAndSave(){
  28. $data = request()->post();
  29. return $this->allowField(true)->isUpdate($data['id']?true:false)->save($data);
  30. }
  31. public function remove(){
  32. $request = Request::instance();
  33. if($request->isPost()) $this->data = $request->post();
  34. if($request->isGet()) $this->data = $request->get();
  35. return $this->delete();
  36. }
  37. }