HouseMark.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class HouseMark extends Model
  7. {
  8. public function add(){
  9. $data = [
  10. 'id' => input('id/d',0),
  11. 'org_id' => input('orgId/d',0),
  12. 'house_id' => input('houseId/d',0),
  13. 'content' => input('content','','trim'),
  14. 'type' => input('type/d',0),
  15. 'end_time' => input('endTime','','trim'),
  16. 'color' => input('color','','trim'),
  17. ];
  18. $result = validate('HouseMark')->check($data,[],'');
  19. if(true !== $result){
  20. HelpHander::error(validate('HouseMark')->getError());
  21. }
  22. $id = $data['id'];
  23. unset($data['id']);
  24. if(!$data['end_time']){
  25. unset($data['end_time']);
  26. }
  27. if($id > 0){
  28. $data['update_time'] = date('Y-m-d H:i:s');
  29. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  30. }else{
  31. $data['create_time'] = date('Y-m-d H:i:s');
  32. $ret = $this->allowField(true)->save($data);
  33. }
  34. if(!$ret){
  35. HelpHander::error('操作失败');
  36. }
  37. return true;
  38. }
  39. public function del($id){
  40. $ret = $this->where('id',$id)->delete();
  41. if(!$ret){
  42. HelpHander::error('删除失败');
  43. }
  44. return true;
  45. }
  46. public function lists($page,$size,$houseId,$orgId){
  47. $map[] = ['house_id','=',$houseId];
  48. $map[] = ['org_id','=',$orgId];
  49. $lists = $this
  50. ->where($map)
  51. ->page($page,$size)
  52. ->order('id desc')
  53. ->select();
  54. $total = $this->where($map)->count();
  55. $data = [
  56. 'total' => $total,
  57. 'list' => $lists?$lists->toArray():[]
  58. ];
  59. return $data;
  60. }
  61. }