Commit 1844e0cc authored by 蔡闯's avatar 蔡闯

app接口bug修复

parent fa968c32
...@@ -14,15 +14,16 @@ class Index extends Base ...@@ -14,15 +14,16 @@ class Index extends Base
$page = Request::param('page',1); $page = Request::param('page',1);
$uid = $this->uid; $uid = $this->uid;
$village_id = Request::param('village_id'); $village_id = Request::param('village_id');
$field ="hvi.village_name,hvi.village_id,hvi.village_address,hvi.province_name,hvi.city_name,hvi.area_name";
if(empty($village_id)) { if(empty($village_id)) {
$data = Db::name('house_user_bind')->alias('hub') $data = Db::name('house_user_bind')->alias('hub')
->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id') ->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
->leftJoin('house_village hvi','hvi.village_id = hv.village_id') ->leftJoin('house_village hvi','hvi.village_id = hv.village_id')
->where(['hub.is_lately_login'=>1,'hub.uid'=>$uid]) ->where(['hub.is_lately_login'=>1,'hub.uid'=>$uid])
->whereOr(['hub.uid'=>$uid]) ->whereOr(['hub.uid'=>$uid])
->field('hvi.village_name,hvi.village_id')->find(); ->field($field)->find();
} else { } else {
$data = Db::name('house_village')->where(['village_id'=>$village_id])->field('village_id,village_name')->find(); $data = Db::name('house_village')->alias('hvi')->where(['village_id'=>$village_id])->field($field)->find();
} }
//首页推荐新闻 //首页推荐新闻
$news= Db::name('news')->where(['village_id'=>$data['village_id'],'is_recommend'=>1])->order('recommend_sort_id','desc') $news= Db::name('news')->where(['village_id'=>$data['village_id'],'is_recommend'=>1])->order('recommend_sort_id','desc')
...@@ -47,9 +48,9 @@ class Index extends Base ...@@ -47,9 +48,9 @@ class Index extends Base
$data['banner'] = $banner; $data['banner'] = $banner;
//公告 //公告
$notice = Db::name('notice')->where(['village_id'=>$village_id])->field('notice_id,title')->select()->toArray(); $notice = Db::name('notice')->where(['village_id'=>$village_id])->order(['sort_id'=>'desc','create_time'=>'desc'])->field('notice_id,title')->limit(3)->select()->toArray();
$data['notice'] = $notice; $data['notice'] = $notice;
; return $this->returnJson($data); return $this->returnJson($data);
} }
...@@ -57,6 +58,9 @@ class Index extends Base ...@@ -57,6 +58,9 @@ class Index extends Base
public function getLayoutList(){ public function getLayoutList(){
$where['village_id'] = Request::param('village_id'); $where['village_id'] = Request::param('village_id');
$data = Db::name('layout_list')->where($where)->select()->toArray(); $data = Db::name('layout_list')->where($where)->select()->toArray();
foreach ($data as $k => $v) {
$data[$k]['code_arr'] = explode('-',$v['code']);
}
return $this->returnJson($data); return $this->returnJson($data);
} }
...@@ -79,6 +83,7 @@ class Index extends Base ...@@ -79,6 +83,7 @@ class Index extends Base
$vacancyArr = explode('-',$v['vacancy_code']); $vacancyArr = explode('-',$v['vacancy_code']);
$code = array_pop($vacancyArr); $code = array_pop($vacancyArr);
$data[$k]['code_name'] = $code.$name; $data[$k]['code_name'] = $code.$name;
$data[$k]['is_build'] = 0 ;
} }
} else{ } else{
$data = $this->getBuildInfo($where); $data = $this->getBuildInfo($where);
...@@ -100,6 +105,7 @@ class Index extends Base ...@@ -100,6 +105,7 @@ class Index extends Base
->toArray(); ->toArray();
foreach ($data as $k =>$v) { foreach ($data as $k =>$v) {
$data[$k]['code_name'] = $v['code'].explode('-',$v['list_code'])[$v['level']-1]; $data[$k]['code_name'] = $v['code'].explode('-',$v['list_code'])[$v['level']-1];
$data[$k]['is_build'] = 1;
} }
return $data; return $data;
} }
...@@ -146,7 +152,6 @@ class Index extends Base ...@@ -146,7 +152,6 @@ class Index extends Base
foreach ($data as $k=>$v) { foreach ($data as $k=>$v) {
$rest = Common::getVacancyAddress($v['vacancy_code'],$v['layout_id']); $rest = Common::getVacancyAddress($v['vacancy_code'],$v['layout_id']);
$data[$k]['vacancy_address'] = $rest['vacancy_address']; $data[$k]['vacancy_address'] = $rest['vacancy_address'];
//获取用户车辆信息 //获取用户车辆信息
$cars = Db::name('car')->where(['uid'=>$this->uid,'village_id'=>$v['village_id']])->field('car_id,license_plate')->select()->toArray(); $cars = Db::name('car')->where(['uid'=>$this->uid,'village_id'=>$v['village_id']])->field('car_id,license_plate')->select()->toArray();
$data[$k]['cars'] = $cars; $data[$k]['cars'] = $cars;
......
...@@ -37,11 +37,26 @@ class Login extends BaseController ...@@ -37,11 +37,26 @@ class Login extends BaseController
Common::synUserData($uid,$phone); //同步用户数据 Common::synUserData($uid,$phone); //同步用户数据
$token['uid']= $uid; $token['uid']= $uid;
$token['time']= date('Y-m-d H:i'); $token['time']= date('Y-m-d H:i');
$token = JWT::encode($token,config('app.jwt_key')); //根据参数生成了 token $token = JWT::encode($token,config('app.jwt_key')); //根据参数生成了token
$res['token'] = $token; $res['token'] = $token;
$res['uid'] = $uid; $res['uid'] = $uid;
$res['phone'] = $phone; $res['phone'] = $phone;
$res['pwd'] = empty($userInfo['password']) ? 0 :1; $res['pwd'] = empty($userInfo['password']) ? 0 :1;
//查询该用户是否绑定了房间,如果有,则返回上一次绑定的房间
$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){
$res['userBindInfo'] = $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){
$res['userBindInfo'] = $userBind;
Db::name('house_user_bind')->where(['uid'=>$uid,'status'=>1])->save(['is_lately_login'=>1]);
} else {
$res['userBindInfo'] = (Object)[];
}
}
return $this->returnJson($res); return $this->returnJson($res);
} else{ } else{
return $this->returnJson([],'验证码不正确!','400'); return $this->returnJson([],'验证码不正确!','400');
......
...@@ -53,6 +53,19 @@ class News extends Base{ ...@@ -53,6 +53,19 @@ class News extends Base{
} }
//公告列表
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')->page($page,config('app.limit'))->select()->toArray();
$total = Db::name('notice')->where($where)->count();
$res['total'] = $total;
$res['data'] = Common::changeField($data);
return $this->returnJson($res);
}
......
...@@ -4,16 +4,16 @@ ...@@ -4,16 +4,16 @@
namespace app\api\controller; namespace app\api\controller;
use app\common\controller\Common; use app\common\controller\Common;
use think\facade\Db; use think\facade\Db;
use think\facade\Request; use think\facade\Request;
use app\model\User as UserModel;
class User extends Base class User extends Base
{ {
//获取用户所入住的小区|搜索小区 //获取用户所入住的小区|搜索小区
public function getUserVillage() { public function getUserVillage() {
$keyword = Request::param('keyword'); $keyword = Request::param('keyword','');
$page = Request::param('page',1); $page = Request::param('page',1);
$province_id = Request::param('province_id'); $province_id = Request::param('province_id');
$city_id = Request::param('city_id'); $city_id = Request::param('city_id');
...@@ -33,7 +33,10 @@ class User extends Base ...@@ -33,7 +33,10 @@ class User extends Base
$res['total'] = Db::name('house_village')->where($where)->where('village_name','like','%'.$keyword.'%')->count(); $res['total'] = Db::name('house_village')->where($where)->where('village_name','like','%'.$keyword.'%')->count();
$rest=[]; $rest=[];
foreach ($villages as $k =>$v) { foreach ($villages as $k =>$v) {
$rest['village_info'] =$villages; $rest['village_name'] = $v['village_name'];
$rest['village_id'] = $v['village_id'];
$rest['village_address'] = $v['province_name'].$v['city_name'].$v['area_name'].$v['village_address'];
$rest['village_logo'] = $v['village_logo'];
$rest['vacancy'] = Common::getVacancy($v['village_id'],$this->uid); $rest['vacancy'] = Common::getVacancy($v['village_id'],$this->uid);
$res['data'][] = $rest; $res['data'][] = $rest;
} }
...@@ -41,11 +44,20 @@ class User extends Base ...@@ -41,11 +44,20 @@ class User extends Base
$where['hub.uid'] = $this->uid; $where['hub.uid'] = $this->uid;
$where['hub.status'] = 1; $where['hub.status'] = 1;
$village_ids = DB::name('house_user_bind')->alias('hub')->where($where)->column('village_id'); $village_ids = DB::name('house_user_bind')->alias('hub')->where($where)->column('village_id');
$village_name = Db::name('house_village')->whereIn('village_id',$village_ids)->column('village_name','village_id'); $village_info = Db::name('house_village')->whereIn('village_id',$village_ids)->field('village_name,village_id,province_name,city_name,area_name,village_logo,village_address')->select()->toArray();
$res['total'] = count($village_ids); $res['total'] = count($village_ids);
$rest=[]; $rest=[];
foreach ($village_ids as $k =>$v) { foreach ($village_ids as $k =>$v) {
$rest['village_name'] = $village_name[$v]; foreach ($village_info as $key =>$val) {
if($val['village_id'] == $v) {
$rest['village_name'] = $val['village_name'];
$rest['village_id'] = $val['village_id'];
$rest['village_address'] = $val['province_name'].$val['city_name'].$val['area_name'].$val['village_address'];
$rest['village_logo'] = $val['village_logo'];
break;
}
}
$rest['vacancy'] = Common::getVacancy($v,$this->uid); $rest['vacancy'] = Common::getVacancy($v,$this->uid);
$res['data'][] = $rest; $res['data'][] = $rest;
} }
...@@ -53,11 +65,10 @@ class User extends Base ...@@ -53,11 +65,10 @@ class User extends Base
if($res['total']==1){ if($res['total']==1){
$res['data'] = array_values($res['data']); $res['data'] = array_values($res['data']);
} }
$res['keyword'] = $keyword;
return $this->returnJson($res); return $this->returnJson($res);
} }
//用户设置密码 //用户设置密码
public function setPassword() { public function setPassword() {
$password = Request::param('password'); $password = Request::param('password');
...@@ -189,8 +200,9 @@ class User extends Base ...@@ -189,8 +200,9 @@ class User extends Base
$where['hub.uid'] = $this->uid; $where['hub.uid'] = $this->uid;
$data = Db::name('house_user_bind')->alias('hub') $data = Db::name('house_user_bind')->alias('hub')
->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id') ->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
->leftJoin('user','user.uid = hub.uid')
->where($where) ->where($where)
->field('hub.name,hv.vacancy_code,hv.layout_id,hv.village_id') ->field('hub.name,hv.vacancy_code,hv.layout_id,hv.village_id,user.sex,user.nickname,user.avatar')
->find(); ->find();
//获取当日值班电话 //获取当日值班电话
if($data) { if($data) {
...@@ -227,7 +239,8 @@ class User extends Base ...@@ -227,7 +239,8 @@ class User extends Base
//人脸图片文件上传 //人脸图片文件上传
public function uploadFaceImg() { public function uploadFaceImg() {
$file = request()->file('img'); $file = request()->file('img');
$path = "/face"; $path = Request::param('path','face');
$path = '/'.$path;
$data = Common::uploadImg($file,$path); $data = Common::uploadImg($file,$path);
if($data) { if($data) {
return $this->returnJson($data,'success'); return $this->returnJson($data,'success');
...@@ -244,15 +257,22 @@ class User extends Base ...@@ -244,15 +257,22 @@ class User extends Base
Db::name('house_user_bind')->where(['uid'=>$uid])->save(['is_lately_login'=>0]); Db::name('house_user_bind')->where(['uid'=>$uid])->save(['is_lately_login'=>0]);
Db::name('house_user_bind')->where(['uid'=>$uid])->save(['is_lately_login'=>1,'house_user_bind_id'=>$bind_id]); Db::name('house_user_bind')->where(['uid'=>$uid])->save(['is_lately_login'=>1,'house_user_bind_id'=>$bind_id]);
return $this->returnJson([],'success'); return $this->returnJson([],'success');
// Db::startTrans();
// try{ }
//
// Db::commit();
// return $this->returnJson([],'success'); //修改头像和昵称
// }catch(\Exception $e){ public function changeUserInfo() {
// Db::rollback(); $data['nickname'] = Request::param('nickname');
// return $this->returnJson([],'error',400); $data['sex'] = Request::param('sex');
// } $data['avatar'] = Request::param('avatar');
$where['uid'] = $this->uid;
$change = Db::name('user')->where($where)->save($data);
if($change) {
return $this->returnJson();
} else {
return $this->returnJson([],'修改失败!',400);
}
} }
......
...@@ -12,4 +12,12 @@ class Village extends Base ...@@ -12,4 +12,12 @@ class Village extends Base
//搜索小区 //搜索小区
public function test() {
$float_1 = 1.11111111111111111111111111111111111111111111111111111;
$float_2 = 1.11111111111111111111111111111111111111111111111111112;
var_dump($float_1==$float_2);
}
} }
\ No newline at end of file
...@@ -896,6 +896,7 @@ class Common extends BaseController ...@@ -896,6 +896,7 @@ class Common extends BaseController
if(!in_array($ext,['pjpeg','jpeg','jpg','gif','bmp','png'])) { if(!in_array($ext,['pjpeg','jpeg','jpg','gif','bmp','png'])) {
return false; return false;
} }
$savename = \think\facade\Filesystem::putFile($path, $file); $savename = \think\facade\Filesystem::putFile($path, $file);
if(isHTTPS()){ if(isHTTPS()){
$http = "https://"; $http = "https://";
......
...@@ -201,7 +201,8 @@ class News extends Base ...@@ -201,7 +201,8 @@ class News extends Base
//公告列表 //公告列表
public function noticeList() { public function noticeList() {
$where['village_id'] = $this->village_id; $where['village_id'] = $this->village_id;
$data = Db::name('notice')->where($where)->field('notice_id,title,author,create_time')->select()->toArray(); $page = Request::param('page',1);
$data = Db::name('notice')->where($where)->field('notice_id,title,author,create_time')->page($page,config('app.limit'))->select()->toArray();
$total = Db::name('notice')->where($where)->count(); $total = Db::name('notice')->where($where)->count();
$res['total'] = $total; $res['total'] = $total;
$res['data'] = Common::changeField($data); $res['data'] = Common::changeField($data);
......
...@@ -68,6 +68,10 @@ return [ ...@@ -68,6 +68,10 @@ return [
'message_masterSecret' => '8b1c955df362e317b987554c', 'message_masterSecret' => '8b1c955df362e317b987554c',
//app社区默认logo
'village_log' => '/upload/village/village_logo.png',
]; ];
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