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

app接口bug修复

parent fa968c32
......@@ -14,15 +14,16 @@ class Index extends Base
$page = Request::param('page',1);
$uid = $this->uid;
$village_id = Request::param('village_id');
$field ="hvi.village_name,hvi.village_id,hvi.village_address,hvi.province_name,hvi.city_name,hvi.area_name";
if(empty($village_id)) {
$data = Db::name('house_user_bind')->alias('hub')
->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
->leftJoin('house_village hvi','hvi.village_id = hv.village_id')
->where(['hub.is_lately_login'=>1,'hub.uid'=>$uid])
->whereOr(['hub.uid'=>$uid])
->field('hvi.village_name,hvi.village_id')->find();
->field($field)->find();
} 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')
......@@ -47,9 +48,9 @@ class Index extends Base
$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;
; return $this->returnJson($data);
return $this->returnJson($data);
}
......@@ -57,6 +58,9 @@ class Index extends Base
public function getLayoutList(){
$where['village_id'] = Request::param('village_id');
$data = Db::name('layout_list')->where($where)->select()->toArray();
foreach ($data as $k => $v) {
$data[$k]['code_arr'] = explode('-',$v['code']);
}
return $this->returnJson($data);
}
......@@ -79,6 +83,7 @@ class Index extends Base
$vacancyArr = explode('-',$v['vacancy_code']);
$code = array_pop($vacancyArr);
$data[$k]['code_name'] = $code.$name;
$data[$k]['is_build'] = 0 ;
}
} else{
$data = $this->getBuildInfo($where);
......@@ -100,6 +105,7 @@ class Index extends Base
->toArray();
foreach ($data as $k =>$v) {
$data[$k]['code_name'] = $v['code'].explode('-',$v['list_code'])[$v['level']-1];
$data[$k]['is_build'] = 1;
}
return $data;
}
......@@ -146,7 +152,6 @@ class Index extends Base
foreach ($data as $k=>$v) {
$rest = Common::getVacancyAddress($v['vacancy_code'],$v['layout_id']);
$data[$k]['vacancy_address'] = $rest['vacancy_address'];
//获取用户车辆信息
$cars = Db::name('car')->where(['uid'=>$this->uid,'village_id'=>$v['village_id']])->field('car_id,license_plate')->select()->toArray();
$data[$k]['cars'] = $cars;
......
......@@ -37,11 +37,26 @@ class Login extends BaseController
Common::synUserData($uid,$phone); //同步用户数据
$token['uid']= $uid;
$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['uid'] = $uid;
$res['phone'] = $phone;
$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);
} else{
return $this->returnJson([],'验证码不正确!','400');
......
......@@ -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 @@
namespace app\api\controller;
use app\common\controller\Common;
use think\facade\Db;
use think\facade\Request;
use app\model\User as UserModel;
class User extends Base
{
//获取用户所入住的小区|搜索小区
public function getUserVillage() {
$keyword = Request::param('keyword');
$keyword = Request::param('keyword','');
$page = Request::param('page',1);
$province_id = Request::param('province_id');
$city_id = Request::param('city_id');
......@@ -33,7 +33,10 @@ class User extends Base
$res['total'] = Db::name('house_village')->where($where)->where('village_name','like','%'.$keyword.'%')->count();
$rest=[];
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);
$res['data'][] = $rest;
}
......@@ -41,11 +44,20 @@ class User extends Base
$where['hub.uid'] = $this->uid;
$where['hub.status'] = 1;
$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);
$rest=[];
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);
$res['data'][] = $rest;
}
......@@ -53,11 +65,10 @@ class User extends Base
if($res['total']==1){
$res['data'] = array_values($res['data']);
}
$res['keyword'] = $keyword;
return $this->returnJson($res);
}
//用户设置密码
public function setPassword() {
$password = Request::param('password');
......@@ -189,8 +200,9 @@ class User extends Base
$where['hub.uid'] = $this->uid;
$data = Db::name('house_user_bind')->alias('hub')
->leftJoin('house_vacancy hv','hv.vacancy_id = hub.vacancy_id')
->leftJoin('user','user.uid = hub.uid')
->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();
//获取当日值班电话
if($data) {
......@@ -227,7 +239,8 @@ class User extends Base
//人脸图片文件上传
public function uploadFaceImg() {
$file = request()->file('img');
$path = "/face";
$path = Request::param('path','face');
$path = '/'.$path;
$data = Common::uploadImg($file,$path);
if($data) {
return $this->returnJson($data,'success');
......@@ -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'=>1,'house_user_bind_id'=>$bind_id]);
return $this->returnJson([],'success');
// Db::startTrans();
// try{
//
// Db::commit();
// return $this->returnJson([],'success');
// }catch(\Exception $e){
// Db::rollback();
// return $this->returnJson([],'error',400);
// }
}
//修改头像和昵称
public function changeUserInfo() {
$data['nickname'] = Request::param('nickname');
$data['sex'] = Request::param('sex');
$data['avatar'] = Request::param('avatar');
$where['uid'] = $this->uid;
$change = Db::name('user')->where($where)->save($data);
if($change) {
return $this->returnJson();
} else {
return $this->returnJson([],'修改失败!',400);
}
}
......
......@@ -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
if(!in_array($ext,['pjpeg','jpeg','jpg','gif','bmp','png'])) {
return false;
}
$savename = \think\facade\Filesystem::putFile($path, $file);
if(isHTTPS()){
$http = "https://";
......
......@@ -201,7 +201,8 @@ class News extends Base
//公告列表
public function noticeList() {
$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();
$res['total'] = $total;
$res['data'] = Common::changeField($data);
......
......@@ -68,6 +68,10 @@ return [
'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