作者 Cool
1 个管道 的构建 通过 耗费 0 秒

Merge branch 'master' of http://114.215.101.231:8099/guosheng/community into Branch_liuzhen

... ... @@ -119,6 +119,42 @@ class House extends Api
}
/**
* @ApiTitle (所有已绑定小区)
* @ApiSummary (所有已绑定小区)
* @ApiMethod (POST)
* @ApiRoute (/api/house/myhouse)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiReturn({
"code": 1,
"msg": "success",
"time": "1598688508",
"data": [{
"id": 16, //小区ID
"name": "兴安苑", //小区名称
"is_current": 0 //是否当前小区:0=否,1=是
}]
})
*/
public function myhouse()
{
$user = $this->auth->getUser();
$list = Db::name('user_house')
->alias('uh')
->join('house h','h.id = uh.house_id')
->where('uh.user_id',$user['id'])
->where('uh.status',2)
->field("h.id,h.name")
->order('uh.status desc')
->select();
foreach($list as &$v){
$v['is_current'] = $user['house_id'] == $v['id'] ? 1 : 0;
}
$this->success('success',$list);
}
/**
* @ApiTitle (首页展开公告)
* @ApiSummary (首页展开公告)
* @ApiMethod (POST)
... ...
... ... @@ -16,6 +16,7 @@ use think\Exception;
use think\exception\PDOException;
use think\Validate;
use think\Cache;
use app\api\model\House;
use app\api\model\HouseJoin;
use app\api\model\UserHouse;
use app\api\model\UserMoneyLog;
... ... @@ -118,7 +119,7 @@ class User extends Api
public function index()
{
$user = $this->auth->getUser();
$house = \app\api\model\House::get($user['house_id']);
$house = House::get($user['house_id']);
$data = [
// 当前小区信息
'house' => !empty($house) ? $house->visible(['id','name'])->toArray() : [],
... ... @@ -202,7 +203,7 @@ class User extends Api
* @ApiTitle (个人中心-选择社区-切换)
* @ApiSummary (个人中心-选择社区-切换)
* @ApiMethod (POST)
* @ApiRoute (/api/user/houseUnbind)
* @ApiRoute (/api/user/houseChange)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="house_id", type="inter", required=true, description="小区ID")
... ... @@ -244,15 +245,27 @@ class User extends Api
$user = $this->auth->getUser();
$house_id = $this->request->param('house_id');
empty($house_id) && $this->error('缺少必要参数');
$house = House::get($house_id);
empty($house) && $this->error('社区信息不存在');
$info = UserHouse::get(['user_id'=>$user['id'],'house_id'=>$house_id]);
empty($info) && $this->error('绑定信息不存在');
$info['status'] != 2 && $this->error('您还没有绑定该小区,无法解绑');
// 启动事务
Db::startTrans();
try{
$info->delete();
$user->house_id = 0;
$user->save();
// 解绑当前小区
if($user['house_id'] == $house_id){
$user->house_id = 0;
$user->save();
}
// 绑定数量减1
if($house['bindnum'] > 0){
House::where('id',$house_id)->setDec('bindnum');
}
// 提交事务
Db::commit();
} catch (\Exception $e) {
... ...