File.php 2.7 KB

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