StampDuty.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class StampDuty 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. 'bl' => input('bl/f',0),
  14. 'type' => input('type/d',0),
  15. 'enable' => input('enable/d',1),
  16. 'org_id' => input('orgId/d',0)
  17. ];
  18. $logdata = json_encode($data);
  19. $result = validate('StampDuty')->check($data,[],'');
  20. if(true !== $result){
  21. HelpHander::error(validate('StampDuty')->getError());
  22. }
  23. $id = $data['id'];
  24. unset($data['id']);
  25. if($id > 0){
  26. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  27. }else{
  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(4,$content,0,$logdata);
  39. return true;
  40. }
  41. public function info($id){
  42. $info = $this->where('id',$id)->where('del',0)->find();
  43. if(!$info){
  44. HelpHander::error('数据不存在');
  45. }
  46. return $info->toArray();
  47. }
  48. public function lists($page,$size,$title,$orgId){
  49. $enable = input('enable/d',-1);
  50. if($enable >= 0){
  51. $map[] = ['enable','=',$enable];
  52. }
  53. $map[] = ['del','=',0];
  54. $map[] = ['org_id','=',$orgId];
  55. if($title != ''){
  56. $map[] = ['title','like','%'.$title.'%'];
  57. }
  58. $lists = $this
  59. ->where($map)
  60. ->page($page,$size)
  61. ->order('id desc')
  62. ->select();
  63. $total = $this->where($map)->count();
  64. $data = [
  65. 'total' => $total,
  66. 'list' => $lists?$lists->toArray():[]
  67. ];
  68. return $data;
  69. }
  70. public function allLists($orgId){
  71. $map[] = ['org_id','=',$orgId];
  72. $map[] = ['del','=',0];
  73. $map[] = ['enable','=',1];
  74. $lists = $this
  75. ->where($map)
  76. ->field('id,title,bl,type')
  77. ->order('id asc')
  78. ->select();
  79. return $lists?$lists->toArray():[];
  80. }
  81. public function del($id){
  82. $ret = $this->where('id',$id)->setField('del',1);
  83. if(!$ret){
  84. HelpHander::error('删除失败');
  85. }
  86. $logdata = json_encode(['id' => $id]);
  87. model('ActionLog')->add(4,'删除印花税目',0,$logdata);
  88. return true;
  89. }
  90. }