...
|
...
|
@@ -9,9 +9,15 @@ |
|
|
namespace app\api\controller;
|
|
|
|
|
|
|
|
|
use app\api\model\HouseComment;
|
|
|
use app\api\model\Message;
|
|
|
use app\api\model\StoreComment;
|
|
|
use app\api\validate\HotValidate;
|
|
|
use app\common\controller\Api;
|
|
|
use think\Cache;
|
|
|
use think\Db;
|
|
|
use think\Exception;
|
|
|
use think\exception\PDOException;
|
|
|
use think\Validate;
|
|
|
use EasyWeChat\Foundation\Application as WXPAY_APP;
|
|
|
use EasyWeChat\Payment\Order as WXPAY_ORDER;
|
...
|
...
|
@@ -298,6 +304,74 @@ class HouseBoard extends Api |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 留言提交
|
|
|
* @ApiWeigh (50)
|
|
|
*
|
|
|
* @ApiTitle (留言提交)
|
|
|
* @ApiSummary (留言提交)
|
|
|
* @ApiMethod (POST)
|
|
|
* @ApiRoute (/api/house_board/comment_add)
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="house_id", type="integer", required=true, description="社区id")
|
|
|
* @ApiParams (name="house_user_id", type="integer", required=true, description="管理员id")
|
|
|
* @ApiParams (name="content", type="string", required=true, description="留言内容")
|
|
|
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
|
|
|
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
|
|
|
* @ApiReturn ({
|
|
|
'code':'1',
|
|
|
'msg':'返回成功'
|
|
|
})
|
|
|
*/
|
|
|
public function comment_add()
|
|
|
{
|
|
|
$param = (new HotValidate())->goCheck('house_comment_add');
|
|
|
if(empty($param['content']) && empty($param['image'])) {
|
|
|
$this->error('请填写内容或上传图片');
|
|
|
}
|
|
|
Db::startTrans();
|
|
|
$result = false;
|
|
|
try{
|
|
|
$param['user_id'] = $this->auth->id;
|
|
|
$model = new HouseComment();
|
|
|
$result = $model->add($param);
|
|
|
// 记录最新内容
|
|
|
$msg_model = new Message();
|
|
|
$where_m = [
|
|
|
'user_id' => $this->auth->id,
|
|
|
'house_id' => $param['house_id'],
|
|
|
'house_user_id' => $param['house_user_id'],
|
|
|
];
|
|
|
$msg = $msg_model->where($where_m)->find();
|
|
|
if($msg) {
|
|
|
$update = [
|
|
|
'id' => $msg['id'],
|
|
|
'type' => 1,
|
|
|
'content' => $param['content'],
|
|
|
'image' => $param['image']
|
|
|
];
|
|
|
$res_msg = $msg_model->edit($update);
|
|
|
} else {
|
|
|
$insert = $where_m;
|
|
|
$insert['type'] = 1;
|
|
|
$insert['content'] = $param['content'];
|
|
|
$insert['image'] = $param['image'];
|
|
|
$res_msg = $msg_model->add($insert);
|
|
|
}
|
|
|
Db::commit();
|
|
|
} catch (PDOException $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
} catch (Exception $e) {
|
|
|
Db::rollback();
|
|
|
$this->error($e->getMessage());
|
|
|
}
|
|
|
if(!$result || !$res_msg) {
|
|
|
$this->error('留言失败');
|
|
|
}
|
|
|
$this->success('留言成功');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @ApiTitle (社区公告-物业留言-详情)
|
|
|
* @ApiSummary (社区公告-物业留言-详情)
|
|
|
* @ApiMethod (POST)
|
...
|
...
|
@@ -305,6 +379,7 @@ class HouseBoard extends Api |
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="house_id", type="inter", required=true, description="社区id")
|
|
|
* @ApiParams (name="user_id", type="inter", required=true, description="社区物业管理员用户id")
|
|
|
* @ApiParams (name="page", type="integer", required=true, description="页数")
|
|
|
*
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
...
|
...
|
@@ -332,6 +407,7 @@ class HouseBoard extends Api |
|
|
$user_id = $this->auth->id; //当前登录用户id
|
|
|
$house_id = $this->request->param('house_id'); //社区id
|
|
|
$wuye_user_id = $this->request->param('user_id'); //物业用户id
|
|
|
$page = $this->request->param('page',1,'intval');
|
|
|
if(empty($house_id) || empty($wuye_user_id)){
|
|
|
$this->error('缺少必要参数');
|
|
|
}
|
...
|
...
|
@@ -340,40 +416,80 @@ class HouseBoard extends Api |
|
|
if(empty($house_admin)){
|
|
|
$this->error('参数有误,社区与管理员id不匹配');
|
|
|
}
|
|
|
|
|
|
$data = Db::name('message')
|
|
|
->where('house_id',$house_id)
|
|
|
->where('user_id',$user_id)
|
|
|
->where('to_user_id',$wuye_user_id)
|
|
|
->order('createtime desc')
|
|
|
->select();
|
|
|
foreach ($data as &$v){
|
|
|
$v['is_right'] = 1;
|
|
|
if($v['type'] == 2){
|
|
|
$v['image'] = cdnurl($v['image'],true);
|
|
|
}
|
|
|
}
|
|
|
$arr = Db::name('message')
|
|
|
->where('house_id',$house_id)
|
|
|
->where('user_id',$wuye_user_id)
|
|
|
->where('to_user_id',$user_id)
|
|
|
->order('createtime desc')
|
|
|
->select();
|
|
|
foreach ($arr as &$v){
|
|
|
$v['is_right'] = 2;
|
|
|
if($v['type'] == 2){
|
|
|
$v['image'] = cdnurl($v['image'],true);
|
|
|
$where = [
|
|
|
'where' => [
|
|
|
'user_id'=>$this->auth->id,
|
|
|
'object_id' => $house_id,
|
|
|
'object_user_id' => $wuye_user_id
|
|
|
],
|
|
|
];
|
|
|
// 修改用户阅读状态
|
|
|
$msg_model = new Message();
|
|
|
$msg = $msg_model->findOrFail($where);
|
|
|
$edit = [
|
|
|
'id' => $msg['id'],
|
|
|
'is_read_user' => 1,
|
|
|
];
|
|
|
$msg_model->edit($edit);
|
|
|
// 获取记录列表
|
|
|
$model = new StoreComment();
|
|
|
$where_c = [
|
|
|
'user_id' => $msg['user_id'],
|
|
|
'house_id' => $msg['object_id'],
|
|
|
'house_user_id' => $msg['object_user_id'],
|
|
|
];
|
|
|
$order = ['createtime'=>'DESC'];
|
|
|
$comment = $model->pageSelect($page,$where_c,'*',$order,config('option.num'));
|
|
|
$list = $comment->items();
|
|
|
$user_model = new \app\api\model\User();
|
|
|
foreach ($list as &$v) {
|
|
|
if($v['type'] == 1) {
|
|
|
$user = $user_model->field('id,nickname,avatar')->where('id',$v['user_id'])->find();
|
|
|
$user['avatar'] = cdnurl($user['avatar']);
|
|
|
} else {
|
|
|
$user = $user_model->field('id,admin_nickname as nickname,admin_avatar as avatar')->where('id',$v['house_user_id'])->find();
|
|
|
$user['avatar'] = cdnurl($user['avatar']);
|
|
|
}
|
|
|
$v['user'] = $user;
|
|
|
}
|
|
|
|
|
|
$info = array_merge($data,$arr);
|
|
|
|
|
|
array_multisort(array_column($info,'createtime'),SORT_DESC,$info);
|
|
|
foreach ($info as &$val){
|
|
|
$val['createtime'] = date('Y-m-d H:i:s',$val['createtime']);
|
|
|
}
|
|
|
|
|
|
$this->success('success',$info);
|
|
|
$return = [
|
|
|
'list' => $list,
|
|
|
'this_page' => $comment->currentPage(),
|
|
|
'total_page' => $comment->lastPage()
|
|
|
];
|
|
|
// $data = Db::name('message')
|
|
|
// ->where('house_id',$house_id)
|
|
|
// ->where('user_id',$user_id)
|
|
|
// ->where('to_user_id',$wuye_user_id)
|
|
|
// ->order('createtime desc')
|
|
|
// ->select();
|
|
|
// foreach ($data as &$v){
|
|
|
// $v['is_right'] = 1;
|
|
|
// if($v['type'] == 2){
|
|
|
// $v['image'] = cdnurl($v['image'],true);
|
|
|
// }
|
|
|
// }
|
|
|
// $arr = Db::name('message')
|
|
|
// ->where('house_id',$house_id)
|
|
|
// ->where('user_id',$wuye_user_id)
|
|
|
// ->where('to_user_id',$user_id)
|
|
|
// ->order('createtime desc')
|
|
|
// ->select();
|
|
|
// foreach ($arr as &$v){
|
|
|
// $v['is_right'] = 2;
|
|
|
// if($v['type'] == 2){
|
|
|
// $v['image'] = cdnurl($v['image'],true);
|
|
|
// }
|
|
|
// }
|
|
|
//
|
|
|
// $info = array_merge($data,$arr);
|
|
|
//
|
|
|
// array_multisort(array_column($info,'createtime'),SORT_DESC,$info);
|
|
|
// foreach ($info as &$val){
|
|
|
// $val['createtime'] = date('Y-m-d H:i:s',$val['createtime']);
|
|
|
// }
|
|
|
|
|
|
$this->success('success',$return);
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
|