AppIconCate.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class AppIconCate extends Model
  7. {
  8. public function add(){
  9. $data = [
  10. 'id' => input('id/d',0),
  11. 'name' => input('name','','trim'),
  12. 'enable' => input('enable/d',0)
  13. ];
  14. $result = validate('AppIconCate')->check($data,[],'');
  15. if(true !== $result){
  16. HelpHander::error(validate('AppIconCate')->getError());
  17. }
  18. $id = $data['id'];
  19. unset($data['id']);
  20. if($id > 0){
  21. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  22. }else{
  23. $ret = $this->allowField(true)->save($data);
  24. }
  25. if(!$ret){
  26. HelpHander::error('操作失败');
  27. }
  28. return true;
  29. }
  30. public function info($id){
  31. $info = $this->where('id',$id)->where('del',0)->find();
  32. if(!$info){
  33. HelpHander::error('数据不存在');
  34. }
  35. return $info->toArray();
  36. }
  37. public function lists(){
  38. $lists = $this
  39. ->where('del',0)
  40. ->order('id asc')
  41. ->select();
  42. return $lists?$lists->toArray():[];
  43. }
  44. public function listDetail(){
  45. $lists = $this
  46. ->where('del',0)
  47. ->order('id asc')
  48. ->select();
  49. $lists = $lists ? $lists->toArray() : [];
  50. $lists[] = [
  51. 'id' => 0,
  52. 'name' => '其他',
  53. 'createTime' => '',
  54. 'enable' => 1
  55. ];
  56. foreach ($lists as $k=>$v){
  57. $apps = Db::name('app_icon')
  58. ->where('del',0)
  59. ->where('cate_id',$v['id'])
  60. ->order('id asc')
  61. ->select();
  62. $lists[$k]['appIconList'] = $apps?$apps:[];
  63. }
  64. return $lists;
  65. }
  66. public function del($id){
  67. $ret = $this->where('id',$id)->setField('del',1);
  68. if(!$ret){
  69. Db::name('app_icon')->where('cate_id',$id)->setField('cate_id',0); // 下属模块移到其他模块
  70. HelpHander::error('删除失败');
  71. }
  72. return true;
  73. }
  74. public function changeStatus($id,$enable){
  75. $ret = $this->where('id',$id)->setField('enable',$enable);
  76. if(!$ret){
  77. HelpHander::error('操作失败');
  78. }
  79. return true;
  80. }
  81. }