HouseContractDefault.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class HouseContractDefault extends Model
  7. {
  8. public function add(){
  9. $data = [
  10. 'id' => input('id/d',0),
  11. 'intro' => input('intro','','trim'),
  12. 'contract_id' => input('contractId/d',0),
  13. 'default_date' => input('defaultDate','','trim'),
  14. 'remark' => input('remark','','trim'),
  15. 'files' => input('files','','trim'),
  16. 'org_id' => input('orgId/d',0),
  17. ];
  18. $result = validate('HouseContractDefault')->check($data,[],'');
  19. if(true !== $result){
  20. HelpHander::error(validate('HouseContractDefault')->getError());
  21. }
  22. $id = $data['id'];
  23. unset($data['id']);
  24. if($id > 0){
  25. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  26. }else{
  27. $ret = $this->allowField(true)->save($data);
  28. }
  29. if(!$ret){
  30. HelpHander::error('操作失败');
  31. }
  32. return true;
  33. }
  34. public function del($id){
  35. $ret = $this->where('id',$id)->setField('del',1);
  36. if(!$ret){
  37. HelpHander::error('删除失败');
  38. }
  39. return true;
  40. }
  41. public function lists($page,$size,$intro,$contractId,$orgId){
  42. $map[] = ['org_id','=',$orgId];
  43. if($intro != ''){
  44. $map[] = ['intro','like','%'.$intro.'%'];
  45. }
  46. if($contractId > 0){
  47. $map[] = ['contract_id','=',$contractId];
  48. }
  49. $lists = $this
  50. ->where($map)
  51. ->page($page,$size)
  52. ->order('id desc')
  53. ->select();
  54. $lists = $lists?$lists->toArray():[];
  55. foreach ($lists as $k=>$v){
  56. $files = $v['files']?json_decode($v['files'],true):[];
  57. $lists[$k]['filesUrl'] = empty($files)?'':$files[0]['url'];
  58. $lists[$k]['filesName'] = empty($files)?'':$files[0]['name'];
  59. }
  60. $total = $this->where($map)->count();
  61. $data = [
  62. 'total' => $total,
  63. 'list' => $lists?$lists:[]
  64. ];
  65. return $data;
  66. }
  67. }