1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class HouseLesseeProp extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'title' => input('title','','trim'),
- 'org_id' => input('orgId/d',0),
- ];
- $result = validate('HouseLesseeProp')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('HouseLesseeProp')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function del($id){
- $res = Db::name('HouseLessee')->where('prop_id',$id)->where('del',0)->find();
- if($res){
- HelpHander::error('已被使用无法删除');
- }
- $ret = $this->where('id',$id)->delete();
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- public function lists($page,$size,$title){
- if($title != ''){
- $map[] = ['title','like','%'.$title.'%'];
- }else{
- $map =[];
- }
- $lists = $this
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $total = $this->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists->toArray():[]
- ];
- return $data;
- }
- public function all($orgId){
- $map[] = ['org_id','=',$orgId];
- $lists = $this
- ->where($map)
- ->field('id,title')
- ->order('id desc')
- ->select();
- return $lists?$lists->toArray():[];
- }
- }
|