Commit 25b6b0e7 authored by 蔡闯's avatar 蔡闯

社区基本信息功能

parent ac5c4c71
...@@ -19,8 +19,14 @@ abstract class BaseController ...@@ -19,8 +19,14 @@ abstract class BaseController
"property" => '物业费', "property" => '物业费',
"electric" => '电费', "electric" => '电费',
"gas" => '燃气费', "gas" => '燃气费',
"parking" => '停车费' "park" => '停车费'
]; ];
protected $myUnit = [
'water' =>"吨",
'electric' =>'度',
'gas' =>'立方'
];
/** /**
* Request实例 * Request实例
* @var \think\Request * @var \think\Request
......
<?php <?php
namespace app\api\controller; namespace app\api\controller;
use app\common\controller\Common; use app\common\controller\Common;
use app\BaseController; use app\BaseController;
use think\facade\Db; use think\facade\Db;
use think\facade\Request; use think\facade\Request;
class Index extends Base class Index extends Base
{ {
public function index() { //app首页信息,如果用户只绑定了一个房间,则默认展示一个房间的
public function index() {
$page = Request::param('page',1);
return "这是我请求的内容"; $uid = $this->uid;
} $village_id = Request::param('village_id');
if(empty($village_id)) {
//建筑列表 $data = Db::name('house_user_bind')->alias('hub')
public function buildList() { ->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
$where['lb.village_id'] = Request::param('village_id'); ->leftJoin('house_village hvi','hvi.village_id = hv.village_id')
$parent_id = Request::param('parent_id',0); ->where(['hub.uid'=>$uid])
$where['lb.parent_id'] = $parent_id; ->field('hvi.village_name,hvi.village_id')->find();
//检查当前的parent_id是否是最下的一个建筑了,如果是,则查询该下面的房屋 } else {
if($parent_id != 0) { $data = Db::name('house_village')->where(['village_id'=>$village_id])->field('village_id,village_name')->find();
$layout_id = Request::param('layout_id'); }
$listInfo = Db::name('layout_list')->where(['layout_id'=>$layout_id])->field('code,level')->find();
$level = $listInfo['level']-1; $news= Db::name('news')->where(['village_id'=>$data['village_id'],'is_recommend'=>1])->order('recommend_sort_id','desc')
$listArr = explode('-',$listInfo['code']); ->field('title,pic,content')
$name = array_pop($listArr); ->page($page,config('app.limit'))
$is_last = Db::name('layout_build')->where(['layout_build_id'=>$parent_id,'level'=>$level])->find(); ->select()->toArray();
if($is_last){ //查找房间
$data = Db::name('house_vacancy')->where(['parent_id'=>$parent_id])->field('vacancy_id,vacancy_code')->select()->toArray(); foreach ($news as $k=>$v) {
foreach ($data as $k => $v) { $news[$k]['content'] = mb_substr(strip_tags($v['content']),0,100);
$vacancyArr = explode('-',$v['vacancy_code']); }
$code = array_pop($vacancyArr); $data['news'] = $news;
$data[$k]['code_name'] = $code.$name; return $this->returnJson($data);
} }
} else{
$data = $this->getBuildInfo($where); //建筑列表
} public function buildList() {
} else { $where['lb.village_id'] = Request::param('village_id');
$data = $this->getBuildInfo($where); $parent_id = Request::param('parent_id',0);
} $where['lb.parent_id'] = $parent_id;
//检查当前的parent_id是否是最下的一个建筑了,如果是,则查询该下面的房屋
return $this->returnJson($data); if($parent_id != 0) {
} $layout_id = Request::param('layout_id');
$listInfo = Db::name('layout_list')->where(['layout_id'=>$layout_id])->field('code,level')->find();
//获取建筑信息 $level = $listInfo['level']-1;
public function getBuildInfo($where) { $listArr = explode('-',$listInfo['code']);
if(Request::param('layout_id')) { $name = array_pop($listArr);
$where['lb.layout_id'] = Request::param('layout_id'); $is_last = Db::name('layout_build')->where(['layout_build_id'=>$parent_id,'level'=>$level])->find();
} if($is_last){ //查找房间
$data = Db::name('layout_build')->alias('lb')->leftJoin('layout_list ll','ll.layout_id = lb.layout_id')->where($where)->order(['lb.layout_id'=>'asc','lb.sort_id'=>'desc']) $data = Db::name('house_vacancy')->where(['parent_id'=>$parent_id])->field('vacancy_id,vacancy_code')->select()->toArray();
->field("lb.layout_build_id,lb.layout_id,lb.code,lb.level,lb.village_id,ll.code as list_code") foreach ($data as $k => $v) {
->select() $vacancyArr = explode('-',$v['vacancy_code']);
->toArray(); $code = array_pop($vacancyArr);
foreach ($data as $k =>$v) { $data[$k]['code_name'] = $code.$name;
$data[$k]['code_name'] = $v['code'].explode('-',$v['list_code'])[$v['level']-1]; }
} } else{
$data = $this->getBuildInfo($where);
return $data; }
} } else {
$data = $this->getBuildInfo($where);
}
//获取单个房间基本信息
public function getVacancyInfo() { return $this->returnJson($data);
$vacancy_id = Request::param('vacancy_id'); }
$data = Db::name('house_vacancy')->alias('hv')
->Join('house_village hvi','hvi.village_id = hv.village_id') //获取建筑信息
->Join('house_user_bind hub','hub.vacancy_id = hv.vacancy_id') public function getBuildInfo($where) {
->where(['hv.vacancy_id'=>$vacancy_id]) if(Request::param('layout_id')) {
->field('hv.vacancy_code,hv.village_id,hv.parent_id,layout_id,hvi.village_name,hvi.village_address,hvi.province_name,hvi.city_name,hvi.area_name') $where['lb.layout_id'] = Request::param('layout_id');
->find(); }
$data['vacancy_address'] = Common::getVacancyAddress($data['vacancy_code'],$data['layout_id']); $data = Db::name('layout_build')->alias('lb')->leftJoin('layout_list ll','ll.layout_id = lb.layout_id')->where($where)->order(['lb.layout_id'=>'asc','lb.sort_id'=>'desc'])
$data['vacancyOwnerInfo'] = Common::getOwnerInfo($vacancy_id); //物业信息 ->field("lb.layout_build_id,lb.layout_id,lb.code,lb.level,lb.village_id,ll.code as list_code")
$data['getUserBindType'] = Common::getUserBindType(); ->select()
$data['getFamilyBindType'] = Common::getFamilyBindType(); ->toArray();
return $this->returnJson($data); foreach ($data as $k =>$v) {
$data[$k]['code_name'] = $v['code'].explode('-',$v['list_code'])[$v['level']-1];
} }
return $data;
//常用电话 }
public function commonPhone() {
$village_id = Request::param('village_id');
$where['village_id'] = $village_id; //获取单个房间基本信息
$where['status'] = 1; public function getVacancyInfo() {
$data = Db::name('village_phone')->where($where)->order(['is_on_call_phone'=>'desc','sort'=>'desc'])->select()->toArray(); $vacancy_id = Request::param('vacancy_id');
return $this->returnJson($data); $data = Db::name('house_vacancy')->alias('hv')
} ->Join('house_village hvi','hvi.village_id = hv.village_id')
->Join('house_user_bind hub','hub.vacancy_id = hv.vacancy_id')
->where(['hv.vacancy_id'=>$vacancy_id])
->field('hv.vacancy_code,hv.village_id,hv.parent_id,layout_id,hvi.village_name,hvi.village_address,hvi.province_name,hvi.city_name,hvi.area_name')
->find();
$data['vacancy_address'] = Common::getVacancyAddress($data['vacancy_code'],$data['layout_id']);
$data['vacancyOwnerInfo'] = Common::getOwnerInfo($vacancy_id); //物业信息
$data['getUserBindType'] = Common::getUserBindType();
$data['getFamilyBindType'] = Common::getFamilyBindType();
return $this->returnJson($data);
}
//常用电话
public function commonPhone() {
$village_id = Request::param('village_id');
$where['village_id'] = $village_id;
$where['status'] = 1;
$data = Db::name('village_phone')->where($where)->order(['is_on_call_phone'=>'desc','sort'=>'desc'])->select()->toArray();
return $this->returnJson($data);
}
//当前用户的所有的房间列表
public function allVacancy() {
$uid = $this->uid;
$where[] = ['hub.uid','=',$uid];
$page = Request::param('page',1);
$data = Db::name('house_user_bind')->alias('hub')->where($where)
->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
->leftJoin('house_village hvi','hvi.village_id = hub.village_id')
->field('hub.house_user_bind_id,hvi.village_name,hv.vacancy_code,hv.layout_id,hub.pass_time,hub.type,hub.status,hub.vacancy_id,hvi.village_logo,hvi.village_id')
->page($page,config('app.limit'))
->select()->toArray();
foreach ($data as $k=>$v) {
$rest = Common::getVacancyAddress($v['vacancy_code'],$v['layout_id']);
$data[$k]['vacancy_address'] = $rest['vacancy_address'];
//获取用户车辆信息
$cars = Db::name('car')->where(['uid'=>$this->uid,'village_id'=>$v['village_id']])->field('car_id,license_plate')->select()->toArray();
$data[$k]['cars'] = $cars;
$car_total = count($cars);
if($car_total ==1) {
$data[$k]['cars'] = $cars[0];
}
$data[$k]['car_total'] = $car_total;
}
$total = Db::name('house_user_bind')->alias('hub')->where($where)->count();
$res['total'] = $total;
$res['data'] = Common::changeField($data,'pass_time');
return $this->returnJson($res);
}
//查看车辆详情
public function detailCar() {
$car_id = Request::param('car_id');
$data = Db::name('car')->where(['car_id'=>$car_id,'uid'=>$this->uid])->find();
return $this->returnJson($data);
}
//修改车辆
public function changeCar() {
$car_id = Request::param('car_id');
$data['license_plate'] = Request::param('license_plate');
$is_exit = Db::name('car')->where('uid','<>',$this->uid)->where($data)->find();
if($is_exit){
return $this->returnJson([],'该车牌号已存在!',400);
}
$data['name'] = Request::param('name');
$data['car_color'] = Request::param('car_color');
$data['brand'] = Request::param('brand');
$data['car_type'] = Request::param('car_type');
$change = Db::name('car')->where(['car_id'=>$car_id])->save($data);
if($change) {
return $this->returnJson([],'操作成功!');
} else {
return $this->returnJson([],'操作失败!',400);
}
}
//用户添加车辆
public function addCar() {
$uid = $this->uid;
$car_id = Request::param('car_id');
$data['phone'] = Db::name('user')->where(['uid'=>$uid])->value('phone');
$data['name'] = Request::param('name');
$data['brand'] = Request::param('brand');
$data['car_color'] = Request::param('car_color');
$data['license_plate'] = Request::param('license_plate');
$data['sort_id'] = Request::param('sort_id',1);
$data['uid'] = $uid;
$data['village_id'] = Request::param('village_id');
if($car_id) {
//判断车牌是否存在
$is_exit = Db::name('car')->where(['license_plate'=>$data['license_plate']])->where('car_id','<>',$car_id)->find();
if($is_exit) {
return $this->returnJson([],'系统中已存在该车牌!',400);
}
$operation = Db::name('car')->where(['car_id'=>$car_id])->save($data);
} else {
$data['create_time'] = time();
//判断车牌是否存在
$is_exit = Db::name('car')->where(['license_plate'=>$data['license_plate'],'village_id'=>$data['village_id']])->find();
if($is_exit) {
return $this->returnJson([],'系统中已存在该车牌!',400);
}
$operation = Db::name('car')->save($data);
}
if($operation) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'操作失败!',400);
}
}
//删除车辆
public function deleteCar() {
$car_id = Request::param('car_id');
$delete = Db::name('car')->where(['car_id'=>$car_id,'uid'=>$this->uid])->delete();
if($delete) {
return $this->returnJson();
} else {
return $this->returnJson([],'删除失败!',400);
}
}
//我的房间详情
public function detailVacancy() {
$bind_id = Request::param('bind_id');
$uid = $this->uid;
$where[] = ['hub.uid','=',$uid];
$where[] = ['hub.house_user_bind_id','=',$bind_id];
$data = Db::name('house_user_bind')->alias('hub')->where($where)
->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
->leftJoin('house_village hvi','hvi.village_id = hub.village_id')
->field('hvi.village_id,hvi.village_name,hv.vacancy_code,hv.layout_id,hub.pass_time,hub.type,hub.status,hub.vacancy_id,hvi.village_logo,hv.name,hv.phone,hub.house_user_bind_id')
->find();
$res = Common::getVacancyAddress($data['vacancy_code'],$data['layout_id']);
$data['vacancy_address'] = $res['vacancy_address'];
if($data['type'] ==0 ){
//查询家属
$data['family'] = $this->getFamily($data['vacancy_id']);
//查询租客
$data['tenant'] = $this->getTenant($data['vacancy_id']);
} elseif($data['type'] ==2){
$data['tenant'] = $this->getTenant($data['vacancy_id']);
}
return $this->returnJson($data);
}
//根据房间id,查询租客
public function getTenant($vacancy_id) {
//查询租客
$tenant = Db::name('house_user_bind')->alias('hub')->rightJoin('user','user.uid = hub.uid')
->where(['hub.vacancy_id'=>$vacancy_id,'hub.type'=>2])
->field('hub.name,hub.phone,user.avatar,user.uid,hub.village_id')->select()->toArray();
foreach ($tenant as $k =>$v) {
$car = Db::name('car')->where(['uid'=>$v['uid'],'village_id'=>$v['village_id']])->select()->toArray();
$tenant[$k]['cars'] = $car;
$tenant[$k]['car_total'] = count($car);
}
return $tenant;
}
//根据房间id,查询家属
public function getFamily($vacancy_id) {
//查询租客
$family = Db::name('house_user_bind')->alias('hub')->rightJoin('user','user.uid = hub.uid')
->where(['hub.vacancy_id'=>$vacancy_id,'hub.type'=>1])
->field('hub.village_id,hub.name,hub.phone,user.avatar,user.uid')->select()->toArray();
foreach ($family as $k =>$v) {
$car = Db::name('car')->where(['uid'=>$v['uid'],'village_id'=>$v['village_id']])->select()->toArray();
$family[$k]['cars'] = $car;
$family[$k]['car_total'] = count($car);
}
return $family;
}
} }
\ No newline at end of file
<?php
namespace app\api\controller;
use app\common\controller\Common;
use think\facade\Db;
use think\facade\Request;
class News extends Base{
//新闻分类
public function newsType() {
$villate_id = Request::param('village_id');
$new_type = Db::name('news_type')->where(['village_id'=>$villate_id])->order('sort_id','desc')->select()->toArray();
return $this->returnJson($new_type);
}
//分类下的新闻列表
public function newsList() {
$type_id = Request::param('type_id');
$page = Request::param('page',1);
$where['news_type_id'] = $type_id;
$data = Db::name('news')->where($where)->page($page,config('app.limit'))->order(['sort_id'=>'desc','create_time'=>'desc'])->field('news_id,title,content,create_time')->page($page,config('app.limit'))->select()->toArray();
foreach ($data as $k => $v) {
$data[$k]['content'] = mb_substr(strip_tags($v['content']),0,100);
}
$res['total'] = Db::name('news')->where($where)->count();
$res['data'] = Common::changeField($data);
return $this->returnJson($res);
}
//新闻详情
public function detailNews() {
$news_id = Request::param('news_id');
$data = Db::name('news')->where(['news_id'=>$news_id])->find();
if($data){
return $this->returnJson(Common::changeField($data));
} else {
return $this->returnJson();
}
}
}
\ No newline at end of file
<?php <?php
namespace app\api\controller; namespace app\api\controller;
use app\common\controller\Common; use app\common\controller\Common;
use think\facade\Db; use think\facade\Db;
use think\facade\Request; use think\facade\Request;
class Payorder extends Base class Payorder extends Base
{ {
//查看当前房间下的未缴费的水电物业等,只有业主才能看到记录 //业主所有房间下的未缴费的水电物业等,只有业主才能看到记录
public function payList() { public function payList() {
$convertArr = $this->convertArr; //获取是业主身份的房间
$vacancy_id = Request::param('vacancy_id'); $vacancys = Db::name('house_user_bind')->alias('hub')
$uid = $this->uid; ->rightJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
->where(['hub.type'=>0,'hub.status'=>1])
$page = Request::param('page',1); ->field('hub.house_user_bind_id,hv.vacancy_id,hv.vacancy_code,hv.layout_id')
$isPay = Request::param('is_pay',0); ->select()->toArray();
//不是房主不显示费用明细 if($vacancys) {
$isOwner = Db::name('house_user_bind')->where(['uid'=>$uid,'vacancy_id'=>$vacancy_id])->find(); $convertArr = $this->convertArr;
if($isOwner['type'] != 0) { $array_keys = array_keys($convertArr);
return $this->returnJson([]); foreach ($vacancys as $k =>$v) {
} $where['vacancy_id'] = $v['vacancy_id'];
$where['vacancy_id'] = $vacancy_id; $where['is_pay'] = 0;
$where['is_pay'] = $isPay; $res = Common::getVacancyAddress($v['vacancy_code'],$v['layout_id']);
$vacancys[$k]['vacancy_address'] = $res['vacancy_address'];
$data = Db::name('cost')->where($where)->order('cost_month','asc')->page($page,config('app.limit'))->select()->toArray(); foreach ($convertArr as $key=>$value) {
foreach ($data as $k => $v){ $where['type'] = $key;
$data[$k]['type'] = isset($convertArr[$v['type']]) ? $convertArr[$v['type']]: $v['type'] ; //总金额
} $data= Db::name('cost')->where($where)->sum('pay_money');
$total = Db::name('cost')->where($where)->count(); $all_list[$key] = $data;
$res['total'] = $total; }
$res['data'] = Common::changeField($data); $vacancys[$k]['pay_list'] = $all_list;
return $this->returnJson($res); //获取自定义的
} unset($where['type']);
$vacancys[$k]['pay_list']['other'] = Db::name('cost')->where($where)->whereNotIn('type',array_keys($convertArr))->sum('pay_money');
//生成订单 }
public function createOrder(){ foreach ($vacancys as $k =>$v) {
$vacancy_id = Request::param('vacancy_id'); foreach ($array_keys as $val ) { //删除水电物业费为0的记录
$bind_id = Request::param('bind_id'); if($v['pay_list'][$val] ==0) {
$cost_ids = Request::param('cost_ids'); unset($vacancys[$k]['pay_list'][$val]);
$total_money = Request::param('total_money',0); }
//验证物业费订单是否是连续的 }
$where['type'] = 'property'; if($v['pay_list']['other'] ==0) {
$where['is_pay'] = 0; unset($vacancys[$k]['pay_list']['other']);
$where['vacancy_id'] = $vacancy_id; }
$property_cost_ids = Db::name('cost')->where($where)->whereIn('cost_id',$cost_ids)->column('cost_id'); //上传的未缴物业费的连续cost_id }
$limit = count($property_cost_ids);
$cost_property_ids = Db::name('cost')->where($where)->limit($limit)->column('cost_id'); } else {
$vacancys = [];
if($cost_property_ids != $property_cost_ids) { }
return $this->returnJson([],'物业费缴费必须连续!'); return $this->returnJson($vacancys);
} }
//判断金额是否一致 //查看已缴费的列表
unset($where['type']); public function getPayList() {
$total = Db::name('cost')->where($where)->whereIn('cost_id',$cost_ids)->sum('pay_money'); //获取是业主身份的房间
if($total != $total_money) { $vacancys = Db::name('house_user_bind')->alias('hub')
return $this->returnJson([],'支付金额不正确!',400); ->rightJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
} ->where(['hub.type'=>0,'hub.status'=>1])
->field('hub.house_user_bind_id,hv.vacancy_id,hv.vacancy_code,hv.layout_id')
$data['uid'] = $this->uid; ->select()->toArray();
if(count($cost_ids)>1){ if($vacancys) {
$data['order_type'] = "多订单收费"; $convertArr = $this->convertArr;
} else { $array_keys = array_keys($convertArr);
$type =Db::name('cost')->whereIn('cost_id',$cost_ids)->value('type'); $unit = $this->myUnit;
$data['order_type'] = $type; foreach ($vacancys as $k =>$v) {
} $where['vacancy_id'] = $v['vacancy_id'];
$data['order_name'] = "社区收费"; $where['is_pay'] = 1;
$data['order_num'] = createOrderNum(); $res = Common::getVacancyAddress($v['vacancy_code'],$v['layout_id']);
$data['vacancy_id'] = $vacancy_id; $vacancys[$k]['vacancy_address'] = $res['vacancy_address'];
$res = $this->getProperty($data['vacancy_id']); foreach ($convertArr as $key=>$value) {
if($res['code'] !=200){ $where['type'] = $key;
return $this->returnJson([],$res['data'],400); //总金额
} $data= Db::name('cost')->where($where)->sum('pay_money');
$rest['total_money'] = $data;
$data['property_id'] =$res['data']['property_id']; if($key == "property" || $key =="park"){
$data['village_id'] =$res['data']['village_id']; $count = Db::name('cost')->where($where)->count();
$data['bind_id'] = $bind_id; $total_num = $count."个月";
$data['money'] = $total; } else if($key == "water" || $key=="electric" || $key == "gas") {
$data['create_time'] = time(); $num = Db::name('cost')->where($where)->sum('area');
$data['cost_ids'] = json_encode($cost_ids); $total_num = $num.$unit[$key];
$data['money'] = $total; }
$order_id = Db::name('pay_order')->insertGetId($data); $rest['total_num'] = $total_num;
if($order_id) { $all[$key] = $rest;
unset($res); //$vacancys[$k][$key] = $rest;
$res['order_id'] = $order_id; }
return $this->returnJson($res); //获取自定义的
} else{ unset($where['type']);
return $this->returnJson([],'添加失败!',400); $count = Db::name('cost')->where($where)->whereNotIn('type',$array_keys)->sum('pay_money');
} // $vacancys[$k]['other'] = $count;
$all['other'] = $count;
} $vacancys[$k]['pay_list'] = $all;
}
//根据房间id获取当前的物业id和小区id //如果已缴费金额为0,删除,不显示
public function getProperty($vacancy_id) { foreach ($vacancys as $k =>$v) {
$data = Db::name('house_vacancy')->alias('hv')->leftJoin('house_village hvi','hvi.village_id = hv.village_id')->where(['hv.vacancy_id'=>$vacancy_id])->field('hvi.village_id,hvi.property_id')->find(); foreach ($array_keys as $val ) { //删除水电物业费为0的记录
if($v['pay_list'][$val]['total_money'] ==0) {
if($data){ unset($vacancys[$k]['pay_list'][$val]);
return ['code'=>200,'data'=>$data]; } else {
} else { $pay_time = Db::name('cost')->where(['is_pay'=>1,'type'=>$val,'vacancy_id'=>$v['vacancy_id']])->order('pay_time','desc')->value('pay_time');
return ['code'=>400,'data'=>'数据错误!']; $vacancys[$k]['pay_list'][$val]['pay_time'] = date('Y-m-d H:i:s',$pay_time);
} }
} }
if($v['pay_list']['other'] ==0) {
//生成支付参数 unset($vacancys[$k]['pay_list']['other']);
public function createPaySign() { } else {
$order_id = Request::param('order_id'); $pay_time = Db::name('cost')->where(['is_pay'=>1,'vacancy_id'=>$v['vacancy_id']])->whereNotIn('type',$array_keys)->order('pay_time','desc')->value('pay_time');
$total_money = Request::param('total_money'); $vacancys[$k]['pay_list'][$val]['pay_time'] = date('Y-m-d H:i:s',$pay_time);
$vacancy_id = Request::param('vacancy_id'); }
$pay_type = Request::param('pay_type','alipay'); //weixin|alipay }
if(empty($order_id)) { //要分开循环删除
return $this->returnJson([],'订单未找到!',400); foreach ($vacancys as $k => $v) {
} if(!isset($v['pay_list']['water']) && !isset($v['pay_list']['property']) && !isset($v['pay_list']['electric']) && !isset($v['pay_list']['gas']) && !isset($v['pay_list']['park']) && !isset($v['pay_list']['other'])){
if($this->checkOrder($order_id,$total_money,$vacancy_id)){ unset($vacancys[$k]);
$orderInfo = Db::name('pay_order')->where(['order_id'=>$order_id])->find(); }
//支付宝支付 }
if($pay_type =='alipay') {
$param['out_trade_no'] = $orderInfo['order_num']; } else {
$param['subject'] = $orderInfo['order_name']; $vacancys = [];
$param['total_amount'] = floatval($orderInfo['money']); }
$res= $this->getAliPaySign($param); return $this->returnJson($vacancys);
//微信支付 }
} else {
$param['order_id'] = $orderInfo['order_id'];
$param['total_money'] = $orderInfo['money']; //某个房间下的某个收费项的以缴费缴费列表
$param['order_name'] = $orderInfo['order_name']; public function vacancyPayedList(){
$param['order_num'] = $orderInfo['order_num']; $vacancy_id = Request::param('vacancy_id');
$res= $this->getWeiXinPaySign($param); $type = Request::param('type'); //property|water|electric|gas|park|other,除了other,其他都能对应表中的type
} $page = Request::param('page',1);
return $this->returnJson($res);
} else { $convertArr = $this->convertArr;
return $this->returnJson([],'非法的订单信息!',400); if(in_array($type,array_keys($convertArr))){
} $where[] = ['type','=',$type];
} } else {
$where[] = ['type','not in',array_keys($convertArr)];
//获取支付宝支付参数 }
public function getAliPaySign($param) { $where[] = ['vacancy_id','=',$vacancy_id];
require_once "../extend/aliPay/AopClient.php"; $where[] = ['is_pay','=',1];
require_once "../extend/aliPay/request/AlipayTradeAppPayRequest.php"; //先查询是否合法
$aop = new \AopClient(); $is_exit = Db::name('house_user_bind')->where(['uid'=>$this->uid,'vacancy_id'=>$vacancy_id,'type'=>0])->find();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do'; if(!$is_exit) {
$aop->appId = config('app.pay_alipay_appid'); return $this->returnJson([],'查询错误!',400);
$aop->rsaPrivateKey = config('app.pay_alipay_merchant_private_key'); }
$aop->alipayrsaPublicKey = config('app.pay_alipay_public_key');
$aop->apiVersion = '1.0'; $data = Db::name('cost')->where($where)->page($page,config('app.limit'))->order('cost_month','desc')->field('cost_id,cost_month,pay_money,type')->select()->toArray();
$aop->signType = config('app.pay_alipay_sign_type'); $total = Db::name('cost')->where($where)->count();
$aop->postCharset = 'utf-8'; $res['total'] = $total;
$aop->format = 'json'; $res['data'] = $data;
$request = new \AlipayTradeAppPayRequest(); return $this->returnJson($res);
$request->setNotifyUrl(config('app.notifyurl')); }
$request->setBizContent(json_encode($param));
$response = $aop->sdkExecute($request); //某个房间下的某个收费项的未缴费缴费列表
return $response; public function vacancyPayList() {
} $vacancy_id = Request::param('vacancy_id');
$type = Request::param('type'); //property|water|electric|gas|park|other,除了other,其他都能对应表中的type
$page = Request::param('page',1);
//获取微信支付参数
public function getWeiXinPaySign($param) { $convertArr = $this->convertArr;
require_once "../extend/weixin/Weixin.php"; if(in_array($type,array_keys($convertArr))){
$configArr = config('app.weixinPay'); $where[] = ['type','=',$type];
$configArr['notifyurl'] = config('app.notifyurl'); } else {
$weixin = new \Weixin($param,$configArr); $where[] = ['type','not in',array_keys($convertArr)];
return $weixin->pay();
}
} $where[] = ['vacancy_id','=',$vacancy_id];
$where[] = ['is_pay','=',0];
//检查订单是否合法 //先查询是否合法
public function checkOrder($order_id,$total_money,$vacancy_id) { $is_exit = Db::name('house_user_bind')->where(['uid'=>$this->uid,'vacancy_id'=>$vacancy_id,'type'=>0])->find();
$where['order_id'] = $order_id; if(!$is_exit) {
$where['uid'] = $this->uid; return $this->returnJson([],'查询错误!',400);
$where['vacancy_id'] = $vacancy_id; }
$money = Db::name('pay_order')->where($where)->value('money');
if($money != $total_money) { $data = Db::name('cost')->where($where)->page($page,config('app.limit'))->order('cost_month','desc')->field('cost_id,cost_month,pay_money,type')->select()->toArray();
return false; $total = Db::name('cost')->where($where)->count();
} $res['total'] = $total;
return true; $res['data'] = $data;
} return $this->returnJson($res);
}
//查看具体的订单详情
public function getDetailPay(){
$cost_id = Request::param('cost_id');
$data = Db::name('cost')->where(['cost_id'=>$cost_id])->find();
return $this->returnJson(Common::changeField($data));
}
//生成订单
public function createOrder(){
$vacancy_id = Request::param('vacancy_id');
$bind_id = Request::param('bind_id');
$cost_ids = Request::param('cost_ids');
$total_money = Request::param('total_money',0);
//验证物业费订单是否是连续的
$where['type'] = 'property';
$where['is_pay'] = 0;
$where['vacancy_id'] = $vacancy_id;
$property_cost_ids = Db::name('cost')->where($where)->whereIn('cost_id',$cost_ids)->column('cost_id'); //上传的未缴物业费的连续cost_id
$limit = count($property_cost_ids);
$cost_property_ids = Db::name('cost')->where($where)->limit($limit)->column('cost_id');
if($cost_property_ids != $property_cost_ids) {
return $this->returnJson([],'物业费缴费必须连续!');
}
//判断金额是否一致
unset($where['type']);
$total = Db::name('cost')->where($where)->whereIn('cost_id',$cost_ids)->sum('pay_money');
if($total != $total_money) {
return $this->returnJson([],'支付金额不正确!',400);
}
$data['uid'] = $this->uid;
if(count($cost_ids)>1){
$data['order_type'] = "多订单收费";
} else {
$type =Db::name('cost')->whereIn('cost_id',$cost_ids)->value('type');
$data['order_type'] = $type;
}
$data['order_name'] = "社区收费";
$data['order_num'] = createOrderNum();
$data['vacancy_id'] = $vacancy_id;
$res = $this->getProperty($data['vacancy_id']);
if($res['code'] !=200){
return $this->returnJson([],$res['data'],400);
}
$data['property_id'] =$res['data']['property_id'];
$data['village_id'] =$res['data']['village_id'];
$data['bind_id'] = $bind_id;
$data['money'] = $total;
$data['create_time'] = time();
$data['cost_ids'] = json_encode($cost_ids);
$data['money'] = $total;
$order_id = Db::name('pay_order')->insertGetId($data);
if($order_id) {
unset($res);
$res['order_id'] = $order_id;
return $this->returnJson($res);
} else{
return $this->returnJson([],'添加失败!',400);
}
}
//根据房间id获取当前的物业id和小区id
public function getProperty($vacancy_id) {
$data = Db::name('house_vacancy')->alias('hv')->leftJoin('house_village hvi','hvi.village_id = hv.village_id')->where(['hv.vacancy_id'=>$vacancy_id])->field('hvi.village_id,hvi.property_id')->find();
if($data){
return ['code'=>200,'data'=>$data];
} else {
return ['code'=>400,'data'=>'数据错误!'];
}
}
//生成支付参数
public function createPaySign() {
$order_id = Request::param('order_id');
$total_money = Request::param('total_money');
$vacancy_id = Request::param('vacancy_id');
$pay_type = Request::param('pay_type','alipay'); //weixin|alipay
if(empty($order_id)) {
return $this->returnJson([],'订单未找到!',400);
}
if($this->checkOrder($order_id,$total_money,$vacancy_id)){
$orderInfo = Db::name('pay_order')->where(['order_id'=>$order_id])->find();
//支付宝支付
if($pay_type =='alipay') {
$param['out_trade_no'] = $orderInfo['order_num'];
$param['subject'] = $orderInfo['order_name'];
$param['total_amount'] = floatval($orderInfo['money']);
$res= $this->getAliPaySign($param);
//微信支付
} else {
$param['order_id'] = $orderInfo['order_id'];
$param['total_money'] = $orderInfo['money'];
$param['order_name'] = $orderInfo['order_name'];
$param['order_num'] = $orderInfo['order_num'];
$res= $this->getWeiXinPaySign($param);
}
return $this->returnJson($res);
} else {
return $this->returnJson([],'非法的订单信息!',400);
}
}
//获取支付宝支付参数
public function getAliPaySign($param) {
require_once "../extend/aliPay/AopClient.php";
require_once "../extend/aliPay/request/AlipayTradeAppPayRequest.php";
$aop = new \AopClient();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = config('app.pay_alipay_appid');
$aop->rsaPrivateKey = config('app.pay_alipay_merchant_private_key');
$aop->alipayrsaPublicKey = config('app.pay_alipay_public_key');
$aop->apiVersion = '1.0';
$aop->signType = config('app.pay_alipay_sign_type');
$aop->postCharset = 'utf-8';
$aop->format = 'json';
$request = new \AlipayTradeAppPayRequest();
$request->setNotifyUrl(config('app.notifyurl'));
$request->setBizContent(json_encode($param));
$response = $aop->sdkExecute($request);
return $response;
}
//获取微信支付参数
public function getWeiXinPaySign($param) {
require_once "../extend/weixin/Weixin.php";
$configArr = config('app.weixinPay');
$configArr['notifyurl'] = config('app.notifyurl');
$weixin = new \Weixin($param,$configArr);
return $weixin->pay();
}
//检查订单是否合法
public function checkOrder($order_id,$total_money,$vacancy_id) {
$where['order_id'] = $order_id;
$where['uid'] = $this->uid;
$where['vacancy_id'] = $vacancy_id;
$money = Db::name('pay_order')->where($where)->value('money');
if($money != $total_money) {
return false;
}
return true;
}
} }
\ No newline at end of file
<?php <?php
namespace app\api\controller; namespace app\api\controller;
use app\common\controller\Common; use app\common\controller\Common;
use think\facade\Db; use think\facade\Db;
use think\facade\Request; use think\facade\Request;
class User extends Base class User extends Base
{ {
//获取用户所入住的小区|搜索小区 //获取用户所入住的小区|搜索小区
public function getUserVillage() { public function getUserVillage() {
$keyword = Request::param('keyword'); $keyword = Request::param('keyword');
if($keyword) { //如果有关键字就搜索关键字的小区 $page = Request::param('page',1);
$villages = Db::name('house_village')->where('village_name','like','%'.$keyword.'%')->field('village_name,village_id')->select()->toArray(); $province_id = Request::param('province_id');
$res=[]; $city_id = Request::param('city_id');
foreach ($villages as $k =>$v) { $area_id = Request::param('area_id');
$res[$k]['village_name'] = $v['village_name']; $where =[];
$res[$k]['vacancy'] = Common::getVacancy($v['village_id'],$this->uid); if($province_id) {
} $where['province_id'] = $province_id;
} else { //没有就展示已入住的小区 }
$where['hub.uid'] = $this->uid; if($city_id) {
$where['hub.status'] = 1; $where['city_id'] = $city_id;
$village_ids = DB::name('house_user_bind')->alias('hub')->where($where)->column('village_id'); }
$village_name = Db::name('house_village')->whereIn('village_id',$village_ids)->column('village_name','village_id'); if($area_id) {
$res=[]; $where['area_id'] = $area_id;
foreach ($village_ids as $k =>$v) { }
$res[$k]['village_name'] = $village_name[$v]; if($keyword) { //如果有关键字就搜索关键字的小区
$res[$k]['vacancy'] = Common::getVacancy($v,$this->uid); $villages = Db::name('house_village')->where($where)->where('village_name','like','%'.$keyword.'%')->field('village_name,village_id')->page($page,config('app.limit'))->select()->toArray();
} $res['total'] = Db::name('house_village')->where($where)->where('village_name','like','%'.$keyword.'%')->count();
} $rest=[];
return $this->returnJson($res); foreach ($villages as $k =>$v) {
} $rest['village_name'] = $v['village_name'];
$rest['vacancy'] = Common::getVacancy($v['village_id'],$this->uid);
//修改|忘记密码 $res['data'][] = $rest;
public function changePassword() { }
if(request()->isPost()) { } else { //没有就展示已入住的小区
$original_password = md5(Request::param('original_password')); $where['hub.uid'] = $this->uid;
$new_password = md5(Request::param('new_password')); $where['hub.status'] = 1;
$code = Request::param('code'); $village_ids = DB::name('house_user_bind')->alias('hub')->where($where)->column('village_id');
$phone = Request::param('phone'); $village_name = Db::name('house_village')->whereIn('village_id',$village_ids)->column('village_name','village_id');
if($code){ $res['total'] = count($village_ids);
if(Common::rightCode($phone,$code)){ $rest=[];
$change = Db::name('user')->where(['uid'=>$this->uid,'phone'=>$phone])->save(['password'=>$new_password]); foreach ($village_ids as $k =>$v) {
if($change){ $rest['village_name'] = $village_name[$v];
return $this->returnJson([]); $rest['vacancy'] = Common::getVacancy($v,$this->uid);
} else { $res['data'][] = $rest;
return $this->returnJson([],'修改失败',400); }
} }
} else { if($res['total']==1){
return $this->returnJson([],"验证码不正确",400); $res['data'] = array_values($res['data']);
} }
} else { return $this->returnJson($res);
//验证原密码是否正确 }
$is_exit = Db::name('user')->where(['uid'=>$this->uid,'phone'=>$phone,'password'=>$original_password])->find();
if($is_exit) { //修改|忘记密码
$change = Db::name('user')->where(['uid'=>$this->uid,'phone'=>$phone])->save(['password'=>$new_password]); public function changePassword() {
if($change){ if(request()->isPost()) {
return $this->returnJson(); $original_password = md5(Request::param('original_password'));
} else { $new_password = md5(Request::param('new_password'));
return $this->returnJson([],'修改失败',400); $code = Request::param('code');
} $phone = Request::param('phone');
} else { if($code){
return $this->returnJson([],'验证码不正确',400); if(Common::rightCode($phone,$code)){
} $change = Db::name('user')->where(['uid'=>$this->uid,'phone'=>$phone])->save(['password'=>$new_password]);
} if($change){
} else { return $this->returnJson([]);
return $this->returnJson([],'请求方式不正确',400); } else {
} return $this->returnJson([],'修改失败',400);
} }
} else {
//用户设置密码 return $this->returnJson([],"验证码不正确",400);
public function setPassword() { }
$data['password'] = md5(Request::param('password')); } else {
$save = Db::name('user')->where(['uid'=>$this->uid])->save($data); //验证原密码是否正确
if($save) { $is_exit = Db::name('user')->where(['uid'=>$this->uid,'phone'=>$phone,'password'=>$original_password])->find();
return $this->returnJson(); if($is_exit) {
} else { $change = Db::name('user')->where(['uid'=>$this->uid,'phone'=>$phone])->save(['password'=>$new_password]);
return $this->returnJson([],'','111111'); if($change){
} return $this->returnJson();
} } else {
return $this->returnJson([],'修改失败',400);
//用户绑定房间 }
public function userBindVacancy(){ } else {
$data['type'] = Request::param('type'); return $this->returnJson([],'验证码不正确',400);
$village_id = Request::param('village_id'); }
$vacancy_id = Request::param('vacancy_id'); }
$data['vacancy_id'] = $vacancy_id; } else {
$data['name'] = Request::param("name"); return $this->returnJson([],'请求方式不正确',400);
$data['phone'] = Request::param("phone"); }
$data['village_id'] = $village_id; }
$is_exit = Common::getOwnerInfo($vacancy_id);
$data['id_card'] = Request::param("id_card"); //用户设置密码
$data['uid'] = $this->uid; public function setPassword() {
$data['status'] = 2; $data['password'] = md5(Request::param('password'));
$data['create_time'] = time(); $save = Db::name('user')->where(['uid'=>$this->uid])->save($data);
$data['memo'] = Request::param('memo'); if($save) {
$data['emer_user'] = Request::param('emer_user');//紧急联系人 return $this->returnJson();
$data['emer_phone'] = Request::param('emer_phone'); //紧急联系人电话 } else {
//查看当前手机号是否重复绑定当前房间,一个房间对应的一个手机号只能有一种身份 return $this->returnJson([],'','111111');
$is_only = Db::name('house_user_bind')->where(['village_id'=>$village_id,'vacancy_id'=>$vacancy_id,'phone'=>$data['phone']])->where('status',"<>",3)->find(); }
if($is_only){ }
return $this->returnJson([],'用户已绑定房间!',400);
} //用户绑定房间
if($data['type'] == 0) { //申请业主不需要填写业主后四位手机号 public function userBindVacancy(){
//检查该房间是否有房主绑定 $data['type'] = Request::param('type');
if(!empty($is_exit)){ $village_id = Request::param('village_id');
return $this->returnJson([],'该房间下已有业主!',); $vacancy_id = Request::param('vacancy_id');
} $data['vacancy_id'] = $vacancy_id;
$save['id_card'] = $data['id_card']; $data['name'] = $car['name'] = Request::param("name");
$save['name'] = $data['name']; $data['phone'] = $car['phone'] = Request::param("phone");
$save['phone'] = $data['phone']; $data['village_id'] = $car['village_id']= $village_id;
$save['uid'] = $data['uid']; $is_exit = Common::getOwnerInfo($vacancy_id);
//修改房间的信息 $data['id_card'] = Request::param("id_card");
Db::name('house_vacancy')->where(['vacancy_id'=>$vacancy_id])->save($save); $data['uid'] =$car['uid'] = $this->uid;
}else{ $data['status'] = 2;
if(empty($is_exit)){ $data['create_time'] =$car['create_time']= time();
return $this->returnJson([],'该房间未绑定业主,不能绑定租客!',); $data['memo'] = Request::param('memo');
} $data['emer_user'] = Request::param('emer_user');//紧急联系人
$ownerPhone = $is_exit['phone']; $data['emer_phone'] = Request::param('emer_phone'); //紧急联系人电话
$phone_num = Request::param('phone_num'); $car['brand'] = Request::param('barnd');
if($phone_num != substr($ownerPhone,7)){ $car['car_type'] = Request::param('car_type');
return $this->returnJson([],'业主后四位手机号不正确!'); $car['license_plate'] = Request::param('license_plate');
}
} //查看当前手机号是否重复绑定当前房间,一个房间对应的一个手机号只能有一种身份
$add = Db::name('house_user_bind')->save($data); $is_only = Db::name('house_user_bind')->where(['village_id'=>$village_id,'vacancy_id'=>$vacancy_id,'phone'=>$data['phone']])->where('status',"<>",3)->find();
if($add) { if($is_only){
return $this->returnJson([],'申请成功,等待审核!',200); return $this->returnJson([],'用户已绑定房间!',400);
} else { }
return $this->returnJson([],'申请失败,请重试!',400); if($data['type'] == 0) { //申请业主不需要填写业主后四位手机号
} //检查该房间是否有房主绑定
if(!empty($is_exit)){
} return $this->returnJson([],'该房间下已有业主!',);
}
//用户申请解绑 $save['id_card'] = $data['id_card'];
public function userUnBind(){ $save['name'] = $data['name'];
$where['house_user_bind_id'] = Request::param('house_user_bind_id'); $save['phone'] = $data['phone'];
$where['uid'] = $this->uid; $save['uid'] = $data['uid'];
$save['status'] = 4; //修改房间的信息
$change =Db::name('house_user_bind')->where($where)->save($save); Db::name('house_vacancy')->where(['vacancy_id'=>$vacancy_id])->save($save);
if($change) { }else{
return $this->returnJson([],'申请成功!'); if(empty($is_exit)){
} else { return $this->returnJson([],'该房间未绑定业主,不能绑定租客!',);
return $this->returnJson([],'申请失败!',400); }
} $ownerPhone = $is_exit['phone'];
} $phone_num = Request::param('phone_num');
if($phone_num != substr($ownerPhone,7)){
return $this->returnJson([],'业主后四位手机号不正确!');
//查看所有的房间,如果是业主,展示房间下的所有租客或家属 }
public function getUserVacancy() { }
$uid = $this->uid;
$where['hub.uid'] = $uid; Db::startTrans();
$data = Db::name('house_user_bind')->alias('hub') try{
->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id') Db::name('house_user_bind')->save($data);
->leftJoin('house_village hvi','hvi.village_id = hub.village_id') if($car['brand'] && $car['car_type'] && $car['license_plate']) {
->where($where)->whereIn('hub.status',[1,2,4]) Db::name('car')->save($car);
->field('hub.type,hub.house_user_bind_id,hub.vacancy_id,parent_id,hv.vacancy_code,hv.layout_id,hv.name,hv.phone,hvi.village_name') }
->select()->toArray(); Db::commit();
foreach ($data as $k =>$v) {
$data[$k]['vacancy_address'] = Common::getVacancyAddress($v['vacancy_code'],$v['layout_id']); return $this->returnJson();
if($v['type'] ==0) { }catch(\Exception $e){
//如果是业主身份,查找下面的租客或家属等 Db::rollback();
$data[$k]['myTenant'] = Db::name('house_user_bind')->where(['vacancy_id'=>$v['vacancy_id']])->whereIn('type',[1,2,3])->field('name,phone,status')->select()->toArray(); return $this->returnJson([],'绑定失败,请重试!',400);
}else{ }
//如果是租客身份,查找所属业主 }
$data[$k]['myOwner'] = Db::name('house_user_bind')->where(['vacancy_id'=>$v['vacancy_id'],'type'=>0,'status'=>1])->field('name,phone,status')->find();
} //用户申请解绑
public function userUnBind(){
} $where['house_user_bind_id'] = Request::param('house_user_bind_id');
return $this->returnJson($data); $where['uid'] = $this->uid;
} $save['status'] = 4;
$change =Db::name('house_user_bind')->where($where)->save($save);
if($change) {
//用户添加车辆 return $this->returnJson([],'申请成功!');
public function addCar() { } else {
$uid = $this->uid; return $this->returnJson([],'申请失败!',400);
$car_id = Request::param('car_id'); }
$data['phone'] = Db::name('user')->where(['uid'=>$uid])->value('phone'); }
$data['name'] = Request::param('name');
$data['brand'] = Request::param('brand');
$data['car_color'] = Request::param('car_color'); //查看所有的房间,如果是业主,展示房间下的所有租客或家属
$data['license_plate'] = Request::param('license_plate'); public function getUserVacancy() {
$data['sort_id'] = Request::param('sort_id',1); $uid = $this->uid;
$data['uid'] = $uid; $where['hub.uid'] = $uid;
$data['village_id'] = Request::param('village_id'); $data = Db::name('house_user_bind')->alias('hub')
if($car_id) { ->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
//判断车牌是否存在 ->leftJoin('house_village hvi','hvi.village_id = hub.village_id')
$is_exit = Db::name('car')->where(['license_plate'=>$data['license_plate']])->where('car_id','<>',$car_id)->find(); ->where($where)->whereIn('hub.status',[1,2,4])
if($is_exit) { ->field('hub.type,hub.house_user_bind_id,hub.vacancy_id,parent_id,hv.vacancy_code,hv.layout_id,hv.name,hv.phone,hvi.village_name')
return $this->returnJson([],'系统中已存在该车牌!',400); ->select()->toArray();
} foreach ($data as $k =>$v) {
$operation = Db::name('car')->where(['car_id'=>$car_id])->save($data); $data[$k]['vacancy_address'] = Common::getVacancyAddress($v['vacancy_code'],$v['layout_id']);
} else { if($v['type'] ==0) {
$data['create_time'] = time(); //如果是业主身份,查找下面的租客或家属等
//判断车牌是否存在 $data[$k]['myTenant'] = Db::name('house_user_bind')->where(['vacancy_id'=>$v['vacancy_id']])->whereIn('type',[1,2,3])->field('name,phone,status')->select()->toArray();
$is_exit = Db::name('car')->where(['license_plate'=>$data['license_plate'],'village_id'=>$data['village_id']])->find(); }else{
if($is_exit) { //如果是租客身份,查找所属业主
return $this->returnJson([],'系统中已存在该车牌!',400); $data[$k]['myOwner'] = Db::name('house_user_bind')->where(['vacancy_id'=>$v['vacancy_id'],'type'=>0,'status'=>1])->field('name,phone,status')->find();
} }
$operation = Db::name('car')->save($data); }
}
if($operation) { return $this->returnJson($data);
return $this->returnJson([],'success'); }
} else {
return $this->returnJson([],'操作失败!',400);
}
}
} }
\ No newline at end of file
<?php <?php
namespace app\api\controller; namespace app\api\controller;
use app\common\controller\Common; use app\common\controller\Common;
use think\facade\Db; use think\facade\Db;
use think\facade\Request; use think\facade\Request;
class Village extends Base class Village extends Base
{ {
//搜索小区
} }
\ No newline at end of file
<?php <?php
namespace app\common\controller; namespace app\common\controller;
use app\BaseController; use app\BaseController;
use think\facade\Db; use think\facade\Db;
use think\facade\Request; use think\facade\Request;
class Common extends BaseController class Common extends BaseController
{ {
//获取省市区 //获取省市区
public function getArea() { public function getArea() {
$where['area_pid'] = Request::param('area_id',0); $where['area_pid'] = Request::param('area_id',0);
$data = Db::name('area')->where($where)->field("area_id,area_name")->select()->toArray(); $data = Db::name('area')->where($where)->field("area_id,area_name")->select()->toArray();
return $this->returnJson($data,'success'); return $this->returnJson($data,'success');
} }
//通过id获取地区名称 //通过id获取地区名称
public function getName($id) { public function getName($id) {
$where['area_id'] = $id; $where['area_id'] = $id;
return Db::name('area')->where($where)->value('area_name'); return Db::name('area')->where($where)->value('area_name');
} }
//查看所有的银行列表 //查看所有的银行列表
public function bankAccountList() { public function bankAccountList() {
$data = Db::name("bank_account")->select()->toArray(); $data = Db::name("bank_account")->select()->toArray();
return $this->returnJson($data,'success'); return $this->returnJson($data,'success');
} }
//对数组中的时间字段进行日期转换 //对数组中的时间字段进行日期转换
public static function changeField($data,$field="create_time",$format="Y-m-d H:i:s") { public static function changeField($data,$field="create_time",$format="Y-m-d H:i:s") {
$prompt = "暂无"; $prompt = "暂无";
if(empty($data)) { if(empty($data)) {
return $data; return $data;
} }
foreach($data as $k =>$v) { foreach($data as $k =>$v) {
if(is_array($v)) { if(is_array($v)) {
if(is_array($field)) { if(is_array($field)) {
foreach ($field as $value) { foreach ($field as $value) {
if($v[$value] != 0 || !is_null($v[$value])){ if($v[$value] != 0 || !is_null($v[$value])){
$data[$k][$value] = date($format,$v[$value]); $data[$k][$value] = date($format,$v[$value]);
} else { } else {
$data[$k][$value] = $prompt; $data[$k][$value] = $prompt;
} }
} }
} else { } else {
if($v[$field] != 0 || !is_null($v[$field])){ if($v[$field] != 0 || !is_null($v[$field])){
$data[$k][$field] = date($format,$v[$field]); $data[$k][$field] = date($format,$v[$field]);
} else { } else {
$data[$k][$field] = $prompt; $data[$k][$field] = $prompt;
} }
} }
} else { } else {
if(is_array($field)) { if(is_array($field)) {
foreach ($field as $value) { foreach ($field as $value) {
if(isset($data[$value]) || $data[$value] !=0){ if(isset($data[$value]) || $data[$value] !=0){
$data[$value] = date($format,$data[$value]); $data[$value] = date($format,$data[$value]);
} else{ } else{
$data[$value] = $prompt; $data[$value] = $prompt;
} }
} }
break; break;
} else { } else {
if(isset($data[$field]) || $data[$field] !=0) { if(isset($data[$field]) || $data[$field] !=0) {
$data[$field] = date($format, $data[$field]); $data[$field] = date($format, $data[$field]);
} else { } else {
$data[$field] = $prompt; $data[$field] = $prompt;
} }
break; break;
} }
} }
} }
return $data; return $data;
} }
//对数组中的图片字段进行日期转换 //对数组中的图片字段进行日期转换
public static function changeImg($data,$field="pic"){ public static function changeImg($data,$field="pic"){
if(empty($data)){ if(empty($data)){
return $data; return $data;
} }
if(isHTTPS()){ if(isHTTPS()){
$http = "https://"; $http = "https://";
} else{ } else{
$http = 'http://'; $http = 'http://';
} }
$server_name = $http.$_SERVER['SERVER_NAME'].'/'; $server_name = $http.$_SERVER['SERVER_NAME'].'/';
$prompt =''; $prompt ='';
foreach($data as $k =>$v) { foreach($data as $k =>$v) {
if(is_array($v)) { if(is_array($v)) {
if(is_array($field)) { if(is_array($field)) {
foreach ($field as $value) { foreach ($field as $value) {
if($v[$value] != '' || !is_null($v[$value])){ if($v[$value] != '' || !is_null($v[$value])){
$data[$k][$value] = $server_name.$v[$value]; $data[$k][$value] = $server_name.$v[$value];
} else { } else {
$data[$k][$value] = $prompt; $data[$k][$value] = $prompt;
} }
} }
} else { } else {
if($v[$field] != '' || !is_null($v[$field])){ if($v[$field] != '' || !is_null($v[$field])){
$data[$k][$field] = $server_name.$v[$field]; $data[$k][$field] = $server_name.$v[$field];
} else { } else {
$data[$k][$field] = $prompt; $data[$k][$field] = $prompt;
} }
} }
} else { } else {
if(is_array($field)) { if(is_array($field)) {
foreach ($field as $value) { foreach ($field as $value) {
if(isset($data[$value]) || $data[$value] !=0){ if(isset($data[$value]) || $data[$value] !=0){
$data[$value] =$server_name.$data[$value]; $data[$value] =$server_name.$data[$value];
} else{ } else{
$data[$value] = $prompt; $data[$value] = $prompt;
} }
} }
break; break;
} else { } else {
if(isset($data[$field]) || $data[$field] !=0) { if(isset($data[$field]) || $data[$field] !=0) {
$data[$field] = $server_name.$data[$field]; $data[$field] = $server_name.$data[$field];
} else { } else {
$data[$field] = $prompt; $data[$field] = $prompt;
} }
break; break;
} }
} }
} }
return $data; return $data;
} }
/** /**
* @param $url_ids string 1,2,3 * @param $url_ids string 1,2,3
* @param $navAl array * @param $navAl array
* @param $type int 1 所有都赋值,0 给特定的赋值 * @param $type int 1 所有都赋值,0 给特定的赋值
*/ */
public static function changeNav($url_ids,$navAl,$type=1) { public static function changeNav($url_ids,$navAl,$type=1) {
$urlsArr = explode(",",$url_ids); $urlsArr = explode(",",$url_ids);
if($type==1 ) { if($type==1 ) {
return $navAl; return $navAl;
} else { } else {
foreach($navAl as $k =>$v ) { foreach($navAl as $k =>$v ) {
$navAl[$k]['is_power'] =0 ; $navAl[$k]['is_power'] =0 ;
if(isset($v['property_nav_id']) && !in_array($v['property_nav_id'],$urlsArr)) { if(isset($v['property_nav_id']) && !in_array($v['property_nav_id'],$urlsArr)) {
unset($navAl[$k]) ; unset($navAl[$k]) ;
} }
if(isset($v['community_nav_id']) && !in_array($v['community_nav_id'],$urlsArr)) { if(isset($v['community_nav_id']) && !in_array($v['community_nav_id'],$urlsArr)) {
unset($navAl[$k]); unset($navAl[$k]);
} }
if(isset($v['admin_nav_id']) && !in_array($v['admin_nav_id'],$urlsArr)) { if(isset($v['admin_nav_id']) && !in_array($v['admin_nav_id'],$urlsArr)) {
unset($navAl[$k]); unset($navAl[$k]);
} }
} }
} }
return $navAl; return $navAl;
} }
//获取流水详情,village_money_list表 //获取流水详情,village_money_list表
public static function getWithDrawDetail($where) { public static function getWithDrawDetail($where) {
$data = Db::name('village_money_list')->alias('ml') $data = Db::name('village_money_list')->alias('ml')
->leftJoin('house_village hv','ml.village_id = hv.village_id') ->leftJoin('house_village hv','ml.village_id = hv.village_id')
->leftJoin('house_property hp','hp.property_id = ml.property_id') ->leftJoin('house_property hp','hp.property_id = ml.property_id')
->where($where) ->where($where)
->field("ml.*,hv.village_name,hp.property_name") ->field("ml.*,hv.village_name,hp.property_name")
->find(); ->find();
if($data) { if($data) {
$where_one['order_id'] = $data['order_id']; $where_one['order_id'] = $data['order_id'];
switch ($data['table_name']) { switch ($data['table_name']) {
case "pay_order" : case "pay_order" :
$orderInfo = Db::name('pay_order')->alias('po') $orderInfo = Db::name('pay_order')->alias('po')
->leftJoin('house_vacancy hv', 'hv.vacancy_id = po.vacancy_id') ->leftJoin('house_vacancy hv', 'hv.vacancy_id = po.vacancy_id')
->leftJoin('user u', 'po.uid = u.uid') ->leftJoin('user u', 'po.uid = u.uid')
->field('po.*,hv.vacancy_address,u.phone,u.nickname') ->field('po.*,hv.vacancy_address,u.phone,u.nickname')
->where($where_one) ->where($where_one)
->find(); ->find();
break; break;
case "withdraw_order": case "withdraw_order":
$orderInfo = Db::name('withdraw_order') $orderInfo = Db::name('withdraw_order')
->where($where_one)->find(); ->where($where_one)->find();
break; break;
default: default:
return false; return false;
} }
return ['data' => $data, 'orderInfo' => $orderInfo]; return ['data' => $data, 'orderInfo' => $orderInfo];
} else { } else {
return false; return false;
} }
} }
//获取流水列表
//获取流水列表 public static function getWithDrawList($where,$page) {
public static function getWithDrawList($where,$page) { $count = Db::name('village_money_list')->alias('ml')
$count = Db::name('village_money_list')->alias('ml') ->leftJoin('house_village hv','ml.village_id = hv.village_id')
->leftJoin('house_village hv','ml.village_id = hv.village_id') ->leftJoin('house_property hp','hp.property_id = ml.property_id')
->leftJoin('house_property hp','hp.property_id = ml.property_id') ->where($where)->count();
->where($where)->count();
$data = Db::name('village_money_list')->alias('ml')
$data = Db::name('village_money_list')->alias('ml') ->leftJoin('house_village hv','ml.village_id = hv.village_id')
->leftJoin('house_village hv','ml.village_id = hv.village_id') ->leftJoin('house_property hp','hp.property_id = ml.property_id')
->leftJoin('house_property hp','hp.property_id = ml.property_id') ->where($where)
->where($where) ->field("ml.id,ml.type,ml.total_money,ml.income,ml.create_time,ml.now_village_money,ml.now_property_money,hv.village_name,hp.property_name")
->field("ml.id,ml.type,ml.total_money,ml.income,ml.create_time,ml.now_village_money,ml.now_property_money,hv.village_name,hp.property_name") ->order('ml.create_time','desc')
->order('ml.create_time','desc') ->page($page,config('app.limit'))->select()->toArray();
->page($page,config('app.limit'))->select()->toArray();
return ['total'=>$count,'data'=>$data];
return ['total'=>$count,'data'=>$data]; }
}
//房间导入
//房间导入 public static function importVacancy($filePath,$village_id) {
public static function importVacancy($filePath,$village_id) {
$where['village_id'] = $village_id;
$where['village_id'] = $village_id; //设置获取excel对象
//设置获取excel对象 $objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容
$objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容 $objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件
$objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件 $sheet = $objPHPExcel->getSheet(0);
$sheet = $objPHPExcel->getSheet(0); $dataAll = $objPHPExcel->getSheet(0)->toArray(); //获取导入的数据;
$dataAll = $objPHPExcel->getSheet(0)->toArray(); //获取导入的数据; $highestRow = $sheet->getHighestRow(); // 取得总行数
$highestRow = $sheet->getHighestRow(); // 取得总行数
//获取社区布局
//获取社区布局 $layout_list = Db::name('layout_list')->where($where)->column('layout_id','code');
$layout_list = Db::name('layout_list')->where($where)->column('layout_id','code');
$park_block_list = Db::name('park_block')->where($where)->column('park_block_id','name');
$park_block_list = Db::name('park_block')->where($where)->column('park_block_id','name'); //获取社区不同布局的所有的建筑id
//获取社区不同布局的所有的建筑id $errorData =[]; //存放导入失败的数据;
$errorData =[]; //存放导入失败的数据; for($j=1;$j<$highestRow;$j++)
for($j=1;$j<$highestRow;$j++) {
{ if(!empty($dataAll[$j][0]) && !empty($dataAll[$j][4]) &&!empty($dataAll[$j][7]) &&!empty($dataAll[$j][8])){
if(!empty($dataAll[$j][0]) && !empty($dataAll[$j][4]) &&!empty($dataAll[$j][7]) &&!empty($dataAll[$j][8])){ $msg = "";
$msg = ""; $vacancyCode = $dataAll[$j][0]; //房间编号
$vacancyCode = $dataAll[$j][0]; //房间编号 $layout_list_code = $dataAll[$j][7];//布局
$layout_list_code = $dataAll[$j][7];//布局 if($layout_list_code) {
if($layout_list_code) { $layout_id = $layout_list[$layout_list_code];
$layout_id = $layout_list[$layout_list_code]; $data['layout_id'] = $layout_id;
$data['layout_id'] = $layout_id; $res_vacancy_code = self::getVacancyCode($vacancyCode,$layout_id);
$res_vacancy_code = self::getVacancyCode($vacancyCode,$layout_id); if($res_vacancy_code['code'] !=200) {
if($res_vacancy_code['code'] !=200) { $msg .= "房间编号不正确!";
$msg .= "房间编号不正确!"; }
} $vacancy_code = $res_vacancy_code['msg'];
$vacancy_code = $res_vacancy_code['msg']; $data['vacancy_code'] = $vacancy_code;
$data['vacancy_code'] = $vacancy_code; $parent_id = $res_vacancy_code['parent_id'];
$parent_id = $res_vacancy_code['parent_id']; $data['parent_id'] = $parent_id;
$data['parent_id'] = $parent_id; } else {
} else { $msg .="社区布局未选择!";
$msg .="社区布局未选择!";
}
} $name = $dataAll[$j][1];//业主名字
$name = $dataAll[$j][1];//业主名字 $id_card = $dataAll[$j][2];//布局;//身份证id
$id_card = $dataAll[$j][2];//布局;//身份证id
if($id_card && !isCreditNo($id_card)) {
if($id_card && !isCreditNo($id_card)) { $msg .= "身份证id不符合!";
$msg .= "身份证id不符合!"; }
} $phone = $dataAll[$j][3];//布局;//手机号
$phone = $dataAll[$j][3];//布局;//手机号 if($phone && !isPhoneNo($phone)) {
if($phone && !isPhoneNo($phone)) { $msg .="手机号不符合!";
$msg .="手机号不符合!"; }
} $area = $dataAll[$j][4];//面积
$area = $dataAll[$j][4];//面积 $car_block_name = $dataAll[$j][5];//车库位置
$car_block_name = $dataAll[$j][5];//车库位置 $park_code = $dataAll[$j][6];//车位编号
$park_code = $dataAll[$j][6];//车位编号 if($car_block_name && $park_code) {
if($car_block_name && $park_code) { $park_block_id = $park_block_list[$car_block_name];
$park_block_id = $park_block_list[$car_block_name]; $park_car_id = Db::name('park_car')->where(['village_id'=>$village_id,'park_block_id'=>$park_block_id,'park_code'=>$park_code])->value('park_car_id');
$park_car_id = Db::name('park_car')->where(['village_id'=>$village_id,'park_block_id'=>$park_block_id,'park_code'=>$park_code])->value('park_car_id'); $data['park_car_id'] = $park_car_id;
$data['park_car_id'] = $park_car_id; $data['park_block_id'] = $park_block_id;
$data['park_block_id'] = $park_block_id; }
}
$house_type = $dataAll[$j][8];//住宅类型
$house_type = $dataAll[$j][8];//住宅类型 switch ($house_type) {
switch ($house_type) { case "住宅" :
case "住宅" : $type =1;
$type =1; break;
break; case "商铺" :
case "商铺" : $type = 2;
$type = 2; break;
break; case "办公" :
case "办公" : $type = 3;
$type = 3; break;
break; default :
default : $msg.= "住宅类型未选择!";
$msg.= "住宅类型未选择!"; }
}
$data['name'] = $bind['name'] = $name;
$data['name'] = $bind['name'] = $name; $data['id_card'] = $bind['id_card']= $id_card;
$data['id_card'] = $bind['id_card']= $id_card; $data['phone'] = $bind['phone'] = $phone;
$data['phone'] = $bind['phone'] = $phone; $data['area'] = $area;
$data['area'] = $area; $data['house_type'] = $type;
$data['house_type'] = $type; $data['create_time'] = $bind['create_time'] = $bind['pass_time']= time();
$data['create_time'] = $bind['create_time'] = $bind['pass_time']= time(); $data['village_id'] = $bind['village_id'] = $village_id;
$data['village_id'] = $bind['village_id'] = $village_id;
if(empty($msg)) { //表明没有错误
if(empty($msg)) { //表明没有错误 $bind['vacancy_id'] = Db::name('house_vacancy')->insertGetId($data);
$bind['vacancy_id'] = Db::name('house_vacancy')->insertGetId($data); //导入到userbind表中
//导入到userbind表中 $bind['type'] = 0;
$bind['type'] = 0; $bind['status'] = 1;
$bind['status'] = 1; if($bind['name'] && $bind['id_card'] && $bind['phone']){
if($bind['name'] && $bind['id_card'] && $bind['phone']){ Db::name('house_user_bind')->save($bind);
Db::name('house_user_bind')->save($bind); }
} } else {
} else { $dataAll[$j][] = $msg;
$dataAll[$j][] = $msg; $errorData[] = $dataAll[$j];
$errorData[] = $dataAll[$j]; }
} }else {
}else { $dataAll[$j][] = "数据不能为空!";
$dataAll[$j][] = "数据不能为空!"; $errorData[] = $dataAll[$j];
$errorData[] = $dataAll[$j]; }
} }
}
if(empty($errorData)) {
if(empty($errorData)) { return ['code'=>200,'data'=>[]];
return ['code'=>200,'data'=>[]]; }else {
}else { //导出错误的数据
//导出错误的数据 $file = "./formwork/importVacancy.xls";
$file = "./formwork/importVacancy.xls"; $phpExcel = \PHPExcel_IOFactory::load($file);
$phpExcel = \PHPExcel_IOFactory::load($file); $title = ['A','B','C','D','E','F','G','H','I','J'];
$title = ['A','B','C','D','E','F','G','H','I','J']; $i = 2;
$i = 2; $optionsArr = Db::name('layout_list')->where(['village_id'=>$village_id])->column('code');
$optionsArr = Db::name('layout_list')->where(['village_id'=>$village_id])->column('code'); $optionsString = implode(',',$optionsArr);//这个是选择布局
$optionsString = implode(',',$optionsArr);//这个是选择布局 $car_blockArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('name');
$car_blockArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('name'); $optionsCarBlockString = implode(',',$car_blockArr);//这个是车库布局
$optionsCarBlockString = implode(',',$car_blockArr);//这个是车库布局 foreach ($errorData as $k =>$v) {
foreach ($errorData as $k =>$v) { foreach ($title as $key=>$value) {
foreach ($title as $key=>$value) { $phpExcel->getActiveSheet()->setCellValue($value.$i,$v[$key]);
$phpExcel->getActiveSheet()->setCellValue($value.$i,$v[$key]); }
} //设置单元楼下拉
//设置单元楼下拉 $phpExcel->getActiveSheet()->getCell('H'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
$phpExcel->getActiveSheet()->getCell('H'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST) -> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION) -> setAllowBlank(false)
-> setAllowBlank(false) -> setShowInputMessage(true)
-> setShowInputMessage(true) -> setShowErrorMessage(true)
-> setShowErrorMessage(true) -> setShowDropDown(true)
-> setShowDropDown(true) -> setErrorTitle('输入的值有误')
-> setErrorTitle('输入的值有误') -> setError('您输入的值不在下拉框列表内.')
-> setError('您输入的值不在下拉框列表内.') -> setPromptTitle('社区布局')
-> setPromptTitle('社区布局') -> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格
-> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格 $phpExcel->getActiveSheet()->getCell('I'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
$phpExcel->getActiveSheet()->getCell('I'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST) -> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION) -> setAllowBlank(false)
-> setAllowBlank(false) -> setShowInputMessage(true)
-> setShowInputMessage(true) -> setShowErrorMessage(true)
-> setShowErrorMessage(true) -> setShowDropDown(true)
-> setShowDropDown(true) -> setErrorTitle('输入的值有误')
-> setErrorTitle('输入的值有误') -> setError('您输入的值不在下拉框列表内.')
-> setError('您输入的值不在下拉框列表内.') -> setPromptTitle('房屋类型')
-> setPromptTitle('房屋类型') -> setFormula1('"住宅,商铺,办公"');; //这一句为要设置数据有效性的单元格
-> setFormula1('"住宅,商铺,办公"');; //这一句为要设置数据有效性的单元格 if($optionsCarBlockString) {
if($optionsCarBlockString) { $phpExcel->getActiveSheet()->getCell('F'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
$phpExcel->getActiveSheet()->getCell('F'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST) -> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION) -> setAllowBlank(false)
-> setAllowBlank(false) -> setShowInputMessage(true)
-> setShowInputMessage(true) -> setShowErrorMessage(true)
-> setShowErrorMessage(true) -> setShowDropDown(true)
-> setShowDropDown(true) -> setErrorTitle('输入的值有误')
-> setErrorTitle('输入的值有误') -> setError('您输入的值不在下拉框列表内.')
-> setError('您输入的值不在下拉框列表内.') -> setPromptTitle('车库位置')
-> setPromptTitle('车库位置') -> setFormula1('"'.$optionsCarBlockString.'"');; //这一句为要设置数据有效性的单元格
-> setFormula1('"'.$optionsCarBlockString.'"');; //这一句为要设置数据有效性的单元格 }
} $i++;
$i++; }
} $objWriter = new \PHPExcel_Writer_Excel5($phpExcel);
$objWriter = new \PHPExcel_Writer_Excel5($phpExcel); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="房间导入失败数据.xls"');
header('Content-Disposition: attachment;filename="房间导入失败数据.xls"'); header('Cache-Control: max-age=0');
header('Cache-Control: max-age=0'); $objWriter->save("php://output");
$objWriter->save("php://output");
}
} }
}
//通过房间编号获取房间的父id
//通过房间编号获取房间的父id public static function getParentId($layout_id,$vacancyCode) {
public static function getParentId($layout_id,$vacancyCode) { $arr = explode('-',$vacancyCode);
$arr = explode('-',$vacancyCode); $level= 0;
$level= 0; $parent_id = 0;
$parent_id = 0; foreach($arr as $k => $v) {
foreach($arr as $k => $v) { $level++;
$level++; $layout_build_id = Db::name('layout_build')->where(['layout_id'=>$layout_id,'code'=>$v,'level'=>$level,'parent_id'=>$parent_id])->value('layout_build_id');
$layout_build_id = Db::name('layout_build')->where(['layout_id'=>$layout_id,'code'=>$v,'level'=>$level,'parent_id'=>$parent_id])->value('layout_build_id'); if($layout_build_id) {
if($layout_build_id) { $parent_id = $layout_build_id;
$parent_id = $layout_build_id; }
} }
} return $parent_id;
return $parent_id; }
}
//通过填写的用户的房间号来转化成真正的房间编号
//通过填写的用户的房间号来转化成真正的房间编号 public static function getVacancyCode($vacancyCode,$layout_id) {
public static function getVacancyCode($vacancyCode,$layout_id) { $vacancyCodeArr = explode('-',$vacancyCode);
$vacancyCodeArr = explode('-',$vacancyCode); $roomCode = array_pop($vacancyCodeArr);//去掉最后一个是房间的
$roomCode = array_pop($vacancyCodeArr);//去掉最后一个是房间的 $vacancy_code = '';
$vacancy_code = ''; $parent_id = 0;
$parent_id = 0; $level = 1;
$level = 1; foreach ($vacancyCodeArr as $k => $v) {
foreach ($vacancyCodeArr as $k => $v) { $parent_id = Db::name('layout_build')->where(['layout_id'=>$layout_id,'parent_id'=>$parent_id,'code'=>$v,'level'=>$level])->value('layout_build_id');
$parent_id = Db::name('layout_build')->where(['layout_id'=>$layout_id,'parent_id'=>$parent_id,'code'=>$v,'level'=>$level])->value('layout_build_id'); if(!$parent_id){
if(!$parent_id){ return ['code'=>400,'msg'=>'房间编号不存在!'];
return ['code'=>400,'msg'=>'房间编号不存在!']; }
} $vacancy_code = $vacancy_code.$parent_id."-";
$vacancy_code = $vacancy_code.$parent_id."-"; $level++;
$level++; }
}
$arrCode = explode('-',rtrim($vacancy_code,'-'));
$arrCode = explode('-',rtrim($vacancy_code,'-')); return ['code'=>200,'msg'=>$vacancy_code.$roomCode,'parent_id'=>array_pop($arrCode)];
return ['code'=>200,'msg'=>$vacancy_code.$roomCode,'parent_id'=>array_pop($arrCode)];
}
}
//用户导入
//用户导入 public static function importTenant($filePath,$village_id) {
public static function importTenant($filePath,$village_id) { $where['village_id'] = $village_id;
$where['village_id'] = $village_id; $objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容
$objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容 $objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件
$objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件 $sheet = $objPHPExcel->getSheet(0);
$sheet = $objPHPExcel->getSheet(0); $dataAll = $objPHPExcel->getSheet(0)->toArray(); //获取导入的数据;
$dataAll = $objPHPExcel->getSheet(0)->toArray(); //获取导入的数据; $highestRow = $sheet->getHighestRow(); // 取得总行数
$highestRow = $sheet->getHighestRow(); // 取得总行数 $errorData =[]; //存放导入失败的数据;
$errorData =[]; //存放导入失败的数据; $insertData = [];
$insertData = []; $layout_list = Db::name('layout_list')->where($where)->column('layout_id','code');
$layout_list = Db::name('layout_list')->where($where)->column('layout_id','code'); for($i=1;$i<$highestRow;$i++) {
for($i=1;$i<$highestRow;$i++) { $msg="";
$msg=""; $name = $dataAll[$i][0];
$name = $dataAll[$i][0]; if(is_null($name)){
if(is_null($name)){ continue;
continue; }
} $phone = $dataAll[$i][1];
$phone = $dataAll[$i][1]; if(!isPhoneNo($phone)){
if(!isPhoneNo($phone)){ $msg.="手机号不正确!";
$msg.="手机号不正确!"; }
} $id_card = $dataAll[$i][2];
$id_card = $dataAll[$i][2]; if(!isCreditNo($id_card)){
if(!isCreditNo($id_card)){ $msg.="身份证号码不正确!";
$msg.="身份证号码不正确!"; }
} $layout_list_code = $dataAll[$i][5];
$layout_list_code = $dataAll[$i][5]; if($layout_list_code) {
if($layout_list_code) { $layout_id = $layout_list[$layout_list_code];
$layout_id = $layout_list[$layout_list_code]; } else {
} else { $msg.="社区布局未选择!";
$msg.="社区布局未选择!"; }
} $vacancyCode = $dataAll[$i][3];
$vacancyCode = $dataAll[$i][3]; //验证房间编号是否存在,是否合理
//验证房间编号是否存在,是否合理 $res_vacancy_code = self::getVacancyCode($vacancyCode,$layout_id);
$res_vacancy_code = self::getVacancyCode($vacancyCode,$layout_id); if($res_vacancy_code['code'] !=200) {
if($res_vacancy_code['code'] !=200) { $msg.= "房间编号不正确!";
$msg.= "房间编号不正确!"; }
} $where['vacancy_code'] = $res_vacancy_code['msg'];
$where['vacancy_code'] = $res_vacancy_code['msg']; $vacancy_id = Db::name('house_vacancy')->where($where)->value('vacancy_id');
$vacancy_id = Db::name('house_vacancy')->where($where)->value('vacancy_id'); $userType = $dataAll[$i][4];
$userType = $dataAll[$i][4]; switch($userType){
switch($userType){ case "租客":
case "租客": $type=2;
$type=2; break;
break; case "业主":
case "业主": $type=0;
$type=0; break;
break; case "家属":
case "家属": $type =1;
$type =1; break;
break; default :
default : $msg.="未选择用户身份!";
$msg.="未选择用户身份!"; }
} //如果type=0,需要检测是否房间绑定了业主
//如果type=0,需要检测是否房间绑定了业主 if($type==0){
if($type==0){ $is_exit = Db::name('house_user_bind')->where(['village_id'=>$village_id,'vacancy_id'=>$vacancy_id,'type'=>0,'status'=>1])->value('house_user_bind_id');
$is_exit = Db::name('house_user_bind')->where(['village_id'=>$village_id,'vacancy_id'=>$vacancy_id,'type'=>0,'status'=>1])->value('house_user_bind_id'); if($is_exit){
if($is_exit){ $msg.='该房间已绑定业主,请在解绑!';
$msg.='该房间已绑定业主,请在解绑!'; }
} }
} $data['vacancy_id'] = $vacancy_id;
$data['vacancy_id'] = $vacancy_id; $data['village_id'] = $village_id;
$data['village_id'] = $village_id; $data['id_card'] = $id_card;
$data['id_card'] = $id_card; $data['name'] = $name;
$data['name'] = $name; $data['phone'] = $phone;
$data['phone'] = $phone; $data['type'] = $type;
$data['type'] = $type; $data['relatives_type'] =1; //默认
$data['relatives_type'] =1; //默认 $data['create_time'] = $data['pass_time'] = time();
$data['create_time'] = $data['pass_time'] = time(); $data['status'] =1;
$data['status'] =1; if(empty($msg)){
if(empty($msg)){ $insertData[] = $data;
$insertData[] = $data; } else {
} else { $dataAll[$i][] = $msg;
$dataAll[$i][] = $msg; $errorData[] = $dataAll[$i];
$errorData[] = $dataAll[$i]; }
} }
} //导入对的数据
//导入对的数据 if(!empty($insertData)){
if(!empty($insertData)){ Db::name('house_user_bind')->insertAll($insertData);
Db::name('house_user_bind')->insertAll($insertData); }
} //如果有错误的数据,导出
//如果有错误的数据,导出 if($errorData){
if($errorData){ //导出错误的数据
//导出错误的数据 $file = "./formwork/importTenant.xls";
$file = "./formwork/importTenant.xls"; $phpExcel = \PHPExcel_IOFactory::load($file);
$phpExcel = \PHPExcel_IOFactory::load($file); $title = ['A','B','C','D','E','F','G'];
$title = ['A','B','C','D','E','F','G']; $i = 2;
$i = 2; $optionsArr = Db::name('layout_list')->where(['village_id'=>$village_id])->column('code');
$optionsArr = Db::name('layout_list')->where(['village_id'=>$village_id])->column('code'); $optionsString = implode(',',$optionsArr);//这个是选择布局
$optionsString = implode(',',$optionsArr);//这个是选择布局 foreach ($errorData as $k =>$v) {
foreach ($errorData as $k =>$v) { foreach ($title as $key=>$value) {
foreach ($title as $key=>$value) { $phpExcel->getActiveSheet()->setCellValue($value.$i,$v[$key]);
$phpExcel->getActiveSheet()->setCellValue($value.$i,$v[$key]); }
} //设置单元楼下拉
//设置单元楼下拉 $phpExcel->getActiveSheet()->getCell('F'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
$phpExcel->getActiveSheet()->getCell('F'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST) -> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION) -> setAllowBlank(false)
-> setAllowBlank(false) -> setShowInputMessage(true)
-> setShowInputMessage(true) -> setShowErrorMessage(true)
-> setShowErrorMessage(true) -> setShowDropDown(true)
-> setShowDropDown(true) -> setErrorTitle('输入的值有误')
-> setErrorTitle('输入的值有误') -> setError('您输入的值不在下拉框列表内.')
-> setError('您输入的值不在下拉框列表内.') -> setPromptTitle('社区布局')
-> setPromptTitle('社区布局') -> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格
-> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格 $phpExcel->getActiveSheet()->getCell('E'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
$phpExcel->getActiveSheet()->getCell('E'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST) -> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION) -> setAllowBlank(false)
-> setAllowBlank(false) -> setShowInputMessage(true)
-> setShowInputMessage(true) -> setShowErrorMessage(true)
-> setShowErrorMessage(true) -> setShowDropDown(true)
-> setShowDropDown(true) -> setErrorTitle('输入的值有误')
-> setErrorTitle('输入的值有误') -> setError('您输入的值不在下拉框列表内.')
-> setError('您输入的值不在下拉框列表内.') -> setPromptTitle('房屋类型')
-> setPromptTitle('房屋类型') -> setFormula1('"租客,业主,家属"'); //这一句为要设置数据有效性的单元格
-> setFormula1('"租客,业主,家属"'); //这一句为要设置数据有效性的单元格
$i++;
$i++; }
} $objWriter = new \PHPExcel_Writer_Excel5($phpExcel);
$objWriter = new \PHPExcel_Writer_Excel5($phpExcel); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="用户导入失败数据.xls"');
header('Content-Disposition: attachment;filename="用户导入失败数据.xls"'); header('Cache-Control: max-age=0');
header('Cache-Control: max-age=0'); $objWriter->save("php://output");
$objWriter->save("php://output"); } else {
} else { return ['code'=>200,'data'=>[]];
return ['code'=>200,'data'=>[]]; }
} }
}
//车辆导入
//车辆导入 public static function importCar($filePath,$village_id) {
public static function importCar($filePath,$village_id) { $where['village_id'] = $village_id;
$where['village_id'] = $village_id; $objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容
$objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容 $objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件
$objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件 $sheet = $objPHPExcel->getSheet(0);
$sheet = $objPHPExcel->getSheet(0); $dataAll = $objPHPExcel->getSheet(0)->toArray(); //获取导入的数据;
$dataAll = $objPHPExcel->getSheet(0)->toArray(); //获取导入的数据; $highestRow = $sheet->getHighestRow(); // 取得总行数
$highestRow = $sheet->getHighestRow(); // 取得总行数 $errorData =[]; //存放导入失败的数据;
$optionsArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('park_block_id','name'); $insertData = [];
$errorData =[]; //存放导入失败的数据;
$insertData = []; for($i=1;$i<$highestRow;$i++) {
$msg="";
for($i=1;$i<$highestRow;$i++) { $name = $dataAll[$i][0];
$msg=""; $phone = $dataAll[$i][1];
$name = $dataAll[$i][0]; if(!isPhoneNo($phone)){
$phone = $dataAll[$i][1]; $msg.="用户手机号不正确!";
if(!isPhoneNo($phone)){ }
$msg.="用户手机号不正确!"; $license_plate = $dataAll[$i][2];
} $car_color = $dataAll[$i][3];
$license_plate = $dataAll[$i][2]; $brand = $dataAll[$i][4];
$car_color = $dataAll[$i][3]; $car_type = $dataAll[$i][5];
$brand = $dataAll[$i][4]; $data['name'] = $name;
$car_type = $dataAll[$i][5]; $data['phone'] = $phone;
$data['name'] = $name; $data['license_plate'] = $license_plate;
$data['phone'] = $phone; $data['car_color'] = $car_color;
$data['license_plate'] = $license_plate; $data['create_time'] = time();
$data['car_color'] = $car_color; $data['village_id'] = $village_id;
$data['create_time'] = time(); $data['brand'] = $brand;
$data['village_id'] = $village_id; $data['car_type'] = $car_type;
$data['brand'] = $brand; if(empty($msg)){
$data['car_type'] = $car_type; $insertData[] = $data;
if(empty($msg)){ } else {
$insertData[] = $data; $dataAll[$i][] = $msg;
} else { $errorData[] = $dataAll[$i];
$dataAll[$i][] = $msg; }
$errorData[] = $dataAll[$i]; }
}
} if(!empty($insertData)){
Db::name('park_car')->insertAll($insertData);
if(!empty($insertData)){ if($errorData) {
Db::name('park_car')->insertAll($insertData); //导出错误的数据
if($errorData) { $file = "./formwork/importCar.xls";
//导出错误的数据 $phpExcel = \PHPExcel_IOFactory::load($file);
$file = "./formwork/importCar.xls"; $title = ['A','B','C','D','E','F','G'];
$phpExcel = \PHPExcel_IOFactory::load($file); $i = 2;
$title = ['A','B','C','D','E','F','G']; $optionsArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('name');
$i = 2; $optionsString = implode(',',$optionsArr);//这个是的车库
$optionsArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('name'); foreach ($errorData as $k =>$v) {
$optionsString = implode(',',$optionsArr);//这个是的车库 foreach ($title as $key=>$value) {
foreach ($errorData as $k =>$v) { $phpExcel->getActiveSheet()->setCellValue($value.$i,$v[$key]);
foreach ($title as $key=>$value) { }
$phpExcel->getActiveSheet()->setCellValue($value.$i,$v[$key]); //设置单元楼下拉
} $phpExcel->getActiveSheet()->getCell('F'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
//设置单元楼下拉 -> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
$phpExcel->getActiveSheet()->getCell('F'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST) -> setAllowBlank(false)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION) -> setShowInputMessage(true)
-> setAllowBlank(false) -> setShowErrorMessage(true)
-> setShowInputMessage(true) -> setShowDropDown(true)
-> setShowErrorMessage(true) -> setErrorTitle('输入的值有误')
-> setShowDropDown(true) -> setError('您输入的值不在下拉框列表内.')
-> setErrorTitle('输入的值有误') -> setPromptTitle('车库')
-> setError('您输入的值不在下拉框列表内.') -> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格
-> setPromptTitle('车库') $i++;
-> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格 }
$i++; $objWriter = new \PHPExcel_Writer_Excel5($phpExcel);
} header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
$objWriter = new \PHPExcel_Writer_Excel5($phpExcel); header('Content-Disposition: attachment;filename="用户导入失败数据.xls"');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Cache-Control: max-age=0');
header('Content-Disposition: attachment;filename="用户导入失败数据.xls"'); $objWriter->save("php://output");
header('Cache-Control: max-age=0'); } else {
$objWriter->save("php://output"); return ['code'=>200,'data'=>[]];
} else { }
return ['code'=>200,'data'=>[]]; } else {
} return ['code'=>200,'data'=>[]];
} else { }
return ['code'=>200,'data'=>[]];
} }
} //车位导入
public static function importCarPark($filePath,$village_id) {
//车位导入 $where['village_id'] = $village_id;
public static function importCarPark($filePath,$village_id) { $objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容
$where['village_id'] = $village_id; $objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件
$objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容 $sheet = $objPHPExcel->getSheet(0);
$objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件 $dataAll = $objPHPExcel->getSheet(0)->toArray(); //获取导入的数据;
$sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); // 取得总行数
$dataAll = $objPHPExcel->getSheet(0)->toArray(); //获取导入的数据; $optionsArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('park_block_id','name');
$highestRow = $sheet->getHighestRow(); // 取得总行数 $errorData =[]; //存放导入失败的数据;
$optionsArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('park_block_id','name'); $insertData = [];//存放最后需要插入到数据库的数据
$errorData =[]; //存放导入失败的数据;
$insertData = [];//存放最后需要插入到数据库的数据 for($i=1;$i<$highestRow;$i++) {
$msg="";
for($i=1;$i<$highestRow;$i++) { $park_code = $dataAll[$i][0];
$msg=""; $park_block_name = $dataAll[$i][1];
$park_code = $dataAll[$i][0]; $type_name = $dataAll[$i][2];
$park_block_name = $dataAll[$i][1]; if($type_name == "非机动车位"){
$type_name = $dataAll[$i][2]; $data['type'] =0;
if($type_name == "非机动车位"){ }
$data['type'] =0; if($park_block_name) {
} $park_block_id = $optionsArr[$park_block_name];
if($park_block_name) { $data['park_block_id'] = $park_block_id;
$park_block_id = $optionsArr[$park_block_name]; } else{
$data['park_block_id'] = $park_block_id; $msg.="车库必选选!";
} else{ }
$msg.="车库必选选!";
} $data['park_code'] = $park_code;
$data['park_code'] = $park_code; //查询当前的车位是否已存在
$is_exit = Db::name('park_car')->where(['village_id'=>$village_id,'park_block_id'=>$park_block_id,'park_code'=>$park_code])->value('park_car_id');
//查询当前的车位是否已存在 if($is_exit) {
$is_exit = Db::name('park_car')->where(['village_id'=>$village_id,'park_block_id'=>$park_block_id,'park_code'=>$park_code])->value('park_car_id'); $msg.="该车位已存在!";
if($is_exit) { }
$msg.="该车位已存在!"; $data['create_time'] = time();
} $data['village_id'] = $village_id;
$data['create_time'] = time();
$data['village_id'] = $village_id; if(empty($msg)){
$insertData[] = $data;
if(empty($msg)){ } else {
$insertData[] = $data; $dataAll[$i][] = $msg;
} else { $errorData[] = $dataAll[$i];
$dataAll[$i][] = $msg; }
$errorData[] = $dataAll[$i]; }
}
} if(!empty($insertData)) {
if(!empty($insertData)) { Db::name('park_car')->insertAll($insertData);
if($errorData){
Db::name('park_car')->insertAll($insertData);
if($errorData){ //导出错误的数据
$file = "./formwork/importCarPark.xls";
//导出错误的数据 $phpExcel = \PHPExcel_IOFactory::load($file);
$file = "./formwork/importCarPark.xls"; $title = ['A','B','C','D'];
$phpExcel = \PHPExcel_IOFactory::load($file); $i = 2;
$title = ['A','B','C','D']; $optionsArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('name');
$i = 2; $optionsString = implode(',',$optionsArr);//这个是的车库
$optionsArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('name'); foreach ($errorData as $k =>$v) {
$optionsString = implode(',',$optionsArr);//这个是的车库 foreach ($title as $key=>$value) {
foreach ($errorData as $k =>$v) { $phpExcel->getActiveSheet()->setCellValue($value.$i,$v[$key]);
foreach ($title as $key=>$value) { }
$phpExcel->getActiveSheet()->setCellValue($value.$i,$v[$key]); //设置单元楼下拉
} $phpExcel->getActiveSheet()->getCell('B'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
//设置单元楼下拉 -> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
$phpExcel->getActiveSheet()->getCell('B'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST) -> setAllowBlank(false)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION) -> setShowInputMessage(true)
-> setAllowBlank(false) -> setShowErrorMessage(true)
-> setShowInputMessage(true) -> setShowDropDown(true)
-> setShowErrorMessage(true) -> setErrorTitle('输入的值有误')
-> setShowDropDown(true) -> setError('您输入的值不在下拉框列表内.')
-> setErrorTitle('输入的值有误') -> setPromptTitle('车库')
-> setError('您输入的值不在下拉框列表内.') -> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格
-> setPromptTitle('车库') $i++;
-> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格 }
$i++; $objWriter = new \PHPExcel_Writer_Excel5($phpExcel);
} header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
$objWriter = new \PHPExcel_Writer_Excel5($phpExcel); header('Content-Disposition: attachment;filename="用户导入失败数据.xls"');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Cache-Control: max-age=0');
header('Content-Disposition: attachment;filename="用户导入失败数据.xls"'); $objWriter->save("php://output");
header('Cache-Control: max-age=0'); } else{
$objWriter->save("php://output"); return ['code'=>200,'data'=>[]];
} else{ }
return ['code'=>200,'data'=>[]];
} } else {
return ['code'=>400,'msg'=>'文件内容为空!'];
} else { }
return ['code'=>400,'msg'=>'文件内容为空!']; }
}
} //每月水费导入
public static function importCost($filePath,$village_id,$type){
//每月水费导入
public static function importCost($filePath,$village_id,$type){ $where['village_id'] = $village_id;
$objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容
$where['village_id'] = $village_id; $objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件
$objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容 $sheet = $objPHPExcel->getSheet(0);
$objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件 $dataAll = $objPHPExcel->getSheet(0)->toArray(); //获取导入的数据;
$sheet = $objPHPExcel->getSheet(0); $highestRow = $sheet->getHighestRow(); // 取得总行数
$dataAll = $objPHPExcel->getSheet(0)->toArray(); //获取导入的数据; $errorData =[]; //存放导入失败的数据;
$highestRow = $sheet->getHighestRow(); // 取得总行数 $insertData = [];//存放最后需要插入到数据库的数据
$errorData =[]; //存放导入失败的数据;
$insertData = [];//存放最后需要插入到数据库的数据 for($i=1;$i<$highestRow;$i++) {
$msg="";
for($i=1;$i<$highestRow;$i++) { $vacancy_code = $dataAll[$i][0];
$msg=""; //判断房间号是否存在
$vacancy_code = $dataAll[$i][0]; $vacancyInfo = Db::name('house_vacancy')->alias('hv')
//判断房间号是否存在 ->leftJoin('layout_build lb','lb.layout_build_id = hv.parent_id')
$vacancyInfo = Db::name('house_vacancy')->alias('hv') ->where(['hv.village_id'=>$village_id,'hv.vacancy_code'=>$vacancy_code])
->leftJoin('layout_build lb','lb.layout_build_id = hv.parent_id') ->field('hv.vacancy_id,lb.water_price,lb.electric_price,lb.gas_price,hv.water_fee,hv.electric_fee,hv.gas_fee,hv.is_inherit')->find();
->where(['hv.village_id'=>$village_id,'hv.vacancy_code'=>$vacancy_code]) if($vacancyInfo) {
->field('hv.vacancy_id,lb.water_price,lb.electric_price,lb.gas_price,hv.water_fee,hv.electric_fee,hv.gas_fee,hv.is_inherit')->find(); $data['vacancy_id'] = $vacancyInfo['vacancy_id'];
if($vacancyInfo) { } else {
$data['vacancy_id'] = $vacancyInfo['vacancy_id']; $msg.="物业编号不存在!";
} else { }
$msg.="物业编号不存在!";
} switch ($type){
case "water":
switch ($type){ if($vacancyInfo['is_inherit'] ==1) {
case "water": $price = $vacancyInfo['water_price'];
if($vacancyInfo['is_inherit'] ==1) { } else {
$price = $vacancyInfo['water_price']; $price = $vacancyInfo['water_fee'];
} else { }
$price = $vacancyInfo['water_fee']; $outFileName = "水费导入失败.xls";
} break;
$outFileName = "水费导入失败.xls"; case "electric":
break; if($vacancyInfo['is_inherit'] ==1) {
case "electric": $price = $vacancyInfo['electric_price'];
if($vacancyInfo['is_inherit'] ==1) { } else {
$price = $vacancyInfo['electric_price']; $price = $vacancyInfo['electric_fee'];
} else { }
$price = $vacancyInfo['electric_fee']; $outFileName = "电费导入失败.xls";
} break;
$outFileName = "电费导入失败.xls"; case "gas":
break; if($vacancyInfo['is_inherit'] ==1) {
case "gas": $price = $vacancyInfo['gas_price'];
if($vacancyInfo['is_inherit'] ==1) { } else {
$price = $vacancyInfo['gas_price']; $price = $vacancyInfo['gas_fee'];
} else { }
$price = $vacancyInfo['gas_fee']; $outFileName = "燃气费导入失败.xls";
} break;
$outFileName = "燃气费导入失败.xls"; default :
break; $outFileName = "未知错误.xls";
default : return ['code'=>400,'msg'=>'小区费用未设置,请先设置费用!'];
$outFileName = "未知错误.xls"; }
return ['code'=>400,'msg'=>'小区费用未设置,请先设置费用!'];
} //查看月份的费用是否存在
$data['cost_month'] = $dataAll[$i][1];
//查看月份的费用是否存在 //判断月份是否超过了当前时间,不能导入超前月份
$data['cost_month'] = $dataAll[$i][1]; if(strtotime(date('Y-m',time())) <= strtotime($data['cost_month'])) {
//判断月份是否超过了当前时间,不能导入超前月份 $msg.="不允许导入超过当前月份的数据!";
if(strtotime(date('Y-m',time())) <= strtotime($data['cost_month'])) { }
$msg.="不允许导入超过当前月份的数据!"; $data['village_id'] = $village_id;
} $data['type'] = $type;
$data['village_id'] = $village_id; $is_exit = Db::name('cost')->where($data)->find();
$data['type'] = $type; if($is_exit) {
$is_exit = Db::name('cost')->where($data)->find(); $msg.="该条记录已存在!";
if($is_exit) { }
$msg.="该条记录已存在!"; $data['price'] = $price;
} $data['area'] = $dataAll[$i][2];
$data['price'] = $price;
$data['area'] = $dataAll[$i][2]; $data['total_money'] = $data['pay_money'] = number_format($price*$data['area'],2);
$data['is_pay'] = 0;
$data['total_money'] = $data['pay_money'] = number_format($price*$data['area'],2); $data['create_time'] = time();
$data['is_pay'] = 0;
$data['create_time'] = time(); if(empty($msg)){
$insertData[] = $data;
if(empty($msg)){ } else {
$insertData[] = $data; $dataAll[$i][3] = $msg;
} else { $errorData[] = $dataAll[$i];
$dataAll[$i][3] = $msg; }
$errorData[] = $dataAll[$i]; }
} if(!empty($insertData) || !empty($errorData)) {
} Db::name('cost')->insertAll($insertData);
if(!empty($insertData) || !empty($errorData)) { if($errorData){
Db::name('cost')->insertAll($insertData); //导出错误的数据
if($errorData){ if($type == "water") {
//导出错误的数据 $file = "./formwork/importWater.xls";
if($type == "water") { } else if($type == "electric") {
$file = "./formwork/importWater.xls"; $file = "./formwork/importElectric.xls";
} else if($type == "electric") { } else {
$file = "./formwork/importElectric.xls"; $file = "./formwork/importGas.xls";
} else { }
$file = "./formwork/importGas.xls"; $phpExcel = \PHPExcel_IOFactory::load($file);
} $title = ['A','B','C','D'];
$phpExcel = \PHPExcel_IOFactory::load($file); $i = 2;
$title = ['A','B','C','D']; foreach ($errorData as $k =>$v) {
$i = 2; foreach ($title as $key=>$value) {
foreach ($errorData as $k =>$v) { $phpExcel->getActiveSheet()->setCellValue($value.$i,$v[$key]);
foreach ($title as $key=>$value) { }
$phpExcel->getActiveSheet()->setCellValue($value.$i,$v[$key]); $i++;
} }
$i++; $objWriter = new \PHPExcel_Writer_Excel5($phpExcel);
} header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
$objWriter = new \PHPExcel_Writer_Excel5($phpExcel); header('Content-Disposition: attachment;filename='.$outFileName);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Cache-Control: max-age=0');
header('Content-Disposition: attachment;filename='.$outFileName); $objWriter->save("php://output");
header('Cache-Control: max-age=0'); } else{
$objWriter->save("php://output"); return ['code'=>200,'data'=>[]];
} else{ }
return ['code'=>200,'data'=>[]]; } else {
} return ['code'=>400,'msg'=>'文件内容为空!'];
} else { }
return ['code'=>400,'msg'=>'文件内容为空!'];
} }
} //验证短信验证码是否正确
public static function rightCode($phone,$code) {
//验证短信验证码是否正确 $is_exit = Db::name('send_code')->where(['phone'=>$phone,'code'=>$code])->where('expires_time',">",time())->find();
public static function rightCode($phone,$code) { if($is_exit){
$is_exit = Db::name('send_code')->where(['phone'=>$phone,'code'=>$code])->where('expires_time',">",time())->find(); return true;
if($is_exit){ }
return true; return false;
} }
return false;
} //app用户登入之后同步数据
public static function synUserData($uid,$phone) {
//app用户登入之后同步数据 //房间列表用户修改
public static function synUserData($uid,$phone) { Db::name('house_vacancy')->where(['phone'=>$phone])->save(['uid'=>$uid]);
//房间列表用户修改 //汽车关联
Db::name('house_vacancy')->where(['phone'=>$phone])->save(['uid'=>$uid]); Db::name('car')->where(['phone'=>$phone])->save(['uid'=>$uid]);
//汽车关联
Db::name('car')->where(['phone'=>$phone])->save(['uid'=>$uid]); }
} //通过房间编号和布局id获取房间地址
public static function getVacancyAddress($vacancyCode,$layout_id) {
//通过房间编号和布局id获取房间地址
public static function getVacancyAddress($vacancy_code,$layout_id) { $layoutCode = Db::name('layout_list')->where(['layout_id'=>$layout_id])->value('code');
$layoutString = Db::name('layout_list')->where(['layout_id'=>$layout_id])->value('code'); $codeArr = explode('-',$layoutCode);
$layoutArr = explode('-',$layoutString); $rom = array_pop($codeArr); //获取最后一个房间的单位
$vacancyCodeArr = explode('-',$vacancy_code); $arr = explode('-',$vacancyCode);
$address=""; $room_code = array_pop($arr);
foreach ($vacancyCodeArr as $k =>$v){ $string = '';
$room_num = '';
$address.=$v.$layoutArr[$k]; foreach ($arr as $v) {
} $code_name = Db::name('layout_build')->where(['layout_build_id'=>$v])->field('code,level')->find();
return $address; $key = $code_name['level'] -1;
} $string.=$code_name['code'].$codeArr[$key];
$room_num.=$code_name['code']."-";
//通过房间id获取业主信息 }
public static function getOwnerInfo($vacancy_id) { $room_num = $room_num.$room_code;
$data = Db::name('house_user_bind')->where(['vacancy_id'=>$vacancy_id,'type'=>0,'status'=>1])->field('type,status,phone,name')->find(); return ['vacancy_address'=>$string.$room_code.$rom,'room_num'=>$room_num];
return $data??[]; }
}
//通过房间id获取业主信息
//获取需要绑定人员设备 public static function getOwnerInfo($vacancy_id) {
public static function getUserBindType() { $data = Db::name('house_user_bind')->where(['vacancy_id'=>$vacancy_id,'type'=>0,'status'=>1])->field('type,status,phone,name')->find();
return ['0'=>'业主','1'=>'家人','2'=>'租客','3'=>'替换业主']; return $data??[];
} }
//获取需要绑定人员设备
public static function getFamilyBindType() { //获取需要绑定人员设备
return ['1'=>'配偶','2'=>'父母','3'=>'子女','4'=>'亲朋好友']; public static function getUserBindType() {
} return ['0'=>'业主','1'=>'家人','2'=>'租客','3'=>'替换业主'];
}
//根据查询到的小区id,获取当前用户所在小区绑定的房间 //获取需要绑定人员设备
public static function getVacancy($village_id,$uid) { public static function getFamilyBindType() {
$data = Db::name('house_user_bind')->alias('hub')->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')->where(['hub.village_id'=>$village_id,'hub.uid'=>$uid])->whereIn('hub.status',[1,2,4]) return ['1'=>'配偶','2'=>'父母','3'=>'子女','4'=>'亲朋好友'];
->field('hub.house_user_bind_id,hub.vacancy_id,hub.type,hv.layout_id,hv.vacancy_code')->select()->toArray(); }
foreach ($data as $key =>$val) {
$data[$key]['vacancy_address'] = self::getVacancyAddress($val['vacancy_code'],$val['layout_id']); //根据查询到的小区id,获取当前用户所在小区绑定的房间
} public static function getVacancy($village_id,$uid) {
$data = Db::name('house_user_bind')->alias('hub')->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')->where(['hub.village_id'=>$village_id,'hub.uid'=>$uid])->whereIn('hub.status',[1,2,4])
return $data; ->field('hub.house_user_bind_id,hub.vacancy_id,hub.type,hv.layout_id,hv.vacancy_code')->select()->toArray();
} foreach ($data as $key =>$val) {
$res = self::getVacancyAddress($val['vacancy_code'],$val['layout_id']);
$data[$key]['vacancy_address'] = $res['vacancy_address'];
}
return $data;
}
} }
\ No newline at end of file
<?php <?php
namespace app\shequ\controller; namespace app\shequ\controller;
use app\admin\controller\Common; use app\admin\controller\Common;
use think\facade\Db; use think\facade\Db;
use think\facade\Request; use think\facade\Request;
//这是关于创建建筑之类的接口 //这是关于创建建筑之类的接口
class Build extends Base class Build extends Base
{ {
protected $middleware = ['app\middleware\CommunityLoginCheck::class','app\middleware\CommunityAfter::class']; protected $middleware = ['app\middleware\CommunityLoginCheck::class','app\middleware\CommunityAfter::class'];
//添加建筑时候选择布局 //添加建筑时候选择布局
public function layoutInfo() { public function layoutInfo() {
$where['village_id'] = $this->village_id; $where['village_id'] = $this->village_id;
$data = Db::name('layout_list')->where($where)->select()->toArray(); $data = Db::name('layout_list')->where($where)->select()->toArray();
$res = []; $res = [];
foreach ($data as $k =>$v) { foreach ($data as $k =>$v) {
$arr = explode('-',$v['code']); $arr = explode('-',$v['code']);
array_pop($arr); //最后一个是房间的,去掉 array_pop($arr); //最后一个是房间的,去掉
$res[] = $this->zuhe($arr,$v['layout_id']); $res[] = $this->zuhe($arr,$v['layout_id']);
} }
return $this->returnJson($res,'success'); return $this->returnJson($res,'success');
} }
public function zuhe($arr,$layout_id) { public function zuhe($arr,$layout_id) {
$res['code'] = $arr[0]; $res['code'] = $arr[0];
$res['layout_id'] = $layout_id; $res['layout_id'] = $layout_id;
$nam = ['code']; $nam = ['code'];
$res['son']['code'] = isset($arr[1]) ? $arr[1] : []; $res['son']['code'] = isset($arr[1]) ? $arr[1] : [];
if(!$res['son']['code']){ if(!$res['son']['code']){
unset($res['son']['code']); unset($res['son']['code']);
return $res; return $res;
} }
$res['son']['son']['code'] = isset($arr[2]) ? $arr[2] :[]; $res['son']['son']['code'] = isset($arr[2]) ? $arr[2] :[];
if(!$res['son']['son']['code']){ if(!$res['son']['son']['code']){
unset($res['son']['son']['code']); unset($res['son']['son']['code']);
return $res; return $res;
} }
$res['son']['son']['son']['code'] = isset($arr[3]) ? $arr[3] : []; $res['son']['son']['son']['code'] = isset($arr[3]) ? $arr[3] : [];
if(!$res['son']['son']['son']['code']){ if(!$res['son']['son']['son']['code']){
unset($res['son']['son']['son']['code']); unset($res['son']['son']['son']['code']);
return $res; return $res;
} }
$res['son']['son']['son']['son']['code'] = isset($arr[4]) ? $arr[4] : []; $res['son']['son']['son']['son']['code'] = isset($arr[4]) ? $arr[4] : [];
if(!$res['son']['son']['son']['son']['code']){ if(!$res['son']['son']['son']['son']['code']){
unset($res['son']['son']['son']['son']['code']); unset($res['son']['son']['son']['son']['code']);
return $res; return $res;
} }
$res['son']['son']['son']['son']['son']['code'] = isset($arr[5]) ? $arr[5] : []; $res['son']['son']['son']['son']['son']['code'] = isset($arr[5]) ? $arr[5] : [];
if(!$res['son']['son']['son']['son']['son']['code']){ if(!$res['son']['son']['son']['son']['son']['code']){
unset($res['son']['son']['son']['son']['son']['code']); unset($res['son']['son']['son']['son']['son']['code']);
return $res; return $res;
} }
$res['son']['son']['son']['son']['son']['son'] = isset($arr[6]) ? $arr[6] : []; $res['son']['son']['son']['son']['son']['son'] = isset($arr[6]) ? $arr[6] : [];
if(!$res['son']['son']['son']['son']['son']['son']){ if(!$res['son']['son']['son']['son']['son']['son']){
unset($res['son']['son']['son']['son']['son']['son']['code']); unset($res['son']['son']['son']['son']['son']['son']['code']);
return $res; return $res;
} }
} }
//创建建筑 //创建建筑
public function createBuild() { public function createBuild() {
$village_id = $this->village_id; $village_id = $this->village_id;
$data['layout_id'] = Request::param('layout_id'); $data['layout_id'] = Request::param('layout_id');
$data['code'] = Request::param('code'); $data['code'] = Request::param('code');
$layoutInfo = DB::name('layout_list')->where(['layout_id'=>$data['layout_id']])->value('code'); $layoutInfo = DB::name('layout_list')->where(['layout_id'=>$data['layout_id']])->value('code');
if($layoutInfo) { if($layoutInfo) {
$codeArr = explode('-',$layoutInfo); $codeArr = explode('-',$layoutInfo);
} else { } else {
return $this->returnJson([],'未找到对应的模板',400); return $this->returnJson([],'未找到对应的模板',400);
} }
$data['parent_id'] = Request::param('parent_id',0); $data['parent_id'] = Request::param('parent_id',0);
//查询是否有相同的编号 //查询是否有相同的编号
$is_exit = DB::name('layout_build')->where($data)->find(); $is_exit = DB::name('layout_build')->where($data)->find();
if($is_exit) { if($is_exit) {
return $this->returnJson([],'相同编号建筑已存在!',400); return $this->returnJson([],'相同编号建筑已存在!',400);
} }
//位置 拼接 //位置 拼接
if($data['parent_id'] ==0) { if($data['parent_id'] ==0) {
$village_name = DB::name('house_village')->where(['village_id'=>$village_id])->value('village_name'); $village_name = DB::name('house_village')->where(['village_id'=>$village_id])->value('village_name');
$data['level'] = 1; $data['level'] = 1;
} else { } else {
$village_name = DB::name('layout_build')->where(['layout_build_id'=>$data['parent_id']])->value('address'); $village_name = DB::name('layout_build')->where(['layout_build_id'=>$data['parent_id']])->value('address');
$p_level = Db::name('layout_build')->where(['layout_build_id'=>$data['parent_id']])->value('level'); $p_level = Db::name('layout_build')->where(['layout_build_id'=>$data['parent_id']])->value('level');
$data['level'] = ++$p_level; $data['level'] = ++$p_level;
} }
$addre = $data['code'].$codeArr[$data['level']-1]; //小区编号转码 $addre = $data['code'].$codeArr[$data['level']-1]; //小区编号转码
$data['property_price'] = $save['property_price']= Request::param('property_price'); $data['property_price'] = $save['property_price']= Request::param('property_price');
$data['water_price'] = $save['water_price']= Request::param('water_price'); $data['water_price'] = $save['water_price']= Request::param('water_price');
$data['electric_price'] = $save['electric_price']= Request::param('electric_price'); $data['electric_price'] = $save['electric_price']= Request::param('electric_price');
$data['gas_price'] = $save['gas_price']= Request::param('gas_price'); $data['gas_price'] = $save['gas_price']= Request::param('gas_price');
$data['parking_price'] = $save['parking_price']= Request::param('parking_price'); $data['parking_price'] = $save['parking_price']= Request::param('parking_price');
$data['explain'] = Request::param('explain'); $data['explain'] = Request::param('explain');
$data['village_id'] = $village_id; $data['village_id'] = $village_id;
$data['name'] = $codeArr[$data['level']-1]; $data['name'] = $codeArr[$data['level']-1];
$data['create_time'] = time(); $data['create_time'] = time();
$data['sort_id'] = Request::param('sort_id'); $data['sort_id'] = Request::param('sort_id');
$data['is_inherit'] = Request::param('is_inherit',1);//默认集成上一级的费用明细 $data['is_inherit'] = Request::param('is_inherit',1);//默认集成上一级的费用明细
$data['measure_area'] = Request::param('measure_area');//面积 $data['measure_area'] = Request::param('measure_area');//面积
$data['address'] = $village_name.$addre; $data['address'] = $village_name.$addre;
//判断是否设置了小区的参数,设置了就不用设置, //判断是否设置了小区的参数,设置了就不用设置,
$is_exit = DB::name('house_village')->where(['village_id'=>$village_id])->field('village_id,property_price,water_price,electric_price,gas_price,park_price')->find(); $is_exit = DB::name('house_village')->where(['village_id'=>$village_id])->field('village_id,property_price,water_price,electric_price,gas_price,park_price')->find();
if(!$is_exit['property_price'] && !$is_exit['water_price'] &&!$is_exit['electric_price'] &&!$is_exit['gas_price']&&!$is_exit['parking_price'] ) { if(!$is_exit['property_price'] && !$is_exit['water_price'] &&!$is_exit['electric_price'] &&!$is_exit['gas_price']&&!$is_exit['parking_price'] ) {
DB::name('house_village')->where(['village_id'=>$village_id])->save($save); DB::name('house_village')->where(['village_id'=>$village_id])->save($save);
} }
$insert = Db::name('layout_build')->insert($data); $insert = Db::name('layout_build')->insert($data);
if($insert) { if($insert) {
return $this->returnJson([],'success'); return $this->returnJson([],'success');
} else{ } else{
return $this->returnJson([],'error',400); return $this->returnJson([],'error',400);
} }
} }
//修改建筑信息 //修改建筑信息
public function changeBuild() { public function changeBuild() {
$layout_build_id = Request::param('layout_build_id'); $layout_build_id = Request::param('layout_build_id');
$where['layout_build_id'] = $layout_build_id; $where['layout_build_id'] = $layout_build_id;
//先查询原先的数据 //先查询原先的数据
$buildInfo = Db::name('layout_build')->where($where)->find(); $buildInfo = Db::name('layout_build')->where($where)->find();
$code = Request::param('code'); $code = Request::param('code');
//查询修改的code是否存在 //查询修改的code是否存在
$is_exit = Db::name('layout_build')->where(['village_id'=>$buildInfo['village_id'],'layout_id'=>$buildInfo['layout_id'],'parent_id'=>$buildInfo['parent_id'],'code'=>$code])->where('layout_build_id','<>',$buildInfo['layout_build_id'])->find(); $is_exit = Db::name('layout_build')->where(['village_id'=>$buildInfo['village_id'],'layout_id'=>$buildInfo['layout_id'],'parent_id'=>$buildInfo['parent_id'],'code'=>$code])->where('layout_build_id','<>',$buildInfo['layout_build_id'])->find();
if($is_exit) { if($is_exit) {
return $this->returnJson([],'该建筑编号已存在!',400); return $this->returnJson([],'该建筑编号已存在!',400);
} }
$data['code']= $code; $data['code']= $code;
$data['explain']= Request::param('explain'); $data['explain']= Request::param('explain');
$data['measure_area']= Request::param('measure_area'); $data['measure_area']= Request::param('measure_area');
$data['property_price'] = $where['property_price'] = Request::param('property_price'); $data['property_price'] = $where['property_price'] = Request::param('property_price');
$data['water_price'] = $where['water_price'] = Request::param('water_price'); $data['water_price'] = $where['water_price'] = Request::param('water_price');
$data['electric_price'] = $where['electric_price'] = Request::param('electric_price'); $data['electric_price'] = $where['electric_price'] = Request::param('electric_price');
$data['gas_price'] = $where['gas_price'] = Request::param('gas_price'); $data['gas_price'] = $where['gas_price'] = Request::param('gas_price');
$data['parking_price'] = $where['parking_price'] = Request::param('parking_price'); $data['parking_price'] = $where['parking_price'] = Request::param('parking_price');
$data['parent_id'] = $buildInfo['parent_id']; $data['parent_id'] = $buildInfo['parent_id'];
$is_inherit = Request::param('is_inherit',1); //物业费等是否继承上一级,1继承,0不继承 $is_inherit = Request::param('is_inherit',1); //物业费等是否继承上一级,1继承,0不继承
if($is_inherit == 1 ) { if($is_inherit == 1 ) {
if($data['parent_id'] == 0) { if($data['parent_id'] == 0) {
$is_find = Db::name('house_village')->where(['village_id'=>$this->village_id])->where($where)->find(); $is_find = Db::name('house_village')->where(['village_id'=>$this->village_id])->where($where)->find();
} else { } else {
$is_find = Db::name('layout_build')->where(['village_id'=>$this->village_id,'layout_build_id'=>$data['parent_id']])->where($where)->find(); $is_find = Db::name('layout_build')->where(['village_id'=>$this->village_id,'layout_build_id'=>$data['parent_id']])->where($where)->find();
} }
if(!$is_find){ if(!$is_find){
return $this->returnJson([],'费用有误,请重新输入!',400); return $this->returnJson([],'费用有误,请重新输入!',400);
} }
} }
//判断是否修改了费用字段 //判断是否修改了费用字段
if($data['property_price'] != $buildInfo['property_price'] || $data['water_price'] != $buildInfo['water_price'] || $data['electric_price'] != $buildInfo['electric_price'] || $data['gas_price'] != $buildInfo['gas_price'] || $data['parking_price'] != $buildInfo['parking_price'] ) { if($data['property_price'] != $buildInfo['property_price'] || $data['water_price'] != $buildInfo['water_price'] || $data['electric_price'] != $buildInfo['electric_price'] || $data['gas_price'] != $buildInfo['gas_price'] || $data['parking_price'] != $buildInfo['parking_price'] ) {
//先修改下面的建筑,然后在修改其他 //先修改下面的建筑,然后在修改其他
$ids = $this->findBuildId($layout_build_id); $ids = $this->findBuildId($layout_build_id);
unset($where['layout_build_id']); unset($where['layout_build_id']);
Db::name('layout_build')->where('layout_build_id','in',$ids)->save($where); Db::name('layout_build')->where('layout_build_id','in',$ids)->save($where);
} }
$data['is_inherit'] = $is_inherit; $data['is_inherit'] = $is_inherit;
$change = Db::name('layout_build')->where(['layout_build_id'=>$layout_build_id])->save($data); $change = Db::name('layout_build')->where(['layout_build_id'=>$layout_build_id])->save($data);
if($change) { if($change) {
return $this->returnJson([],'success'); return $this->returnJson([],'success');
} else{ } else{
return $this->returnJson([],'error',400); return $this->returnJson([],'error',400);
} }
} }
//删除建筑 //删除建筑
public function deleteBuild() { public function deleteBuild() {
//如果该建筑下有子建筑,则无法删除 //如果该建筑下有子建筑,则无法删除
$layout_build_id = Request::param('layout_build_id'); $layout_build_id = Request::param('layout_build_id');
$is_exit = Db::name('layout_build')->where(['village_id'=>$this->village_id,'parent_id'=>$layout_build_id])->find(); $is_exit = Db::name('layout_build')->where(['village_id'=>$this->village_id,'parent_id'=>$layout_build_id])->find();
if($is_exit) { if($is_exit) {
return $this->returnJson([],'该建筑有子建筑,无法删除!',400); return $this->returnJson([],'该建筑有子建筑,无法删除!',400);
} }
$del = Db::name('layout_build')->where(['layout_build_id'=>$layout_build_id])->delete(); $del = Db::name('layout_build')->where(['layout_build_id'=>$layout_build_id])->delete();
if($del) { if($del) {
return $this->returnJson([],'success'); return $this->returnJson([],'success');
} else { } else {
return $this->returnJson([],'删除失败',400); return $this->returnJson([],'删除失败',400);
} }
} }
//建筑列表 //建筑列表
public function buildList() { public function buildList() {
$village_id = $this->village_id; $village_id = $this->village_id;
$where['lb.village_id'] = $village_id; $where['lb.village_id'] = $village_id;
$where['lb.parent_id'] = Request::param('parent_id',0); $where['lb.parent_id'] = Request::param('parent_id',0);
if(Request::param('layout_id')) { if(Request::param('layout_id')) {
$where['lb.layout_id'] = Request::param('layout_id'); $where['lb.layout_id'] = Request::param('layout_id');
} }
$page = Request::param('page',1); $page = Request::param('page',1);
$data = Db::name('layout_build')->alias('lb')->leftJoin('layout_list ll','ll.layout_id = lb.layout_id')->where($where)->order(['lb.layout_id'=>'asc','lb.sort_id'=>'desc'])->page($page,config('app.limit')) $data = Db::name('layout_build')->alias('lb')->leftJoin('layout_list ll','ll.layout_id = lb.layout_id')->where($where)->order(['lb.layout_id'=>'asc','lb.sort_id'=>'desc'])->page($page,config('app.limit'))
->field("lb.*,ll.name as layout_name,ll.level as layout_level") ->field("lb.*,ll.name as layout_name,ll.level as layout_level")
->select() ->select()
->toArray(); ->toArray();
foreach ($data as $k => $v) { foreach ($data as $k => $v) {
$is_exit = Db::name('layout_build')->where(['parent_id'=>$v['layout_build_id']])->value('layout_build_id'); $is_exit = Db::name('layout_build')->where(['parent_id'=>$v['layout_build_id']])->value('layout_build_id');
if($is_exit){ if($is_exit){
$data[$k]['hasChildren'] = true; $data[$k]['hasChildren'] = true;
} else{ } else{
$data[$k]['hasChildren'] = false; $data[$k]['hasChildren'] = false;
} }
//查看当前是否是最后一级建筑 //查看当前是否是最后一级建筑
if($v['level'] == ($v['layout_level']-1)){ if($v['level'] == ($v['layout_level']-1)){
$data[$k]['isEnd'] = true; $data[$k]['isEnd'] = true;
//获取建筑的物业编号 //获取建筑的物业编号
$code = []; $code = [];
$data[$k]['buildNum'] = $this->createNum($v['layout_build_id'],$code); $data[$k]['buildNum'] = $this->createNum($v['layout_build_id'],$code);
} else { } else {
$data[$k]['isEnd'] = false; $data[$k]['isEnd'] = false;
$data[$k]['buildNum'] = '-'; $data[$k]['buildNum'] = '-';
} }
} }
$count = Db::name('layout_build')->alias('lb')->where($where)->count(); $count = Db::name('layout_build')->alias('lb')->where($where)->count();
$res['count'] = $count; $res['count'] = $count;
$res['data'] = Common::changeField($data); $res['data'] = Common::changeField($data);
return $this->returnJson($res,'success'); return $this->returnJson($res,'success');
} }
//根据建筑id拼接物业编号 //根据建筑id拼接物业编号
public function createNum($build_id,$code) { public function createNum($build_id,$code) {
$data = Db::name('layout_build')->where(['layout_build_id'=>$build_id])->field('layout_build_id,parent_id,code')->find(); $data = Db::name('layout_build')->where(['layout_build_id'=>$build_id])->field('layout_build_id,parent_id,code')->find();
array_unshift($code,$data['code']); array_unshift($code,$data['code']);
if($data['parent_id'] == 0) { if($data['parent_id'] == 0) {
return implode('-',$code); return implode('-',$code);
} else { } else {
return $this->createNum($data['parent_id'],$code); return $this->createNum($data['parent_id'],$code);
} }
} }
//根据建筑id获取同一级的建筑
//根据建筑id获取同一级的建筑 public function getCurrent() {
public function getCurrent() { $build_id = Request::param('build_id');
$build_id = Request::param('build_id'); $layoutInfo = Db::name('layout_build')->alias('lb')
$layoutInfo = Db::name('layout_build')->alias('lb') ->leftJoin('layout_list ll','ll.layout_id = lb.layout_id')
->leftJoin('layout_list ll','ll.layout_id = lb.layout_id') ->where(['layout_build_id'=>$build_id])
->where(['layout_build_id'=>$build_id]) ->field('lb.level,lb.code,lb.layout_build_id,lb.layout_id,lb.village_id,ll.code as ll_code')->find();
->field('lb.level,lb.code,lb.layout_build_id,lb.layout_id,lb.village_id,ll.code as ll_code')->find(); $where['layout_id'] = $layoutInfo['layout_id'];
$where['layout_id'] = $layoutInfo['layout_id']; $where['village_id'] = $layoutInfo['village_id'];
$where['village_id'] = $layoutInfo['village_id']; $where['level'] = $layoutInfo['level'];
$where['level'] = $layoutInfo['level']; $data = Db::name('layout_build')->where($where)->field('layout_build_id,layout_id,code,level')->select()->toArray();
$data = Db::name('layout_build')->where($where)->field('layout_build_id,layout_id,code,level')->select()->toArray(); if($layoutInfo){
if($layoutInfo){ $res['code_name'] = explode('-',$layoutInfo['ll_code'])[$layoutInfo['level']-1];
$res['code_name'] = explode('-',$layoutInfo['ll_code'])[$layoutInfo['level']-1]; } else {
} else { $res['code_name'] ='';
$res['code_name'] =''; }
} $res['data'] = $data;
$res['data'] = $data; return $this->returnJson($res);
return $this->returnJson($res);
}
}
//查看社区的水电物业费等
//查看社区的水电物业费等 public function costPrice() {
public function costPrice() { $where['village_id'] = Request::param('village_id');
$where['village_id'] = Request::param('village_id'); $data =DB::name('house_village')->where($where)->field('village_id,property_price,water_price,electric_price,gas_price,park_price')->find();
$data =DB::name('house_village')->where($where)->field('village_id,property_price,water_price,electric_price,gas_price,park_price')->find(); return $this->returnJson($data,'success');
return $this->returnJson($data,'success');
}
}
//根据id查看建筑详情
//根据id查看建筑详情 public function queryCostPrice(){
public function queryCostPrice(){ $where['lb.layout_build_id'] = Request::param('layout_build_id');//建筑id
$where['lb.layout_build_id'] = Request::param('layout_build_id');//建筑id $where['lb.village_id'] = $this->village_id;
$where['lb.village_id'] = $this->village_id; $res = Db::name('layout_build')->alias('lb')->leftJoin('layout_list ll','ll.layout_id = lb.layout_id')->where($where)
$res = Db::name('layout_build')->alias('lb')->leftJoin('layout_list ll','ll.layout_id = lb.layout_id')->where($where) ->field('lb.is_inherit,lb.layout_build_id,lb.layout_build_id,lb.property_price,lb.water_price,lb.electric_price,lb.gas_price,lb.parking_price,lb.code,lb.explain,lb.parent_id,lb.create_time,lb.measure_area,lb.address,lb.sort_id,ll.code as code_name, ll.name')
->field('lb.is_inherit,lb.layout_build_id,lb.layout_build_id,lb.property_price,lb.water_price,lb.electric_price,lb.gas_price,lb.parking_price,lb.code,lb.explain,lb.parent_id,lb.create_time,lb.measure_area,lb.address,lb.sort_id,ll.code as code_name, ll.name') ->find();
->find(); $data = Common::changeField($res);
$data = Common::changeField($res); return $this->returnJson($data,'success');
return $this->returnJson($data,'success');
}
}
//获取水电费等集成当前建筑的id
//获取水电费等集成当前建筑的id public function findBuildId($pid){
public function findBuildId($pid){ static $id = [];
static $id = []; $ids = DB::name('layout_build')->where(['parent_id'=>$pid,'is_inherit'=>1])->column('layout_build_id');
$ids = DB::name('layout_build')->where(['parent_id'=>$pid,'is_inherit'=>1])->column('layout_build_id'); if(!empty($ids)){
if(!empty($ids)){ foreach ($ids as $v) {
foreach ($ids as $v) { $this->findBuildId($v);
$this->findBuildId($v); $id[] = $v;
$id[] = $v; }
} }
} sort($id);
sort($id); return $id;
return $id; }
}
//获取子元素的所有建筑ID
//获取子元素的所有建筑ID public function allBuildId($pid) {
public function allBuildId($pid) { static $id = [];
static $id = []; $ids = DB::name('layout_build')->where(['parent_id'=>$pid])->column('layout_build_id');
$ids = DB::name('layout_build')->where(['parent_id'=>$pid])->column('layout_build_id'); if(!empty($ids)){
if(!empty($ids)){ foreach ($ids as $v) {
foreach ($ids as $v) { $this->findBuildId($v);
$this->findBuildId($v); $id[] = $v;
$id[] = $v; }
} }
} sort($id);
sort($id); return $id;
return $id; }
}
} }
\ No newline at end of file
<?php <?php
namespace app\shequ\controller; namespace app\shequ\controller;
use think\facade\Db; use app\admin\controller\Common;
use think\facade\Request; use think\facade\Db;
use think\facade\Request;
class Village extends Base
{ class Village extends Base
protected $middleware = ['app\middleware\CommunityLoginCheck::class','app\middleware\CommunityAfter::class']; {
protected $middleware = ['app\middleware\CommunityLoginCheck::class','app\middleware\CommunityAfter::class'];
//社区房屋排布编号
public function arrangementList() { //社区房屋排布编号
$where['village_id'] = Request::param('village_id'); public function arrangementList() {
$data = Db::name('layout_list')->where($where)->select()->toArray(); $where['village_id'] = Request::param('village_id');
return $this->returnJson($data,'success'); $data = Db::name('layout_list')->where($where)->select()->toArray();
} return $this->returnJson($data,'success');
}
//添加|修改社区排布
public function createArrangement() { //添加|修改社区排布
$layout_id = Request::param('layout_id'); public function createArrangement() {
$data['village_id'] = $where['village_id'] = Request::param('village_id'); $layout_id = Request::param('layout_id');
$data['code'] = Request::param('code'); $data['village_id'] = $where['village_id'] = Request::param('village_id');
$data['name'] = Request::param('name'); $data['code'] = Request::param('code');
$data['pic'] = Request::param('pic'); $data['name'] = Request::param('name');
$data['level'] = $where['level'] = count(explode('-',$data['code'])); $data['pic'] = Request::param('pic');
if($layout_id) { $data['level'] = $where['level'] = count(explode('-',$data['code']));
//当前布局下没有房屋,可以修改 if($layout_id) {
$where['layout_id'] = $layout_id; //当前布局下没有房屋,可以修改
$is_exit = Db::name('layout_build')->where($where)->find(); $where['layout_id'] = $layout_id;
$is_exit = Db::name('layout_build')->where($where)->find();
if($is_exit) {
return $this->returnJson([],'已有该布局排布,添加失败',400); if($is_exit) {
} return $this->returnJson([],'已有该布局排布,添加失败',400);
}
//检查是否有类似的布局
unset($where['layout_id']); //检查是否有类似的布局
$is_exit = Db::name('layout_list')->where($where)->find(); unset($where['layout_id']);
$is_exit = Db::name('layout_list')->where($where)->find();
if($is_exit){
return $this->returnJson([],'已有该布局排布,添加失败',400); if($is_exit){
} return $this->returnJson([],'已有该布局排布,添加失败',400);
unset($where['level']); }
$change = Db::name('layout_list')->where($where)->save($data); unset($where['level']);
if($change) { $change = Db::name('layout_list')->where($where)->save($data);
return $this->returnJson([],'success'); if($change) {
} else { return $this->returnJson([],'success');
return $this->returnJson([],'error',400); } else {
} return $this->returnJson([],'error',400);
} else { }
} else {
//检查是否有类似的布局
$is_exit = Db::name('layout_list')->where($where)->find(); //检查是否有类似的布局
if($is_exit){ $is_exit = Db::name('layout_list')->where($where)->find();
return $this->returnJson([],'已有该布局排布,添加失败',400); if($is_exit){
} return $this->returnJson([],'已有该布局排布,添加失败',400);
$add = Db::name('layout_list')->insert($data); }
if($add) { $add = Db::name('layout_list')->insert($data);
return $this->returnJson([],'success'); if($add) {
} else { return $this->returnJson([],'success');
return $this->returnJson([],'error',400); } else {
} return $this->returnJson([],'error',400);
}
}
} }
}
//删除社区排布编号
public function deleteArrangement() { //删除社区排布编号
$layout_id =Request::param('layout_id'); public function deleteArrangement() {
$where['layout_id'] = $layout_id; $layout_id =Request::param('layout_id');
$is_exit = Db::name('layout_build')->where($where)->find(); $where['layout_id'] = $layout_id;
if($is_exit){ $is_exit = Db::name('layout_build')->where($where)->find();
return $this->returnJson([],'以用该布局创建了建筑,请先删除建筑,在删除',400); if($is_exit){
} return $this->returnJson([],'以用该布局创建了建筑,请先删除建筑,在删除',400);
$delete = Db::name('layout_list')->where($where)->delete(); }
if($delete) { $delete = Db::name('layout_list')->where($where)->delete();
return $this->returnJson([],'success',200); if($delete) {
} else { return $this->returnJson([],'success',200);
return $this->returnJson([],'error'); } else {
} return $this->returnJson([],'error');
} }
}
//查看社区的基本信息
public function villageInfo() {
$where['village_id'] = $this->village_id;
$data =DB::name('house_village')->where($where)
->field('village_id,property_price,water_price,electric_price,gas_price,park_price,village_Logo,village_name,village_address,province_id,province_name,city_id,city_name,area_id,area_name')->find();
return $this->returnJson($data,'success');
}
//修改小区的基本信息
public function changeVillageInfo(){
$property_price = Request::param('property_price');
$water_price = Request::param('water_price');
$electric_price = Request::param('electric_price');
$gas_price = Request::param('gas_price');
$park_price = Request::param('park_price');
if(!isset($park_price) || !isset($gas_price) || !isset($electric_price) || !isset($water_price) || !isset($property_price)){
return $this->returnJson([],'费用必传递!',400);
}
$where['village_id'] = $this->village_id;
//查看小区的水电物业费等
$info = Db::name('house_village')->where($where)->field('property_price,water_price,electric_price,gas_price,park_price,village_logo')->find();
//修改了小区的费用
if($info['property_price'] != $property_price || $info['water_price'] != $water_price || $info['electric_price'] != $electric_price || $info['gas_price'] != $gas_price ||$info['park_price'] != $park_price ) {
$save['property_price'] = $property_price;
$save['water_price'] = $water_price;
$save['electric_price'] = $electric_price;
$save['gas_price'] = $gas_price;
$save['park_price'] = $park_price;
Db::startTrans();
try{
Db::name('layout_build')->where($where)->save($save);
DB::name('house_village')->where($where)->save($save);
Db::commit();
return $this->returnJson();
}catch(\Exception $e){
Db::rollback();
return $this->returnJson([],'修改失败',400);
}
}
$data['village_name'] = Request::param('village_name');
$data['village_address'] = Request::param('village_address');
$data['province_id'] = Request::param('province_id');
$data['province_name'] = Request::param('province_name');
$data['city_id'] = Request::param('city_id');
$data['city_name'] = Request::param('city_name');
$data['area_id'] = Request::param('area_id');
$data['area_name'] = Request::param('area_name');
$data['village_logo'] = Request::param('logo');
$change = DB::name('house_village')->where($where)->save($data);
if(!$change) {
return $this->returnJson([], '修改失败', 400);
}
return $this->returnJson();
}
//banner图添或修改
public function addBanner() {
$banner_id =Request::param('banner_id');
$data['pic'] =Request::param('pic');
$data['url'] =Request::param('url');
$data['sort_id'] =Request::param('sort_id',1);
if($banner_id){
$where['banner_id'] = $banner_id;
$where['village_id'] = $this->village_id;
$operation = Db::name('village_banner')->where($where)->save($data);
} else {
$data['village_id'] = $this->village_id;
$data['create_time'] = time();
$operation = Db::name('village_banner')->insert($data);
}
if($operation) {
return $this->returnJson();
} else {
return $this->returnJson([],'操作失败!',400);
}
}
//删除banner
public function deleteBanner() {
$banner_id =Request::param('banner_id');
$where['banner_id'] = $banner_id;
$where['village_id'] = $this->village_id;
$delete = Db::name('village_banner')->where($where)->delete();
if($delete) {
return $this->returnJson();
} else {
return $this->returnJson([],'删除失败!',400);
}
}
//banner列表
public function bannerList(){
$where['village_id'] = $this->village_id;
$data =Db::name('village_banner')->where($where)->order(['sort_id'=>'desc','create_time'=>'desc'])->select()->toArray();
return $this->returnJson(Common::changeField($data));
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment