Commit f30d1b87 authored by 蔡闯's avatar 蔡闯

物业服务时间修改

parent 89bc9a1f
...@@ -157,9 +157,6 @@ class Index extends Base ...@@ -157,9 +157,6 @@ class Index extends Base
$cars = Db::name('car')->where(['uid'=>$this->uid,'village_id'=>$v['village_id']])->field('car_id,license_plate,brand')->select()->toArray(); $cars = Db::name('car')->where(['uid'=>$this->uid,'village_id'=>$v['village_id']])->field('car_id,license_plate,brand')->select()->toArray();
$data[$k]['cars'] = $cars; $data[$k]['cars'] = $cars;
$car_total = count($cars); $car_total = count($cars);
if($car_total ==1) {
$data[$k]['cars'] = $cars[0];
}
$data[$k]['car_total'] = $car_total; $data[$k]['car_total'] = $car_total;
$data[$k]['type_zh'] = $userType[$v['type']]; $data[$k]['type_zh'] = $userType[$v['type']];
} }
...@@ -174,33 +171,32 @@ class Index extends Base ...@@ -174,33 +171,32 @@ class Index extends Base
return $this->returnJson($data); return $this->returnJson($data);
} }
//修改车辆 // //修改车辆
public function changeCar() { // public function changeCar() {
$car_id = Request::param('car_id'); // $car_id = Request::param('car_id');
$data['license_plate'] = Request::param('license_plate'); // $data['license_plate'] = Request::param('license_plate');
$is_exit = Db::name('car')->where('uid','<>',$this->uid)->where($data)->find(); // $is_exit = Db::name('car')->where('uid','<>',$this->uid)->where($data)->find();
if($is_exit){ // if($is_exit){
return $this->returnJson([],'该车牌号已存在!',400); // return $this->returnJson([],'该车牌号已存在!',400);
} // }
$data['name'] = Request::param('name'); // $data['name'] = Request::param('name');
$data['car_color'] = Request::param('car_color'); // $data['car_color'] = Request::param('car_color');
$data['village_id'] = Request::param('village_id'); // $data['village_id'] = Request::param('village_id');
$data['brand'] = Request::param('brand'); // $data['brand'] = Request::param('brand');
$data['car_type'] = Request::param('car_type'); // $data['car_type'] = Request::param('car_type');
$data['car_color'] = Request::param('car_color'); //
// $change = Db::name('car')->where(['car_id'=>$car_id])->save($data);
$change = Db::name('car')->where(['car_id'=>$car_id])->save($data); //
// if($change) {
if($change) { // return $this->returnJson([],'操作成功!');
return $this->returnJson([],'操作成功!'); // } else {
} else { // return $this->returnJson([],'操作失败!',400);
return $this->returnJson([],'操作失败!',400); // }
} //
// }
}
//用户添加车辆 //用户添加车辆
public function addCar() { public function changeCar() {
$uid = $this->uid; $uid = $this->uid;
$car_id = Request::param('car_id'); $car_id = Request::param('car_id');
$data['phone'] = Db::name('user')->where(['uid'=>$uid])->value('phone'); $data['phone'] = Db::name('user')->where(['uid'=>$uid])->value('phone');
...@@ -209,11 +205,11 @@ class Index extends Base ...@@ -209,11 +205,11 @@ class Index extends Base
$data['car_color'] = Request::param('car_color'); $data['car_color'] = Request::param('car_color');
$data['license_plate'] = Request::param('license_plate'); $data['license_plate'] = Request::param('license_plate');
$data['sort_id'] = Request::param('sort_id',1); $data['sort_id'] = Request::param('sort_id',1);
$data['car_type'] = Request::param('car_type');
$data['uid'] = $uid; $data['uid'] = $uid;
$data['village_id'] = Request::param('village_id'); $data['village_id'] = Request::param('village_id');
$data['car_color'] = Request::param('car_color');
if($car_id) { if($car_id) {
//判断车牌是否存在 //判断车牌是否存在changeCar
$is_exit = Db::name('car')->where(['license_plate'=>$data['license_plate']])->where('car_id','<>',$car_id)->find(); $is_exit = Db::name('car')->where(['license_plate'=>$data['license_plate']])->where('car_id','<>',$car_id)->find();
if($is_exit) { if($is_exit) {
return $this->returnJson([],'系统中已存在该车牌!',400); return $this->returnJson([],'系统中已存在该车牌!',400);
...@@ -228,10 +224,11 @@ class Index extends Base ...@@ -228,10 +224,11 @@ class Index extends Base
} }
$operation = Db::name('car')->save($data); $operation = Db::name('car')->save($data);
} }
if($operation) {
if($operation !== false) {
return $this->returnJson([],'success'); return $this->returnJson([],'success');
} else { } else {
return $this->returnJson([],'操作失败!',400); return $this->returnJson([],'修改失败!',400);
} }
} }
...@@ -239,7 +236,7 @@ class Index extends Base ...@@ -239,7 +236,7 @@ class Index extends Base
public function deleteCar() { public function deleteCar() {
$car_id = Request::param('car_id'); $car_id = Request::param('car_id');
$delete = Db::name('car')->where(['car_id'=>$car_id,'uid'=>$this->uid])->delete(); $delete = Db::name('car')->where(['car_id'=>$car_id,'uid'=>$this->uid])->delete();
if($delete) { if($delete !== false) {
return $this->returnJson(); return $this->returnJson();
} else { } else {
return $this->returnJson([],'删除失败!',400); return $this->returnJson([],'删除失败!',400);
...@@ -319,7 +316,7 @@ class Index extends Base ...@@ -319,7 +316,7 @@ class Index extends Base
$save['status'] = $status; $save['status'] = $status;
$save['pass_time'] = time(); $save['pass_time'] = time();
$change = Db::name('house_user_bind')->where(['house_user_bind_id'=>$bind_id])->save($save); $change = Db::name('house_user_bind')->where(['house_user_bind_id'=>$bind_id])->save($save);
if($change) { if($change !== false) {
return $this->returnJson(); return $this->returnJson();
} else { } else {
return $this->returnJson([],'操作失败!',400); return $this->returnJson([],'操作失败!',400);
......
...@@ -48,17 +48,23 @@ class Payreturn extends BaseController ...@@ -48,17 +48,23 @@ class Payreturn extends BaseController
} }
} }
//根据获取到的订单id,更改状态 //根据获取到的订单id,更改状态,更改房间的物业服务时间
private function changePayStatus($out_trade_no) { private function changePayStatus($out_trade_no) {
$where['order_num'] = $out_trade_no; $where['order_num'] = $out_trade_no;
$save['pay_time'] = time(); $save['pay_time'] = time();
$save['is_pay'] = 1; $save['is_pay'] = 1;
$cost_ids = DB::name('pay_order')->where(['order_num'=>$out_trade_no])->value('cost_ids'); $cost_ids = DB::name('pay_order')->where(['order_num'=>$out_trade_no])->value('cost_ids');
$cost_ids_arr = json_decode($cost_ids); $cost_ids_arr = json_decode($cost_ids);
$costInfo = Db::name('cost')->where('cost_id','in',$cost_ids_arr)->where(['type'=>'property'])->order('cost_month','desc')->field('cost_month,vacancy_id')->find();
Db::startTrans(); Db::startTrans();
try{ try{
if($costInfo) {
$property_end_time = $costInfo['cost_month'];
DB::name('house_vacancy')->where(['vacancy_id'=>$costInfo['vacancy_id']])->save(['property_end_time'=>$property_end_time]);
}
Db::name('pay_order')->where($where)->save($save); Db::name('pay_order')->where($where)->save($save);
Db::name('cost')->where('cost_id','in',$cost_ids_arr)->save($save); Db::name('cost')->where('cost_id','in',$cost_ids_arr)->save($save);
Db::commit(); Db::commit();
return true; return true;
}catch(\Exception $e){ }catch(\Exception $e){
......
<?php <?php
namespace app\shequ\controller; namespace app\shequ\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 Vacancy extends Base class Vacancy extends Base
{ {
protected $middleware = ['app\middleware\CommunityLoginCheck::class','app\middleware\CommunityAfter::class']; protected $middleware = ['app\middleware\CommunityLoginCheck::class','app\middleware\CommunityAfter::class'];
//房间列表 //房间列表
public function vacancyList() { public function vacancyList() {
$page = Request::param('page',1); $page = Request::param('page',1);
$where[] = ['hv.village_id','=',$this->village_id]; $where[] = ['hv.village_id','=',$this->village_id];
if(Request::param('phone')) { if(Request::param('phone')) {
$where[] = ['hv.phone','=',Request::param('phone')]; $where[] = ['hv.phone','=',Request::param('phone')];
} }
if(Request::param('name')) { if(Request::param('name')) {
$where[] = ['hv.name','=',Request::param('name')]; $where[] = ['hv.name','=',Request::param('name')];
} }
if(Request::param('vacancy_code')) { if(Request::param('vacancy_code')) {
$vacancy_code = Request::param('vacancy_code'); $vacancy_code = Request::param('vacancy_code');
$where[] = ['hv.vacancy_code','like',$vacancy_code."%"]; $where[] = ['hv.vacancy_code','like',$vacancy_code."%"];
} }
$total = Db::name('house_vacancy')->alias('hv') $total = Db::name('house_vacancy')->alias('hv')
->where($where) ->where($where)
->count(); ->count();
$data = Db::name('house_vacancy')->alias('hv')->field('hv.layout_id,hv.vacancy_code,hv.vacancy_id,hv.vacancy_code,hv.name,hv.phone,hv.create_time,hv.village_name,hv.village_id,hv.area,hv.id_card') $data = Db::name('house_vacancy')->alias('hv')->field('hv.layout_id,hv.vacancy_code,hv.vacancy_id,hv.vacancy_code,hv.name,hv.phone,hv.create_time,hv.village_name,hv.village_id,hv.area,hv.id_card')
->where($where) ->where($where)
->order('create_time','desc') ->order('create_time','desc')
->page($page,config('app.limit')) ->page($page,config('app.limit'))
->select()->toArray(); ->select()->toArray();
foreach ($data as $k =>$v) { foreach ($data as $k =>$v) {
$res = $this->getVacancyAddress($v['vacancy_code'],$v['layout_id']); $res = $this->getVacancyAddress($v['vacancy_code'],$v['layout_id']);
$data[$k]['vacancy_address'] = $res['vacancy_address']; $data[$k]['vacancy_address'] = $res['vacancy_address'];
$data[$k]['room_num'] = $res['room_num']; $data[$k]['room_num'] = $res['room_num'];
} }
$res['total'] = $total; $res['total'] = $total;
$res['data'] = Common::changeField($data); $res['data'] = Common::changeField($data);
return $this->returnJson($res,'success'); return $this->returnJson($res,'success');
} }
//房间详情 //房间详情
public function detailVacancy() { public function detailVacancy() {
$vacancy_id = Request::param('vacancy_id'); $vacancy_id = Request::param('vacancy_id');
$where['hv.vacancy_id'] = $vacancy_id; $where['hv.vacancy_id'] = $vacancy_id;
$where['hv.village_id'] = $this->village_id; $where['hv.village_id'] = $this->village_id;
$data = Db::name('house_vacancy')->alias('hv')->where($where)->find(); $data = Db::name('house_vacancy')->alias('hv')->where($where)->find();
$res = $this->getVacancyAddress($data['vacancy_code'],$data['layout_id']); $res = $this->getVacancyAddress($data['vacancy_code'],$data['layout_id']);
$data['vacancy_address'] = $res['vacancy_address'];; $data['vacancy_address'] = $res['vacancy_address'];;
unset($data['village_name']);//用连表查询的社区名称 unset($data['village_name']);//用连表查询的社区名称
if($data['is_inherit'] ==1 ) { if($data['is_inherit'] ==1 ) {
$p_info = Db::name('layout_build')->where(['layout_build_id'=>$data['parent_id']]) $p_info = Db::name('layout_build')->where(['layout_build_id'=>$data['parent_id']])
->field('property_price,water_price,electric_price,gas_price,parking_price')->find(); ->field('property_price,water_price,electric_price,gas_price,parking_price')->find();
$data['property_fee'] = $p_info['property_price']; $data['property_fee'] = $p_info['property_price'];
$data['water_fee'] = $p_info['water_price']; $data['water_fee'] = $p_info['water_price'];
$data['electric_fee'] = $p_info['electric_price']; $data['electric_fee'] = $p_info['electric_price'];
$data['gas_fee'] = $p_info['gas_price']; $data['gas_fee'] = $p_info['gas_price'];
$data['parking_fee'] = $p_info['parking_price']; $data['parking_fee'] = $p_info['parking_price'];
} }
return $this->returnJson(Common::changeField($data),'success'); return $this->returnJson(Common::changeField($data),'success');
} }
//添加| 修改 房间 //添加| 修改 房间
public function createVacancy() { public function createVacancy() {
$vacancy_id = Request::param('vacancy_id'); $vacancy_id = Request::param('vacancy_id');
$data['layout_id'] = Request::param('layout_id'); $data['layout_id'] = Request::param('layout_id');
$data['village_id'] = $add['village_id']= $this->village_id; $data['village_id'] = $add['village_id']= $this->village_id;
$vacancy_code = Request::param('vacancy_code'); $vacancy_code = Request::param('vacancy_code');
if($vacancy_id) { if($vacancy_id) {
$res = $this->checkVacancyCode($vacancy_code,$vacancy_id,$data['layout_id'] ); $res = $this->checkVacancyCode($vacancy_code,$vacancy_id,$data['layout_id'] );
} else { } else {
$res = $this->checkVacancyCode($vacancy_code,0,$data['layout_id'] ); $res = $this->checkVacancyCode($vacancy_code,0,$data['layout_id'] );
} }
if($res['code'] !=200) { if($res['code'] !=200) {
return $this->returnJson([],$res['msg'],400); return $this->returnJson([],$res['msg'],400);
} }
$data['vacancy_code'] = $vacancy_code ; $data['vacancy_code'] = $vacancy_code ;
$data['name'] = $add['name'] = Request::param('name'); //业主姓名 $data['name'] = $add['name'] = Request::param('name'); //业主姓名
$data['id_card'] = $add['id_card'] = Request::param('id_card'); //身份证id / $data['id_card'] = $add['id_card'] = Request::param('id_card'); //身份证id /
$phone = Request::param('phone'); //业主手机号 $phone = Request::param('phone'); //业主手机号
if(!isPhoneNo($phone)) { if(!isPhoneNo($phone)) {
return $this->returnJson([],'手机号不合法!',400); return $this->returnJson([],'手机号不合法!',400);
} }
$data['phone'] = $add['phone']= $phone; $data['phone'] = $add['phone']= $phone;
$data['property_start_time'] = date('Y-m',strtotime(Request::param('property_start_time'))); $data['property_start_time'] = date('Y-m',strtotime(Request::param('property_start_time')));
$data['property_end_time'] = date('Y-m',strtotime(Request::param('property_end_time'))); $data['property_end_time'] = date('Y-m',strtotime(Request::param('property_end_time')));
$data['village_name'] = Db::name('house_village')->where(['village_id'=>$data['village_id']])->value('village_name'); if($data['property_start_time'] && $data['property_end_time']) {
$data['area'] = Request::param('area'); //判断物业服务开始时间和结束时间是否合理
$data['status'] = Request::param('status',1); $res = $this->checkVacancyPropertyTime($data['property_start_time'],$data['property_end_time']);
$data['memo'] = Request::param('memo'); if($res['code'] !=200) {
$data['park_flag'] = Request::param('park_flag',1); //是否有车位 return $this->returnJson([],$res['msg'],400);
$data['house_type'] = Request::param('house_type',1); //类型 1住宅 2商铺 3办公 }
$data['is_inherit'] = Request::param('is_inherit',1); }
$data['property_fee'] = Request::param('property_fee'); $data['village_name'] = Db::name('house_village')->where(['village_id'=>$data['village_id']])->value('village_name');
$data['water_fee'] = Request::param('water_fee'); $data['area'] = Request::param('area');
$data['electric_fee'] = Request::param('electric_fee'); $data['status'] = Request::param('status',1);
$data['gas_fee'] = Request::param('gas_fee'); $data['memo'] = Request::param('memo');
$data['parking_fee'] = Request::param('parking_fee'); $data['park_flag'] = Request::param('park_flag',1); //是否有车位
$data['parent_id'] = Request::param('parent_id'); $data['house_type'] = Request::param('house_type',1); //类型 1住宅 2商铺 3办公
$data['is_inherit'] = Request::param('is_inherit',1);
$add['type'] = $add['status'] = 1; $data['property_fee'] = Request::param('property_fee');
$data['water_fee'] = Request::param('water_fee');
$park_code = Request::param('park_code'); $data['electric_fee'] = Request::param('electric_fee');
$data['gas_fee'] = Request::param('gas_fee');
if($park_code) { $data['parking_fee'] = Request::param('parking_fee');
//判断是否有该编号的车位 $data['parent_id'] = Request::param('parent_id');
$is_exit = Db::name('park_car')->where(['village_id'=>$this->village_id,'park_code'=>$park_code])->field('park_car_id,status')->find();
if(!$is_exit) { $add['type'] = $add['status'] = 1;
return $this->returnJson([],'暂未查询到该编号的车位!',400);
} $park_code = Request::param('park_code');
if($is_exit['status'] == 1) {
return $this->returnJson([],'该车位已占用,请先解绑对应的车位!',400); if($park_code) {
} //判断是否有该编号的车位
$data['park_car_id'] = $is_exit['park_car_id']; $is_exit = Db::name('park_car')->where(['village_id'=>$this->village_id,'park_code'=>$park_code])->field('park_car_id,status')->find();
} if(!$is_exit) {
if($vacancy_id) { //修改 return $this->returnJson([],'暂未查询到该编号的车位!',400);
$operation = Db::name('house_vacancy')->where(['vacancy_id'=>$vacancy_id])->update($data); }
$change = Db::name('house_user_bind')->where(['vacancy_id'=>$vacancy_id])->save($add); if($is_exit['status'] == 1) {
if($operation || $change) { return $this->returnJson([],'该车位已占用,请先解绑对应的车位!',400);
return $this->returnJson([],'success'); }
} else { $data['park_car_id'] = $is_exit['park_car_id'];
return $this->returnJson([],'error',400); }
} if($vacancy_id) { //修改
} else { $operation = Db::name('house_vacancy')->where(['vacancy_id'=>$vacancy_id])->update($data);
$data['create_time'] = $add['pass_time']=$add['create_time'] = time(); $change = Db::name('house_user_bind')->where(['vacancy_id'=>$vacancy_id])->save($add);
Db::startTrans(); if($operation || $change) {
try{ return $this->returnJson([],'success');
$operation = Db::name('house_vacancy')->insertGetId($data); } else {
$add['vacancy_id'] = $operation; return $this->returnJson([],'error',400);
$change = Db::name('house_user_bind')->save($add); }
Db::commit(); } else {
return $this->returnJson([],'success'); $data['create_time'] = $add['pass_time']=$add['create_time'] = time();
}catch(\Exception $e){ Db::startTrans();
Db::rollback(); try{
return $this->returnJson([],'error',400); $operation = Db::name('house_vacancy')->insertGetId($data);
} $add['vacancy_id'] = $operation;
$change = Db::name('house_user_bind')->save($add);
} Db::commit();
} return $this->returnJson([],'success');
}catch(\Exception $e){
//查看房间的绑定的人员 Db::rollback();
public function vacancyBindUser() { return $this->returnJson([],'error',400);
$vacancy_id = Request::param('vacancy_id'); }
$data = Db::name('house_user_bind')->where(['vacancy_id'=>$vacancy_id])->field('house_user_bind_id,name,phone,type,pass_time,unbind_time,status')
->order('pass_time','desc') }
->select()->toArray(); }
return $this->returnJson(Common::changeField($data,['pass_time','unbind_time']),'success');
} //查看房间的绑定的人员
public function vacancyBindUser() {
//删除房间 $vacancy_id = Request::param('vacancy_id');
public function deleteVacancy() { $data = Db::name('house_user_bind')->where(['vacancy_id'=>$vacancy_id])->field('house_user_bind_id,name,phone,type,pass_time,unbind_time,status')
$vacancy_id = Request::param('vacancy_id'); ->order('pass_time','desc')
$where[] = $where_one[] = ['status','in',[0,1,2]]; ->select()->toArray();
$where[] = $where_two[] = ['vacancy_id','=',$vacancy_id]; return $this->returnJson(Common::changeField($data,['pass_time','unbind_time']),'success');
//查询房间是否绑定了用户,如果存在,则不删除 }
$is_exit = DB::name('house_user_bind')->where($where)->find();
if($is_exit) { //删除房间
return $this->returnJson([],'该房间下有用户记录,请先解绑!',400); public function deleteVacancy() {
} $vacancy_id = Request::param('vacancy_id');
$del1 = Db::name('house_user_bind')->where($where_one)->delete(); $where[] = $where_one[] = ['status','in',[0,1,2]];
$where[] = $where_two[] = ['vacancy_id','=',$vacancy_id];
$del = Db::name('house_vacancy')->where($where_two)->delete(); //查询房间是否绑定了用户,如果存在,则不删除
if($del || $del1) { $is_exit = DB::name('house_user_bind')->where($where)->find();
return $this->returnJson([],'success'); if($is_exit) {
} else { return $this->returnJson([],'该房间下有用户记录,请先解绑!',400);
return $this->returnJson([],'error',400); }
} $del1 = Db::name('house_user_bind')->where($where_one)->delete();
}
$del = Db::name('house_vacancy')->where($where_two)->delete();
//检查房间编号是否合法 if($del || $del1) {
public function checkVacancyCode($vacancy_code,$vacancy_id=0,$layout_id) { return $this->returnJson([],'success');
if($vacancy_id == 0){ } else {
$vacancyInfo = Db::name('house_vacancy')->where(['village_id'=>$this->village_id,'vacancy_code'=>$vacancy_code,'layout_id'=>$layout_id])->field('vacancy_id')->find(); return $this->returnJson([],'error',400);
} else{ }
$vacancyInfo = Db::name('house_vacancy')->where(['village_id'=>$this->village_id,'vacancy_code'=>$vacancy_code,'layout_id'=>$layout_id])->where('vacancy_id','<>',$vacancy_id)->field('vacancy_id,vacancy_code')->find(); }
}
if($vacancyInfo) { //检查房间编号是否合法
return ['code'=>400,'msg'=>'物业编号已存在!']; public function checkVacancyCode($vacancy_code,$vacancy_id=0,$layout_id) {
} if($vacancy_id == 0){
$array = explode ('-',$vacancy_code); $vacancyInfo = Db::name('house_vacancy')->where(['village_id'=>$this->village_id,'vacancy_code'=>$vacancy_code,'layout_id'=>$layout_id])->field('vacancy_id')->find();
} else{
//查看布局是否黑 $vacancyInfo = Db::name('house_vacancy')->where(['village_id'=>$this->village_id,'vacancy_code'=>$vacancy_code,'layout_id'=>$layout_id])->where('vacancy_id','<>',$vacancy_id)->field('vacancy_id,vacancy_code')->find();
$layoutCode = Db::name('layout_list')->where(['layout_id'=>$layout_id])->value('code'); }
if(count($array) != count(explode('-',$layoutCode))){ if($vacancyInfo) {
return ['code'=>400,'msg'=>'房间位置不合法!']; return ['code'=>400,'msg'=>'物业编号已存在!'];
} }
//去掉最后一个房间编号的 $array = explode ('-',$vacancy_code);
array_pop($array);
$count = Db::name('layout_build')->where('layout_build_id','in',$array)->count(); //查看布局是否黑
if($count != count($array)) { $layoutCode = Db::name('layout_list')->where(['layout_id'=>$layout_id])->value('code');
return ['code'=>400,'msg'=>'房间位置不合法!']; if(count($array) != count(explode('-',$layoutCode))){
} else { return ['code'=>400,'msg'=>'房间位置不合法!'];
return ['code'=>200,'msg'=>'success!']; }
} //去掉最后一个房间编号的
array_pop($array);
$count = Db::name('layout_build')->where('layout_build_id','in',$array)->count();
} if($count != count($array)) {
return ['code'=>400,'msg'=>'房间位置不合法!'];
//通过房间编号获取房间地址 } else {
public function getVacancyAddress($vacancyCode,$layout_id=0) { return ['code'=>200,'msg'=>'success!'];
if($layout_id == 0) { }
$layout_id = Db::name('house_vacancy')->where(['village_id'=>$this->village_id,'vacancy_code'=>$vacancyCode])->value('layout_id');
} }
$layoutCode = Db::name('layout_list')->where(['layout_id'=>$layout_id,'village_id'=>$this->village_id])->value('code');
$codeArr = explode('-',$layoutCode); //判断输入的物业开始时间和结束时间是否合理
$rom = array_pop($codeArr); //获取最后一个房间的单位 public function checkVacancyPropertyTime($stat_time,$end_time){
$arr = explode('-',$vacancyCode); if($stat_time ==$end_time) {
$room_code = array_pop($arr); return ['code'=>400,'msg'=>"开始时间和结束时间不能相同!"];
$string = ''; }
$room_num = ''; $new_time = date('Y-m',time());
foreach ($arr as $v) { if($stat_time == $new_time) {
$code_name = Db::name('layout_build')->where(['layout_build_id'=>$v])->field('code,level')->find(); return ['code'=>400,'msg'=>"开始时间不能早于当前月份!"];
$key = $code_name['level'] -1; }
$string.=$code_name['code'].$codeArr[$key];
$room_num.=$code_name['code']."-"; if($stat_time > $end_time || $stat_time =$end_time) {
} return ['code'=>400,'msg'=>"开始时间不能大于结束时间!"];
$room_num = $room_num.$room_code; }
return ['vacancy_address'=>$string.$room_code.$rom,'room_num'=>$room_num];
} $new_year = explode('-',$new_time)[0];
$end_year = explode('-',$end_time)[0];
//通过物业编号拼接房间编号 $time_diff = $new_year - $end_year;
public function getVacancyRoomNum($vacancy_code){ if($time_diff > 3) {
$vacancy_codeArr = explode('-',$vacancy_code); return ['code'=>400,'msg'=>"结束时间不能设置不能超过2年!"];
array_pop($vacancy_codeArr); }
$room_num = '';
foreach ($vacancy_codeArr as $v){
$num = Db::name('layout_build')->where(['layout_build_id'=>$v])->value('code'); }
$room_num.=$num."-";
} //通过房间编号获取房间地址
return trim($room_num,'-'); public function getVacancyAddress($vacancyCode,$layout_id=0) {
if($layout_id == 0) {
} $layout_id = Db::name('house_vacancy')->where(['village_id'=>$this->village_id,'vacancy_code'=>$vacancyCode])->value('layout_id');
}
//房间批量导入 $layoutCode = Db::name('layout_list')->where(['layout_id'=>$layout_id,'village_id'=>$this->village_id])->value('code');
public function importVacancy() { $codeArr = explode('-',$layoutCode);
$rom = array_pop($codeArr); //获取最后一个房间的单位
$filePath = Request::param('filePath'); $arr = explode('-',$vacancyCode);
if(!file_exists($filePath)){ $room_code = array_pop($arr);
return $this->returnJson([],'文件不存在!',400); $string = '';
} $room_num = '';
$village_id = $this->village_id ?? 1; foreach ($arr as $v) {
$res = Common::importVacancy($filePath,$village_id); $code_name = Db::name('layout_build')->where(['layout_build_id'=>$v])->field('code,level')->find();
if($res['code']==200) { $key = $code_name['level'] -1;
return $this->returnJson([],'success'); $string.=$code_name['code'].$codeArr[$key];
} elseif($res['code'] ==400) { $room_num.=$code_name['code']."-";
return $this->returnJson([],$res['msg'],400); }
} $room_num = $room_num.$room_code;
} return ['vacancy_address'=>$string.$room_code.$rom,'room_num'=>$room_num];
}
//excel文件上传
public function uploadFile() { //通过物业编号拼接房间编号
$file = request()->file('xls'); public function getVacancyRoomNum($vacancy_code){
$ext = $file->getOriginalExtension(); $vacancy_codeArr = explode('-',$vacancy_code);
if($ext != 'xls') { array_pop($vacancy_codeArr);
return $this->returnJson([],'请上传xls文件',400); $room_num = '';
} foreach ($vacancy_codeArr as $v){
$savename = \think\facade\Filesystem::putFile('', $file,'datea'); $num = Db::name('layout_build')->where(['layout_build_id'=>$v])->value('code');
$data['filePath'] = "./upload/".$savename; $room_num.=$num."-";
return $this->returnJson($data,'success'); }
return trim($room_num,'-');
}
}
//房间批量下载模板下载
public function downloadImportVacancy() { //房间批量导入
$file = "./formwork/importVacancy.xls"; public function importVacancy() {
$phpExcel = \PHPExcel_IOFactory::load($file);
$village_id = $this->village_id ?? 1; $filePath = Request::param('filePath');
$optionsArr = Db::name('layout_list')->where(['village_id'=>$village_id])->column('code'); if(!file_exists($filePath)){
$optionsString = implode(',',$optionsArr);//这个是选择布局 return $this->returnJson([],'文件不存在!',400);
$car_blockArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('name'); }
$optionsCarBlockString = implode(',',$car_blockArr);//这个是车库布局 $village_id = $this->village_id ?? 1;
for($i=2;$i<3;$i++) { $res = Common::importVacancy($filePath,$village_id);
$phpExcel->getActiveSheet()->getCell('H'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST) if($res['code']==200) {
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION) return $this->returnJson([],'success');
-> setAllowBlank(false) } elseif($res['code'] ==400) {
-> setShowInputMessage(true) return $this->returnJson([],$res['msg'],400);
-> setShowErrorMessage(true) }
-> setShowDropDown(true) }
-> setErrorTitle('输入的值有误')
-> setError('您输入的值不在下拉框列表内.') //excel文件上传
-> setPromptTitle('社区布局') public function uploadFile() {
-> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格 $file = request()->file('xls');
if($optionsCarBlockString) { $ext = $file->getOriginalExtension();
$phpExcel->getActiveSheet()->getCell('F'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST) if($ext != 'xls') {
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION) return $this->returnJson([],'请上传xls文件',400);
-> setAllowBlank(false) }
-> setShowInputMessage(true) $savename = \think\facade\Filesystem::putFile('', $file,'datea');
-> setShowErrorMessage(true) $data['filePath'] = "./upload/".$savename;
-> setShowDropDown(true) return $this->returnJson($data,'success');
-> setErrorTitle('输入的值有误')
-> setError('您输入的值不在下拉框列表内.') }
-> setPromptTitle('车库位置')
-> setFormula1('"'.$optionsCarBlockString.'"');; //这一句为要设置数据有效性的单元格 //房间批量下载模板下载
} public function downloadImportVacancy() {
$phpExcel->getActiveSheet()->getCell('I'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST) $file = "./formwork/importVacancy.xls";
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION) $phpExcel = \PHPExcel_IOFactory::load($file);
-> setAllowBlank(false) $village_id = $this->village_id ?? 1;
-> setShowInputMessage(true) $optionsArr = Db::name('layout_list')->where(['village_id'=>$village_id])->column('code');
-> setShowErrorMessage(true) $optionsString = implode(',',$optionsArr);//这个是选择布局
-> setShowDropDown(true) $car_blockArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('name');
-> setErrorTitle('输入的值有误') $optionsCarBlockString = implode(',',$car_blockArr);//这个是车库布局
-> setError('您输入的值不在下拉框列表内.') for($i=2;$i<3;$i++) {
-> setPromptTitle('房屋类型') $phpExcel->getActiveSheet()->getCell('H'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
-> setFormula1('"住宅,商铺,办公"'); //这一句为要设置数据有效性的单元格 -> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
-> setAllowBlank(false)
-> setShowInputMessage(true)
} -> setShowErrorMessage(true)
$objWriter = new \PHPExcel_Writer_Excel5($phpExcel); -> setShowDropDown(true)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); -> setErrorTitle('输入的值有误')
header('Content-Disposition: attachment;filename="房间导入.xls"'); -> setError('您输入的值不在下拉框列表内.')
header('Cache-Control: max-age=0'); -> setPromptTitle('社区布局')
$objWriter->save("php://output"); -> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格
} if($optionsCarBlockString) {
$phpExcel->getActiveSheet()->getCell('F'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
//当前房间下的费用明细 -> setAllowBlank(false)
public function vacancyCost(){ -> setShowInputMessage(true)
$convertArr = $this->convertArr; -> setShowErrorMessage(true)
$cost_month = Request::param('month'); -> setShowDropDown(true)
$page = Request::param('page',1); -> setErrorTitle('输入的值有误')
$vacancy_id = Request::param('vacancy_id'); -> setError('您输入的值不在下拉框列表内.')
$isPay = Request::param('is_pay'); -> setPromptTitle('车库位置')
$type = Request::param('type'); -> setFormula1('"'.$optionsCarBlockString.'"');; //这一句为要设置数据有效性的单元格
$where['village_id'] = $this->village_id; }
$where['vacancy_id'] = $vacancy_id; $phpExcel->getActiveSheet()->getCell('I'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
if($cost_month){ -> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
$where['cost_month'] =$cost_month; -> setAllowBlank(false)
} -> setShowInputMessage(true)
if($isPay) { -> setShowErrorMessage(true)
$where['is_pay'] = $isPay; -> setShowDropDown(true)
} -> setErrorTitle('输入的值有误')
if($type && $type == "other") { -> setError('您输入的值不在下拉框列表内.')
$where['is_default'] = 0; //自定义收费的 -> setPromptTitle('房屋类型')
-> setFormula1('"住宅,商铺,办公"'); //这一句为要设置数据有效性的单元格
} elseif($type == "other") {
$where['is_default'] = 1;
} }
$data = Db::name('cost')->where($where)->order('cost_id','desc')->field('cost_id,price,type,total_money,cost_month,is_pay,area,pay_time,prefer_money,pay_money,explain,is_default')->page($page,config('app.limit'))->select()->toArray(); $objWriter = new \PHPExcel_Writer_Excel5($phpExcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
foreach ($data as $k => $v){ header('Content-Disposition: attachment;filename="房间导入.xls"');
$data[$k]['type'] = $convertArr[$v['type']]; header('Cache-Control: max-age=0');
} $objWriter->save("php://output");
$total = Db::name('cost')->where($where)->count(); }
$res['total'] = $total;
$res['data'] = Common::changeField($data,'pay_time');
return $this->returnJson($res); //当前房间下的费用明细
} public function vacancyCost(){
$convertArr = $this->convertArr;
//每月账单详情 $cost_month = Request::param('month');
public function detailCost() { $page = Request::param('page',1);
$where['cost_id'] = Request::param('cost_id'); $vacancy_id = Request::param('vacancy_id');
$where['village_id'] = $this->village_id; $isPay = Request::param('is_pay');
$data = Db::name('cost')->where($where)->find(); $type = Request::param('type');
switch ($data['type']){ $where['village_id'] = $this->village_id;
case "property": $where['vacancy_id'] = $vacancy_id;
$data['type'] ="物业费"; if($cost_month){
break; $where['cost_month'] =$cost_month;
case "water": }
$data['type'] ="水费"; if($isPay) {
break; $where['is_pay'] = $isPay;
case "gas": }
$data['type'] ="燃气费"; if($type && $type == "other") {
break; $where['is_default'] = 0; //自定义收费的
case "electric":
$data['type'] ="电费"; } elseif($type == "other") {
break; $where['is_default'] = 1;
case "park": }
$data['type'] ="停车费"; $data = Db::name('cost')->where($where)->order('cost_id','desc')->field('cost_id,price,type,total_money,cost_month,is_pay,area,pay_time,prefer_money,pay_money,explain,is_default')->page($page,config('app.limit'))->select()->toArray();
break;
} foreach ($data as $k => $v){
$data[$k]['type'] = $convertArr[$v['type']];
return $this->returnJson(Common::changeField($data,['create_time','pay_time'])); }
$total = Db::name('cost')->where($where)->count();
$res['total'] = $total;
} $res['data'] = Common::changeField($data,'pay_time');
return $this->returnJson($res);
}
//修改某个房间的费用明细
public function changeCost() { //每月账单详情
$where['cost_id'] = Request::param('cost_id'); public function detailCost() {
$where['village_id'] = $this->village_id; $where['cost_id'] = Request::param('cost_id');
$where['is_default'] = 1; $where['village_id'] = $this->village_id;
$data['price'] =Request::param('price'); $data = Db::name('cost')->where($where)->find();
$data['area'] =Request::param('area'); switch ($data['type']){
$data['total_money'] = $data['price'] * $data['area']; case "property":
$data['prefer_money'] = Request::param('prefer_money',0); $data['type'] ="物业费";
$data['explain'] = Request::param('explain'); break;
if($data['prefer_money'] !=0 && !isset($data['explain'])) { case "water":
return $this->returnJson([],'优惠说明必填!',400); $data['type'] ="水费";
} break;
$data['pay_money'] = $data['total_money']-$data['prefer_money']; case "gas":
$data['is_pay'] =Request::param('is_pay',0); $data['type'] ="燃气费";
$change = Db::name('cost')->where($where)->save($data); break;
if($change) { case "electric":
Db::name('cost_log')->insert(['cost_id'=>$where['cost_id'],'community_admin_id'=>$this->uid,'data'=>json_encode($data)]); $data['type'] ="电费";
return $this->returnJson(); break;
} else { case "park":
return $this->returnJson([],'修改失败',400); $data['type'] ="停车费";
} break;
} }
//添加|修改自定义收费 return $this->returnJson(Common::changeField($data,['create_time','pay_time']));
public function createCustomizeCost(){
$cost_id =Request::param('cost_id');
$type = Request::param("type"); }
if(empty($type)){
return $this->returnJson([],'收费类目必填!');
} //修改某个房间的费用明细
$data['type'] = $type; public function changeCost() {
$data['pay_money'] = $data['total_money'] = Request::param('pay_money'); $where['cost_id'] = Request::param('cost_id');
$data['explain'] = Request::param('explain'); $where['village_id'] = $this->village_id;
$data['is_pay'] = Request::param('is_pay',0); $where['is_default'] = 1;
if($cost_id) { $data['price'] =Request::param('price');
$where['cost_id'] = $cost_id; $data['area'] =Request::param('area');
$operation = Db::name('cost')->where($where)->save($data); $data['total_money'] = $data['price'] * $data['area'];
} else{ $data['prefer_money'] = Request::param('prefer_money',0);
$data['village_id'] = $this->village_id; $data['explain'] = Request::param('explain');
$data['vacancy_id'] = Request::param('vacancy_id'); if($data['prefer_money'] !=0 && !isset($data['explain'])) {
$data['create_time'] = time(); return $this->returnJson([],'优惠说明必填!',400);
$data['is_default'] = 0; }
$operation = Db::name('cost')->insert($data); $data['pay_money'] = $data['total_money']-$data['prefer_money'];
} $data['is_pay'] =Request::param('is_pay',0);
if($operation) { $change = Db::name('cost')->where($where)->save($data);
return $this->returnJson(); if($change) {
} else { Db::name('cost_log')->insert(['cost_id'=>$where['cost_id'],'community_admin_id'=>$this->uid,'data'=>json_encode($data)]);
return $this->returnJson([],'操作成功!',400); return $this->returnJson();
} } else {
} return $this->returnJson([],'修改失败',400);
}
}
//添加|修改自定义收费
public function createCustomizeCost(){
$cost_id =Request::param('cost_id');
$type = Request::param("type");
if(empty($type)){
return $this->returnJson([],'收费类目必填!');
}
$data['type'] = $type;
$data['pay_money'] = $data['total_money'] = Request::param('pay_money');
$data['explain'] = Request::param('explain');
$data['is_pay'] = Request::param('is_pay',0);
if($cost_id) {
$where['cost_id'] = $cost_id;
$operation = Db::name('cost')->where($where)->save($data);
} else{
$data['village_id'] = $this->village_id;
$data['vacancy_id'] = Request::param('vacancy_id');
$data['create_time'] = time();
$data['is_default'] = 0;
$operation = Db::name('cost')->insert($data);
}
if($operation) {
return $this->returnJson();
} else {
return $this->returnJson([],'操作成功!',400);
}
}
} }
\ 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