Icons.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class Icons extends Model
  7. {
  8. public function add(){
  9. $data = [
  10. 'id' => input('id/d',0),
  11. 'path' => input('path','','trim')
  12. ];
  13. $result = validate('Icons')->check($data,[],'');
  14. if(true !== $result){
  15. HelpHander::error(validate('Icons')->getError());
  16. }
  17. $id = $data['id'];
  18. unset($data['id']);
  19. if($id > 0){
  20. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  21. }else{
  22. $ret = $this->allowField(true)->save($data);
  23. }
  24. if(!$ret){
  25. HelpHander::error('操作失败');
  26. }
  27. return true;
  28. }
  29. public function info($id){
  30. $info = $this->where('id',$id)->find();
  31. if(!$info){
  32. HelpHander::error('数据不存在');
  33. }
  34. return $info->toArray();
  35. }
  36. public function lists($page,$size){
  37. $lists = $this
  38. ->page($page,$size)
  39. ->order('id asc')
  40. ->select();
  41. $total = $this->count();
  42. $data = [
  43. 'total' => $total,
  44. 'list' => $lists?$lists->toArray():[]
  45. ];
  46. return $data;
  47. }
  48. public function del($id){
  49. $ret = $this->where('id',$id)->delete();
  50. if(!$ret){
  51. HelpHander::error('删除失败');
  52. }
  53. return true;
  54. }
  55. }