123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use app\Request;
- use think\Db;
- use think\Model;
- class HouseTurn extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'title' => input('title','','trim'),
- 'number' => input('number'),//门牌号
- 'tenant_area' => input('tenantArea'),//面积
- 'spec' => input('spec'),//规格
- 'remark' => input('remark'),//备注
- 'imgs' => input('imgs'),//房屋图片
- 'img2' => input('img2'),//产权证
- 'enable' => input('enable'),
- 'create_time' => date("Y-m-d H:i:s",time()),
- 'update_time' => date("Y-m-d H:i:s",time()),
- 'building_id' => input('buildingId/d'),
- 'level_id' => input('levelId/d'),
- 'org_id' => input('orgId/d',0),
- 'important' => input('important/d',0),
- 'aspect' => input('aspect','','trim'),
- 'unit' => input('unit','','trim'),
- 'decoration' => input('decoration/d',0),
- 'decoration_time' => input('decorationTime','','trim'),
- ];
- $logdata = json_encode($data);
- if(!$data['decoration_time']){
- unset($data['decoration_time']);
- }
- if($data['unit'] && is_numeric($data['unit'])){ // 如果只有数据加上单元
- $data['unit'] = $data['unit'].'单元';
- }
- $result = validate('HouseTurn')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('HouseTurn')->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('操作失败');
- }
- if($id > 0){
- $content = '修改周转房';
- }else{
- $content = '添加周转房';
- }
- model('ActionLog')->add(16,$content,0,$logdata);
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- $data = $info->toArray();
- $building = Db::name('house_building')->where('id',$data['building_id'])->find();
- $community = Db::name('house_community')->where('id',$building['community_id'])->find();
- $district = Db::name('house_district')->where('id',$community['district_id'])->find();
- $data['buildingName'] = $building['title'];
- $data['district_id'] = $community['district_id'];
- $data['community_id'] = $building['community_id'];
- $data['communityName'] = $community['title'];
- $data['districtName'] = $district['title'];
- $data['levelName'] = Db::name('house_level')->where('id',$data['level_id'])->value('title');
- if($data['cur_lessee_id'] > 0){
- $data['lesseeName'] = Db::name('house_lessee')->where('id',$data['cur_lessee_id'])->value('title');
- }else{
- $data['lesseeName'] = '';
- }
- return $data;
- }
- public function del($id){
- $ret = $this->where('id',$id)->update(['del'=>1]);
- if(!$ret){
- HelpHander::error('删除失败');
- }
- $logdata = json_encode(['id' => $id]);
- model('ActionLog')->add(16,'删除周转房',0,$logdata);
- return true;
- }
- public function lists($page,$size,$title,$status,$enable,$lessee,$userId,$orgId,$type=0,$vacancy=0){
- $map[] = ['org_id','=',$orgId];
- $map[] = ['del','=',0];
- if($title != ''){
- $map[] = ['title','like','%'.$title.'%'];
- }
- if($lessee != ''){
- $map[] = ['lessee_name','like','%'.$lessee.'%'];
- }
- if($status >= 0){
- $map[] = ['status','=','%'.$status.'%'];
- }
- if($enable >= 0){
- $map[] = ['enable','=','%'.$enable.'%'];
- }
- if($type > 0){
- $map[] = ['type','=','%'.$type.'%'];
- }
- if($vacancy == 1){ //空置
- $map[] = ['cur_lessee_id','=',0];
- }else if($vacancy == 1){ //在用
- $map[] = ['cur_lessee_id','>',0];
- }
- $auths = Db::name('house_auth')->where('user_id',$userId)->where('type',2)->value('ids');
- if(!$auths){
- $map[] = ['level_id','=',-1];
- }else{
- $map[] = ['level_id','in',$auths];
- }
- $lists = Db::name('house_turn_list')
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $lists[$k]['levelName'] = Db::name('house_level')->where('id',$v['level_id'])->value('title');
- }
- $total = Db::name('house_turn_list')
- ->where($map)->count();
- // 使用
- $usecount = Db::name('house_turn_list')
- ->where($map)
- ->where('cur_lessee_id','>',0)
- ->count();
- // 重点
- $zdcount = Db::name('house_turn_list')
- ->where($map)
- ->where('important','=',1)
- ->count();
- $data = [
- 'total' => $total,
- 'useTotal' => $usecount,
- 'kzTotal' => $total - $usecount,
- 'list' => $lists
- ];
- return $data;
- }
- public function uhlists($page,$size,$title,$status,$lessee,$userId,$orgId,$startTime,$endTime){
- $map[] = ['org_id','=',$orgId];
- if($title != ''){
- $map[] = ['title','like','%'.$title.'%'];
- }
- if($lessee != ''){
- $map[] = ['lessee_name','like','%'.$lessee.'%'];
- }
- if($status >= 0){
- $map[] = ['status','=','%'.$status.'%'];
- }
- if($startTime && $endTime){
- $map[] = ['start_time','>=',$startTime];
- $map[] = ['start_time','<=',$endTime];
- }
- $auths = Db::name('house_auth')->where('user_id',$userId)->where('type',2)->value('ids');
- if(!$auths){
- $map[] = ['level_id','=',-1];
- }else{
- $map[] = ['level_id','in',$auths];
- }
- $lists = Db::name('house_turn_lessee_list')
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $lists[$k]['levelName'] = Db::name('house_level')->where('id',$v['level_id'])->value('title');
- }
- $total = Db::name('house_turn_lessee_list')
- ->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists
- ];
- return $data;
- }
- public function listsold($page,$size,$title,$status,$enable,$lessee,$userId,$orgId){
- $map[] = ['ht.org_id','=',$orgId];
- $map[] = ['ht.del','=',0];
- if($title != ''){
- $map[] = ['ht.number','like','%'.$title.'%'];
- }
- if($lessee != ''){
- $map[] = ['hl.title','like','%'.$lessee.'%'];
- }
- if($status >= 0){
- $map[] = ['ht.status','=','%'.$lessee.'%'];
- }
- if($enable >= 0){
- $map[] = ['ht.enable','=','%'.$enable.'%'];
- }
- $auths = Db::name('house_auth')->where('user_id',$userId)->where('type',2)->value('ids');
- if(!$auths){
- $map[] = ['ht.level_id','=',-1];
- }else{
- $map[] = ['ht.level_id','in',$auths];
- }
- $lists = Db::name('house_turn')
- ->alias('ht')
- ->join('house_building hb','hb.id = ht.building_id')
- ->join('house_community hc','hc.id = hb.community_id')
- ->join('house_district hd','hd.id = hc.district_id')
- ->join('house_lessee hl','hl.id = ht.cur_lessee_id','left')
- ->field('ht.*,hb.title as buildingName,hc.title as communityName,hc.id as community_id,hd.title as districtName,hd.id as distract_id,hl.title as lesseeName')
- ->where($map)
- ->page($page,$size)
- ->order('ht.id desc')
- ->select();
- // $lists = $this
- // ->where($map)
- // ->page($page,$size)
- // ->order('id desc')
- // ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- // $building = Db::name('house_building')->where('id',$v['building_id'])->find();
- // $community = Db::name('house_community')->where('id',$building['community_id'])->find();
- // $district = Db::name('house_district')->where('id',$community['district_id'])->find();
- //
- // $lists[$k]['buildingName'] = $building['title'];
- // $lists[$k]['district_id'] = $community['district_id'];
- // $lists[$k]['community_id'] = $building['community_id'];
- // $lists[$k]['communityName'] = $community['title'];
- // $lists[$k]['districtName'] = $district['title'];
- $lists[$k]['levelName'] = Db::name('house_level')->where('id',$v['level_id'])->value('title');
- // if($v['cur_lessee_id'] > 0){
- // $lists[$k]['lesseeName'] = Db::name('house_lessee')->where('id',$v['cur_lessee_id'])->value('title');
- // }else{
- // $lists[$k]['lesseeName'] = '';
- // }
- }
- $total = Db::name('house_turn')
- ->alias('ht')
- ->join('house_building hb','hb.id = ht.building_id')
- ->join('house_community hc','hc.id = hb.community_id')
- ->join('house_district hd','hd.id = hc.district_id')
- ->join('house_lessee hl','hl.id = ht.cur_lessee_id','left')
- ->where($map)->count();
- // 使用
- $usecount = Db::name('house_turn')
- ->alias('ht')
- ->join('house_building hb','hb.id = ht.building_id')
- ->join('house_community hc','hc.id = hb.community_id')
- ->join('house_district hd','hd.id = hc.district_id')
- ->join('house_lessee hl','hl.id = ht.cur_lessee_id','left')
- ->where($map)
- ->where('ht.cur_lessee_id','>',0)
- ->count();
- // 重点
- $zdcount = Db::name('house_turn')
- ->alias('ht')
- ->join('house_building hb','hb.id = ht.building_id')
- ->join('house_community hc','hc.id = hb.community_id')
- ->join('house_district hd','hd.id = hc.district_id')
- ->join('house_lessee hl','hl.id = ht.cur_lessee_id','left')
- ->where($map)
- ->where('ht.important','=',1)
- ->count();
- $data = [
- 'total' => $total,
- 'useTotal' => $usecount,
- 'kzTotal' => $total - $usecount,
- 'list' => $lists
- ];
- return $data;
- }
- public function export($title,$status,$enable,$lessee,$userId,$orgId,$vacancy=0){
- $map[] = ['ht.org_id','=',$orgId];
- $map[] = ['ht.del','=',0];
- if($title != ''){
- $map[] = ['ht.number','like','%'.$title.'%'];
- }
- if($lessee != ''){
- $map[] = ['hl.title','like','%'.$lessee.'%'];
- }
- if($status >= 0){
- $map[] = ['ht.status','=','%'.$lessee.'%'];
- }
- if($enable >= 0){
- $map[] = ['ht.enable','=','%'.$enable.'%'];
- }
- if($vacancy == 1){ //空置
- $map[] = ['ht.cur_lessee_id','=',0];
- }else if($vacancy == 1){ //在用
- $map[] = ['ht.cur_lessee_id','>',0];
- }
- $auths = Db::name('house_auth')->where('user_id',$userId)->where('type',2)->value('ids');
- if(!$auths){
- $map[] = ['ht.level_id','=',-1];
- }else{
- $map[] = ['ht.level_id','in',$auths];
- }
- $lists = Db::name('house_turn')
- ->alias('ht')
- ->join('house_building hb','hb.id = ht.building_id')
- ->join('house_community hc','hc.id = hb.community_id')
- ->join('house_district hd','hd.id = hc.district_id')
- ->join('house_lessee hl','hl.id = ht.cur_lessee_id','left')
- ->field('ht.*,hb.title as buildingName,hc.title as communityName,hc.id as community_id,hd.title as districtName,hd.id as distract_id,hl.title as lesseeName')
- ->where($map)
- ->order('ht.id desc')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $lists[$k]['levelName'] = Db::name('house_level')->where('id',$v['level_id'])->value('title');
- if($v['enable'] == 1){
- $lists[$k]['enable_text'] = "启用";
- }else{
- $lists[$k]['enable_text'] = "禁用";
- }
- if($v['decoration'] == 1){
- $lists[$k]['decoration_text'] = "启用";
- }else{
- $lists[$k]['decoration_text'] = "禁用";
- }
- }
- // foreach ($lists as $k=>$v){
- // $lists[$k]['cate_name'] = Db::name('office_cate')->where('id',$v['cate_id'])->value('title');
- // $lists[$k]['unit_name'] = Db::name('office_unit')->where('id',$v['unit_id'])->value('title');
- // if($v['enable'] == 1){
- // $lists[$k]['enable_text'] = '启用';
- // }else{
- // $lists[$k]['enable_text'] = '禁用';
- // }
- // }
- $columns = [
- ["title" => "所属城区","key" => "districtName"],
- ["title" => "所属小区","key" => "communityName"],
- ["title" => "所属楼房","key" => "buildingName"],
- ["title" => "单元","key" => "unit"],
- ["title" => "房间号","key" => "number"],
- ["title" => "规格","key" => "spec"],
- ["title" => "面积","key" => "tenantArea"],
- ["title" => "入住人","key" => "lesseeName"],
- ["title" => "级别","key" => "levelName"],
- ["title" => "统一装修","key" => "decorationText"],
- ["title" => "装修时间","key" => "decorationTime"],
- ["title" => "状态","key" => "enableText"],
- ["title" => "朝向","key" => "aspect"],
- ["title" => "创建日期","key" => "createTime"],
- ];
- $data = [
- 'columns' => $columns,
- 'list' => $lists
- ];
- return $data;
- }
- // 改变为商品房
- public function changeStatus($id,$sImg,$sRemark){
- $info = Db::name('house_turn')->where('id',$id)->where('del',0)->find();
- if(!$info){
- HelpHander::error('记录不存在');
- }
- if($info['status'] == 1){
- HelpHander::error('已经是商品房,无需重复操作');
- }
- $res = Db::name('house_turn')->where('id',$id)->update([
- 'status' => 1,
- 's_img' => $sImg,
- 's_remark' => $sRemark,
- 's_time' => date('Y-m-d H:i:s')
- ]);
- if(!$res){
- HelpHander::error('操作失败');
- }
- $logdata = json_encode(['id' => $id,'sImg'=>$sImg,'sRemark'=>$sRemark]);
- model('ActionLog')->add(16,'周转房转商品房',0,$logdata);
- return true;
- }
- /**
- * 获取数量
- * @param $lessee
- * @return float|string
- */
- public function getCountByLessee($lessee){
- $map[] = ['del','=',0];
- $map[] = ['enable','=',1];
- $map[] = ['status','=',0];
- if($lessee == 1){ //租赁出去的
- $map[] = ['cur_lessee_id','>',0];
- }else{
- $map[] = ['cur_lessee_id','=',0];
- }
- $count = Db::name('house_turn')
- ->where($map)
- ->count();
- return $count;
- }
- // 根据面积获取数量
- public function getArea($type){
- if($type == 1){
- $map[] = ['tenant_area','<',70];
- }else if($type == 2){
- $map[] = ['tenant_area','<',90];
- $map[] = ['tenant_area','>=',70];
- }else if($type == 3){
- $map[] = ['tenant_area','<',110];
- $map[] = ['tenant_area','>=',90];
- }else{
- $map[] = ['tenant_area','>',110];
- }
- $map[] = ['del','=',0];
- $map[] = ['enable','=',1];
- $map[] = ['status','=',0];
- $count = Db::name('house_turn')->where($map)->count();
- return $count;
- }
- }
|