Program.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class Program extends Model
  7. {
  8. public function add(){
  9. $data = [
  10. 'id' => input('id/d',0),
  11. 'title' => input('title','','trim'),
  12. 'sn' => input('sn','','trim'),
  13. 'content' => input('content','','trim'),
  14. 'enable' => input('enable/d',1),
  15. 'org_id' => input('orgId/d',0),
  16. 'company_id' => input('companyId/d',0)
  17. ];
  18. $logdata = json_encode($data);
  19. $result = validate('Program')->check($data,[],'');
  20. if(true !== $result){
  21. HelpHander::error(validate('Program')->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(3,$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,$companyId,$orgId){
  49. $map[] = ['del','=',0];
  50. $map[] = ['org_id','=',$orgId];
  51. $map[] = ['company_id','=',$companyId];
  52. if($title != ''){
  53. $map[] = ['title','like','%'.$title.'%'];
  54. }
  55. $lists = $this
  56. ->where($map)
  57. ->page($page,$size)
  58. ->order('id desc')
  59. ->select();
  60. $total = $this->where($map)->count();
  61. $data = [
  62. 'total' => $total,
  63. 'list' => $lists?$lists->toArray():[]
  64. ];
  65. return $data;
  66. }
  67. public function allLists($orgId){
  68. $map[] = ['org_id','=',$orgId];
  69. $map[] = ['del','=',0];
  70. $map[] = ['enable','=',1];
  71. $lists = $this
  72. ->where($map)
  73. ->field('id,title,company_id')
  74. ->order('id desc')
  75. ->select();
  76. return $lists?$lists->toArray():[];
  77. }
  78. public function del($id){
  79. $ret = $this->where('id',$id)->setField('del',1);
  80. if(!$ret){
  81. HelpHander::error('删除失败');
  82. }
  83. $logdata = json_encode(['id' => $id]);
  84. model('ActionLog')->add(3,'删除项目',0,$logdata);
  85. return true;
  86. }
  87. }