OfficialSeal.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class OfficialSeal extends Model
  7. {
  8. public function add(){
  9. $data = [
  10. 'id' => input('id/d',0),
  11. 'title' => input('title','','trim'),
  12. 'content' => input('content','','trim'),
  13. 'type' => input('type/d',0),
  14. 'org_id' => input('orgId/d',0),
  15. ];
  16. $logdata = json_encode($data);
  17. $result = validate('OfficialSeal')->check($data,[],'');
  18. if(true !== $result){
  19. HelpHander::error(validate('OfficialSeal')->getError());
  20. }
  21. $id = $data['id'];
  22. unset($data['id']);
  23. if($id > 0){
  24. $data['update_time'] = date('Y-m-d H:i:s');
  25. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  26. }else{
  27. $data['create_time'] = date('Y-m-d H:i:s');
  28. $ret = $this->allowField(true)->save($data);
  29. }
  30. if(!$ret){
  31. HelpHander::error('操作失败');
  32. }
  33. if($id > 0){
  34. $content = '修改印章';
  35. }else{
  36. $content = '添加印章';
  37. }
  38. model('ActionLog')->add(7,$content,0,$logdata);
  39. return true;
  40. }
  41. public function info($id){
  42. $info = $this->where('id',$id)->find();
  43. if(!$info){
  44. HelpHander::error('数据不存在');
  45. }
  46. return $info->toArray();
  47. }
  48. public function lists($page,$size,$title,$orgId){
  49. $map[] = ['del','=',0];
  50. $map[] = ['org_id','=',$orgId];
  51. if($title){
  52. $map[] = ['title','like','%'.$title.'%'];
  53. }
  54. $lists = $this
  55. ->where($map)
  56. ->page($page,$size)
  57. ->order('id desc')
  58. ->select();
  59. $total = $this->where($map)->count();
  60. $data = [
  61. 'total' => $total,
  62. 'list' => $lists?$lists->toArray():[]
  63. ];
  64. return $data;
  65. }
  66. public function all($type,$orgId){
  67. $map[] = ['del','=',0];
  68. $map[] = ['org_id','=',$orgId];
  69. if($type > 0){
  70. $map[] = ['type','=',$type];
  71. }
  72. $lists = $this
  73. ->where($map)
  74. ->field('id,title')
  75. ->order('id desc')
  76. ->select();
  77. return $lists?$lists->toArray():[];
  78. }
  79. public function del($id){
  80. $ret = $this->where('id',$id)->setField('del',1);
  81. if(!$ret){
  82. HelpHander::error('删除失败');
  83. }
  84. $logdata = json_encode(['id' => $id]);
  85. model('ActionLog')->add(7,'删除印章',0,$logdata);
  86. return true;
  87. }
  88. }