123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class HouseCommunity extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'title' => input('title','','trim'),
- 'district_id' => input('districtId',0),
- 'org_id' => input('orgId/d',0),
- 'type' => input('type/d',1)
- ];
- $result = validate('HouseCommunity')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('HouseCommunity')->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('HouseBuilding')->where('community_id',$id)->find();
- if($res){
- HelpHander::error('已被使用无法删除');
- }
- $ret = $this->where('id',$id)->delete();
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- public function lists($page,$size,$title,$districtId,$type){
- if($title != ''){
- $map[] = ['title','like','%'.$title.'%'];
- }
- if($districtId > 0){
- $map[] = ['district_id','=',$districtId];
- }
- $map[] = ['type','=',$type];
- $map = isset($map)?$map:true;
- $lists = $this
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- foreach ($lists as $k=>$v){
- $lists[$k]['districtName'] = Db::name('house_district')->where('id',$v['district_id'])->value('title');
- }
- $total = $this->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists->toArray():[]
- ];
- return $data;
- }
- }
|