Commit 93209d00 authored by 蔡闯's avatar 蔡闯

版本1.0

parent 324c1da2
Pipeline #121 failed with stages
...@@ -91,12 +91,12 @@ abstract class BaseController ...@@ -91,12 +91,12 @@ abstract class BaseController
echo json_encode(['code'=>400,'msg'=>'身份证号码不符合!','data'=>[]]);exit; echo json_encode(['code'=>400,'msg'=>'身份证号码不符合!','data'=>[]]);exit;
} }
} }
$phone = \think\facade\Request::param('phone'); // $phone = \think\facade\Request::param('phone');
if($phone) { // if($phone) {
if(!isPhoneNo($phone)) { // if(!isPhoneNo($phone)) {
echo json_encode(['code'=>400,'msg'=>'手机号码不符合!','data'=>[]]);exit; // echo json_encode(['code'=>400,'msg'=>'手机号码不符合!','data'=>[]]);exit;
} // }
} // }
} }
......
<?php
namespace app\admin\controller;
use think\facade\Request;
use think\facade\Db;
class Account extends Base
{
protected $middleware = ['app\middleware\CheckValidata::class'];
//相关账号列表
public function accountList()
{
$page = Request::param('page',1);
$limit = Request::param('limit',config('app.limit'));
$where[] = ['type','=',1];
$account_name = Request::param('account_name');
if($account_name) {
$where[] = ['account_name','like','%'.$account_name.'%'];
}
$data = Db::name('account')->where($where)->order('create_time','desc')->page($page,$limit)->select()->toArray();
$res['total'] = Db::name('account')->where($where)->count();
$res['data'] = changeField($data);
foreach ($data as $k =>$v) {
if($v['content']) {
$data[$k]['content'] = json_decode($v['content'],true);
}
}
return $this->returnJson($res);
}
//添加|修改相关账号信息
public function addAccount()
{
$account_id = Request::param('account_id');
$data['phone'] = Request::param('phone','');
$data['user_name'] = Request::param('user_name');
$data['account_pwd'] = Request::param('account_pwd');
$data['account_name'] = Request::param('account_name');
$data['type'] = Request::param('type',1);
$data['explain'] = Request::param('explain','');
$data['account_url'] = Request::param('account_url');
$data['content'] = json_encode(Request::param('content'));
$data['create_time'] = time();
if($account_id){
$where['account_id'] = $account_id;
$operater = Db::name('account')->where($where)->update($data);
} else {
$operater = Db::name('account')->insert($data);
}
if($operater) {
return $this->returnJson([],'操作成功!');
} else {
return $this->returnJson([],'操作失败!',400);
}
}
//账号详情
public function accountDetail()
{
$account_id = Request::param('account_id');
$where['account_id'] = $account_id;
$info = Db::name('account')->where($where)->find();
if($info) {
if($info['content'] != null) {
$info['content'] = json_decode($info['content'],true);
}
return $this->returnJson($info);
} else {
return $this->returnJson([],'未找到该数据!',400);
}
}
//删除账号
public function delAccount()
{
$account_id = Request::param('account_id');
$where['account_id'] = $account_id;
$info = Db::name('account')->where($where)->delete();
if($info) {
return $this->returnJson([],'删除成功!');
} else {
return $this->returnJson([],'未找到该数据!',400);
}
}
}
\ No newline at end of file
<?php
namespace app\admin\controller;
//admin管理人员列
use think\facade\Db;
use think\facade\Request;
class Adminuser extends Base
{
protected $middleware = ['app\middleware\AdminLoginCheck::class','app\middleware\AdminAfter::class'];
//创建权限角色
public function createRole() {
$data['name'] = Request::param("name");
$data['status'] = 1;
$data['create_admin_id'] = Request::param('admin_id');
$data['create_time'] = time();
$data['url_ids'] = implode(",",Request::param("url_ids") );
//查询是否存在相同的name或者url_ids是否相同
$is_exit= Db::name('admin_role')->where(['name'=>$data['name']])->find();
if($is_exit) {
return $this->returnJson([],'角色以存在!');
}
$add = Db::name('admin_role')->insert($data);
if($add) {
return $this->returnJson([],'角色创建成功');
} else {
return $this->returnJson([],'角色创建失败',400);
}
}
//修改角色
public function changeRole() {
$where['role_id'] = Request::param('role_id');
$data['name'] = Request::param("name");
$data['status'] = Request::param("status");
$data['url_ids'] = implode(",",Request::param("url_ids"));
$change = Db::name('admin_role')->where($where)->save($data);
if($change) {
return $this->returnJson([],'修改成功');
} else {
return $this->returnJson([],'修改失败',400);
}
}
//查看所有的角色列表
public function roleList() {
$page = Request::param('page',1);
$data = Db::name('admin_role')->page($page,config('app.limit'))->select()->toArray();
$res['count'] = Db::name('admin_role')->count();
$res['data'] = Common::changeField($data);
return $this->returnJson($res,'success');
}
//查看具体的角色详情
public function detailRole() {
$where['role_id'] = Request::param('role_id');
$data = Db::name('admin_role')->where($where)->find();
$data = Common::changeField($data);
$allNav = Db::name('admin_nav')->field("admin_nav_id,url,url_name,admin_nav_status,parent_id")->select()->toArray();
$urls = Common::changeNav($data['url_ids'],$allNav);
$data['url_ids'] = $this->getTree($urls,0,'admin_nav_id');
return $this->returnJson($data,'success');
}
//删除角色
public function deleteRole() {
//被删除的角色是否已在使用
$where['role_id'] = Request::param('role_id');
$is_exit = Db::name('admin')->where($where)->find();
if($is_exit) {
return $this->returnJson([],'当前角色以被使用,无法删除',400);
}
$dele = Db::name('admin_role')->where($where)->delete();
if($dele) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//创建|修改 管理员
public function createAdmin() {
$admin_id = Request::param('admin_now_id');
$data['last_operation_admin'] = $data['create_admin_id'] = Request::param('admin_id'); //当前登入的管理员id
$data['username'] = Request::param("username");
$password = Request::param("password");
if(isset($password)) {
$data['password'] = md5($password);
}
$data['role_id'] = Request::param("role_id");
$data['name'] = Request::param("name");
$data['phone'] = Request::param("phone");
$data['status'] = Request::param("status",1);
$is_exit = Db::name('admin')->where(['username'=>$data['username']])->find();
if($admin_id) { //修改
$where['admin_id'] = $admin_id;
if($is_exit['admin_id'] != $admin_id) {
return $this->returnJson([],'管理员账号已存在',400);
}
$add = Db::name('admin')->where($where)->save($data);
} else {
//添加,是否存在相同的账号
$data['create_time'] = time();
$is_exit = Db::name('admin')->where(['username'=>$data['username']])->find();
if($is_exit) {
return $this->returnJson([],'管理员账号已存在',400);
}
$add = Db::name('admin')->insert($data);
}
if($add) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//删除管理员
public function deleteAdmin() {
$admin_id = Request::param('admin_id');
$sum = Db::name('admin')->where(['status'=>1])->count();
if($sum <= 1) {
return $this->returnJson([],'最起码需要保留一位管理员',400);
}
$where['admin_id'] = $admin_id;
$dele = Db::name('admin')->where($where)->delete();
if($dele) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//查看管理员详情
public function detailAdmin() {
$where['admin.admin_id'] = Request::param('admin_id');
$data = Db::name('admin')->alias('admin')->leftJoin('admin_role ar','ar.role_id = admin.role_id')->where($where)
->field('admin.name,admin.phone,admin.admin_id,admin.username,admin.status,admin.role_id,ar.url_ids,ar.name,admin.type,ar.name')->find();
$res['adminInfo'] = $data;
return $this->returnJson($data,'success');
}
//查看管理员列表
public function adminList() {
$page = Request::param('page',1);
$data= Db::name('admin')->page($page,config('app.limit'))->field('admin_id,create_time,username,status,role_id,type,name,phone')->select()->toArray();
$res['total'] = Db::name('admin')->count();
$res['data'] = Common::changeField($data);
return $this->returnJson($res,'success');
}
//根据用户的id返回能访问的url
public function nav_urls() {
$id = Request::param('admin_id');
$where['admin.admin_id'] = $id;
$where['admin.status'] = 1;
$data = Db::name('admin')->alias('admin')->leftJoin('admin_role ar','ar.role_id = admin.role_id')->where($where)->field('admin.*,ar.url_ids')->find();
$allNav = Db::name('admin_nav')->field("admin_nav_id,url,url_name,admin_nav_status,parent_id,icon")->where(['admin_nav_status'=>1])->select()->toArray();
$urls = Common::changeNav($data['url_ids'],$allNav,$data['type']);
$urlArr = $this->getTree($urls,0,'admin_nav_id');
return $this->returnJson($urlArr,'success');
}
}
\ No newline at end of file
...@@ -17,14 +17,25 @@ class Base extends BaseController ...@@ -17,14 +17,25 @@ class Base extends BaseController
public function __construct(App $app) public function __construct(App $app)
{ {
parent::__construct($app); parent::__construct($app);
if(config("app.open_check")) { //是否开启验证 if(Request::header('token')) {
$token = Request::header('token'); $token = Request::header('token');
if(!$token) { //判断是否在redis中
echo json_encode(['code'=>401,'msg'=>'token不存在!!!!!']);exit; if($token) {
$decodeData = JWT::decode($token,config('app.jwt_key'),array("HS256"));
$decodeData = json_decode($decodeData,true);
if($decodeData) {
if($decodeData['expire_time'] < time()) {
echo json_encode(['code'=>400,'msg'=>'token已过期!']);exit;
} }
$decodeData = (array)JWT::decode($token,config("app.jwt_key"),array("HS256")); $this->admin_id = $decodeData['admin_id'];
$this->uid = $decodeData['uid']; } else{
echo json_encode(['code'=>400,'msg'=>'非法的token!']);exit;
}
} else{
echo json_encode(['code'=>400,'msg'=>'token不存在']);exit;
}
} else {
echo json_encode(['code'=>400,'msg'=>'token不存在']);exit;
} }
} }
......
<?php
namespace app\admin\controller;
use think\facade\Db;
use think\facade\Request;
class Common extends Base
{
//获取省市区
public function getArea() {
$where['area_pid'] = Request::param('area_id',0);
$data = Db::name('area')->where($where)->field("area_id,area_name")->select()->toArray();
return $this->returnJson($data,'success');
}
//通过id获取地区名称
public function getName($id) {
$where['area_id'] = $id;
return Db::name('area')->where($where)->value('area_name');
}
//查看所有的银行列表
public function bankAccountList() {
$data = Db::name("bank_account")->select()->toArray();
return $this->returnJson($data,'success');
}
//对返回的数据进行转换
public static function changeField($data,$field="create_time") {
if(empty($data)) {
return $data;
}
foreach($data as $k =>$v) {
if(is_array($v)) {
if(is_array($field)) {
foreach ($field as $value) {
$data[$k][$value] = date('Y-m-d H:i:s',$v[$value]);
}
} else {
$data[$k][$field] = date('Y-m-d H:i:s', $v[$field]);
}
} else {
if(is_array($field)) {
foreach ($field as $value) {
if(isset($data[$value])){
$data[$value] = date('Y-m-d H:i:s',$data[$value]);
}
}
break;
} else {
if(isset($data[$field])) {
$data[$field] = date('Y-m-d H:i:s', $data[$field]);
}
break;
}
}
}
return $data;
}
/**
* @param $url_ids string 1,2,3
* @param $navAl array
* @param $type int 1 所有都赋值,0 给特定的赋值
*/
public static function changeNav($url_ids,$navAl,$type=0) {
$urlsArr = explode(",",$url_ids);
if($type==1 ) {
return $navAl;
} else {
foreach($navAl as $k =>$v ) {
$navAl[$k]['is_power'] =0 ;
if(isset($v['property_nav_id']) && !in_array($v['property_nav_id'],$urlsArr)) {
unset($navAl[$k]) ;
}
if(isset($v['community_nav_id']) && !in_array($v['community_nav_id'],$urlsArr)) {
unset($navAl[$k]);
}
if(isset($v['admin_nav_id']) && !in_array($v['admin_nav_id'],$urlsArr)) {
unset($navAl[$k]);
}
}
}
return $navAl;
}
//获取流水详情,village_money_list表
public static function getWithDrawDetail($where) {
$data = Db::name('village_money_list')->alias('ml')
->leftJoin('house_village hv','ml.village_id = hv.village_id')
->leftJoin('house_property hp','hp.property_id = ml.property_id')
->where($where)
->field("ml.*,hv.village_name,hp.property_name")
->find();
if($data) {
$where_one['order_id'] = $data['order_id'];
switch ($data['table_name']) {
case "pay_order" :
$orderInfo = Db::name('pay_order')->alias('po')
->leftJoin('house_vacancy hv', 'hv.vacancy_id = po.vacancy_id')
->leftJoin('user u', 'po.uid = u.uid')
->field('po.*,hv.vacancy_address,u.phone,u.nickname')
->where($where_one)
->find();
break;
case "withdraw_order":
$orderInfo = Db::name('withdraw_order')
->where($where_one)->find();
break;
default:
return false;
}
return ['data' => $data, 'orderInfo' => $orderInfo];
} else {
return false;
}
}
//获取流水列表
public static function getWithDrawList($where,$page) {
$count = Db::name('village_money_list')->alias('ml')
->leftJoin('house_village hv','ml.village_id = hv.village_id')
->leftJoin('house_property hp','hp.property_id = ml.property_id')
->where($where)->count();
$data = Db::name('village_money_list')->alias('ml')
->leftJoin('house_village hv','ml.village_id = hv.village_id')
->leftJoin('house_property hp','hp.property_id = ml.property_id')
->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")
->order('ml.create_time','desc')
->page($page,config('app.limit'))->select()->toArray();
return ['total'=>$count,'data'=>$data];
}
}
\ No newline at end of file
<?php
namespace app\admin\controller;
use think\facade\Db;
use think\facade\Request;
class Company extends Base
{
protected $middleware = ['app\middleware\CheckValidata::class'];
//公司详情
public function companyDetail()
{
$where['company_id'] = Request::param('id');
$data = Db::name('company')->where($where)->find();
return $this->returnJson($data);
}
//编辑公司信息
public function companyEdit(){
$where['company_id'] =1;
$data['company_name'] = Request::param('company_name');
$data['province_id'] = Request::param('province_id');
$data['city_id'] = Request::param('city_id');
$data['area_id'] = Request::param('area_id');
$data['province_name'] = Request::param('province_name');
$data['city_name'] = Request::param('city_name');
$data['area_name'] = Request::param('area_name');
$data['address'] = Request::param('address');
$data['phone'] = Request::param('phone');
$res = Db::name('company')->where($where)->update($data);
return $this->returnJson([],'修改成功!');
}
}
\ No newline at end of file
<?php
namespace app\admin\controller;
use app\BaseController;
class Config extends BaseController
{
}
\ No newline at end of file
<?php
namespace app\admin\controller;
use think\facade\Request;
use think\facade\Db;
class Feedback extends Base
{
//意见反馈列表
public function feedBackList(){
$page = Request::param('page',1);
$limit = Request::param('limit',config('app.limit'));
$list =Db::name('feedback')->alias('f')->leftJoin('user u','f.uid = u.uid')->order('f.create_time','desc')->field('f.*,u.nickname')->page($page,$limit)->select()->toArray();
foreach ($list as $k =>$v) {
$list[$k]['content'] = mb_substr($v['content'],0,50,'utf-8');
if($v['pics']) {
$list[$k]['pics'] = json_decode($v['pics'],true);
} else{
$list[$k]['pics'] = [];
}
}
$count =Db::name('feedback')->count();
$res['total'] = $count;
$res['data'] = changeField($list);
return $this->returnJson($res,'success');
}
//意见反馈详情
public function feedBackDetail(){
$id = Request::param('feedback_id');
$where['feedback_id'] = $id;
$info = Db::name('feedback')->where($where)->alias('f')->leftJoin('user u','f.uid = u.uid')->field('f.*,u.nickname')->find();
if($info['pics']) {
$info['pics'] = json_decode($info['pics'],true);
} else{
$info['pics'] = [];
}
return $this->returnJson(changeField($info),'success');
}
}
\ No newline at end of file
<?php
namespace app\admin\controller;
use app\api\model\Admin as AdminModel;
use TencentCloud\Cdb\V20170320\Models\VerifyRootAccountRequest;
use think\facade\Db;
use think\facade\Request;
class Index extends Base {
protected $middleware = ['app\middleware\AdminLoginCheck::class','app\middleware\AdminAfter::class'];
public function index()
{
return "这是admin下的控制器";
}
public function hello($name = 'ThinkPHP6')
{
return 'hello,' . $name;
}
//小区列表
public function villageList() {
//查询,
$where = [];
if(Request::param('status')){
$where[] = ['ruer_house_village.status','=',Request::param('status')];
}
if(Request::param('property_id')){
$where[] = ['ruer_house_village.property_id','=',Request::param('property_id')];
}
if(Request::param('village_name')){
$where[]= ['ruer_house_village.village_name','like',"%".Request::param('village_name')."%"];
}
if(Request::param('province_id')){
$where[]= ['ruer_house_village.province_id','=',Request::param('province_id')];
}
if(Request::param('city_id')){
$where[]= ['ruer_house_village.city_id','=',Request::param('city_id')];
}
if(Request::param('area_id')){
$where[]= ['ruer_house_village.area_id','=',Request::param('area_id')];
}
$page = Request::param("page",1);
$count = Db::name('house_village')->alias("hv")->join('ruer_community_admin ca','ca.community_admin_id = hv.community_admin_id')->where($where)->count();
$data = Db::name('house_village')->alias("hv")->join('ruer_community_admin ca','ca.community_admin_id = hv.community_admin_id')
->where($where)
->order('hv.create_time','desc')
->page($page,config("app.limit"))
->field("hv.*,ca.account,ca.status as status_admin,ca.phone")
->select()->toArray();
$res['total'] = $count;
$res['data'] = Common::changeField($data);
return $this->returnJson($res,'success');
}
//小区详情
public function detailVillage() {
$where['hv.village_id'] = Request::param('village_id');
if(Request::param('property_id')) {
$where['hv.property_id'] = Request::param('property_id');
}
$data = Db::name('house_village')->alias("hv")->join('community_admin ca','ca.community_admin_id = hv.community_admin_id')->leftJoin('house_property hp','hp.property_id = hv.property_id')
->where($where)
->field("hv.*,ca.account,ca.status as status_admin,ca.phone,ca.name,hp.property_name,hp.property_id")
->find();
$data= Common::changeField($data);
return $this->returnJson($data,'success');
}
//删除小区
public function deleteVillage() {
$id = Request::param('village_id');
$admin_id = Request::param('admin_id');
if($admin_id != $this->uid) {
return $this->returnJson([],'账号异常',400);
}
$where['village_id'] = $id;
$del = Db::name('house_village')->where($where)->delete();
if($del) {
Db::name('log')->insert(['explain'=>"管理员_".$admin_id."删除了小区_".$id,'time'=>date('Y-m-d H:i:s',time())]);
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//物业列表
public function propertyList() {
//查询,
$where[] = ['pa.type','=',1];
$orwhere = [];
if(Request::param('status')){
$where[] = ['ruer_house_property.status','=',Request::param('status')];
}
if(Request::param('property_name')){
$where[]= ['ruer_house_property.property_name','like',"%".Request::param('property_name')."%"];
$orwhere[] = ['ruer_house_property.property_phone','like',"%".Request::param('property_name')."%"];
}
if(Request::param('province_id')){
$where[]= ['ruer_house_property.province_id','=',Request::param('province_id')];
}
if(Request::param('city_id')){
$where[]= ['ruer_house_property.city_id','=',Request::param('city_id')];
}
if(Request::param('area_id')){
$where[]= ['ruer_house_property.area_id','=',Request::param('area_id')];
}
$page = Request::param("page",1);
$count = Db::name('house_property')->alias("hp")->join('ruer_property_admin pa','pa.property_admin_id = hp.property_admin_id')->where($where)->whereOr($orwhere)->count();
$data = Db::name('house_property')->alias("hp")->join('ruer_property_admin pa','pa.property_admin_id = hp.property_admin_id')
->where($where)
->whereOr($orwhere)
->page($page,config('app.limit'))
->field("hp.*,pa.account,pa.status as status_admin")
->select()->toArray();
$res['total'] = $count;
$res['data'] = $data;
return $this->returnJson($res,'success');
}
//修改|添加 物业信息
public function changeProperty() {
$property_id = Request::param("property_id");
$data['property_name']= Request::param("property_name");
$data['property_phone'] = $save['phone']= Request::param("property_phone");
$data['property_address'] = Request::param("property_address");
$data['province_name'] = Request::param("province_name");
$data['province_id'] = Request::param("province_id");
$data['city_name'] = Request::param("city_name");
$data['city_id'] = Request::param("city_id");
$data['area_name'] = Request::param("area_name");
$data['area_id'] = Request::param("area_id");
$save['account'] = Request::param("account");
$save['create_time'] = $data['create_time'] = time();
$save['name'] = Request::param("name");
if(Request::param("password")){
$save['password'] = md5(Request::param("password"));
}
if($property_id) {
$where['property_id'] = $property_id;
$op = Db::name('house_property')->where($where)->save($data);
$property_admin_id = Db::name('house_property')->where($where)->value("property_admin_id");
$op1 = Db::name('property_admin')->where(['property_admin_id'=>$property_admin_id])->save($save);
if($op || $op1) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
} else {
//插入物业管理人员表
Db::startTrans();
try{
$save['property_id'] = Db::name('house_property')->insertGetId($data);
$save['type'] = 1;
$change['property_admin_id']= Db::name('property_admin')->insertGetId($save);
Db::name('house_property')->where(['property_id'=>$save['property_id']])->save($change);
Db::commit();
return $this->returnJson([],'success');
}catch(\Exception $e){
Db::rollback();
return $this->returnJson([],'error',400);
}
}
}
//更改物业公司状态
public function changePropertyStatus() {
$where['property_id'] = Request::param('property_id');
$data['status'] = Request::param('status',1);
$change = Db::name('house_property')->where($where)->update($data);
if($change) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'状态修改失败!',400);
}
}
//删除物业公司
public function deleteProperty() {
$id = Request::param('property_id');
$admin_id = Request::param('admin_id');
$where['property_id'] = $id;
//该物业下是否有小区,
$is_has = Db::name('house_village')->where($where)->find();
if($is_has) {
return $this->returnJson([],'该物业下有小区存在,无法删除',400);
}
$del = Db::name('house_property')->where($where)->delete();
if($del) {
Db::name('log')->insert(['explain'=>"管理员_".$admin_id."删除了物业公司_".$id,'time'=>date('Y-m-d H:i:s',time())]);
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//查看单个物业公司详情
public function detailProperty() {
$where['hp.property_id'] = Request::param('property_id');
$data = Db::name('house_property')->alias("hp")->join('property_admin pa','pa.property_admin_id = hp.property_admin_id')
->where($where)
->field("hp.*,pa.account,pa.status as status_admin")
->find();
$data = Common::changeField($data);
return $this->returnJson($data,'success');
}
//查看总后台所有的导航栏
public function navList() {
$type = Request::param('type',3); //1:总后台;2:物业后台;3:社区后台
if($type == 1) {
$data = Db::name('admin_nav')->where(['admin_nav_status'=>1])->order(['level'=>'asc','sort_id'=>'desc'])->field('admin_nav_id,url,url_name,admin_nav_status,parent_id')->select()->toArray();
return $this->returnJson($this->getTree($data,0,'admin_nav_id'),'success');
} elseif($type == 2){
$data = Db::name('property_nav')->where(['property_nav_status'=>1])->order(['level'=>'asc','sort_id'=>'desc'])->field('property_nav_id,url,url_name,property_nav_status,parent_id')->select()->toArray();
return $this->returnJson($this->getTree($data,0,'property_nav_id'),'success');
} else {
$data = Db::name('community_nav')->where(['community_nav_status'=>1])->order(['level'=>'asc','sort_id'=>'desc'])->field('community_nav_id,url,url_name,community_nav_status,parent_id')->select()->toArray();
return $this->returnJson($this->getTree($data,0,'community_nav_id'),'success');
}
}
//获取当前导航栏的详情和上一级的详情
public function detailNav() {
$type = Request::param('type',3);
$id = Request::param('id');
if($type==1) {
$data = DB::name('admin_nav')->where(['admin_nav_id'=>$id])->find();
if($data['parent_id'] != 0) {
$res['p_nav'] = DB::name('admin_nav')->where(['admin_nav_id'=>$data['parent_id']])->field('admin_nav_id,url,url_name,admin_nav_status,level,parent_id,sort_id,icon')->find();
} else{
$res['p_nav'] = [];
}
$res['nav'] = $data;
} elseif($type==2) {
$data = DB::name('property_nav')->where(['property_nav_id'=>$id])->field('property_nav_id,url,url_name,property_nav_status,level,parent_id,sort_id,icon')->find();
if($data['parent_id'] != 0) {
$res['p_nav'] = DB::name('property_nav')->where(['property_nav_id'=>$data['parent_id']])->find();
} else{
$res['p_nav'] = [];
}
$res['nav'] = $data;
} else {
$data = DB::name('community_nav')->where(['community_nav_id'=>$id])->field('community_nav_id,url,url_name,community_nav_status,level,parent_id,sort_id,icon')->find();
if($data['parent_id'] != 0) {
$res['p_nav'] = DB::name('community_nav')->where(['community_nav_id'=>$data['parent_id']])->find();
} else{
$res['p_nav'] = [];
}
$res['nav'] = $data;
}
return $this->returnJson($res,'success');
}
//添加导航栏
public function addNav() {
$type = Request::param('type',3); //1:总后台;2:物业后台;3:社区后台
$data['parent_id'] = Request::param('parent_id',0);
$data['icon'] = Request::param('icon');
$data['url'] = Request::param('url','');
$data['url_name'] = Request::param('url_name');
$data['sort_id'] = Request::param('sort_id');
$data['create_time'] = time();
if($type == 1) {
$p_info = Db::name('admin_nav')->where(['admin_nav_id'=>$data['parent_id']])->find();
if($p_info) {
$data['level'] = $p_info['level'] +1;
} else {
$data['level'] =1;
}
$data['admin_nav_status'] = 1;
$add = Db::name('admin_nav')->insert($data);
} elseif($type == 2) {
$p_info = Db::name('property_nav')->where(['property_nav_id'=>$data['parent_id']])->find();
if($p_info) {
$data['level'] = $p_info['level'] +1;
} else {
$data['level'] =1;
}
$data['property_nav_status'] = 1;
$add = Db::name('property_nav')->insert($data);
} else {
$p_info = Db::name('community_nav')->where(['community_nav_id'=>$data['parent_id']])->find();
if($p_info) {
$data['level'] = $p_info['level'] +1;
} else {
$data['level'] =1;
}
$data['community_nav_status'] = 1;
$add = Db::name('community_nav')->insert($data);
}
if($add) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//修改导航栏
public function changeNav() {
$id = Request::param('id');
$type = Request::param('type',3);
$data['url'] = Request::param('url','');
$data['url_name'] = Request::param('url_name');
$data['icon'] = Request::param('icon');
$data['sort_id'] = Request::param('sort_id',1);
$status = Request::param('status',1);
if($type ==1) {
$where['admin_nav_id'] = $id;
$where['admin_nav_status'] = $status;
$table="admin_nav";
} elseif ($type ==2) {
$where['property_nav_id'] = $id;
$where['property_nav_status'] = $status;
$table="property_nav";
} else {
$where['community_nav_id'] = $id;
$where['community_nav_status'] = $status;
$table="community_nav";
}
$change = Db::name($table)->where($where)->save($data);
if($change) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'修改失败!',400);
}
}
//删除导航栏
public function deleteNav() {
$id = Request::param('id');
$type = Request::param('type',3); //1:总后台;2:物业后台;3:社区后台
//只能删除子导航栏,或者父导航栏没有自导航栏,
if(!$this->isHasNext($type,$id)) {
return $this->returnJson([],'删除失败,当前菜单下有子菜单',400);
}
if($type==1) {
$where['admin_nav_id'] = $id;
$del = Db::name('admin_nav')->where($where)->delete();
} elseif($type ==2) {
$where['property_nav_id'] = $id;
$del = Db::name('property_nav')->where($where)->delete();
} else {
$where['community_nav_id'] = $id;
$del = Db::name('community_nav')->where($where)->delete();
}
if($del) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//用来判断导航栏是否存在下一级
public function isHasNext($type,$id) {
if($type==1) {
$is_zi = Db::name('admin_nav')->where(['parent_id'=>$id])->find();
} elseif($type==2) {
$is_zi = Db::name('property_nav')->where(['parent_id'=>$id])->find();
} else{
$is_zi = Db::name('community_nav')->where(['parent_id'=>$id])->find();
}
if($is_zi) {
return false;
}
return true;
}
}
...@@ -13,82 +13,30 @@ use think\facade\Validate; ...@@ -13,82 +13,30 @@ use think\facade\Validate;
class Login extends BaseController class Login extends BaseController
{ {
protected $middleware = ['app\middleware\CheckValidata::class'];
public function login(){
public function login() {
if(Request::isPost()){ if(Request::isPost()){
$account = Request::param('account');
$username = Request::param('username'); $pass_word = Request::param('pass_word');
$password = Request::param('password'); $where['account'] = $account;
$where['pass_word'] = md5($pass_word);
//验证字段是否合理
$validate = Validate::rule([
'username|账号' => 'require', //第二个可写可不写,如果写了的话,后面自定义msesage可以自动用这个来提示,第三个验证规则可以用来确定表user中的字段的唯一性,需要与username字段对应
'password|密码' => 'require',
]);
$result = $validate->check([
'username' => $username,
'password' => $password,
]);
if(!$result){
$msg = $validate->getError();
return $this->returnJson([],$msg,'404');
}
//数据库验证数据 //数据库验证数据
$where['ad.username'] = $username; $is_find = Db::name('admin')->where($where)->find();
$where['ad.password'] = md5($password); if($is_find) {
$where['ad.status'] = 1; $to['admin_id'] = $is_find['admin_id'];
$to['expire_time'] = time() + 43200; //设置12小时过期
$userInfo = Db::name('admin')->alias("ad")->join('admin_role','admin_role.role_id = ad.role_id')->where($where)->field("ad.type,ad.admin_id,ad.username,admin_role.name,admin_role.url_ids")->find(); $jwt = JWT::encode(json_encode($to),config('app.jwt_key')); //根据参数生成了 token
$res['token'] = $jwt;
$data['uid'] = $userInfo['admin_id']; $res['user_name'] = $is_find['user_name'];
return $this->returnJson($res,'登入成功');
$jwt = JWT::encode($data,config('app.jwt_key')); //根据参数生成了 token
if($userInfo){
//把jwt放入set缓存中
$redis= Cache::store('redis')->handler();
$redis->setnx("admin_tokens"."_".$data['uid'],$jwt);
$redis->EXPIRE("admin_tokens"."_".$data['uid'],3600); //设置过期时间,一小时
//查询相关的能访问的导航权限
//超级管理员
if($userInfo['type']==1) {
$res = Db::name('admin_nav')->where(['admin_nav_status'=>1])->order("sort_id,level")->field("admin_nav_id,url_name,url,parent_id")->select()->toArray();
} else { //普通管理员
$res = Db::name('admin_nav')->where(['admin_nav_status'=>1])->whereIn('admin_nav_id',$userInfo['url_ids'])->field("admin_nav_id,url_name,url,parent_id")->order("sort_id,level")->select()->toArray();
}
$navs = $this->getTree($res,0,"admin_nav_id");
$userInfo['urls_id'] =$navs;
return $this->returnJson(['token'=>$jwt,'adminInfo'=>$userInfo],'success');
} else { } else {
return $this->returnJson([],'用户不存在!',400); return $this->returnJson([],'账号或密码错误!','400');
} }
}else { }else {
return $this->returnJson([],'请求错误!',400); return $this->returnJson([],'请求错误!','400');
} }
} }
//退出
public function logout() {
$token = Request::header('token');
//判断是否在redis中
$redis= Cache::store('redis')->handler();
$decodeData = (array)JWT::decode($token,"zhihuishequ",array("HS256"));
if(!isset($decodeData['code'])){
$r_token= $redis->del("admin_tokens_".$decodeData['uid']);
if(!$r_token || $r_token!=$token) {
return $this->returnJson([],'success');
}
} else {
return $this->returnJson([],'error',400);
}
}
} }
\ No newline at end of file
<?php
namespace app\admin\controller;
use think\facade\Request;
use think\facade\Db;
class Message extends Base
{
//公众号提交的留言列表
public function messageList(){
$page = Request::param('page',1);
$limit = Request::param('limit',config('app.limit'));
$list =Db::name('message')->alias('m')->page($page,$limit)->order('create_time','desc')->select()->toArray();
foreach ($list as $k =>$v) {
$list[$k]['content'] = mb_substr($v['content'],0,50,'utf-8');
switch ($v['from']){
case 1:
$list[$k]['from'] = "客满了官网";
break;
case 2:
$list[$k]['from'] = "睿者智能官网";
break;
case 3:
$list[$k]['from'] = "客满了公众号";
break;
case 4:
$list[$k]['from'] = "睿者智能公众号";
break;
}
}
$count =Db::name('message')->count();
$res['total'] = $count;
$res['data'] = changeField($list);
return $this->returnJson($res,'success');
}
//意见反馈详情
public function messageDetail(){
$id = Request::param('message_id');
$where['message_id'] = $id;
$info = Db::name('message')->where($where)->find();
if($info) {
return $this->returnJson(changeField($info),'success');
} else {
return $this->returnJson([],'未找到该数据!',400);
}
}
public function messageDel(){
$id = Request::param('message_id');
$where['message_id'] = $id;
$info = Db::name('message')->where($where)->delete();
if($info) {
return $this->returnJson([],'删除成功!');
} else {
return $this->returnJson([],'未找到该数据!',400);
}
}
public function changeMessage()
{
$id = Request::param('message_id');
$where['message_id'] = $id;
$data['is_operation'] = 1;
$info = Db::name('message')->where($where)->update($data);
if($info) {
return $this->returnJson([],'标注成功!');
} else {
return $this->returnJson([],'未找到该数据!',400);
}
}
}
\ No newline at end of file
<?php
namespace app\admin\controller;
use think\facade\Request;
use think\facade\Db;
class Order extends Base
{
protected $middleware = ['app\middleware\AdminLoginCheck::class','app\middleware\AdminAfter::class'];
//流水管理
public function orderList(){
$page = Request::param('page',1);
$where= [];
if(Request::param('property_name')) {
$property_name = Request::param('property_name');
$where[] = ['hp.property_name','like','%'.$property_name.'%'];
}
if(Request::param('village_name')) {
$village_name = Request::param('village_name');
$where[] = ['hv.village_name','like','%'.$village_name.'%'];
}
$rest = Common::getWithDrawList($where,$page);
$res['total'] = $rest['total'];
$res['data'] = Common::changeField($rest['data']);
return $this->returnJson($res,'success');
}
//查看流水详情
public function detailOrder() {
$id = Request::param('id');
$where['id'] = $id;
$rest = Common::getWithDrawDetail($where);
if(!$rest) {
return $this->returnJson([],'暂未获取到任何数据',400);
}
$res['data'] = $rest['data'];
$res['orderInfo'] = Common::changeField($rest['orderInfo'],['create_time','pay_time']);
return $this->returnJson($res,'success');
}
}
\ No newline at end of file
<?php
namespace app\admin\controller;
use think\facade\Db;
use think\facade\Request;
class Project extends Base
{
//项目列表
public function projectList()
{
$page = Request::param('page',1);
$limit = Request::param('limit',config('app.limit'));
$project_name = Request::param('keyword');
$where = [];
if($project_name) {
$where[] = ['project_name','like','%'.$project_name.'%'];
}
$res['count'] = Db::name('project')->where($where)->count();
$data = Db::name('project')->where($where)->page($page,$limit)->select()->toArray();
$res['data'] = changeField($data);
return $this->returnJson($res);
}
//添加|修改项目
public function addProject()
{
$project_id = Request::param('project_id');
$data['project_name'] = Request::param('project_name');
if($project_id) {
$is_exit = Db::name('project')->where($data)->where('project_id',"<>",$project_id)->find();
} else{
//查看是否存在
$is_exit = Db::name('project')->where($data)->find();
}
if($is_exit) {
return $this->returnJson([],'项目已存在',400);
}
$data['explain'] = Request::param('explain');
$data['create_time'] = time();
if($project_id) {
$where['project_id'] = $project_id;
$operate = Db::name('project')->where($where)->update($data);
} else {
$operate = Db::name('project')->insert($data);
}
if($operate !==false) {
return $this->returnJson([],'操作成功!');
} else {
return $this->returnJson([],'操作失败!',400);
}
}
//添加|修改子项目
public function addProjectPart(){
$project_part_id = Request::param('project_part_id');
$data['project_id'] = Request::param('project_id');
$data['project_part_name'] = Request::param('project_part_name');
if($project_part_id) {
//查看是否存在
$is_exit = Db::name('project_part')->where($data)->where('project_part_id','<>',$project_part_id)->find();
} else {
//查看是否存在
$is_exit = Db::name('project_part')->where($data)->find();
}
if($is_exit) {
return $this->returnJson([],'项目已存在!',400);
}
$data['content'] = json_encode(Request::param('content'));
$data['principal'] = json_encode(Request::param('principal'));
$data['create_time'] = time();
$data['status'] = Request::param('status',0);
$data['explain'] = Request::param('explain');
if($project_part_id) {
$where['project_part_id'] = $project_part_id;
$operater = Db::name('project_part')->where($where)->update($data);
} else {
$operater = Db::name('project_part')->insert($data);
}
if($operater) {
return $this->returnJson([],'操作成功!');
} else {
return $this->returnJson([],'操作失败!',400);
}
}
//查询相关的子项目的详情
public function detailProjectPart(){
$where['part.project_part_id'] = Request::param('project_part_id');
$data = Db::name('project_part')
->alias('part')
->leftJoin('project p','part.project_id = p.project_id')
->where($where)
->field('part.*,p.project_name,p.explain as project_explain')
->find();
$data['content'] = json_decode($data['content'],true);
$data['principal'] = json_decode($data['principal'],true);
return $this->returnJson(changeField($data));
}
//子项目列表
}
\ No newline at end of file
<?php
namespace app\admin\controller;
use think\facade\Db;
use think\facade\Request;
class Web extends Base
{
protected $middleware = ['app\middleware\CheckValidata::class'];
//导航栏列表
public function navList()
{
$where['web_id'] = Request::param('web_id',1);
$data = Db::name('web_nav')->where($where)->order(['sort'=>'desc','nav_id'=>'asc'])->select()->toArray();
return $this->returnJson($data);
}
//修改|添加导航栏
public function editNav()
{
$nav_id = Request::param('nav_id');
$data['nav_name'] = Request::param('nav_name');
$data['sort'] = Request::param('sort',0);
$data['url'] = Request::param('url','');
$data['web_id'] = Request::param('web_id',1);
$pic = Request::param('pic');
$data['pic'] = str_replace(config('app.alioss.pic_url'),'',$pic);
if($nav_id) {
$where['nav_id'] = $nav_id;
$operation = Db::name('web_nav')->where($where)->update($data);
} else {
$operation = Db::name('web_nav')->insert($data);
}
if($operation) {
return $this->returnJson();
} else {
return $this->returnJson([],'操作失败!',400);
}
}
//删除导航栏
public function deleteNav()
{
$where['nav_id'] = Request::param('nav_id',1);
$res = Db::name('web_nav')->where($where)->delete();
if($res) {
return $this->returnJson();
} else {
return $this->returnJson([],'删除失败!',400);
}
}
//对不同的导航栏下的文字进行管理
public function editWord()
{
$data['content'] = json_encode(Request::param('content'));
$data['web_id'] =$whe['web_id'] = Request::param('web_id');
$data['nav_id'] = $whe['nav_id']=Request::param('nav_id');
$exit = Db::name('web_word')->where($whe)->find();
if($exit) {
$operation = Db::name('web_word')->where($whe)->update($data);
} else {
$operation = Db::name('web_word')->insert($data);
}
if($operation) {
return $this->returnJson();
} else {
return $this->returnJson([],'操作失败!',400);
}
}
//获取导航栏的相对于的文字内容
public function getWord()
{
$nav_id = Request::param('nav_id');
$where['nav_id'] = $nav_id;
$res = Db::name('web_word')->where($where)->find();
$result = json_decode($res['content'],true);
return $this->returnJson($result);
}
//删除导航栏的文字内容
public function delWord()
{
$nav_id = Request::param('nav_id');
$where['nav_id'] = $nav_id;
$res = Db::name('web_word')->where($where)->delete();
if($res) {
return $this->returnJson();
} else {
return $this->returnJson([],'删除失败!',400);
}
}
}
\ No newline at end of file
<?php
namespace app\api\controller;
use Firebase\JWT\JWT;
use think\facade\Request;
class Base extends \app\BaseController
{
public function __construct(\think\App $app)
{
parent::__construct($app);
if(Request::header("token")){
$decodeData= (array)JWT::decode(Request::header('token'),config('app.jwt_key'),array("HS256"));
$this->uid = $decodeData['uid'];
} else {
echo json_encode(['code'=>401,'msg'=>"token不存在!"]);exit;
}
}
}
\ No newline at end of file
<?php
namespace app\api\controller;
use think\facade\Db;
use think\facade\Request;
class Feedback extends Base{
public function uploadFeedBack(){
$data['content'] = Request::param('content');
$data['uid'] = $this->uid;
$data['type'] = Request::param('type',1);
$data['create_time'] = time();
$pics = Request::param('pics');
if($pics) {
$data['pics'] = json_encode($pics);
}
$add = Db::name('feedback')->insert($data);
if($add) {
return $this->returnJson([],200);
} else {
return $this->returnJson([],'添加失败!','400');
}
}
}
\ No newline at end of file
<?php
namespace app\api\controller;
use app\common\controller\Common;
use app\BaseController;
use think\facade\Db;
use think\facade\Request;
class Index extends Base
{
//app首页信息,如果用户只绑定了一个房间,则默认展示一个房间的
public function index() {
$page = Request::param('page',1);
$uid = $this->uid;
$village_id = Request::param('village_id');
$field ="hvi.village_name,hvi.village_id,hvi.village_address,hvi.province_name,hvi.city_name,hvi.area_name";
if(empty($village_id)) {
$data = Db::name('house_user_bind')->alias('hub')
->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
->leftJoin('house_village hvi','hvi.village_id = hv.village_id')
->where(['hub.is_lately_login'=>1,'hub.uid'=>$uid])
->whereOr(['hub.uid'=>$uid])
->field($field)->find();
echo Db::name('house_user_bind')->getLastSql();exit;
} else {
$data = Db::name('house_village')->alias('hvi')->where(['village_id'=>$village_id])->field($field)->find();
}
//首页推荐新闻
$news= Db::name('news')->where(['village_id'=>$data['village_id'],'is_recommend'=>1])->order('recommend_sort_id','desc')
->field('news_id,title,pic,content')
->page($page,config('app.limit'))
->select()->toArray();
foreach ($news as $k=>$v) {
$news[$k]['content'] = mb_substr(strip_tags($v['content']),0,100);
}
$data['news'] = $news;
//首页轮播图
$banner = Db::name('village_banner')->where(['village_id'=>$village_id])->order(['sort_id'=>'desc','create_time'=>'desc'])->field('pic,url')->select()->toArray();
if(!$banner) {
$banner = config('app.banner');
}
$data['banner'] = $banner;
//公告
$notice = Db::name('notice')->where(['village_id'=>$village_id])->order(['sort_id'=>'desc','create_time'=>'desc'])->field('notice_id,title')->limit(3)->select()->toArray();
$data['notice'] = $notice;
return $this->returnJson($data);
}
//获取布局
public function getLayoutList(){
$where['village_id'] = Request::param('village_id');
$data = Db::name('layout_list')->where($where)->select()->toArray();
foreach ($data as $k => $v) {
$data[$k]['code_arr'] = explode('-',$v['code']);
}
return $this->returnJson($data);
}
//建筑列表
public function buildList() {
$where['lb.village_id'] = Request::param('village_id');
$parent_id = Request::param('parent_id',0);
$where['lb.parent_id'] = $parent_id;
//检查当前的parent_id是否是最下的一个建筑了,如果是,则查询该下面的房屋
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;
$listArr = explode('-',$listInfo['code']);
$name = array_pop($listArr);
$is_last = Db::name('layout_build')->where(['layout_build_id'=>$parent_id,'level'=>$level])->find();
if($is_last){ //查找房间
$data = Db::name('house_vacancy')->where(['parent_id'=>$parent_id])->field('vacancy_id,vacancy_code')->select()->toArray();
foreach ($data as $k => $v) {
$vacancyArr = explode('-',$v['vacancy_code']);
$code = array_pop($vacancyArr);
$data[$k]['code_name'] = $code.$name;
$data[$k]['is_build'] = 0 ;
}
} else{
$data = $this->getBuildInfo($where);
}
} else {
$data = $this->getBuildInfo($where);
}
return $this->returnJson($data);
}
//获取建筑信息
public function getBuildInfo($where) {
if(Request::param('layout_id')) {
$where['lb.layout_id'] = Request::param('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'])
->field("lb.layout_build_id,lb.layout_id,lb.code,lb.level,lb.village_id,ll.code as list_code")
->select()
->toArray();
foreach ($data as $k =>$v) {
$data[$k]['code_name'] = $v['code'].explode('-',$v['list_code'])[$v['level']-1];
$data[$k]['is_build'] = 1;
}
return $data;
}
//获取单个房间基本信息
public function getVacancyInfo() {
$vacancy_id = Request::param('vacancy_id');
$data = Db::name('house_vacancy')->alias('hv')
->leftJoin('house_village hvi','hvi.village_id = hv.village_id')
->leftJoin('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['isHasOwner'] = empty($data['vacancyOwnerInfo']) ? 0 : 1;
$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_id'=>'desc'])->select()->toArray();
return $this->returnJson($data);
}
//当前用户的所有的房间列表
public function allVacancy() {
$uid = $this->uid;
$userType = $this->userType;
$where[] = ['hub.uid','=',$uid];
$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')
->where(['hub.status'=>1])
->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,brand')->select()->toArray();
$data[$k]['cars'] = $cars;
$car_total = count($cars);
$data[$k]['car_total'] = $car_total;
$data[$k]['type_zh'] = $userType[$v['type']];
}
$data = Common::changeField($data,'pass_time');
return $this->returnJson($data);
}
//查看车辆详情
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['village_id'] = Request::param('village_id');
// $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 changeCar() {
$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['car_type'] = Request::param('car_type');
$data['uid'] = $uid;
$data['village_id'] = Request::param('village_id');
if($car_id) {
//判断车牌是否存在changeCar
$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 !== false) {
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 !== false) {
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];
$where[] = ['hub.status','=',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('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'];
//获取用户车辆信息
$cars = Db::name('car')->where(['uid'=>$this->uid,'village_id'=>$data['village_id']])->select()->toArray();
$data['car'] = $cars;
if($data['type'] ==0 ){
//查询家属
$family = $this->getFamily($data['vacancy_id']);
//查询租客
$tenant = $this->getTenant($data['vacancy_id']);
$data['user'] = array_merge($family,$tenant);
} elseif($data['type'] == 2){
$data['user'] = $this->getTenant($data['vacancy_id']);
} else {
$data['user'] = [];
}
return $this->returnJson($data);
}
//根据房间id,查询租客
public function getTenant($vacancy_id) {
//查询租客
$where['hub.vacancy_id'] = $vacancy_id;
$where['hub.type'] = 2;
$tenant = $this->getUser($where);
foreach ($tenant as $k =>$v) {
$tenant[$k]['type_zh'] = "租客";
}
return $tenant;
}
//根据房间id,查询家属
public function getFamily($vacancy_id) {
//查询租客
$where['hub.vacancy_id'] = $vacancy_id;
$where['hub.type'] = 1;
$family = $this->getUser($where);
foreach ($family as $k =>$v) {
$family[$k]['type_zh'] = "家属";
}
return $family;
}
//获取绑定用户信息
public function getUser($where){
$user = Db::name('house_user_bind')->alias('hub')->leftJoin('user','user.uid = hub.uid')
->where($where)
->where('hub.uid','<>',$this->uid)
->whereNotIn('hub.status',[0,3])
->where('hub.uid','<>',null)
->field('hub.house_user_bind_id,hub.name,hub.phone,user.avatar,user.uid,hub.village_id,hub.status,hub.type')->select()->toArray();
return $user;
}
//业主审核租客和家属,或家属租客申请解绑
public function changeStatus() {
$bind_id = Request::param('bind_id');
$status = Request::param('status'); //1接受,0拒绝,4申请解绑,3已解绑
$save['status'] = $status;
$save['pass_time'] = time();
$change = Db::name('house_user_bind')->where(['house_user_bind_id'=>$bind_id])->save($save);
if($change !== false) {
return $this->returnJson();
} else {
return $this->returnJson([],'操作失败!',400);
}
}
}
\ No newline at end of file
<?php
namespace app\api\controller;
use app\common\controller\Common;
use app\BaseController;
use Firebase\JWT\JWT;
use think\facade\Db;
use think\facade\Request;
class Login extends BaseController
{
//用户登入
public function login(){
$phone = Request::param('phone');
$password = md5(Request::param('password'));
$code = Request::param('code');
if($code) {
//验证短信验证码是否正确
if(Common::rightCode($phone,$code)){
$userInfo = Db::name('user')->where(['phone'=>$phone])->find();
if($userInfo) {
if($userInfo['status'] !=1) {
return $this->returnJson([],'用户被禁用,请联系管理员!','400');
}
$uid = $userInfo['uid'];
} else {
//注册
$data['phone'] = $phone;
$data['nickname'] = substr_replace($phone,"*",3,5);
$data['create_time'] =$data['last_time']=time();
$data['add_ip'] = $data['last_ip'] = request()->ip();
$uid= Db::name('user')->insertGetId($data);
}
Common::synUserData($uid,$phone); //同步用户数据
$token['uid']= $uid;
$token['time']= date('Y-m-d H:i');
$token = JWT::encode($token,config('app.jwt_key')); //根据参数生成了token
$res['token'] = $token;
$res['uid'] = $uid;
$res['phone'] = $phone;
$res['pwd'] = empty($userInfo['password']) ? 0 :1;
//查询该用户是否绑定了房间,如果有,则返回上一次绑定的房间
$res['userBindInfo'] = $this->findOnlyRoom($uid);
return $this->returnJson($res);
} else{
return $this->returnJson([],'验证码不正确!','400');
}
}
if($password){
$where['password'] = $password;
$where['phone'] = $phone;
$userInfo = Db::name('user')->where($where)->find();
if($userInfo){
//更该登入信息
$data['last_time']=time();
$data['last_ip'] = request()->ip();
Db::name('user')->where(['phone'=>$phone])->save($data);
$token['uid']= $userInfo['uid'];
$token['time']= date('Y-m-d H:i');
$token = JWT::encode($token,config('app.jwt_key')); //根据参数生成了 token
$res['token'] = $token;
$res['uid'] = $userInfo['uid'];
$res['phone'] = $phone;
$res['pwd'] = empty($userInfo['password']) ? 0 :1;
//查询该用户是否绑定了房间,如果有,则返回上一次绑定的房间
$res['userBindInfo'] = $this->findOnlyRoom($userInfo['uid']);
Common::synUserData($userInfo['uid'],$phone);
return $this->returnJson($res,200);
} else {
return $this->returnJson([],'密码不正确!','400');
}
}
return $this->returnJson([],'参数错误,请检查!','400');
}
//查询是否有房间唯一,如果唯一返回
public function findOnlyRoom($uid) {
//查询该用户是否绑定了房间,如果有,则返回上一次绑定的房间
$userBind = Db::name('house_user_bind')->where(['uid'=>$uid,'status'=>1,'is_lately_login'=>1])->field('house_user_bind_id,village_id,vacancy_id')->find();
if($userBind){
return $userBind;
} else {
//查询是否有房间
$userBind = Db::name('house_user_bind')->where(['uid'=>$uid,'status'=>1])->field('house_user_bind_id,village_id,vacancy_id')->find();
if($userBind){
return $userBind;
Db::name('house_user_bind')->where(['uid'=>$uid,'status'=>1])->save(['is_lately_login'=>1]);
} else {
return (Object)[];
}
}
}
//发送短信验证码
public function sendCode() {
$phone = Request::param('phone');
$temp_id = 165103;
$temp_para['code'] = createPhoneCode(6);
$client = new \JSMS(config('app.message_appKey'), config('app.message_masterSecret'));
$res=$client->sendMessage($phone, $temp_id, $temp_para);
if($res['http_code'] ==200) {
$data['expires_time'] = time() + 300;
$data['code'] = $temp_para['code'] ;
$data['phone'] = $phone;
//先删除该手机号的验证码数据,
Db::name('send_code')->where(['phone'=>$phone])->delete();
Db::name('send_code')->insert($data);
return $this->returnJson([]);
} else {
$this->returnJson([],'短信验证码发送失败','400');
}
}
//修改|忘记密码
public function changePassword() {
if(request()->isPost()) {
$original_password = md5(Request::param('original_password'));
$new_password = md5(Request::param('new_password'));
$code = Request::param('code');
$phone = Request::param('phone');
if($code){
if(Common::rightCode($phone,$code)){
$change = Db::name('user')->where(['phone'=>$phone])->save(['password'=>$new_password]);
if($change){
return $this->returnJson([]);
} else {
return $this->returnJson([],'修改失败',400);
}
} else {
return $this->returnJson([],"验证码不正确",400);
}
} else {
//验证原密码是否正确
$is_exit = Db::name('user')->where(['phone'=>$phone,'password'=>$original_password])->find();
if($is_exit) {
$change = Db::name('user')->where(['phone'=>$phone])->save(['password'=>$new_password]);
if($change){
return $this->returnJson();
} else {
return $this->returnJson([],'修改失败',400);
}
} else {
return $this->returnJson([],'验证码不正确',400);
}
}
} else {
return $this->returnJson([],'请求方式不正确',400);
}
}
}
\ 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,pic')->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 !== false){
return $this->returnJson(Common::changeField($data));
} else {
return $this->returnJson();
}
}
//公告详情
public function detailNotice() {
$notice_id = Request::param('notice_id');
$where['notice_id'] = $notice_id;
$data = Db::name('notice')->where($where)->find();
return $this->returnJson(Common::changeField($data),'success');
}
//公告列表
public function noticeList() {
$where['village_id'] = Request::param('village_id');
$page = Request::param('page',1);
$data = Db::name('notice')->order(['sort_id'=>'desc','create_time'=>'desc'])->where($where)->field('notice_id,title,author,create_time,content')->page($page,config('app.limit'))->select()->toArray();
$total = Db::name('notice')->where($where)->count();
foreach ($data as $k =>$v) {
$data[$k]['content'] = mb_substr(strip_tags($v['content']),0,100);
}
$res['total'] = $total;
$res['data'] = Common::changeField($data);
return $this->returnJson($res);
}
}
\ 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 Payorder extends Base
{
//业主所有房间下的未缴费的水电物业等,只有业主才能看到记录
public function payList() {
//获取是业主身份的房间
$vacancys = Db::name('house_user_bind')->alias('hub')
->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
->leftJoin('house_village hvi','hvi.village_id = hv.village_id')
->where(['hub.type'=>0,'hub.status'=>1,'hub.uid'=>$this->uid])
->field('hub.house_user_bind_id,hv.vacancy_id,hv.vacancy_code,hv.layout_id,hvi.village_name,hv.property_end_time')
->select()->toArray();
if($vacancys) {
$convertArr = $this->convertArr;
$array_keys = array_keys($convertArr);
foreach ($vacancys as $k =>$v) {
$where['vacancy_id'] = $v['vacancy_id'];
$where['is_pay'] = 0;
$res = Common::getVacancyAddress($v['vacancy_code'],$v['layout_id']);
$vacancys[$k]['vacancy_address'] = $res['vacancy_address'];
foreach ($convertArr as $key=>$value) {
$where['type'] = $key;
//如果是物业费用,根据物业服务结束时间,赛选数据,其他不用
if($key=='property') {
$property_end_time = $v['property_end_time'];
$dataInfo = Db::name('cost')->where($where)->where('cost_month','>',$property_end_time)->order('create_time','desc')->field('cost_id,pay_money,create_time')->select()->toArray();
} else {
$dataInfo = Db::name('cost')->where($where)->order('create_time','desc')->field('cost_id,pay_money,create_time')->select()->toArray();
}
if(!$dataInfo) {
continue;
}
$total = 0;
$costIds=[];
foreach ($dataInfo as $ke =>$va) {
$total+=$va['pay_money'];
$costIds[]=$va['cost_id'];
}
//总金额
$rest['money'] =$total;
$rest['type'] = $key;
$rest['type_zh'] = $convertArr[$key];
$rest['create_time'] = $dataInfo[0]['create_time']; //最近的账单生成的时间
$rest['cost_ids'] = $costIds;
$vacancys[$k]['pay_list'][] = Common::changeField($rest);
}
//获取自定义的
unset($where['type']);
$dataInfo = Db::name('cost')->where($where)->whereNotIn('type',$array_keys)->order('create_time','desc')->field('cost_id,pay_money,create_time')->select()->toArray();
if(!$dataInfo) {
continue;
}
$total = 0;
$costIds=[];
foreach ($dataInfo as $ke =>$va) {
$total+=$va['pay_money'];
$costIds[]=$va['cost_id'];
}
$rest_other['money'] = $total;
$rest_other['type'] = "other";
$rest_other['type_zh'] = "自定义";
$rest_other['create_time'] = $dataInfo[0]['create_time']; //最近的账单生成的时间
$rest_other['cost_ids'] = $costIds;
$vacancys[$k]['pay_list'][] = Common::changeField($rest_other);
}
//删除没有收费的房间
foreach ($vacancys as $ke => $va) {
if(empty($va['pay_list']) || !isset($va['pay_list'])) {
unset($vacancys[$ke]);
}
}
$vacancys = array_values($vacancys);
} else {
$vacancys = [];
}
return $this->returnJson($vacancys);
}
//查看已缴费的列表
public function getPayList() {
//获取是业主身份的房间
$vacancys = Db::name('house_user_bind')->alias('hub')
->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
->leftJoin('house_village hvi','hvi.village_id=hv.village_id')
->where(['hub.type'=>0,'hub.status'=>1,'hub.uid'=>$this->uid])
->field('hub.house_user_bind_id,hv.vacancy_id,hv.vacancy_code,hv.layout_id,hvi.village_name')
->select()->toArray();
if($vacancys) {
$convertArr = $this->convertArr;
$array_keys = array_keys($convertArr);
$unit = $this->myUnit;
foreach ($vacancys as $k =>$v) {
$where=[];
$where['vacancy_id'] = $v['vacancy_id'];
$where['is_pay'] = 1;
$res = Common::getVacancyAddress($v['vacancy_code'],$v['layout_id']);
$vacancys[$k]['vacancy_address'] = $res['vacancy_address'];
foreach ($convertArr as $key=>$value) {
$where['type'] = $key;
//总金额
$data= Db::name('cost')->where($where)->sum('pay_money');
//如果金额是0就跳过
if($data == 0) {
continue;
}
// echo json_encode($where);
$rest['total_money'] = $data;
if($key == "property" || $key =="park"){
$count = Db::name('cost')->where($where)->count();
$total_num = $count."个月";
} else if($key == "water" || $key=="electric" || $key == "gas") {
$num = Db::name('cost')->where($where)->sum('area');
$total_num = $num.$unit[$key];
}
$rest['total_num'] = $total_num;
$rest['name'] = $key;
$rest['name_zh'] = $value;
//获取最近的支付订单时间
$time = Db::name('cost')->where($where)->order('pay_time','desc')->value('pay_time');
$rest['pay_time'] = $time;
$all[] = $rest;
}
//获取自定义的
unset($where['type']);
$count = Db::name('cost')->where($where)->whereNotIn('type',$array_keys)->sum('pay_money');
//获取最近一次支付时间
$time = Db::name('cost')->where($where)->whereNotIn('type',['property','water','gas','electric','park'])->order('pay_time','desc')->value('pay_time');
$other['pay_time'] = $time;
$other['name'] = "other";
$other['name_zh'] = "自定义";
$other['total_num'] = $count;
if($other['total_num'] !=0){
$all[] = $other;
}
if(empty($all)) {
unset($vacancys[$k]);
} else {
$vacancys[$k]['pay_list'] = Common::changeField($all,'pay_time');
//需要删除$all,数组,不然会影响下一次循环
unset($all);
}
}
} else {
$vacancys = [];
}
return $this->returnJson($vacancys,'pay_time');
}
//某个房间下的某个收费项的以缴费缴费列表
public function vacancyPayedList(){
$vacancy_id = Request::param('vacancy_id');
$type = Request::param('type'); //property|water|electric|gas|park|other,除了other,其他都能对应表中的type
$page = Request::param('page',1);
$convertArr = $this->convertArr;
if(in_array($type,array_keys($convertArr))){
$where[] = ['type','=',$type];
} else {
$where[] = ['type','not in',array_keys($convertArr)];
}
$where[] = ['vacancy_id','=',$vacancy_id];
$where[] = ['is_pay','=',1];
//先查询是否合法
$is_exit = Db::name('house_user_bind')->where(['uid'=>$this->uid,'vacancy_id'=>$vacancy_id,'type'=>0])->find();
if(!$is_exit) {
return $this->returnJson([],'查询错误!',400);
}
$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();
$total = Db::name('cost')->where($where)->count();
$res['total'] = $total;
$res['data'] = $data;
return $this->returnJson($res);
}
//某个房间下的某个收费项的未缴费缴费列表
//具体房间未缴费列表
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);
$convertArr = $this->convertArr;
if(in_array($type,array_keys($convertArr))){
$where[] = ['type','=',$type];
} else {
$where[] = ['type','not in',array_keys($convertArr)];
}
$where[] = ['vacancy_id','=',$vacancy_id];
$where[] = ['is_pay','=',0];
//查询该房间的服务结束时间,只有物业费才需要判断,
if($type == 'property') {
$property_end_time = Db::name('house_vacancy')->where(['vacancy_id'=>$vacancy_id])->value('property_end_time');
if($property_end_time){
$where[] = ['cost_month','>',$property_end_time];
} else {
//展示空数据
return $this->returnJson();
}
}
//先查询是否合法
$is_exit = Db::name('house_user_bind')->where(['uid'=>$this->uid,'vacancy_id'=>$vacancy_id,'type'=>0])->find();
if(!$is_exit) {
return $this->returnJson([],'查询错误!',400);
}
$data = Db::name('cost')->where($where)->page($page,config('app.limit'))->order('cost_month','asc')->field('cost_id,cost_month,pay_money,type')->select()->toArray();
$total = Db::name('cost')->where($where)->count();
$res['total'] = $total;
$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();
$typeArr = $this->convertArr;
$myunit = $this->myUnit;
$priceUnit = $this->priceUnit;
$vacancyInfo = Db::name('house_vacancy')->where(['vacancy_id'=>$data['vacancy_id']])->field('vacancy_code,layout_id')->find();
$vacancyAddress = Common::getVacancyAddress($vacancyInfo['vacancy_code'],$vacancyInfo['layout_id']);
$data['vacancy_address'] = $vacancyAddress['vacancy_address'];
$data['type_zh'] = isset($typeArr[$data['type']]) ? $typeArr[$data['type']] : "自定义";
if($data['is_pay']==1) {
$orderInfo = Db::name('pay_order')->where(['order_id'=>$data['order_id']])->field('order_num,pay_type')->find();
if($orderInfo) {
$data['pay_type'] = $orderInfo['pay_type'];
$data['order_num'] = $orderInfo['order_num'];
} else {
$data['pay_type'] = "暂无";
$data['order_num'] = "暂无";
}
} else {
$data['pay_type'] = "暂无";
$data['order_num'] = "暂无";
}
if(in_array($data['type'],['water','electric','gas','property'])) {
$data['area'] = $data['area'].$myunit[$data['type']];
$data['price'] = $data['price'].$priceUnit[$data['type']];
} else{
$data['area'] = "无";
$data['price'] = "暂无";
}
return $this->returnJson(Common::changeField($data,['pay_time','create_time']));
}
//生成订单
public function createOrder(){
$vacancy_id = Request::param('vacancy_id');
$bind_id = Request::param('bind_id');
$cost_ids = Request::param('cost_ids');
//验证物业费订单是否是连续的
$where['type'] = 'property';
$where['is_pay'] = 0;
$where['vacancy_id'] = $vacancy_id;
//获取房间的物业服务时间,
$property_end_time = Db::name('house_vacancy')->where(['vacancy_id'=>$vacancy_id])->value('property_end_time');
if($property_end_time) {
$whereOne[] = ['cost_month','>',$property_end_time];
} else {
$whereOne = [];
}
$property_cost_ids = Db::name('cost')->where($where)->where($whereOne)->whereIn('cost_id',$cost_ids)->column('cost_id'); //上传的未缴物业费的连续cost_id
//如果物业费选择了,则判断
if($property_cost_ids) {
$limit = count($property_cost_ids);
$cost_property_ids = Db::name('cost')->where($where)->where($whereOne)->limit($limit)->column('cost_id');
if($cost_property_ids != $property_cost_ids) {
return $this->returnJson([],'物业费缴费必须连续!',400);
}
}
$total_money = Request::param('total_money',0);
//判断金额是否一致
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;
//cost表中关联order_id
Db::name('cost')->whereIn('cost_id',$cost_ids)->save(['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);
Db::name('pay_order')->where(['order_id'=>$order_id])->save(['pay_type'=>"支付宝"]);
//微信支付
} 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);
//更改订单的支付方式
Db::name('pay_order')->where(['order_id'=>$order_id])->save(['pay_type'=>"微信"]);
}
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->apiVersion = '1.0';
// $aop->postCharset = 'utf-8';
// $aop->format = 'json';
$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->signType = config('app.pay_alipay_sign_type');
$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');
$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
namespace app\api\controller;
use app\BaseController;
use think\facade\Db;
class Payreturn extends BaseController
{
//支付宝支付成功后的异步通知地址
public function aliPayReturn() {
require_once "../extend/aliPay/AopClient.php";
//生成日志
$this->createPayLog($_POST,"支付宝");
$aop = new \AopClient();
$public_key = config('app.pay_alipay_public_key');
$aop->alipayrsaPublicKey = $public_key;
$flag = $aop->rsaCheckV1($_POST, NULL, "RSA2");
if($flag){
if($this->changePayStatus($_POST['out_trade_no'])){
die('success');
}
}
die('fail');
}
//微信 值后的异步通知地址
public function weiXinPayReturn(){
$testxml = file_get_contents("php://input");
$jsonxml = json_encode(simplexml_load_string($testxml, 'SimpleXMLElement', LIBXML_NOCDATA));
$result = json_decode($jsonxml, true);
//生成日志
$this->createPayLog($result,"微信");
if($result){
//如果成功返回了
if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
if($this->changePayStatus($result['out_trade_no'])){
die("<xml>
<return_code><![CDATA[SUCCESS]]></return_code>
<return_msg><![CDATA[OK]]></return_msg>
</xml>");
}
}
}
}
//根据获取到的订单id,更改状态,更改房间的物业服务时间
private function changePayStatus($out_trade_no) {
$where['order_num'] = $out_trade_no;
$save['pay_time'] = time();
$save['is_pay'] = 1;
$cost_ids = DB::name('pay_order')->where(['order_num'=>$out_trade_no])->value('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();
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('cost')->where('cost_id','in',$cost_ids_arr)->save($save);
Db::commit();
return true;
}catch(\Exception $e){
Db::rollback();
return false;
}
}
public function createPayLog($data,$type){
$save['create_time'] = time();
$save['data'] = json_encode($data);
$save['type'] = $type;
$save['out_trade_no'] = $data['out_trade_no'];
Db::name('pay_log')->insert($save);
}
}
\ No newline at end of file
<?php
namespace app\api\controller;
use app\common\controller\Common;
use think\facade\Db;
use think\facade\Request;
use function fast\e;
class User extends Base
{
//获取用户所入住的小区|搜索小区
public function getUserVillage() {
$keyword = Request::param('keyword','');
$page = Request::param('page',1);
// $province_id = Request::param('province_id');
// $city_id = Request::param('city_id');
// $area_id = Request::param('area_id');
$where =[];
if($keyword) { //如果有关键字就搜索关键字的小区
$villages = Db::name('house_village')->where($where)->where('village_name','like','%'.$keyword.'%')->field('village_name,village_id,province_name,city_name,area_name,village_logo,village_address')->page($page,config('app.limit'))->select()->toArray();
$res['total'] = Db::name('house_village')->where($where)->where('village_name','like','%'.$keyword.'%')->count();
$rest=[];
foreach ($villages as $k =>$v) {
$rest['village_name'] = $v['village_name'];
$rest['village_id'] = $v['village_id'];
$rest['village_address'] = $v['province_name'].$v['city_name'].$v['area_name'].$v['village_address'];
$rest['village_logo'] = $v['village_logo'];
$rest['vacancy'] = Common::getVacancy($v['village_id'],$this->uid);
$res['data'][] = $rest;
}
} else { //没有就展示已入住的小区
$where['hub.uid'] = $this->uid;
$where['hub.status'] = 1;
$village_ids = DB::name('house_user_bind')->alias('hub')->where($where)->group('village_id')->column('village_id');
$village_info = Db::name('house_village')->whereIn('village_id',$village_ids)->field('village_name,village_id,province_name,city_name,area_name,village_logo,village_address')->select()->toArray();
$res['total'] = count($village_ids);
$rest=[];
foreach ($village_ids as $k =>$v) {
foreach ($village_info as $key =>$val) {
if($val['village_id'] == $v) {
$rest['village_name'] = $val['village_name'];
$rest['village_id'] = $val['village_id'];
$rest['village_address'] = $val['province_name'].$val['city_name'].$val['area_name'].$val['village_address'];
$rest['village_logo'] = $val['village_logo'];
break;
}
}
$rest['vacancy'] = Common::getVacancy($v,$this->uid);
$res['data'][] = $rest;
}
}
if($res['total']==1){
$res['data'] = array_values($res['data']);
}
$res['keyword'] = $keyword;
return $this->returnJson($res);
}
//用户设置密码
public function setPassword() {
$password = Request::param('password');
if(strlen($password) <7) {
return $this->returnJson([],'密码长度最起码7位',400);
}
$data['password'] = md5($password);
$save = Db::name('user')->where(['uid'=>$this->uid])->save($data);
if($save) {
return $this->returnJson();
} else {
return $this->returnJson([],'设置失败',400);
}
}
//用户绑定房间
public function userBindVacancy(){
//判断参数是否为空
$data['type'] = Request::param('type');
$village_id = Request::param('village_id');
$vacancy_id = Request::param('vacancy_id');
$data['vacancy_id'] = $vacancy_id;
$data['name'] = $car['name'] = Request::param("name");
$data['phone'] = $car['phone'] = Request::param("phone");
$data['village_id'] = $car['village_id']= $village_id;
$is_exit = Common::getOwnerInfo($vacancy_id);
$data['id_card'] = Request::param("id_card");
$data['uid'] =$car['uid'] = $this->uid;
$data['status'] = 2;
$data['create_time'] =$car['create_time']= time();
$data['memo'] = Request::param('memo');
$car['brand'] = Request::param('brand');
$car['car_type'] = Request::param('car_type');
$car['license_plate'] = Request::param('license_plate');
$car['car_color'] = Request::param('car_color');
//查看当前手机号是否重复绑定当前房间,一个房间对应的一个手机号只能有一种身份
$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) { //申请业主不需要填写业主后四位手机号
//检查该房间是否有房主绑定
if(!empty($is_exit)){
return $this->returnJson([],'该房间下已有业主!',400);
}
$save['id_card'] = $data['id_card'];
$save['name'] = $data['name'];
$save['phone'] = $data['phone'];
$save['uid'] = $data['uid'];
//修改房间的信息
Db::name('house_vacancy')->where(['vacancy_id'=>$vacancy_id])->save($save);
}else{
if(empty($is_exit)){
return $this->returnJson([],'该房间未绑定业主,不能绑定租客!',400);
}
$ownerPhone = $is_exit['phone'];
$phone_num = Request::param('phone_num');
if($phone_num != substr($ownerPhone,7)){
return $this->returnJson([],'业主后四位手机号不正确!',400);
}
}
Db::startTrans();
try{
Db::name('house_user_bind')->save($data);
if($car['brand'] && $car['car_type'] && $car['license_plate']) {
//查看系统中是否存在了,存在则修改,不存在则添加
$is_exit = Db::name('car')->where(['village_id'=>$village_id,'license_plate'=>$data['license_plate']])->find();
if($is_exit){
Db::name('car')->where(['village_id'=>$village_id,'license_plate'=>$data['license_plate']])->save($car);
}else{
Db::name('car')->save($car);
}
}
Db::commit();
return $this->returnJson();
}catch(\Exception $e){
Db::rollback();
return $this->returnJson([],'绑定失败,请重试!',400);
}
}
//用户申请解绑
public function userUnBind(){
$where['house_user_bind_id'] = Request::param('house_user_bind_id');
$where['uid'] = $this->uid;
$save['status'] = 4;
$change =Db::name('house_user_bind')->where($where)->save($save);
if($change) {
return $this->returnJson([],'申请成功!');
} else {
return $this->returnJson([],'申请失败!',400);
}
}
//查看所有的房间,如果是业主,展示房间下的所有租客或家属
// public function getUserVacancy() {
// $uid = $this->uid;
// $where['hub.uid'] = $uid;
// $data = Db::name('house_user_bind')->alias('hub')
// ->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
// ->leftJoin('house_village hvi','hvi.village_id = hub.village_id')
// ->where($where)->whereIn('hub.status',[1,2,4])
// ->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();
// foreach ($data as $k =>$v) {
// $data[$k]['vacancy_address'] = Common::getVacancyAddress($v['vacancy_code'],$v['layout_id']);
// if($v['type'] ==0) {
// //如果是业主身份,查找下面的租客或家属等
// $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();
// }else{
// //如果是租客身份,查找所属业主
// $data[$k]['myOwner'] = Db::name('house_user_bind')->where(['vacancy_id'=>$v['vacancy_id'],'type'=>0,'status'=>1])->field('name,phone,status')->find();
// }
// }
//
// return $this->returnJson($data);
// }
//个人中心,如果没与传递bind_id,则返回最新的已绑定的房间信息
public function person(){
$bind_id = Request::param('bind_id');
$village_id = Request::param('village_id');
if($bind_id){
$where['hub.house_user_bind_id'] = $bind_id;
$where['hub.status'] = 1;
}
$where['hub.uid'] = $this->uid;
$where['hub.village_id'] = $village_id;
$data = Db::name('house_user_bind')->alias('hub')
->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
->leftJoin('user','user.uid = hub.uid')
->order('hub.create_time','desc')
->where($where)
->field('hub.house_user_bind_id as bind_id,hub.name,hv.vacancy_code,hv.layout_id,hv.village_id,user.sex,user.nickname,user.avatar,user.face_img')
->find();
if(!$data) {
//如果,新用户,只能返回基础信息
$whereOne['uid'] = $this->uid;
$data = Db::name('user')->alias('user')
->where($whereOne)->field('user.sex,user.nickname,user.avatar,user.face_img')->find();
}
//获取当日值班电话
$phone = Db::name('village_phone')->where(['village_id' => $village_id, 'is_on_call_phone' => 1, 'status' => 1])->value('phone');
$data['today_phone'] = $phone;
if(isset($data['vacancy_code'])) {
$res = Common::getVacancyAddress($data['vacancy_code'],$data['layout_id']);
$data['vacancy_address'] = $res['vacancy_address'];
}
return $this->returnJson($data);
}
//更改人脸图片信息
public function changeUserFaceImg() {
$where['uid'] = $this->uid;
$data['face_img'] = Request::param('face_img');
if(empty($data)) {
return $this->returnJson([],'图片必传!',400);
}
$change = Db::name('user')->where($where)->save($data);
if($change) {
return $this->returnJson();
} else {
return $this->returnJson([],'更改失败!');
}
}
//人脸图片文件上传
public function uploadFaceImg() {
$path = Request::param('path','face');
$file = request()->file('img');
if(!$file || !in_array($path,['header','face'])){
return $this->returnJson([],'参数错误!',400);
}
$path = '/'.$path;
$data = Common::uploadImg($file,$path);
if($data) {
return $this->returnJson($data,'success');
} else {
return $this->returnJson([],'请上传图片文件',400);
}
}
//多图片上传接口(form表单形式)
public function uploadImgs() {
$file = $_FILES['images'];
$arr = [];
foreach ($file['type'] as $k){
$ext_arr = explode('/',$k);
if(!in_array($ext_arr[1],['jpeg','jpg','gif','bmp','png'])) {
return $this->returnJson([],'请上传图片文件',400);
}
$ext[] = $ext_arr[1];
}
foreach ($file['tmp_name'] as $k=>$v) {
$path = './upload/feedback/';
$filename = date("YmdHis").getRandomStr(10).'.'.$ext[$k];
if(move_uploaded_file($v,$path.$filename)){
$arr[] = "http://".$_SERVER['SERVER_NAME']."/upload/feedback/".$filename;
}else{
return $this->returnJson([],'图片上传失败!',400);
}
}
if($arr) {
return $this->returnJson($arr,'success');
} else {
return $this->returnJson([],'图片上传失败!',400);
}
}
//通过base64图片上传
public function uploadImgsBase(){
$arr = Request::param('images');
$res = [];
if(empty($arr)) {
return $this->returnJson([],'请上传图片!',400);
}
foreach ($arr as $v) {
if (preg_match('/^(data:\s*image\/(\w+);base64,)/',$v,$result)){
$ext = $result[2];//图片后缀
$path = './upload/feedback/';
$filename = date("YmdHis").getRandomStr(10).'.'.$ext;
$new_file=$path.$filename;
if (!file_exists($path)) {
//检查是否有该文件夹,如果没有就创建,并给予最高权限
mkdir($path, 0777,true);
}
if(file_put_contents($new_file, base64_decode(str_replace($result[1], '', $v)))) {
$res[] = "http://".$_SERVER['SERVER_NAME']."/upload/feedback/".$filename;
}
} else {
return $this->returnJson([],'请上传正确的数据!',400);
}
}
return $this->returnJson($res,'success');
}
//设置本次登入的房间未最近一次登入的,下次登入自动切换
public function setUserBind(){
$bind_id = Request::param('house_user_bind_id');
$uid = $this->uid;
Db::name('house_user_bind')->where(['uid'=>$uid])->save(['is_lately_login'=>0]);
Db::name('house_user_bind')->where(['uid'=>$uid,'house_user_bind_id'=>$bind_id])->save(['is_lately_login'=>1]);
return $this->returnJson([],'success');
}
//修改头像和昵称
public function changeUserInfo() {
$data['nickname'] = Request::param('nickname');
$data['sex'] = Request::param('sex');
$data['avatar'] = Request::param('avatar');
$where['uid'] = $this->uid;
$change = Db::name('user')->where($where)->save($data);
if($change) {
return $this->returnJson();
} else {
return $this->returnJson([],'修改失败!',400);
}
}
}
\ No newline at end of file
<?php
namespace app\api\controller;
use app\common\controller\Common;
use app\common\controller\Jpush;
use think\facade\Db;
use think\facade\Request;
class Village extends Base
{
//搜索小区
public function test() {
// $phone = "135883180489";
// $content = "新版本推送";
// Jpush::push_oppo($phone,$content);
$arr=[2,1,4,24,57,1,31,434,762];
$length = count($arr);
for($i=0;$i<$length;$i++){
for($j=0;$j<$length-$i-1;$j++) {
if($arr[$j] < $arr[$j+1]) {
$tem = $arr[$j+1];
$arr[$j+1] = $arr[$j];
$arr[$j] = $tem;
}
}
}
return $this->returnJson($arr);
}
}
\ No newline at end of file
...@@ -286,4 +286,3 @@ function changeField($data,$field="create_time",$format="Y-m-d H:i:s") { ...@@ -286,4 +286,3 @@ function changeField($data,$field="create_time",$format="Y-m-d H:i:s") {
...@@ -11,8 +11,8 @@ class Common extends BaseController ...@@ -11,8 +11,8 @@ class Common extends BaseController
//获取省市区 //获取省市区
public function getArea() { public function getArea() {
$where['area_pid'] = Request::param('area_id',0); $where['ParentId'] = Request::param('id',100000);
$data = Db::name('area')->where($where)->field("area_id,area_name")->select()->toArray(); $data = Db::name('area')->where($where)->field("id,Name")->select()->toArray();
return $this->returnJson($data,'success'); return $this->returnJson($data,'success');
} }
...@@ -31,878 +31,63 @@ class Common extends BaseController ...@@ -31,878 +31,63 @@ class Common extends BaseController
} }
//对数组中的时间字段进行日期转换
public static function changeField($data,$field="create_time",$format="Y-m-d H:i:s") {
$prompt = "暂无";
if(empty($data)) {
return $data;
}
foreach($data as $k =>$v) {
if(is_array($v)) {
if(is_array($field)) {
foreach ($field as $value) {
if($v[$value] != 0 || !is_null($v[$value])){
$data[$k][$value] = date($format,$v[$value]);
} else {
$data[$k][$value] = $prompt;
}
}
} else {
if($v[$field] != 0 || !is_null($v[$field])){
$data[$k][$field] = date($format,$v[$field]);
} else {
$data[$k][$field] = $prompt;
}
}
} else {
if(is_array($field)) {
foreach ($field as $value) {
if(isset($data[$value]) || $data[$value] !=0){
$data[$value] = date($format,$data[$value]);
} else{
$data[$value] = $prompt;
}
}
break;
} else {
if(isset($data[$field]) || $data[$field] !=0) {
$data[$field] = date($format, $data[$field]);
} else {
$data[$field] = $prompt;
}
break;
}
}
}
return $data;
}
//对数组中的图片字段进行日期转换
public static function changeImg($data,$field="pic"){
if(empty($data)){
return $data;
}
if(isHTTPS()){
$http = "https://";
} else{
$http = 'http://';
}
$server_name = $http.$_SERVER['SERVER_NAME'].'/';
$prompt ='';
foreach($data as $k =>$v) {
if(is_array($v)) {
if(is_array($field)) {
foreach ($field as $value) {
if($v[$value] != '' || !is_null($v[$value])){
$data[$k][$value] = $server_name.$v[$value];
} else {
$data[$k][$value] = $prompt;
}
}
} else {
if($v[$field] != '' || !is_null($v[$field])){
$data[$k][$field] = $server_name.$v[$field];
} else {
$data[$k][$field] = $prompt;
}
}
} else {
if(is_array($field)) {
foreach ($field as $value) {
if(isset($data[$value]) || $data[$value] !=0){
$data[$value] =$server_name.$data[$value];
} else{
$data[$value] = $prompt;
}
}
break;
} else {
if(isset($data[$field]) || $data[$field] !=0) {
$data[$field] = $server_name.$data[$field];
} else {
$data[$field] = $prompt;
}
break;
}
}
}
return $data;
}
/**
* @param $url_ids string 1,2,3
* @param $navAl array
* @param $type int 1 所有都赋值,0 给特定的赋值
*/
public static function changeNav($url_ids,$navAl,$type=1) {
$urlsArr = explode(",",$url_ids);
if($type==1 ) {
return $navAl;
} else {
foreach($navAl as $k =>$v ) {
$navAl[$k]['is_power'] =0 ;
if(isset($v['property_nav_id']) && !in_array($v['property_nav_id'],$urlsArr)) {
unset($navAl[$k]) ;
}
if(isset($v['community_nav_id']) && !in_array($v['community_nav_id'],$urlsArr)) {
unset($navAl[$k]);
}
if(isset($v['admin_nav_id']) && !in_array($v['admin_nav_id'],$urlsArr)) {
unset($navAl[$k]);
}
}
}
return $navAl;
}
//获取流水详情,village_money_list表
public static function getWithDrawDetail($where) {
$data = Db::name('village_money_list')->alias('ml')
->leftJoin('house_village hv','ml.village_id = hv.village_id')
->leftJoin('house_property hp','hp.property_id = ml.property_id')
->where($where)
->field("ml.*,hv.village_name,hp.property_name")
->find();
if($data) {
$where_one['order_id'] = $data['order_id'];
switch ($data['table_name']) {
case "pay_order" :
$orderInfo = Db::name('pay_order')->alias('po') //阿里云图片上传
->leftJoin('house_vacancy hv', 'hv.vacancy_id = po.vacancy_id') public function uploadAlioss()
->leftJoin('user u', 'po.uid = u.uid')
->field('po.*,hv.vacancy_address,u.phone,u.nickname')
->where($where_one)
->find();
break;
case "withdraw_order":
$orderInfo = Db::name('withdraw_order')
->where($where_one)->find();
break;
default:
return false;
}
return ['data' => $data, 'orderInfo' => $orderInfo];
} else {
return false;
}
}
//获取流水列表
public static function getWithDrawList($where,$page) {
$count = Db::name('village_money_list')->alias('ml')
->leftJoin('house_village hv','ml.village_id = hv.village_id')
->leftJoin('house_property hp','hp.property_id = ml.property_id')
->where($where)->count();
$data = Db::name('village_money_list')->alias('ml')
->leftJoin('house_village hv','ml.village_id = hv.village_id')
->leftJoin('house_property hp','hp.property_id = ml.property_id')
->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")
->order('ml.create_time','desc')
->page($page,config('app.limit'))->select()->toArray();
return ['total'=>$count,'data'=>$data];
}
//房间导入
public static function importVacancy($filePath,$village_id) {
$where['village_id'] = $village_id;
//设置获取excel对象
$objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容
$objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件
$sheet = $objPHPExcel->getSheet(0);
$dataAll = $objPHPExcel->getSheet(0)->toArray(); //获取导入的数据;
$highestRow = $sheet->getHighestRow(); // 取得总行数
//获取社区布局
$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');
//获取社区不同布局的所有的建筑id
$errorData =[]; //存放导入失败的数据;
for($j=1;$j<$highestRow;$j++)
{ {
if(!empty($dataAll[$j][0]) && !empty($dataAll[$j][4]) &&!empty($dataAll[$j][7]) &&!empty($dataAll[$j][8])){ // 配置文件
$msg = ""; $alioss = config('alioss.');
$vacancyCode = $dataAll[$j][0]; //房间编号 $keyId = $alioss['keyId'];
$layout_list_code = $dataAll[$j][7];//布局 $keySecret = $alioss['keySecret'];
if($layout_list_code) { $endpoint = $alioss['endpoint'];
$layout_id = $layout_list[$layout_list_code]; $bucket = $alioss['bucket'];
$data['layout_id'] = $layout_id; $errors = [
$res_vacancy_code = self::getVacancyCode($vacancyCode,$layout_id); UPLOAD_ERR_INI_SIZE => '上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值',
if($res_vacancy_code['code'] !=200) { UPLOAD_ERR_FORM_SIZE => '上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值',
$msg .= "房间编号不正确!"; UPLOAD_ERR_PARTIAL => '文件只有部分被上传',
UPLOAD_ERR_NO_FILE => '没有文件被上传',
UPLOAD_ERR_NO_TMP_DIR => '找不到临时文件夹',
UPLOAD_ERR_CANT_WRITE => '文件写入失败'
];
if ($_FILES['image']['error'] !== UPLOAD_ERR_OK) {
return $this->returnJson([],$errors[$_FILES['image']['error']],400);
} }
$vacancy_code = $res_vacancy_code['msg']; $file = request()->file('image');
$data['vacancy_code'] = $vacancy_code; if (!$file) {
$parent_id = $res_vacancy_code['parent_id']; return $this->returnJson([],"请选择上传图片",400);
$data['parent_id'] = $parent_id;
} else {
$msg .="社区布局未选择!";
}
$name = $dataAll[$j][1];//业主名字
$id_card = $dataAll[$j][2];//布局;//身份证id
if($id_card && !isCreditNo($id_card)) {
$msg .= "身份证id不符合!";
}
$phone = $dataAll[$j][3];//布局;//手机号
if($phone && !isPhoneNo($phone)) {
$msg .="手机号不符合!";
}
$area = $dataAll[$j][4];//面积
$car_block_name = $dataAll[$j][5];//车库位置
$park_code = $dataAll[$j][6];//车位编号
if($car_block_name && $park_code) {
$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');
$data['park_car_id'] = $park_car_id;
$data['park_block_id'] = $park_block_id;
} }
$info = $file->getInfo();
$house_type = $dataAll[$j][8];//住宅类型 $size = $info['size'];//字节
switch ($house_type) { if ($size > 8 * 1024 * 1024) {
case "住宅" : return $this->returnJson([],"图片大小请不要超过8M",400);
$type =1;
break;
case "商铺" :
$type = 2;
break;
case "办公" :
$type = 3;
break;
default :
$msg.= "住宅类型未选择!";
}
$data['name'] = $bind['name'] = $name;
$data['id_card'] = $bind['id_card']= $id_card;
$data['phone'] = $bind['phone'] = $phone;
$data['area'] = $area;
$data['house_type'] = $type;
$data['create_time'] = $bind['create_time'] = $bind['pass_time']= time();
$data['village_id'] = $bind['village_id'] = $village_id;
if(empty($msg)) { //表明没有错误
$bind['vacancy_id'] = Db::name('house_vacancy')->insertGetId($data);
//导入到userbind表中
$bind['type'] = 0;
$bind['status'] = 1;
if($bind['name'] && $bind['id_card'] && $bind['phone']){
Db::name('house_user_bind')->save($bind);
} }
// 文件名称生成
$name = $info['name'];
$type = substr($name, strrpos($name, '.') + 1);//取后缀
$file_name = sha1(date('YmdHis', time()) . uniqid()) . '.' . $type;
// 文件路径生成
$file_path = 'hotel/hotel/' . $this->admin_id . '/' . date('Ym') . '/' . date('d');
$url = $file_path . '/' . $file_name;
try {
$ossClient = new OssClient($keyId, $keySecret, $endpoint);
$result = $ossClient->uploadFile($bucket, $url, $info['tmp_name']);
if (isset($result['info']['http_code']) AND $result['info']['http_code'] == 200) {
$url_arr = config('alioss.pic_url') . '/' . $url;
} else { } else {
$dataAll[$j][] = $msg; return $this->returnJson([],"图片上传错误",400);
$errorData[] = $dataAll[$j];
}
}else {
$dataAll[$j][] = "数据不能为空!";
$errorData[] = $dataAll[$j];
} }
} catch (OssException $e) {
$msg = $e->getMessage();
return $this->returnJson([],$msg,400);
} }
return $this->returnJson($url_arr);
if(empty($errorData)) {
return ['code'=>200,'data'=>[]];
}else {
//导出错误的数据
$file = "./formwork/importVacancy.xls";
$phpExcel = \PHPExcel_IOFactory::load($file);
$title = ['A','B','C','D','E','F','G','H','I','J'];
$i = 2;
$optionsArr = Db::name('layout_list')->where(['village_id'=>$village_id])->column('code');
$optionsString = implode(',',$optionsArr);//这个是选择布局
$car_blockArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('name');
$optionsCarBlockString = implode(',',$car_blockArr);//这个是车库布局
foreach ($errorData as $k =>$v) {
foreach ($title as $key=>$value) {
$phpExcel->getActiveSheet()->setCellValue($value.$i,$v[$key]);
} }
//设置单元楼下拉
$phpExcel->getActiveSheet()->getCell('H'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
-> setAllowBlank(false)
-> setShowInputMessage(true)
-> setShowErrorMessage(true)
-> setShowDropDown(true)
-> setErrorTitle('输入的值有误')
-> setError('您输入的值不在下拉框列表内.')
-> setPromptTitle('社区布局')
-> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格
$phpExcel->getActiveSheet()->getCell('I'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
-> setAllowBlank(false)
-> setShowInputMessage(true)
-> setShowErrorMessage(true)
-> setShowDropDown(true)
-> setErrorTitle('输入的值有误')
-> setError('您输入的值不在下拉框列表内.')
-> setPromptTitle('房屋类型')
-> setFormula1('"住宅,商铺,办公"');; //这一句为要设置数据有效性的单元格
if($optionsCarBlockString) {
$phpExcel->getActiveSheet()->getCell('F'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
-> setAllowBlank(false)
-> setShowInputMessage(true)
-> setShowErrorMessage(true)
-> setShowDropDown(true)
-> setErrorTitle('输入的值有误')
-> setError('您输入的值不在下拉框列表内.')
-> setPromptTitle('车库位置')
-> setFormula1('"'.$optionsCarBlockString.'"');; //这一句为要设置数据有效性的单元格
}
$i++;
}
$objWriter = new \PHPExcel_Writer_Excel5($phpExcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="房间导入失败数据.xls"');
header('Cache-Control: max-age=0');
$objWriter->save("php://output");
}
}
//通过房间编号获取房间的父id
public static function getParentId($layout_id,$vacancyCode) {
$arr = explode('-',$vacancyCode);
$level= 0;
$parent_id = 0;
foreach($arr as $k => $v) {
$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');
if($layout_build_id) {
$parent_id = $layout_build_id;
}
}
return $parent_id;
}
//通过填写的用户的房间号来转化成真正的房间编号
public static function getVacancyCode($vacancyCode,$layout_id) {
$vacancyCodeArr = explode('-',$vacancyCode);
$roomCode = array_pop($vacancyCodeArr);//去掉最后一个是房间的
$vacancy_code = '';
$parent_id = 0;
$level = 1;
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');
if(!$parent_id){
return ['code'=>400,'msg'=>'房间编号不存在!'];
}
$vacancy_code = $vacancy_code.$parent_id."-";
$level++;
}
$arrCode = explode('-',rtrim($vacancy_code,'-'));
return ['code'=>200,'msg'=>$vacancy_code.$roomCode,'parent_id'=>array_pop($arrCode)];
}
//用户导入
public static function importTenant($filePath,$village_id) {
$where['village_id'] = $village_id;
$objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容
$objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件
$sheet = $objPHPExcel->getSheet(0);
$dataAll = $objPHPExcel->getSheet(0)->toArray(); //获取导入的数据;
$highestRow = $sheet->getHighestRow(); // 取得总行数
$errorData =[]; //存放导入失败的数据;
$insertData = [];
$layout_list = Db::name('layout_list')->where($where)->column('layout_id','code');
for($i=1;$i<$highestRow;$i++) {
$msg="";
$name = $dataAll[$i][0];
if(is_null($name)){
continue;
}
$phone = $dataAll[$i][1];
if(!isPhoneNo($phone)){
$msg.="手机号不正确!";
}
$id_card = $dataAll[$i][2];
if(!isCreditNo($id_card)){
$msg.="身份证号码不正确!";
}
$layout_list_code = $dataAll[$i][5];
if($layout_list_code) {
$layout_id = $layout_list[$layout_list_code];
} else {
$msg.="社区布局未选择!";
}
$vacancyCode = $dataAll[$i][3];
//验证房间编号是否存在,是否合理
$res_vacancy_code = self::getVacancyCode($vacancyCode,$layout_id);
if($res_vacancy_code['code'] !=200) {
$msg.= "房间编号不正确!";
}
$where['vacancy_code'] = $res_vacancy_code['msg'];
$vacancy_id = Db::name('house_vacancy')->where($where)->value('vacancy_id');
$userType = $dataAll[$i][4];
switch($userType){
case "租客":
$type=2;
break;
case "业主":
$type=0;
break;
case "家属":
$type =1;
break;
default :
$msg.="未选择用户身份!";
}
//如果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');
if($is_exit){
$msg.='该房间已绑定业主,请在解绑!';
}
}
$data['vacancy_id'] = $vacancy_id;
$data['village_id'] = $village_id;
$data['id_card'] = $id_card;
$data['name'] = $name;
$data['phone'] = $phone;
$data['type'] = $type;
$data['relatives_type'] =1; //默认
$data['create_time'] = $data['pass_time'] = time();
$data['status'] =1;
if(empty($msg)){
$insertData[] = $data;
} else {
$dataAll[$i][] = $msg;
$errorData[] = $dataAll[$i];
}
}
//导入对的数据
if(!empty($insertData)){
Db::name('house_user_bind')->insertAll($insertData);
}
//如果有错误的数据,导出
if($errorData){
//导出错误的数据
$file = "./formwork/importTenant.xls";
$phpExcel = \PHPExcel_IOFactory::load($file);
$title = ['A','B','C','D','E','F','G'];
$i = 2;
$optionsArr = Db::name('layout_list')->where(['village_id'=>$village_id])->column('code');
$optionsString = implode(',',$optionsArr);//这个是选择布局
foreach ($errorData as $k =>$v) {
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)
-> setAllowBlank(false)
-> setShowInputMessage(true)
-> setShowErrorMessage(true)
-> setShowDropDown(true)
-> setErrorTitle('输入的值有误')
-> setError('您输入的值不在下拉框列表内.')
-> setPromptTitle('社区布局')
-> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格
$phpExcel->getActiveSheet()->getCell('E'.$i)->getDataValidation()-> setType(\PHPExcel_Cell_DataValidation::TYPE_LIST)
-> setErrorStyle(\PHPExcel_Cell_DataValidation::STYLE_INFORMATION)
-> setAllowBlank(false)
-> setShowInputMessage(true)
-> setShowErrorMessage(true)
-> setShowDropDown(true)
-> setErrorTitle('输入的值有误')
-> setError('您输入的值不在下拉框列表内.')
-> setPromptTitle('房屋类型')
-> setFormula1('"租客,业主,家属"'); //这一句为要设置数据有效性的单元格
$i++;
}
$objWriter = new \PHPExcel_Writer_Excel5($phpExcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="用户导入失败数据.xls"');
header('Cache-Control: max-age=0');
$objWriter->save("php://output");
} else {
return ['code'=>200,'data'=>[]];
}
}
//车辆导入
public static function importCar($filePath,$village_id) {
$where['village_id'] = $village_id;
$objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容
$objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件
$sheet = $objPHPExcel->getSheet(0);
$dataAll = $objPHPExcel->getSheet(0)->toArray(); //获取导入的数据;
$highestRow = $sheet->getHighestRow(); // 取得总行数
$errorData =[]; //存放导入失败的数据;
$insertData = [];
for($i=1;$i<$highestRow;$i++) {
$msg="";
$name = $dataAll[$i][0];
$phone = $dataAll[$i][1];
if(!isPhoneNo($phone)){
$msg.="用户手机号不正确!";
}
$license_plate = $dataAll[$i][2];
$car_color = $dataAll[$i][3];
$brand = $dataAll[$i][4];
$car_type = $dataAll[$i][5];
$data['name'] = $name;
$data['phone'] = $phone;
$data['license_plate'] = $license_plate;
$data['car_color'] = $car_color;
$data['create_time'] = time();
$data['village_id'] = $village_id;
$data['brand'] = $brand;
$data['car_type'] = $car_type;
if(empty($msg)){
$insertData[] = $data;
} else {
$dataAll[$i][] = $msg;
$errorData[] = $dataAll[$i];
}
}
if(!empty($insertData)){
Db::name('park_car')->insertAll($insertData);
if($errorData) {
//导出错误的数据
$file = "./formwork/importCar.xls";
$phpExcel = \PHPExcel_IOFactory::load($file);
$title = ['A','B','C','D','E','F','G'];
$i = 2;
$optionsArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('name');
$optionsString = implode(',',$optionsArr);//这个是的车库
foreach ($errorData as $k =>$v) {
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)
-> setAllowBlank(false)
-> setShowInputMessage(true)
-> setShowErrorMessage(true)
-> setShowDropDown(true)
-> setErrorTitle('输入的值有误')
-> setError('您输入的值不在下拉框列表内.')
-> setPromptTitle('车库')
-> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格
$i++;
}
$objWriter = new \PHPExcel_Writer_Excel5($phpExcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="用户导入失败数据.xls"');
header('Cache-Control: max-age=0');
$objWriter->save("php://output");
} else {
return ['code'=>200,'data'=>[]];
}
} else {
return ['code'=>200,'data'=>[]];
}
}
//车位导入
public static function importCarPark($filePath,$village_id) {
$where['village_id'] = $village_id;
$objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容
$objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件
$sheet = $objPHPExcel->getSheet(0);
$dataAll = $objPHPExcel->getSheet(0)->toArray(); //获取导入的数据;
$highestRow = $sheet->getHighestRow(); // 取得总行数
$optionsArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('park_block_id','name');
$errorData =[]; //存放导入失败的数据;
$insertData = [];//存放最后需要插入到数据库的数据
for($i=1;$i<$highestRow;$i++) {
$msg="";
$park_code = $dataAll[$i][0];
$park_block_name = $dataAll[$i][1];
$type_name = $dataAll[$i][2];
if($type_name == "非机动车位"){
$data['type'] =0;
}
if($park_block_name) {
$park_block_id = $optionsArr[$park_block_name];
$data['park_block_id'] = $park_block_id;
} else{
$msg.="车库必选选!";
}
$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) {
$msg.="该车位已存在!";
}
$data['create_time'] = time();
$data['village_id'] = $village_id;
if(empty($msg)){
$insertData[] = $data;
} else {
$dataAll[$i][] = $msg;
$errorData[] = $dataAll[$i];
}
}
if(!empty($insertData)) {
Db::name('park_car')->insertAll($insertData);
if($errorData){
//导出错误的数据
$file = "./formwork/importCarPark.xls";
$phpExcel = \PHPExcel_IOFactory::load($file);
$title = ['A','B','C','D'];
$i = 2;
$optionsArr = Db::name('park_block')->where(['village_id'=>$village_id])->column('name');
$optionsString = implode(',',$optionsArr);//这个是的车库
foreach ($errorData as $k =>$v) {
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)
-> setAllowBlank(false)
-> setShowInputMessage(true)
-> setShowErrorMessage(true)
-> setShowDropDown(true)
-> setErrorTitle('输入的值有误')
-> setError('您输入的值不在下拉框列表内.')
-> setPromptTitle('车库')
-> setFormula1('"'.$optionsString.'"');; //这一句为要设置数据有效性的单元格
$i++;
}
$objWriter = new \PHPExcel_Writer_Excel5($phpExcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="用户导入失败数据.xls"');
header('Cache-Control: max-age=0');
$objWriter->save("php://output");
} else{
return ['code'=>200,'data'=>[]];
}
} else {
return ['code'=>400,'msg'=>'文件内容为空!'];
}
}
//每月水费导入
public static function importCost($filePath,$village_id,$type){
$where['village_id'] = $village_id;
$objReader = \PHPExcel_IOFactory::createReader('Excel5');//配置成2003版本,因为office版本可以向下兼容
$objPHPExcel = $objReader->load($filePath,$encode='utf-8');//$file 为解读的excel文件
$sheet = $objPHPExcel->getSheet(0);
$dataAll = $objPHPExcel->getSheet(0)->toArray(); //获取导入的数据;
$highestRow = $sheet->getHighestRow(); // 取得总行数
$errorData =[]; //存放导入失败的数据;
$insertData = [];//存放最后需要插入到数据库的数据
for($i=1;$i<$highestRow;$i++) {
$msg="";
$vacancy_code = $dataAll[$i][0];
//判断房间号是否存在
$vacancyInfo = Db::name('house_vacancy')->alias('hv')
->leftJoin('layout_build lb','lb.layout_build_id = hv.parent_id')
->where(['hv.village_id'=>$village_id,'hv.vacancy_code'=>$vacancy_code])
->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();
if($vacancyInfo) {
$data['vacancy_id'] = $vacancyInfo['vacancy_id'];
} else {
$msg.="物业编号不存在!";
}
switch ($type){
case "water":
if($vacancyInfo['is_inherit'] ==1) {
$price = $vacancyInfo['water_price'];
} else {
$price = $vacancyInfo['water_fee'];
}
$outFileName = "水费导入失败.xls";
break;
case "electric":
if($vacancyInfo['is_inherit'] ==1) {
$price = $vacancyInfo['electric_price'];
} else {
$price = $vacancyInfo['electric_fee'];
}
$outFileName = "电费导入失败.xls";
break;
case "gas":
if($vacancyInfo['is_inherit'] ==1) {
$price = $vacancyInfo['gas_price'];
} else {
$price = $vacancyInfo['gas_fee'];
}
$outFileName = "燃气费导入失败.xls";
break;
default :
$outFileName = "未知错误.xls";
return ['code'=>400,'msg'=>'小区费用未设置,请先设置费用!'];
}
//查看月份的费用是否存在
$data['cost_month'] = $dataAll[$i][1];
//判断月份是否超过了当前时间,不能导入超前月份
if(strtotime(date('Y-m',time())) <= strtotime($data['cost_month'])) {
$msg.="不允许导入超过当前月份的数据!";
}
$data['village_id'] = $village_id;
$data['type'] = $type;
$is_exit = Db::name('cost')->where($data)->find();
if($is_exit) {
$msg.="该条记录已存在!";
}
$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['create_time'] = time();
if(empty($msg)){
$insertData[] = $data;
} else {
$dataAll[$i][3] = $msg;
$errorData[] = $dataAll[$i];
}
}
if(!empty($insertData) || !empty($errorData)) {
Db::name('cost')->insertAll($insertData);
if($errorData){
//导出错误的数据
if($type == "water") {
$file = "./formwork/importWater.xls";
} else if($type == "electric") {
$file = "./formwork/importElectric.xls";
} else {
$file = "./formwork/importGas.xls";
}
$phpExcel = \PHPExcel_IOFactory::load($file);
$title = ['A','B','C','D'];
$i = 2;
foreach ($errorData as $k =>$v) {
foreach ($title as $key=>$value) {
$phpExcel->getActiveSheet()->setCellValue($value.$i,$v[$key]);
}
$i++;
}
$objWriter = new \PHPExcel_Writer_Excel5($phpExcel);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename='.$outFileName);
header('Cache-Control: max-age=0');
$objWriter->save("php://output");
} else{
return ['code'=>200,'data'=>[]];
}
} else {
return ['code'=>400,'msg'=>'文件内容为空!'];
}
}
//验证短信验证码是否正确
public static function rightCode($phone,$code) {
if($code==894582){
return true;
}
$is_exit = Db::name('send_code')->where(['phone'=>$phone,'code'=>$code])->where('expires_time',">",time())->find();
if($is_exit){
return true;
}
return false;
}
//app用户登入之后同步数据
public static function synUserData($uid,$phone) {
//房间列表用户修改
Db::name('house_vacancy')->where(['phone'=>$phone])->save(['uid'=>$uid]);
//汽车关联
Db::name('car')->where(['phone'=>$phone])->save(['uid'=>$uid]);
//
Db::name('house_user_bind')->where(['phone'=>$phone])->save(['uid'=>$uid]);
}
//通过房间编号和布局id获取房间地址
public static function getVacancyAddress($vacancyCode,$layout_id) {
$layoutCode = Db::name('layout_list')->where(['layout_id'=>$layout_id])->value('code');
$codeArr = explode('-',$layoutCode);
$rom = array_pop($codeArr); //获取最后一个房间的单位
$arr = explode('-',$vacancyCode);
$room_code = array_pop($arr);
$string = '';
$room_num = '';
foreach ($arr as $v) {
$code_name = Db::name('layout_build')->where(['layout_build_id'=>$v])->field('code,level')->find();
$key = $code_name['level'] -1;
$string.=$code_name['code'].$codeArr[$key];
$room_num.=$code_name['code']."-";
}
$room_num = $room_num.$room_code;
return ['vacancy_address'=>$string.$room_code.$rom,'room_num'=>$room_num];
}
//通过房间id获取业主信息
public static function getOwnerInfo($vacancy_id) {
$data = Db::name('house_user_bind')->where(['vacancy_id'=>$vacancy_id,'type'=>0,'status'=>1])->field('type,status,phone,name')->find();
return $data??[];
}
//获取需要绑定人员设备
public static function getUserBindType() {
return ['0'=>'业主','1'=>'家人','2'=>'租客','3'=>'替换业主'];
}
//获取需要绑定人员设备
public static function getFamilyBindType() {
return ['1'=>'配偶','2'=>'父母','3'=>'子女','4'=>'亲戚','5'=>'好友'];
}
//根据查询到的小区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])
->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;
}
//图片上传
public static function uploadImg($file,$path) {
$ext = $file->getOriginalExtension();
if(!in_array($ext,['jpeg','jpg','gif','bmp','png'])) {
return false;
}
$savename = \think\facade\Filesystem::putFile($path, $file);
$data['data'] = "/upload/".$savename;
return $data;
}
} }
\ No newline at end of file
...@@ -7,4 +7,7 @@ return [ ...@@ -7,4 +7,7 @@ return [
// \think\middleware\LoadLangPack::class, // \think\middleware\LoadLangPack::class,
// Session初始化 // Session初始化
// \think\middleware\SessionInit::class // \think\middleware\SessionInit::class
// 'alias' => [
// 'checkData' => app\middleware\CheckValidata::class
// ],
]; ];
<?php
declare (strict_types = 1);
namespace app\middleware;
use think\facade\Validate;
class CheckValidata
{
/**
* 处理请求
*
* @param \think\Request $request
* @param \Closure $next
* @return Response
*/
public function handle($request, \Closure $next)
{
$action = request()->action(); //根据路由获取对应的方法
$controller = request()->controller(); //根据路由获取对应的方法
$module = app('http')->getName(); //获取模块名
$param = $request->param(); //获取所有的参数
$fun = $module . "_" . $controller."_".$action;//数组的key的验证规则
$this->$fun($param);
return $next($request);
}
function __call($name, $arguments)
{
$filename = dirname(dirname(dirname(__FILE__)))."/config/validata.php";
if(file_exists($filename)) {
require $filename;
if(isset($validatarule[$name])) {
$validate = Validate::rule($validatarule[$name]);
$this->returnMsg($validate, $arguments[0]);
}
}
}
public function returnMsg($validate, $param)
{
$result = $validate->check($param);
if (!$result) {
$msg = $validate->getError();
$rs['code'] = "000001";
$rs['message'] = $msg;
$rs['data'] = [];
echo json_encode($rs);
exit;
}
}
}
<?php
namespace app\wechatapi\controller;
use app\BaseController;
use think\facade\Db;
use think\facade\Request;
class Company extends BaseController
{
//公司详情
public function companyDetail()
{
$where['company_id'] =1;
$data = Db::name('company')->where($where)->find();
return $this->returnJson($data);
}
//获取导航栏的相对于的文字内容
public function getWord()
{
$nav_id = Request::param('nav_id');
$where['nav_id'] = $nav_id;
$res = Db::name('web_word')->where($where)->find();
$result = json_decode($res['content'],true);
return $this->returnJson($result);
}
//导航栏列表
public function navList()
{
$where['web_id'] = Request::param('web_id',1);
$data = Db::name('web_nav')->where($where)->order(['sort'=>'desc','nav_id'=>'asc'])->select()->toArray();
return $this->returnJson($data);
}
}
<?php
namespace app\wechatapi\controller;
use app\BaseController;
use think\facade\Db;
use think\facade\Request;
class Message extends BaseController {
protected $middleware = ['app\middleware\CheckValidata::class'];
public function submitMessage(){
$data['province_id'] = Request::param('province_id',0);
$data['city_id'] = Request::param('city_id',0);
$data['area_id'] = Request::param('area_id',0);
$data['area_name'] = Request::param('area_name');
$data['province_name'] = Request::param('province_name');
$data['city_name'] = Request::param('city_name');
$data['ip'] = Request::ip();
$data['industry'] = Request::param('industry',''); //行业
$data['city_name'] = Request::param('from',0);
$data['content'] = Request::param('content');
$data['user_name'] = Request::param('user_name');
$data['create_time'] = time();
$data['phone'] = Request::param('phone');
$data['business'] = Request::param('business','');
$add = Db::name('message')->insert($data);
if($add) {
return $this->returnJson([],200);
} else {
return $this->returnJson([],'添加失败!','400');
}
}
}
\ No newline at end of file
<?php
// +----------------------------------------------------------------------
// | 阿里云OSS配置
// +----------------------------------------------------------------------
return [
'keyId' => 'LTAI4GFAtgRK4cSyZ9DVBEd3', //Access Key ID
'keySecret' => 'e6n82Q4Hiha49gSBexTBKVAqR2Wrrg', //Access Key Secret
'endpoint' => 'http://oss-cn-hangzhou.aliyuncs.com', //阿里云oss 外网地址endpoint
'bucket' => 'coboriel', //Bucket名称
'pic_url'=>'https://pic.coboriel.com',//阿里云oss
];
...@@ -83,7 +83,8 @@ return [ ...@@ -83,7 +83,8 @@ return [
'keyId' => 'LTAI4GFAtgRK4cSyZ9DVBEd3', //Access Key ID 'keyId' => 'LTAI4GFAtgRK4cSyZ9DVBEd3', //Access Key ID
'keySecret' => 'e6n82Q4Hiha49gSBexTBKVAqR2Wrrg', //Access Key Secret 'keySecret' => 'e6n82Q4Hiha49gSBexTBKVAqR2Wrrg', //Access Key Secret
'endpoint' => 'http://oss-cn-hangzhou.aliyuncs.com', //阿里云oss 外网地址endpoint 'endpoint' => 'http://oss-cn-hangzhou.aliyuncs.com', //阿里云oss 外网地址endpoint
'bucket' => 'coboriel' //Bucket名称 'bucket' => 'coboriel', //Bucket名称
'pic_url'=>'https://pic.coboriel.com',//阿里云oss
], ],
......
<?php
return $validatarule = [
//修改公司信息
'admin_Company_companyEdit' =>[
'id|参数' => 'require|integer',
'email|邮箱' => 'email',
'phone|手机号' => 'mobile',
'company_name|公司名称' => 'require|max:30',
],
//提交留言验证
'wechatapi_Message_submitMessage' => [
'content|留言内容' => 'require',
'phone|手机号' => 'require|mobile',
'user_name|姓名' => 'require|max:30',
],
//登入
'admin_Login_login' =>[
'account|用户名' => 'require', //第二个可写可不写,如果写了的话,后面自定义msesage可以自动用这个来提示,第三个验证规则可以用来确定表user中的字段的唯一性,需要与username字段对应
'pass_word|密码' => 'require|min:6',
],
];
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