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

版本1.0

parent 324c1da2
Pipeline #121 failed with stages
......@@ -91,12 +91,12 @@ abstract class BaseController
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;
}
}
// $phone = \think\facade\Request::param('phone');
// if($phone) {
// if(!isPhoneNo($phone)) {
// 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
public function __construct(App $app)
{
parent::__construct($app);
if(config("app.open_check")) { //是否开启验证
if(Request::header('token')) {
$token = Request::header('token');
if(!$token) {
echo json_encode(['code'=>401,'msg'=>'token不存在!!!!!']);exit;
//判断是否在redis中
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->uid = $decodeData['uid'];
$this->admin_id = $decodeData['admin_id'];
} 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
This diff is collapsed.
......@@ -13,82 +13,30 @@ use think\facade\Validate;
class Login extends BaseController
{
protected $middleware = ['app\middleware\CheckValidata::class'];
public function login(){
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');
}
$account = Request::param('account');
$pass_word = Request::param('pass_word');
$where['account'] = $account;
$where['pass_word'] = md5($pass_word);
//数据库验证数据
$where['ad.username'] = $username;
$where['ad.password'] = md5($password);
$where['ad.status'] = 1;
$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();
$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');
$is_find = Db::name('admin')->where($where)->find();
if($is_find) {
$to['admin_id'] = $is_find['admin_id'];
$to['expire_time'] = time() + 43200; //设置12小时过期
$jwt = JWT::encode(json_encode($to),config('app.jwt_key')); //根据参数生成了 token
$res['token'] = $jwt;
$res['user_name'] = $is_find['user_name'];
return $this->returnJson($res,'登入成功');
} else {
return $this->returnJson([],'用户不存在!',400);
return $this->returnJson([],'账号或密码错误!','400');
}
}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
This diff is collapsed.
<?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
This diff is collapsed.
<?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
This diff is collapsed.
<?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") {
This diff is collapsed.
......@@ -7,4 +7,7 @@ return [
// \think\middleware\LoadLangPack::class,
// Session初始化
// \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 [
'keyId' => 'LTAI4GFAtgRK4cSyZ9DVBEd3', //Access Key ID
'keySecret' => 'e6n82Q4Hiha49gSBexTBKVAqR2Wrrg', //Access Key Secret
'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