Certificate.php 2.6 KB

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