Commit 00ab1955 authored by 蔡闯's avatar 蔡闯

2020-12-21

parents
/.idea
/.vscode
/vendor
*.log
.env
\ No newline at end of file
sudo: false
language: php
branches:
only:
- stable
cache:
directories:
- $HOME/.composer/cache
before_install:
- composer self-update
install:
- composer install --no-dev --no-interaction --ignore-platform-reqs
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip .
- composer require --update-no-dev --no-interaction "topthink/think-image:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0"
- composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0"
- composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0"
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip .
script:
- php think unit
deploy:
provider: releases
api_key:
secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw=
file:
- ThinkPHP_Core.zip
- ThinkPHP_Full.zip
skip_cleanup: true
on:
tags: true
ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn)
All rights reserved。
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
Apache Licence是著名的非盈利开源组织Apache采用的协议。
该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
允许代码修改,再作为开源或商业软件发布。需要满足
的条件:
1. 需要给代码的用户一份Apache Licence ;
2. 如果你修改了代码,需要在被修改的文件中说明;
3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
带有原来代码中的协议,商标,专利声明和其他原来作者规
定需要包含的说明;
4. 如果再发布的产品中包含一个Notice文件,则在Notice文
件中需要带有本协议内容。你可以在Notice中增加自己的
许可,但不可以表现为对Apache Licence构成更改。
具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
ThinkPHP 6.0
===============
> 运行环境要求PHP7.1+。
[官方应用服务市场](https://market.topthink.com) | [`ThinkPHP`开发者扶持计划](https://sites.thinkphp.cn/1782366)
ThinkPHPV6.0版本由[亿速云](https://www.yisu.com/)独家赞助发布。
## 主要新特性
* 采用`PHP7`强类型(严格模式)
* 支持更多的`PSR`规范
* 原生多应用支持
* 更强大和易用的查询
* 全新的事件系统
* 模型事件和数据库事件统一纳入事件系统
* 模板引擎分离出核心
* 内部功能中间件化
* SESSION/Cookie机制改进
* 对Swoole以及协程支持改进
* 对IDE更加友好
* 统一和精简大量用法
## 安装
~~~
composer create-project topthink/think tp 6.0.*
~~~
如果需要更新框架使用
~~~
composer update topthink/framework
~~~
## 文档
[完全开发手册](https://www.kancloud.cn/manual/thinkphp6_0/content)
## 参与开发
请参阅 [ThinkPHP 核心框架包](https://github.com/top-think/framework)
## 版权信息
ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
本项目包含的第三方源码和二进制文件之版权信息另行标注。
版权所有Copyright © 2006-2020 by ThinkPHP (http://thinkphp.cn)
All rights reserved。
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
更多细节参阅 [LICENSE.txt](LICENSE.txt)
deny from all
\ No newline at end of file
<?php
declare (strict_types = 1);
namespace app;
use think\Service;
/**
* 应用服务类
*/
class AppService extends Service
{
public function register()
{
// 服务注册
}
public function boot()
{
// 服务启动
}
}
<?php
declare (strict_types = 1);
namespace app;
use think\App;
use think\exception\ValidateException;
use think\Response;
use think\Validate;
/**
* 控制器基础类
*/
abstract class BaseController
{
/**
* Request实例
* @var \think\Request
*/
protected $request;
/**
* 应用实例
* @var \think\App
*/
protected $app;
/**
* 是否批量验证
* @var bool
*/
protected $batchValidate = false;
/**
* 控制器中间件
* @var array
*/
protected $middleware = [];
/**
* 构造方法
* @access public
* @param App $app 应用对象
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = $this->app->request;
// 控制器初始化
$this->initialize();
}
// 初始化,过滤参数
protected function initialize()
{
$is_card = \think\facade\Request::param('id_card');
if($is_card) {
if(!isCreditNo($is_card)) {
echo json_encode(['code'=>400,'msg'=>'身份证号码不符合!','data'=>[]]);exit;
}
}
$phone = \think\facade\Request::param('phone');
if($phone) {
if(!isPhoneNo($phone)) {
echo json_encode(['code'=>400,'msg'=>'手机号码不符合!','data'=>[]]);exit;
}
}
}
/**
* 验证数据
* @access protected
* @param array $data 数据
* @param string|array $validate 验证器名或者验证规则数组
* @param array $message 提示信息
* @param bool $batch 是否批量验证
* @return array|string|true
* @throws ValidateException
*/
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
{
if (is_array($validate)) {
$v = new Validate();
$v->rule($validate);
} else {
if (strpos($validate, '.')) {
// 支持场景
[$validate, $scene] = explode('.', $validate);
}
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
$v = new $class();
if (!empty($scene)) {
$v->scene($scene);
}
}
$v->message($message);
// 是否批量验证
if ($batch || $this->batchValidate) {
$v->batch(true);
}
return $v->failException(true)->check($data);
}
/**
*下面是自定义的方法
*/
//用来返回json数据
protected function returnJson($data,$msg='',$code=200,$type="json"){
$result = [
'code' => $code,
'msg' => $msg,
'data' => $data,
];
return Response::create($result,$type);
}
//无限极分类
public function getTree($data,$parent_id=0,$pk='id'){
$tree = array();
foreach($data as $k => $v)
{
if($v['parent_id'] == $parent_id)
{ //父亲找到儿子
$v['son'] = self::getTree($data, $v[$pk],$pk);
$tree[] = $v;
unset($data[$k]);
}
}
return $tree;
}
}
<?php
namespace app;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\Handle;
use think\exception\HttpException;
use think\exception\HttpResponseException;
use think\exception\ValidateException;
use think\Response;
use Throwable;
/**
* 应用异常处理类
*/
class ExceptionHandle extends Handle
{
/**
* 不需要记录信息(日志)的异常类列表
* @var array
*/
protected $ignoreReport = [
HttpException::class,
HttpResponseException::class,
ModelNotFoundException::class,
DataNotFoundException::class,
ValidateException::class,
];
/**
* 记录异常信息(包括日志或者其它方式记录)
*
* @access public
* @param Throwable $exception
* @return void
*/
public function report(Throwable $exception): void
{
// 使用内置的方式记录异常日志
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @access public
* @param \think\Request $request
* @param Throwable $e
* @return Response
*/
public function render($request, Throwable $e): Response
{
// 添加自定义异常处理机制
// 其他错误交给系统处理
return parent::render($request, $e);
}
}
<?php
namespace app;
// 应用请求对象类
class Request extends \think\Request
{
}
<?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['type']);
$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
<?php
namespace app\admin\controller;
use app\BaseController;
use Firebase\JWT\JWT;
use think\App;
use think\facade\Request;
class Base extends BaseController
{
protected $uid; //后台管理员管理员id
public function __construct(App $app)
{
parent::__construct($app);
if(config("app.open_check")) { //是否开启验证
$token = Request::header('token');
if(!$token) {
echo json_encode(['code'=>401,'msg'=>'token不存在!!!!!']);exit;
}
$decodeData = (array)JWT::decode($token,config("app.jwt_key"),array("HS256"));
$this->uid = $decodeData['uid'];
}
}
}
\ No newline at end of file
<?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=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')
->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
This diff is collapsed.
<?php
namespace app\admin\controller;
use app\BaseController;
use Firebase\JWT\JWT;
use think\App;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Request;
use think\facade\Validate;
class Login extends BaseController
{
public function login() {
if(Request::isPost()){
$username = Request::param('username');
$password = Request::param('password');
//验证字段是否合理
$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;
$where['ad.password'] = md5($password);
$where['ad.status'] = 1;
$userInfo = Db::name('admin')->alias("ad")->join('ruer_admin_role','ruer_admin_role.role_id = ad.role_id')->where($where)->field("ad.admin_id,ad.username,ruer_admin_role.name,ruer_admin_role.type,ruer_admin_role.url_ids")->find();
$data['uid'] = $userInfo['admin_id'];
$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 {
return $this->returnJson([],'用户不存在!',400);
}
}else {
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 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\api\controller;
use think\facade\Request;
class Base extends \app\BaseController
{
//路由中间件
protected $middleware = ['\app\middleware\Logincheck::class'];
public function __construct(\think\App $app)
{
parent::__construct($app);
$decodeData= (array)JWT::decode(Request::param('token'),"zhihuishequ",array("HS256"));
$this->uid = $decodeData['uid'];
$this->userinfo = Db::name("admin")->where(['admin_id'=>$this->uid])->field("admin_id,username,status,type")->find();
//把用户的数据,权限都写入到当中;
}
}
\ No newline at end of file
<?php
namespace app\api\controller;
use app\BaseController;
class Index extends Base
{
protected $middleware = ['app\middleware\Logincheck::class'];
public function index() {
return "这是我请求的内容";
}
}
\ No newline at end of file
<?php
namespace app\api\model;
use think\Model;
class Admin extends Model
{
protected $pk = 'admin_id'; //设置主键,默认id,可以不写
}
\ No newline at end of file
<?php
// 应用公共文件
/**
* @param $url
* @return array
*/
function curl_get($url){
$headerArray = array("Content-type:application/json;", "Accept:application/json;");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
$output = curl_exec($ch);
curl_close($ch);
return $output = json_decode($output, true);
}
/**
* @param $url
* @param array $data
* @param $headerArray
* @return array
*/
function curl_post($url , $data=array(),$headerArray){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
// POST数据
curl_setopt($ch, CURLOPT_POST, 1);
// 把post的变量加上
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);
return $output = json_decode($output, true);;
}
/**
* 判断是否为合法的身份证号码
* @param $IDcard
* @return boolean
*/
function isCreditNo($vStr){
$vCity = array(
'11','12','13','14','15','21','22',
'23','31','32','33','34','35','36',
'37','41','42','43','44','45','46',
'50','51','52','53','54','61','62',
'63','64','65','71','81','82','91'
);
if (!preg_match('/^([\d]{17}[xX\d]|[\d]{15})$/', $vStr)) return false;
if (!in_array(substr($vStr, 0, 2), $vCity)) return false;
$vStr = preg_replace('/[xX]$/i', 'a', $vStr);
$vLength = strlen($vStr);
if ($vLength == 18) {
$vBirthday = substr($vStr, 6, 4) . '-' . substr($vStr, 10, 2) . '-' . substr($vStr, 12, 2);
} else {
$vBirthday = '19' . substr($vStr, 6, 2) . '-' . substr($vStr, 8, 2) . '-' . substr($vStr, 10, 2);
}
if (date('Y-m-d', strtotime($vBirthday)) != $vBirthday) return false;
if ($vLength == 18) {
$vSum = 0;
for ($i = 17 ; $i >= 0 ; $i--) {
$vSubStr = substr($vStr, 17 - $i, 1);
$vSum += (pow(2, $i) % 11) * (($vSubStr == 'a') ? 10 : intval($vSubStr , 11));
}
if($vSum % 11 != 1) return false;
}
return true;
}
//获取毫秒时间戳
function msectime(){
list($msec, $sec) = explode(' ', microtime());
$msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
return $msectime;
}
/**
* 生成随机字符串
*
* @return string
*/
function getRandomStr($length=16)
{
$str = '';
$str_pol = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyl';
$max = strlen($str_pol) - 1;
for ($i = 0; $i < $length; $i++) {
$str .= $str_pol[mt_rand(0, $max)];
}
return $str;
}
//见证手机号是否合法
function isPhoneNo($phone){
if(preg_match("/^1[34578]\d{9}$/", $phone)){
return true;
} else {
return false;
}
}
//图片上传
<?php
// 事件定义文件
return [
'bind' => [
],
'listen' => [
'AppInit' => [],
'HttpRun' => [],
'HttpEnd' => [],
'LogLevel' => [],
'LogWrite' => [],
],
'subscribe' => [
],
];
<?php
// 全局中间件定义文件
return [
// 全局请求缓存
// \think\middleware\CheckRequestCache::class,
// 多语言加载
// \think\middleware\LoadLangPack::class,
// Session初始化
// \think\middleware\SessionInit::class
];
<?php
declare (strict_types = 1);
namespace app\middleware;
use Firebase\JWT\JWT;
use think\facade\Cache;
use think\facade\Request;
/**
* Class Logincheck
* @package app\middleware
* admin后台登入后置中间件,有操作之后更新redis缓存过期时间
*/
class AdminAfter
{
/**
* 处理请求
*
* @param \think\Request $request
* @param \Closure $next
* @return Response
*/
public function handle($request, \Closure $next)
{
$response = $next($request);
$token = Request::header('token');
//判断是否在redis中
$decodeData = (array)JWT::decode($token,"zhihuishequ",array("HS256"));
$redis= Cache::store('redis')->handler();
$keys[] = "admin_tokens_".$decodeData['uid'];
foreach ($keys as $value){
if($redis->exists($value)) {
$redis->EXPIRE($value,3600); //设置过期时间,
}
}
return $response;
}
}
<?php
declare (strict_types = 1);
namespace app\middleware;
use Firebase\JWT\JWT;
use think\facade\Cache;
use think\facade\Request;
/**
* Class Logincheck
* @package app\middleware
*admin后台登入的中间件,验证后台是否登入
*/
class AdminLoginCheck
{
/**
* 处理请求
*
* @param \think\Request $request
* @param \Closure $next
* @return Response
*/
public function handle($request, \Closure $next)
{
if(Request::header('token')) {
$token = Request::header('token');
//判断是否在redis中
$redis= Cache::store('redis')->handler();
$decodeData = (array)JWT::decode($token,config('app.jwt_key'),array("HS256"));
if(!isset($decodeData['code'])){
$r_token= $redis->get("admin_tokens_".$decodeData['uid']);
if(!$r_token && $r_token!=$token) {
return response()->data(json_encode(['code'=>401,'msg'=>'非法的token!!!!']))->code(400);
}
} else {
return response()->data(json_encode(['code'=>401,'msg'=>'非法的token!!!!']))->code(400);
}
} else {
return response()->data(json_encode(['code'=>401,'msg'=>'token不存在']))->code(401);
}
return $next($request);
}
}
<?php
declare (strict_types = 1);
namespace app\middleware;
use Firebase\JWT\JWT;
use think\facade\Cache;
use think\facade\Request;
class CommunityAfter
{
/**
* 处理请求
*
* @param \think\Request $request
* @param \Closure $next
* @return Response
*/
public function handle($request, \Closure $next)
{
$response = $next($request);
$token = Request::header('token');
//判断是否在redis中
$decodeData = (array)JWT::decode($token,Config('app.jwt_key'),array("HS256"));
$redis= Cache::store('redis')->handler();
$keys[] = "community_tokens_".$decodeData['uid'];
foreach ($keys as $value){
if($redis->exists($value)) {
$redis->EXPIRE($value,3600); //设置过期时间,
}
}
return $response;
}
}
<?php
declare (strict_types = 1);
namespace app\middleware;
use Firebase\JWT\JWT;
use think\facade\Cache;
use think\facade\Request;
class CommunityLoginCheck
{
/**
* 处理请求
*
* @param \think\Request $request
* @param \Closure $next
* @return Response
*/
public function handle($request, \Closure $next)
{
//查看总管理员是否登入了,如果总管理员登入了可以直接不用物业管理员登入
if(Request::header('token')) {
$token = Request::header('token');
//判断是否在redis中
$redis= Cache::store('redis')->handler();
$decodeData = (array)JWT::decode($token,config('app.jwt_key'),array("HS256"));
if(!isset($decodeData['code'])) {
$c_token= $redis->get("community_tokens_".$decodeData['uid']); //小区管理员是否登入
if( !$c_token && $c_token!=$token) {
return response()->data(json_encode(['code'=>401,'msg'=>'非法的token!!!!']))->code(401);
}
} else {
return response()->data(json_encode($decodeData))->code(401);
}
} else {
return response()->data(json_encode(['code'=>401,'msg'=>'token不存在']))->code(401);
}
return $next($request);
}
}
<?php
declare (strict_types = 1);
namespace app\middleware;
use Firebase\JWT\JWT;
use think\facade\Cache;
use think\facade\Request;
class PropertyAfter
{
/**
* 处理请求
*
* @param \think\Request $request
* @param \Closure $next
* @return Response
*/
public function handle($request, \Closure $next)
{
$response = $next($request);
$token = Request::header('token');
//判断是否在redis中
$decodeData = (array)JWT::decode($token,Config('app.jwt_key'),array("HS256"));
$redis= Cache::store('redis')->handler();
$keys[] = "property_tokens_".$decodeData['uid'];
foreach ($keys as $value){
if($redis->exists($value)) {
$redis->EXPIRE($value,3600); //设置过期时间,
}
}
return $response;
}
}
<?php
declare (strict_types = 1);
namespace app\middleware;
use Firebase\JWT\JWT;
use think\facade\Cache;
use think\facade\Request;
class PropertyLoginCheck
{
/**
* 处理请求
*
* @param \think\Request $request
* @param \Closure $next
* @return Response
*/
public function handle($request, \Closure $next)
{
//查看总管理员是否登入了,如果总管理员登入了可以直接不用物业管理员登入
if(Request::header('token')) {
$token = Request::header('token');
//判断是否在redis中
$redis= Cache::store('redis')->handler();
$decodeData = (array)JWT::decode($token,Config('app.jwt_key'),array("HS256"));
$p_token= $redis->get("property_tokens_".$decodeData['uid']); //物业管理员是否登入
if( !$p_token && $p_token!=$token) {
return response()->data(json_encode(['code'=>400,'msg'=>'非法的token!!!!']))->code(400);
}
} else {
return response()->data(json_encode(['code'=>400,'msg'=>'token不存在']))->code(401);
}
return $next($request);
}
}
<?php
use app\ExceptionHandle;
use app\Request;
// 容器Provider定义文件
return [
'think\Request' => Request::class,
'think\exception\Handle' => ExceptionHandle::class,
];
<?php
use app\AppService;
// 系统服务定义文件
// 服务在完成全局初始化之后执行
return [
AppService::class,
];
<?php
namespace app\shequ\controller;
use app\admin\controller\Common;
use think\App;
use think\facade\Db;
use think\facade\Request;
class Admin extends Base
{
protected $middleware = ['app\middleware\CommunityLoginCheck::class','app\middleware\CommunityAfter::class'];
//添加或修改小区管理员
public function createAdmin() {
$community_admin_id = Request::param('community_admin_id');
$data['account'] = Request::param('account');
if(Request::param('password')){
$data['password'] = md5(Request::param('password'));
}
$data['name'] = Request::param('name');
$data['role_id'] = Request::param('role_id');
$data['phone'] = Request::param('phone');
$data['status'] = Request::param('status');
$data['type'] = Request::param('type',0);
if($community_admin_id){
$where['community_admin_id'] = $community_admin_id;
$where['village_id'] = Request::param('village_id');
$opation = Db::name('community_admin')->where($where)->save($data);
} else {
$data['village_id'] = Request::param('village_id');
$data['create_time'] = time();
$opation = Db::name('community_admin')->insert($data);
}
if($opation) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//查看所有的小区管理人员
public function adminList() {
$where['ca.village_id'] = Request::param('village_id');
$page = Request::param('page',1);
$total = Db::name('community_admin')->alias('ca')->where($where)->count();
$data = Db::name('community_admin')->alias('ca')->leftJoin('ruer_community_role cr','cr.role_id = ca.role_id')->where($where)
->field("ca.community_admin_id,ca.account,ca.status,ca.phone,ca.name,cr.name as role_name,cr.role_id,ca.type")
->page($page,config('app.limit'))
->select()->toArray();
$res['total'] = $total;
$res['data'] = $data;
return $this->returnJson($res,'success');
}
//查看管理员详情
public function detailAdmin() {
$where['admin.community_admin_id'] = Request::param('admin_id');
$data = Db::name('community_admin')->alias('admin')->leftJoin('community_role ar','ar.role_id = admin.role_id')->where($where)
->field('admin.role_id,admin.type,admin.community_admin_id,admin.account,admin.status,admin.role_id, admin.name as admin_name,ar.url_ids,ar.name')->find();
$allNav = DB::name('community_nav')->where(['community_nav_status'=>1])->field('community_nav_id,url,url_name,parent_id')->select()->toArray();
$urls = Common::changeNav($data['url_ids'],$allNav,$data['type']);
$urlArr = $this->getTree($urls,0,'community_nav_id');
$res['adminInfo'] = $data;
$res['urlInfo'] = $urlArr;
return $this->returnJson($res,'success');
}
//删除小区管理员
public function deleteAdmin() {
$property_admin_id = Request::param('community_admin_id');
$where['community_admin_id'] = $property_admin_id;
$opation = Db::name('community_admin')->where($where)->delete();
if($opation) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//创建|修改角色
public function createRole() {
$role_id = Request::param('role_id');
$data['village_id'] = Request::param('village_id');
$data['name'] = Request::param('name');
$data['status'] = Request::param('status');
$data['type'] = Request::param('type',0); //1表示超级管理,0表示普通的
$data['url_ids'] = implode(',',Request::param('url_ids'));
if($role_id){
$opation = Db::name('community_role')->where(['role_id'=>$role_id])->save($data);
} else {
$opation = Db::name('community_role')->insert($data);
}
if($opation) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//删除角色列表
public function deleteRole() {
//1.首先判断当前角色是否有管理员挂钩,如果没有,才能删除
$where['role_id'] = Request::param('role_id');
$where['village_id'] = Request::param('village_id');
if($where['village_id'] != $this->village_id) {
return $this->returnJson([],'账号异常',400);
}
$is_exit = Db::name('community_admin')->where($where)->find();
if($is_exit){
return $this->returnJson([],'该角色目前已有管理员赋值,不能删除',400);
}
$del = Db::name('community_role')->where($where)->delete();
if($del) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//全部角色列表
public function roleList() {
$where['village_id'] = Request::param('village_id');
$page = Request::param('page',1);
$total = Db::name('community_role')->where($where)->count();
$data = Db::name('community_role')->where($where)->page($page,config('app.limit'))->select()->toArray();
$res['total'] = $total;
$res['data'] = $data;
return $this->returnJson($res,'success');
}
//查看角色详情
public function detailRole() {
$where['role_id'] = Request::param('role_id');
$data = Db::name('community_role')->where($where)->find();
$data = Common::changeField($data);
$allNav = Db::name('community_nav')->field("community_nav_id,url,url_name,community_nav_status,parent_id")->select()->toArray();
$res = Common::changeNav($data['url_ids'],$allNav,$data['type']);
$data['url_ids'] = $this->getTree($res,0,'community_nav_id');
return $this->returnJson($data,'success');
}
//全部导航栏列表
public function navList() {
$data = Db::name('community_nav')->where(['status'=>1])->order(['level'=>'asc','sort_id'=>'desc'])->select()->toArray();
return $this->returnJson($this->getTree($data,0,'community_nav_id'),'success');
}
//根据用户的id返回能访问的url
public function nav_urls() {
$id = Request::param('admin_id');
$where['admin.community_admin_id'] = $id;
$where['admin.status'] = 1;
$data = Db::name('community_admin')->alias('admin')->leftJoin('community_role ar','ar.role_id = admin.role_id')->where($where)->field('admin.*,ar.url_ids')->find();
$allNav = Db::name('community_nav')->field("community_nav_id,url,url_name,community_nav_status,parent_id")->where(['community_nav_status'=>1])->select()->toArray();
$urlsArr = explode(",",$data['url_ids']);
if(!$data['type'] ==1 ) {
foreach($allNav as $k => $v) {
if(!in_array($v['community_nav_id'],$urlsArr)){
unset($allNav[$k]);
}
}
}
$urlArr = $this->getTree($allNav,0,'community_nav_id');
return $this->returnJson($urlArr,'success');
}
}
\ No newline at end of file
<?php
namespace app\shequ\controller;
use app\BaseController;
use Firebase\JWT\JWT;
use think\App;
use think\facade\Request;
class Base extends BaseController
{
protected $uid; //社区后台管理员管理员id
protected $village_id; //小区id
public function __construct(App $app)
{
parent::__construct($app);
if(config("app.open_check")) { //是否开启验证
$token = Request::header('token');
if(!$token) {
echo json_encode(['code'=>401,'msg'=>'token不存在']);exit;
}
$decodeData = (array)JWT::decode($token,config("app.jwt_key"),array("HS256"));
$this->uid = $decodeData['uid'];
$this->village_id = $decodeData['village_id'];
}
}
}
\ No newline at end of file
This diff is collapsed.
<?php
namespace app\shequ\controller;
use app\BaseController;
use think\facade\Db;
use think\facade\Request;
class Index extends BaseController
{
protected $middleware = ['app\middleware\CommunityLoginCheck::class','app\middleware\CommunityAfter::class'];
public function index()
{
$res = Db::name('admin')->select();
var_dump($res);
return "这是shequ下的控制器";
}
public function hello($name = 'ThinkPHP6')
{
return 'hello,' . $name;
}
}
<?php
namespace app\shequ\controller;
use app\BaseController;
use Firebase\JWT\JWT;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Request;
class Login extends BaseController
{
public function Login() {
$where['cad.account'] = Request::param("account");
$where['cad.password'] = md5(Request::param("password"));
$where['cad.status'] = 1;
$userInfo = Db::name('community_admin')->alias("cad")->leftJoin('ruer_community_role cr','cr.role_id = cad.role_id')
->field("cad.community_admin_id,cad.account,cad.name,cad.type,cr.url_ids,cad.village_id")
->where($where)->find();
if($userInfo){
//查看当前小区的状态
$villageInfo= Db::name('house_village')->where(['village_id'=>$userInfo['village_id'],'status'=>1])
->field('village_id,village_name,village_address,village_logo,province_id,province_name,city_id,city_name,area_id,area_name')
->find();
if(!$villageInfo){
return $this->returnJson([],'小区不存在或当前小区被禁用,请联系管理员!',400);
}
$data['uid'] = $userInfo['community_admin_id'];
$data['village_id'] = $villageInfo['village_id'];
$jwt = JWT::encode($data,config("app.jwt_key")); //根据参数生成了 token
//把jwt放入set缓存中
$redis= Cache::store('redis')->handler();
$redis->setnx("community_tokens_".$data['uid'],$jwt);
$redis->EXPIRE("community_tokens_".$data['uid'],3600); //设置过期时间
//查询相关的能访问的导航权限
//超级管理员
if($userInfo['type']==1) {
$res = Db::name('community_nav')->where(['community_nav_status'=>1])->order("sort_id,level")->field("community_nav_id,url_name,url,parent_id")->select()->toArray();
} else { //普通管理员
$res = Db::name('community_nav')->where(['community_nav_status'=>1])->whereIn('community_nav_id',$userInfo['url_ids'])->field("community_nav_id,url_name,url,parent_id")->order("sort_id,level")->select()->toArray();
}
$navs = $this->getTree($res,0,"community_nav_id");
$userInfo['urls_id'] =$navs;
return $this->returnJson(['token'=>$jwt,'adminInfo'=>$userInfo,'villageInfo'=>$villageInfo],'success');
} else {
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("community_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\shequ\controller;
//社区新闻模块
use app\admin\controller\Common;
use think\facade\Db;
use think\facade\Request;
class News extends Base
{
protected $middleware = ['app\middleware\CommunityLoginCheck::class','app\middleware\CommunityAfter::class'];
//添加 | 修改新闻栏目
public function createNewsType() {
$news_type_id = Request::param('news_type_id');
$data['name'] = Request::param('name');
$data['sort_id'] = Request::param('sort_id');
if($news_type_id) {
$where['news_type_id'] = $news_type_id;
$where['village_id'] = $this->village_id;
$operation = Db::name('news_type')->where($where)->save($data);
} else{
$data['village_id'] = $this->village_id;
$operation = Db::name('news_type')->save($data);
}
if($operation) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'操作失败!',400);
}
}
//删除新闻栏目
public function deleteNewsType() {
$news_type_id = Request::param('news_type_id');
$where['news_type_id'] = $news_type_id;
$where['village_id'] = $this->village_id;
$del = Db::name('news_type')->where($where)->delete();
//删除相关的所有新闻
$del1 = Db::name('news')->where($where)->delete();
if($del || $del1) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'删除失败',200);
}
}
//新闻栏目列表
public function NewsTypeList() {
$where['village_id'] = $this->village_id;
$page = Request::param('page',1);
$data = Db::name('news_type')->where($where)->page($page,config('app.limit'))->order('sort_id','desc')->select()->toArray();
$total = Db::name('news_type')->where($where)->count();
$res['total'] = $total;
$res['data'] = $data;
return $this->returnJson($res,'success');
}
//添加|修改新闻
public function createNews() {
$news_id = Request::param('news_id');
$data['title'] = Request::param('title');
$data['content'] = Request::param('content');
$data['author'] = Request::param('author');
$data['news_type_id'] = Request::param('news_type_id');
$data['create_time'] = time();
$data['pic'] = Request::param('pic');
$data['sort_id'] = Request::param('sort_id',1);
$data['village_id'] = $this->village_id;
if($news_id) {
$where['news_id'] = Request::param('news_id');
$add = Db::name('news')->where($where)->save($data);
} else {
$add = Db::name('news')->save($data);
}
if($add) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//删除新闻
public function deleteNews() {
$where['news_id'] = Request::param('news_id');
$del = Db::name('news')->where($where)->delete();
if($del) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'删除失败!',400);
}
}
//新闻列表
public function newsList() {
$page = Request::param('page',1);
$where[]= ['n.village_id','=',$this->village_id];
$news_type_id = Request::param('news_type_id');
$title = Request::param('title');
if($news_type_id) {
$where[] = ['n.news_type_id','=',$news_type_id];
}
if($title) {
$where[] = ['n.title','like','%'.$title.'%'];
}
$total = Db::name('news')->alias('n')->leftJoin('news_type nt','n.news_type_id = nt.news_type_id')->where($where)->count();
$data = Db::name('news')->alias('n')->leftJoin('news_type nt','n.news_type_id = nt.news_type_id')->order(['n.sort_id'=>'desc','n.create_time'=>'desc'])
->field('n.news_id,n.news_type_id,n.title,n.author,n.create_time,n.sort_id,nt.name')
->page($page,config('app.limit'))->where($where)->select()->toArray();
$res['total'] = $total;
$res['data'] = Common::changeField($data);
return $this->returnJson($res,'success');
}
//查看新闻详情
public function detailNews() {
$news_id = Request::param('news_id');
$where[] = ['n.news_id','=',$news_id];
$data = Db::name('news')->alias('n')->leftJoin('news_type nt','n.news_type_id = nt.news_type_id')->where($where)->find();
return $this->returnJson($data,'success');
}
}
\ No newline at end of file
<?php
namespace app\shequ\controller;
//关于订单的接口
use app\admin\controller\Common;
use think\facade\Db;
use think\facade\Request;
class Order extends Base
{
protected $middleware = ['app\middleware\CommunityLoginCheck::class','app\middleware\CommunityAfter::class'];
public function orderList() {
//流水管理
$page = Request::param('page',1);
if(Request::param('income')) {
$where[] = ['ml.income','=',Request::param('income')];
}
$where[] = ['ml.village_id','=',$this->village_id];
if(Request::param('start_time') && Request::param('end_time') ) {
$start_time = strtotime(Request::param('start_time'));
$end_time = strtotime(Request::param('end_time'));
if($start_time >= $end_time) {
return $this->returnJson([],'开始时间不能大于结束时间!',400);
}
$where[] = ['ml.create_time','between',[$start_time,$end_time]];
}
$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\shequ\controller;
//车位及车辆管理
use app\admin\controller\Common;
use think\facade\Db;
use think\facade\Request;
class Parking extends Base
{
protected $middleware = ['app\middleware\CommunityLoginCheck::class','app\middleware\CommunityAfter::class'];
//添加车位区块
public function createParkArea() {
$park_block_id = Request::param('park_block_id');
$data['village_id'] = $this->village_id;
$data['name'] = Request::param('name');
$data['sort_id'] = Request::param('sort_id');
$data['explain'] = Request::param('explain');
//修改
if($park_block_id) {
$where['park_block_id'] = $park_block_id;
$operation = Db::name('park_block')->where($where)->update($data);
} else{
$data['create_time'] = time();
$operation = Db::name('park_block')->save($data);
}
if($operation) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'操作失败',400);
}
}
//删除车位区块
public function deleteParkArea() {
$where['village_id'] = $this->village_id;
$where['park_block_id'] = Request::param('park_block_id');
//查看该区域下是否有车位
$is_exit = Db::name('park_car')->where($where)->find();
if($is_exit) {
return $this->returnJson([],'该区域下有车位,请先删除车位!',400);
}
$del = Db::name('park_block')->where($where)->delete();
if($del) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'删除失败',400);
}
}
//车位区域列表
public function parkAreaList() {
$page= Request::param('page',1);
$where['village_id'] = $this->village_id;
$res['total'] = Db::name('park_block')->where($where)->count();
$data = Db::name('park_block')->where($where)->order('sort_id','desc')->page($page,config('app.limit'))->select()->toArray();
$res['data'] =Common::changeField($data);
return $this->returnJson($res,'success');
}
//添加车位
public function createCarArea() {
$park_car_id = Request::param('park_car_id');
$data['vacancy_code'] = Request::param('vacancy_code');
$data['village_id'] = $this->village_id;
$data['vacancy_id'] = Db::name('house_vacancy')->where($data)->value('vacancy_id');
$data['park_code'] = Request::param('park_code');
$data['sort_id'] = Request::param('sort_id');
$data['explain'] = Request::param('explain');
$data['park_block_id'] = Request::param('park_block_id');
if($park_car_id) { //修改
$where['park_car_id'] = $park_car_id;
$operation = Db::name('park_car')->where($where)->save($data);
} else {
$data['create_time'] = time();
$operation = Db::name('park_car')->save($data);
}
if($operation) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'操作失败',400);
}
}
//删除车位
public function deleteCarArea() {
$where['village_id'] = $this->village_id;
$where['park_car_id'] = Request::param('park_car_id');
$del = Db::name('park_car')->where($where)->delete();
if($del) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'操作失败',400);
}
}
//车位列表
public function carAreaList() {
$vacancy = new Vacancy($this->app);
$page = Request::param('page',1);
$park_block_id = Request::param('park_block_id');
$park_code = Request::param('park_code');
$vacancy_code = Request::param('vacancy_code');
$where[] = ['pc.village_id','=',$this->village_id];
if($park_block_id) {
$where[] = ['pc.park_block_id','=',$park_block_id];
}
if($park_code) {
$where[] = ['pc.park_code','=',$park_code];
}
if($vacancy_code) {
$where[] = ['pc.vacancy_code','=',$vacancy_code];
}
$data = Db::name('park_car')->alias('pc')->leftJoin('house_vacancy hv','hv.vacancy_id = pc.vacancy_id')->where($where)->order('sort_id','desc')->page($page,config('app.limit'))
->field('pc.*,hv.vacancy_code')
->select()->toArray();
foreach ($data as $k =>$v) {
$data[$k]['vacancy_address'] = $vacancy->getVacancyAddress($v['vacancy_code']);
}
$total = Db::name('park_car')->alias('pc')->leftJoin('house_vacancy hv','hv.vacancy_id = pc.vacancy_id')->where($where)->count();
$res['total'] = $total;
$res['data'] = $data;
return $this->returnJson($res,'success');
}
//添加|修改车辆
public function createCar() {
}
//删除车辆
public function deleteCar() {
}
//车辆列表
public function CarList() {
}
}
\ No newline at end of file
<?php
namespace app\shequ\controller;
use app\admin\controller\Common;
use think\facade\Db;
use think\facade\Request;
class UserBind extends Base
{
protected $middleware = ['app\middleware\CommunityLoginCheck::class','app\middleware\CommunityAfter::class'];
//用户解绑房间
public function unbind() {
$where['house_user_bind_id'] = Request::param('bind_id');
$status= Request::param('status',3);
if($status == 1) {
$save['pass_time'] = time();
}
if($status == 3) {
$save['unbind_time'] = time();
}
$save['status'] = $status;
$change = Db::name('house_user_bind')->where($where)->update($save);
if($change) {
return $this->returnJson([],'success',200);
} else {
return $this->returnJson([],'error',200);
}
}
//业主列表| 租客列表 | 家属列表
public function houseOwnerList(){
$vacancy = new Vacancy($this->app);
$page = Request::param('page',1);
$where[] = ['hub.type','=',Request::param('type',0)];
if(Request::param('phone')) {
$where[] = ['hub.phone','=',Request::param('phone')];
}
if(Request::param('status')) {
$where[] = ['hub.status','=',Request::param('status')];
}
$total = DB::name('house_user_bind')->alias('hub')->where($where)->count();
$data = DB::name('house_user_bind')->alias('hub')
->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
->where($where)
->order(['hub.pass_time'=>'desc','hub.status'=>'desc'])
->page($page,config('app.limit'))
->field('hub.house_user_bind_id,hub.name,hub.phone,hub.id_card,hub.pass_time,hub.unbind_time,hv.vacancy_code,hv.layout_id')
->select()->toArray();
foreach ($data as $k => $v) {
$data[$k]['vacancy_address'] = $vacancy->getVacancyAddress($v['vacancy_code'],$v['layout_id']);
}
$res['total'] = $total;
$res['data'] = Common::changeField($data,['pass_time','unbind_time']);
return $this->returnJson($res,'success');
}
//修改入住人员信息
public function changeHouseOwner() {
$where['house_user_bind_id'] = Request::param('bind_id');
$save['name'] = Request::param('name');
$save['phone'] = Request::param('phone');
$is_card = Request::param('id_card');
if(!isCreditNo($is_card)) {
return $this->returnJson([],'身份证号码不正确!',400);
}
$save['id_card'] = $is_card;
$save['type'] = Request::param('type');
$save['relatives_type'] = Request::param('relatives_type');
$save['memo'] = Request::param('memo');
$change = Db::name('house_user_bind')->where($where)->update($save);
if($change) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//删除绑定人员,需要用户先解绑
public function deleteHouseOwner() {
$where['house_user_bind_id'] = Request::param('bind_id');
$where['village_id'] = $this->village_id;
$bindInfo = Db::name('house_user_bind')->where($where)->field('house_user_bind_id,status')->find();
if($bindInfo['status'] != 3) {
return $this->returnJson([],'请先解绑用户!',400);
}
$del = Db::name('house_user_bind')->where($where)->delete();
if($del) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//绑定人员详情
public function detailHouseOwner() {
$vacancy = new Vacancy($this->app);
$where['house_user_bind_id'] = Request::param('bind_id');
$data = Db::name('house_user_bind')->alias('ub')->leftJoin('house_vacancy hv','hv.vacancy_id = ub.vacancy_id')->where($where)
->field('ub.*,hv.vacancy_code,hv.layout_id')
->find();
$data = Common::changeField($data);
if($data) {
$data['vacancy_address'] = $vacancy->getVacancyAddress($data['vacancy_code'],$data['layout_id']);
} else {
$data = [];
}
return $this->returnJson($data,'success');
}
//添加绑定的人员
public function createBindUser() {
$data['village_id'] = $this->village_id;
$data['name'] = Request::param('name');
$data['phone'] = Request::param('phone');
$data['create_time'] = $data['pass_time']= time();
$data['memo'] = Request::param('memo');
$data['type'] = Request::param('type');
$data['relatives_type'] = Request::param('relatives_type');
$data['status'] = Request::param('status',1);
$data['id_card'] = Request::param('id_card');
//根据房间编号获取房间id,
$vacancy_code = Request::param('vacancy_code');
$vacancy_id = DB::name('house_vacancy')->where(['village_id'=>$this->village_id,'vacancy_code'=>$vacancy_code])->value('vacancy_id');
if(!$vacancy_id) {
return $this->returnJson([],'房间编号不存在!',400);
}
$data['vacancy_id'] = $vacancy_id;
//查看该用户是否绑定了同一个房间的多个身份
$is_exit = Db::name('house_user_bind')->where(['vacancy_id'=>$vacancy_id,'id_card'=>$data['id_card']])->find();
if($is_exit) {
return $this->returnJson([],'该身份证用户在该房间下以绑定,请勿重复绑定!',400);
}
//业主只能有一个
$is_owner = Db::name('house_user_bind')->where(['village_id'=>$this->village_id,'vacancy_id'=>$vacancy_id,'type'=>0,'status'=>1])->find();
if($is_owner) {
return $this->returnJson([],'该房间编号下以绑定业主,请先解绑!',400);
}
$add = Db::name('house_user_bind')->save($data);
if($add) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'添加失败',400);
}
}
}
\ No newline at end of file
<?php
namespace app\shequ\controller;
//关于房屋的操作
use app\admin\controller\Common;
use think\facade\Db;
use think\facade\Request;
class Vacancy extends Base
{
protected $middleware = ['app\middleware\CommunityLoginCheck::class','app\middleware\CommunityAfter::class'];
//房间列表
public function vacancyList() {
$page = Request::param('page',1);
$where = [];
if(Request::param('phone')) {
$where[] = ['hv.phone','=',Request::param('phone')];
}
if(Request::param('name')) {
$where[] = ['hv.name','=',Request::param('name')];
}
$total = Db::name('house_vacancy')->alias('hv')
->where($where)
->count();
$data = Db::name('house_vacancy')->alias('hv')->field('hv.vacancy_id,hv.vacancy_code,hv.name,hv.phone,hv.create_time,hv.village_name,hv.village_id,hv.area,hv.id_card')
->where($where)
->order('create_time','desc')
->page($page,config('app.limit'))
->select()->toArray();
$res['total'] = $total;
$res['data'] = Common::changeField($data);
return $this->returnJson($res,'success');
}
//房间详情
public function detailVacancy() {
$vacancy_id = Request::param('vacancy_id');
$where['hv.vacancy_id'] = $vacancy_id;
$where['hv.village_id'] = $this->village_id;
$data = Db::name('house_vacancy')->alias('hv')->where($where)->find();
$vacancyAddress = $this->getVacancyAddress($data['vacancy_code'],$data['layout_id']);
$data['vacancy_address'] = $vacancyAddress;
unset($data['village_name']);//用连表查询的社区名称
if($data['is_inherit'] ==1 ) {
$p_info = Db::name('layout_build')->where(['layout_build_id'=>$data['parent_id']])->field('property_price,water_price,electric_price,gas_price,parking_price')->find();
$data['property_price'] = $p_info['property_price'];
$data['water_price'] = $p_info['water_price'];
$data['electric_price'] = $p_info['electric_price'];
$data['gas_price'] = $p_info['gas_price'];
$data['parking_price'] = $p_info['parking_price'];
}
return $this->returnJson(Common::changeField($data),'success');
}
//添加| 修改 房间
public function createVacancy() {
$vacancy_id = Request::param('vacancy_id');
$data['village_id'] = $add['village_id']= $this->village_id;
$vacancy_code = Request::param('vacancy_code');
if($vacancy_id) {
$res = $this->checkVacancyCode($vacancy_code,$vacancy_id);
} else {
$res = $this->checkVacancyCode($vacancy_code);
}
if($res['code'] !=200) {
return $this->returnJson([],$res['msg'],400);
}
$data['vacancy_code'] = $vacancy_code ;
$data['name'] = $add['name'] = Request::param('name'); //业主姓名
$data['id_card'] = $add['id_card'] = Request::param('id_card'); //身份证id /
$phone = Request::param('phone'); //业主手机号
if(!isPhoneNo($phone)) {
return $this->returnJson([],'手机号不合法!',400);
}
$data['phone'] = $add['phone']= $phone;
$data['property_start_time'] = date('Y-m',strtotime(Request::param('property_start_time')));
$data['property_end_time'] = date('Y-m',strtotime(Request::param('property_end_time')));
$data['village_name'] = Db::name('house_village')->where(['village_id'=>$data['village_id']])->value('village_name');
$data['area'] = Request::param('area');
$data['status'] = Request::param('status',1);
$data['memo'] = Request::param('memo');
$data['park_flag'] = Request::param('park_flag',1); //是否有车位
$data['house_type'] = Request::param('house_type',1); //类型 1住宅 2商铺 3办公
$data['is_inherit'] = Request::param('is_inherit',1);
$data['property_fee'] = Request::param('property_fee');
$data['water_fee'] = Request::param('water_fee');
$data['electric_fee'] = Request::param('electric_fee');
$data['gas_fee'] = Request::param('gas_fee');
$data['parking_fee'] = Request::param('parking_fee');
$data['parent_id'] = Request::param('parent_id');
$data['layout_id'] = Request::param('layout_id');
$add['type'] = $add['status'] = 1;
$park_code = Request::param('park_code');
if($park_code) {
//判断是否有该编号的车位
$is_exit = Db::name('park_car')->where(['village_id'=>$this->village_id,'park_code'=>$park_code])->field('park_car_id,status')->find();
if(!$is_exit) {
return $this->returnJson([],'暂未查询到该编号的车位!',400);
}
if($is_exit['status'] == 1) {
return $this->returnJson([],'该车位已占用,请先解绑对应的车位!',400);
}
$data['park_car_id'] = $is_exit['park_car_id'];
}
if($vacancy_id) { //修改
$operation = Db::name('house_vacancy')->where(['vacancy_id'=>$vacancy_id])->update($data);
$change = Db::name('house_user_bind')->where(['vacancy_id'=>$vacancy_id])->save($add);
if($operation || $change) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
} else {
$data['create_time'] = $add['pass_time']=$add['create_time'] = time();
Db::startTrans();
try{
$operation = Db::name('house_vacancy')->insertGetId($data);
$add['vacancy_id'] = $operation;
$change = Db::name('house_user_bind')->save($add);
Db::commit();
return $this->returnJson([],'success');
}catch(\Exception $e){
Db::rollback();
return $this->returnJson([],'error',400);
}
}
}
//查看房间的绑定的人员
public function vacancyBindUser() {
$vacancy_id = Request::param('vacancy_id');
$data = Db::name('house_user_bind')->where(['vacancy_id'=>$vacancy_id])->field('house_user_bind_id,name,phone,type,pass_time,unbind_time,status')
->order('pass_time','desc')
->select()->toArray();
return $this->returnJson(Common::changeField($data,['pass_time','unbind_time']),'success');
}
//删除房间
public function deleteVacancy() {
$vacancy_id = Request::param('vacancy_id');
$where[] = $where_one[] = ['status','in',[0,1,2]];
$where[] = $where_two[] = ['vacancy_id','=',$vacancy_id];
//查询房间是否绑定了用户,如果存在,则不删除
$is_exit = DB::name('house_user_bind')->where($where)->find();
if($is_exit) {
return $this->returnJson([],'该房间下有用户记录,请先解绑!',400);
}
$del1 = Db::name('house_user_bind')->where($where_one)->delete();
$del = Db::name('house_vacancy')->where($where_two)->delete();
if($del || $del1) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//检查房间编号是否合法
public function checkVacancyCode($vacancy_code,$vacancy_id=0) {
if($vacancy_id == 0){
$vacancyInfo = Db::name('house_vacancy')->where(['village_id'=>$this->village_id,'vacancy_code'=>$vacancy_code])->field('vacancy_id')->find();
} else{
$vacancyInfo = Db::name('house_vacancy')->where(['village_id'=>$this->village_id,'vacancy_code'=>$vacancy_code])->where('vacancy_id','<>',$vacancy_id)->field('vacancy_id,vacancy_code')->find();
}
if($vacancyInfo) {
return ['code'=>400,'msg'=>'房间编号已存在!'];
}
$array = explode ('-',$vacancy_code);
//去掉最后一个房间编号的
array_pop($array);
$count = Db::name('layout_build')->where('layout_build_id','in',$array)->count();
if($count != count($array)) {
return ['code'=>400,'msg'=>'房间编号不合法!'];
} else {
return ['code'=>200,'msg'=>'success!'];
}
}
//通过房间编号获取房间地址
public function getVacancyAddress($vacancyCode,$layout_id=0) {
if($layout_id == 0) {
$layout_id = Db::name('house_vacancy')->where(['village_id'=>$this->village_id,'vacancy_code'=>$vacancyCode])->value('layout_id');
}
$layoutCode = Db::name('layout_list')->where(['layout_id'=>$layout_id,'village_id'=>$this->village_id])->value('code');
$codeArr = explode('-',$layoutCode);
$rom = array_pop($codeArr); //获取最后一个房间的单位
$arr = explode('-',$vacancyCode);
$room_code = array_pop($arr);
$string = '';
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];
}
return $string.$room_code.$rom;
}
//房间导入
}
\ No newline at end of file
<?php
namespace app\shequ\controller;
use think\facade\Db;
use think\facade\Request;
class Village extends Base
{
protected $middleware = ['app\middleware\CommunityLoginCheck::class','app\middleware\CommunityAfter::class'];
//社区房屋排布编号
public function arrangementList() {
$where['village_id'] = Request::param('village_id');
$data = Db::name('layout_list')->where($where)->select()->toArray();
return $this->returnJson($data,'success');
}
//添加|修改社区排布
public function createArrangement() {
$layout_id = Request::param('layout_id');
$data['village_id'] = $where['village_id'] = Request::param('village_id');
$data['code'] = Request::param('code');
$data['name'] = Request::param('name');
$data['level'] = $where['level'] = count(explode('-',$data['code']));
if($layout_id) {
//当前布局下没有房屋,可以修改
$where['layout_id'] = $layout_id;
$is_exit = Db::name('layout_build')->where($where)->find();
if($is_exit) {
return $this->returnJson([],'已有该布局排布,添加失败',400);
}
//检查是否有类似的布局
unset($where['layout_id']);
$is_exit = Db::name('layout_list')->where($where)->find();
if($is_exit){
return $this->returnJson([],'已有该布局排布,添加失败',400);
}
unset($where['level']);
$change = Db::name('layout_list')->where($where)->save($data);
if($change) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
} else {
//检查是否有类似的布局
$is_exit = Db::name('layout_list')->where($where)->find();
if($is_exit){
return $this->returnJson([],'已有该布局排布,添加失败',400);
}
$add = Db::name('layout_list')->insert($data);
if($add) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
}
//删除社区排布编号
public function deleteArrangement() {
$layout_id =Request::param('layout_id');
$where['layout_id'] = $layout_id;
$is_exit = Db::name('layout_build')->where($where)->find();
if($is_exit){
return $this->returnJson([],'以用该布局创建了建筑,请先删除建筑,在删除',400);
}
$delete = Db::name('layout_list')->where($where)->delete();
if($delete) {
return $this->returnJson([],'success',200);
} else {
return $this->returnJson([],'error');
}
}
}
\ No newline at end of file
<?php
namespace app\wuye\controller;
use app\admin\controller\Base;
use app\admin\controller\Common;
use think\facade\Db;
use think\facade\Request;
class Admin extends Base
{
//protected $middleware = ['app\middleware\PropertyLoginCheck::class','app\middleware\PropertyAfter::class'];
//添加或修改物业管理员
public function createAdmin() {
$property_admin_id = Request::param('property_admin_id');
$data['account'] = Request::param('account');
if(Request::param('password')){
$data['password'] = md5(Request::param('password'));
}
$data['property_id'] = Request::param('property_id');
$data['role_id'] = Request::param('role_id');
$data['phone'] = Request::param('phone');
$data['status'] = Request::param('status');
$data['village_id'] = Request::param('status');
$data['type'] = Request::param('type',0);
$data['village_ids'] = implode(',',Request::param('village_ids'));
if($property_admin_id){
$where['property_admin_id'] = $property_admin_id;
$opation = Db::name('property_admin')->where($where)->save($data);
} else {
$opation = Db::name('property_admin')->insert($data);
}
if($opation) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//查看所有的物业管理人员
public function adminList() {
$where['pa.property_id'] = Request::param('property_id');
$page = Request::param('page',1);
$res['total'] = Db::name('property_admin')->alias('pa')->where($where)->count();
$data = Db::name('property_admin')->alias('pa')->join('ruer_property_role pr','pa.role_id = pr.role_id')->where($where)
->page($page,config('app.limit'))
->field("pa.property_id,pa.property_admin_id,pa.account,pa.status,pa.phone,pr.name,pa.type,pa.role_id,pa.create_time")
->select()->toArray();
$res['data'] = Common::changeField($data);
return $this->returnJson($res,'success');
}
//删除物业管理员
public function deleteAdmin() {
$property_admin_id = Request::param('property_admin_id');
$where['property_admin_id'] = $property_admin_id;
$opation = Db::name('property_admin')->where($where)->delete();
if($opation) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//查看管理员详情
public function detailAdmin() {
$property_admin_id = Request::param('property_admin_id');
$where['property_admin_id'] = $property_admin_id;
$data = Db::name('property_admin')->alias('pa')->join('ruer_property_role pr','pa.role_id = pr.role_id')->where($where)
->field("pa.property_id,pa.property_admin_id,pa.account,pa.status,pa.phone,pr.name,pr.url_ids,pa.type,pa.role_id,pa.create_time")
->find();
if($data) {
$allNav = Db::name('property_nav')->field("property_nav_id,url,url_name,property_nav_status,parent_id")->select()->toArray();
$nav = Common::changeNav($data['url_ids'],$allNav,$data['type']);
$res['adminInfo'] = $data;
$res['urlInfo'] = $this->getTree($nav,0,'property_nav_id');
return $this->returnJson($res,'success');
} else {
return $this->returnJson([],'success');
}
}
//创建|修改角色
public function createRole() {
$role_id = Request::param('role_id');
$data['property_id'] = Request::param('property_id');
$data['name'] = Request::param('name');
$data['status'] = 1;
$data['type'] = Request::param('type',0); //1表示超级管理,0表示普通的
$data['url_ids'] = implode(',',Request::param('url_ids',''));
if($role_id){
$opation = Db::name('property_role')->where(['role_id'=>$role_id])->save($data);
} else{
$opation = Db::name('property_role')->insert($data);
}
if($opation) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//删除角色列表
public function deleteRole() {
//1.首先判断当前角色是否有管理员挂钩,如果没有,才能删除
$where['role_id'] = Request::param('role_id');
$where['property_id'] = Request::param('property_id');
$is_exit = Db::name('property_admin')->where($where)->find();
if($is_exit){
return $this->returnJson([],'该角色目前已有管理员使用,不能删除',400);
}
$del = Db::name('property_role')->where($where)->delete();
if($del) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//全部角色列表
public function roleList() {
$where['property_id'] = Request::param('property_id');
$page = Request::param('page',1);
$data = Db::name('property_role')->where($where)->page($page,config('app.limit'))->select()->toArray();
$total = Db::name('property_role')->where($where)->count();
$res['total'] = $total;
$res['data'] = $data;
return $this->returnJson($res,'success');
}
//查看角色详情角色
public function detailRole() {
$where['role_id'] = Request::param('role_id');
$data = Db::name('property_role')->where($where)->find();
$data = Common::changeField($data);
$allNav = Db::name('property_nav')->field("property_nav_id,url,url_name,property_nav_status,parent_id")->select()->toArray();
$res = Common::changeNav($data['url_ids'],$allNav,$data['type']);
$data['url_ids'] = $this->getTree($res,0,'property_nav_id');
return $this->returnJson($data,'success');
}
//全部导航栏列表
public function navList() {
$data = Db::name('property_nav')->where(['property_nav_status'=>1])->order(['level'=>'asc','sort_id'=>'desc'])->select()->toArray();
return $this->returnJson($this->getTree($data,0,'property_nav_id'),'success');
}
//根据用户的id返回能访问的url
public function nav_urls() {
$id = Request::param('admin_id');
$where['admin.property_admin_id'] = $id;
$where['admin.status'] = 1;
$data = Db::name('property_admin')->alias('admin')->leftJoin('property_role ar','ar.role_id = admin.role_id')->where($where)->field('admin.*,ar.url_ids')->find();
$allNav = Db::name('property_nav')->field("property_nav_id,url,url_name,property_nav_status,parent_id")->where(['property_nav_status'=>1])->select()->toArray();
$urlsArr = explode(",",$data['url_ids']);
if(!$data['type'] ==1 ) {
foreach($allNav as $k => $v) {
if(!in_array($v['property_nav_id'],$urlsArr)){
unset($allNav[$k]);
}
}
}
$urlArr = $this->getTree($allNav,0,'property_nav_id');
return $this->returnJson($urlArr,'success');
}
}
\ No newline at end of file
<?php
namespace app\wuye\controller;
use app\BaseController;
use Firebase\JWT\JWT;
use think\App;
use think\facade\Request;
class Base extends BaseController
{
protected $uid; //物业后台管理员管理员id
// protected $village_id; //小区id
protected $property_id; //物业id
public function __construct(App $app)
{
parent::__construct($app);
if(config("app.open_check")) { //是否开启验证
$token = Request::header('token');
if(!$token) {
echo json_encode(['code'=>400,'msg'=>'token不存在']);exit;
}
$decodeData = (array)JWT::decode($token,config("app.jwt_key"),array("HS256"));
$this->uid = $decodeData['uid'];
$this->property_id = $decodeData['property_id'];
// $admin = Request::param('admin_id');
// $property_id = Request::param('property_id');
//
// if(isset($admin)){ //如果接口传递了admin_id就验证
// if($admin != $this->uid) {
// echo json_encode(['code'=>401,'msg'=>'当前登入账号异常!!!!!']);exit;
// }
// }
// if(isset($property_id)){ //如果接口传递了admin_id就验证
// if($property_id != $this->property_id) {
// echo json_encode(['code'=>401,'msg'=>'当前登入账号异常!!!!!']);exit;
// }
// }
}
}
}
\ No newline at end of file
<?php
namespace app\wuye\controller;
use app\admin\controller\Base;
use app\admin\controller\Common;
use think\facade\Db;
use think\facade\Request;
class Index extends Base
{
//protected $middleware = ['app\middleware\PropertyLoginCheck::class','app\middleware\PropertyAfter::class'];
//添加| 修改 小区
public function createCommunity() {
$village_id = Request::param('village_id');
$data['village_name'] = Request::param('village_name');
$data['village_address'] = Request::param('village_address');
$data['property_price'] = Request::param('property_price',0.00);
$data['water_price'] = Request::param('water_price',0.00);
$data['electric_price'] = Request::param('electric_price',0.00);
$data['gas_price'] = Request::param('gas_price',0.00);
$data['park_price'] = Request::param('park_price',0.00);
$data['status'] = $add['type'] = 1;
$data['province_id'] = Request::param('province_id');
$data['province_name'] = Request::param('province_name');
$data['city_id'] = Request::param('city_id');
$data['city_name'] = Request::param('city_name');
$data['area_id'] = Request::param('area_id');
$data['area_name'] = Request::param('area_name');
$add['account'] =Request::param('account');
$add['phone'] =Request::param('phone');
$add['name'] =Request::param('name');
if($village_id) {
//修改
if(Request::param('password')){
$add['password'] = md5(Request::param('password'));
}
$op = Db::name('house_village')->where(['village_id'=>$village_id])->save($data);
$community_admin_id = Db::name('house_village')->where(['village_id'=>$village_id])->value("community_admin_id");
$op1 = Db::name('community_admin')->where(['community_admin_id'=>$community_admin_id])->save($add);
if($op || $op1) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
} else {
$data['property_id'] = Request::param('property_id');
$data['create_time'] = $add['create_time'] = time();
$add['password'] = md5(Request::param('password'));
//插入小区管理人员表
Db::startTrans();
try{
$add['village_id'] = Db::name('house_village')->insertGetId($data);
$change['community_admin_id']= Db::name('community_admin')->insertGetId($add);
Db::name('house_village')->where(['village_id'=>$add['village_id']])->save($change);
Db::name('house_property')->where(['property_id'=>$data['province_id'] ])->inc('village_num')->update();
Db::commit();
return $this->returnJson([],'success');
}catch(\Exception $e){
Db::rollback();
return $this->returnJson([],'error',400);
}
}
}
//删除小区
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 villageList() {
$uid = $this->uid;
//查看是否是超级管理员
$adminInfo = Db::name('property_admin')->where(['property_admin_id'=>$uid])->find();
if($adminInfo['type'] == 1) { //超级管理员能访问所有小区
$page = Request::param("page",1);
$where[] = ['ca.type','=',1];
$where[] = ['hv.property_id','=',Request::param("property_id")];
$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)
->page($page,config("app.limit"))
->field("hv.*,ca.account,ca.status as status_admin,ca.phone")
->select()->toArray();
} else {
$where[] = ['hv.property_id','=',Request::param("property_id")];
$where[] = ['ca.type','=',1];
$count = Db::name('house_village')->alias("hv")->join('ruer_community_admin ca','ca.community_admin_id = hv.community_admin_id')->where($where)
->whereIn('hv.village_id',$adminInfo['village_ids'])->count();
$data = Db::name('house_village')->alias("hv")->join('ruer_community_admin ca','ca.community_admin_id = hv.community_admin_id')
->where($where)
->whereIn('hv.village_id',$adminInfo['village_ids'])
->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');
}
}
\ No newline at end of file
<?php
namespace app\wuye\controller;
use Firebase\JWT\JWT;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Request;
class Login extends \app\BaseController
{
public function Login() {
$where['pad.account'] = Request::param("username");
$where['pad.password'] = md5(Request::param("password"));
$userInfo = Db::name('property_admin')->alias("pad")->leftJoin('ruer_property_role','ruer_property_role.role_id = pad.role_id')->where($where)->field("pad.property_id,pad.property_admin_id,pad.account,ruer_property_role.name,pad.type,ruer_property_role.url_ids")->find();
if($userInfo){
//判断物业公司装填
$status = DB::name('house_property')->where(['property_id'=>$userInfo['property_id']])->value('status');
if($status != 1) {
return $this->returnJson([],'物业公司不存在或被禁用!',400);
}
//把jwt放入redis缓存中
$data['uid'] = $userInfo['property_admin_id'];
$data['property_id'] = $userInfo['property_id'];
$jwt = JWT::encode($data,config("app.jwt_key")); //根据参数生成了 token;
$redis= Cache::store('redis')->handler();
$redis->setnx("property_tokens_".$data['uid'],$jwt);
$redis->EXPIRE("property_tokens_".$data['uid'],3600); //设置过期时间
//查询相关的能访问的导航权限
//超级管理员
if($userInfo['type']==1) {
$res = Db::name('property_nav')->where(['property_nav_status'=>1])->order(['level'=>'asc','sort_id'=>'desc'])->field("property_nav_id,url_name,url,parent_id")->select()->toArray();
} else { //普通管理员
$res = Db::name('property_nav')->where(['property_nav_status'=>1])->whereIn('property_nav_id',$userInfo['url_ids'])->field("property_nav_id,url_name,url,parent_id")->order(['level'=>'asc','sort_id'=>'desc'])->select()->toArray();
}
$navs = $this->getTree($res,0,"property_nav_id");
$userInfo['urls_id'] =$navs;
return $this->returnJson(['token'=>$jwt,'adminInfo'=>$userInfo],'success');
} else {
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("property_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\wuye\controller;
use app\admin\controller\Base;
use app\admin\controller\Common;
use think\facade\Db;
use think\facade\Request;
class Order extends Base
{
//protected $middleware = ['app\middleware\PropertyLoginCheck::class','app\middleware\PropertyAfter::class'];
public function orderList() {
//流水管理
$page = Request::param('page',1);
$where= [];
if(Request::param('property_id')) {
$where[] = ['hp.property_id','=',Request::param('property_id')];
} else {
return $this->returnJson([],'缺少参数',400);
}
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\wuye\controller;
use app\admin\controller\Base;
use think\facade\Db;
use think\facade\Request;
class Property extends Base
{
//protected $middleware = ['app\middleware\PropertyLoginCheck::class','app\middleware\PropertyAfter::class'];
//添加|删除 物业工作人员
public function addWorker() {
$wid = Request::param('wid');
$data['property_id'] = Request::param('property_id');
$data['phone'] = Request::param('phone');
$data['name'] = Request::param('name');
$data['nickname'] = Request::param('nickname');
$id_card = Request::param('id_card');
if(!isCreditNo($id_card)){
return $this->returnJson([],'身份证号不正确',400);
}
$data['id_card'] = $id_card;
$data['job_number'] = Request::param('job_number');
$data['sex'] = Request::param('sex');
$data['create_time'] = time();
if($wid){
$where['wid'] = $wid;
$option = Db::name('house_worker')->where($where)->save($data);
} else{
$option = Db::name('house_worker')->insert($data);
}
if($option) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
//删除物业员工
public function deleteWorker() {
$where['wid'] = Request::param('wid');
$del = Db::name('house_worker')->where($where)->delete();
if($del) {
return $this->returnJson([],'success');
} else {
return $this->returnJson([],'error',400);
}
}
}
\ No newline at end of file
{
"name": "topthink/think",
"description": "the new thinkphp framework",
"type": "project",
"keywords": [
"framework",
"thinkphp",
"ORM"
],
"homepage": "http://thinkphp.cn/",
"license": "Apache-2.0",
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
},
{
"name": "yunwuxin",
"email": "448901948@qq.com"
}
],
"require": {
"php": ">=7.1.0",
"topthink/framework": "^6.0.0",
"topthink/think-orm": "^2.0",
"topthink/think-multi-app": "^1.0",
"firebase/php-jwt": "^5.2"
},
"require-dev": {
"symfony/var-dumper": "^4.2",
"topthink/think-trace":"^1.0"
},
"autoload": {
"psr-4": {
"app\\": "app"
},
"psr-0": {
"": "extend/"
}
},
"config": {
"preferred-install": "dist"
},
"scripts": {
"post-autoload-dump": [
"@php think service:discover",
"@php think vendor:publish"
]
}
}
This diff is collapsed.
<?php
// +----------------------------------------------------------------------
// | 应用设置
// +----------------------------------------------------------------------
return [
// 应用地址
'app_host' => env('app.host', ''),
// 应用的命名空间
'app_namespace' => '',
// 是否启用路由
'with_route' => true,
// 默认应用模块
'default_app' => 'admin',
// 默认时区
'default_timezone' => 'Asia/Shanghai',
// 应用映射(自动多应用模式有效)
'app_map' => [],
// 域名绑定(自动多应用模式有效)
'domain_bind' => [],
// 禁止URL访问的应用列表(自动多应用模式有效)
'deny_app_list' => [],
// 异常页面的模板文件
'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl',
// 错误显示信息,非调试模式有效
'error_message' => '页面错误!请稍后再试~',
// 显示错误信息
'show_error_msg' => false,
//接口数据分页
'limit' => 15,
//登入验证
'open_check' =>true,
//token加密的key
'jwt_key' => 'zhihuishequ',
];
This diff is collapsed.
<?php
// +----------------------------------------------------------------------
// | 控制台配置
// +----------------------------------------------------------------------
return [
// 指令定义
'commands' => [
],
];
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
*
!.gitignore
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
User-agent: *
Disallow:
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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