作者 何书鹏
1 个管道 的构建 通过 耗费 0 秒

留言消息

... ... @@ -177,9 +177,9 @@ class HouseAdmin extends Api
$house_id = $this->request->param('house_id');
$mobile = $this->request->param('mobile');
$captcha = $this->request->param('captcha');
if (!$house_id || !$mobile || !$captcha) {
$this->error('缺少必要参数');
}
empty($house_id) && $this->error('缺少必要参数');
empty($mobile) && $this->error('请输入手机号');
empty($captcha) && $this->error('请输入验证码');
if (!Validate::regex($mobile, "^1\d{10}$")) {
$this->error('手机号格式不正确');
}
... ... @@ -539,6 +539,7 @@ class HouseAdmin extends Api
"total_num": 1, //总条数
"list": [{
"id": 1, //业主ID
"avatar": "http://community.qiniu.brotop.cn", //业主头像
"name": "liujianch", //业主名称
"remark": "" //业主备注
}]
... ... @@ -552,16 +553,21 @@ class HouseAdmin extends Api
$house_id = $this->request->param('house_id');
$keyword = $this->request->param('keyword');
empty($house_id) && $this->error('缺少必要参数');
$where['house_id'] = $house_id;
$where['status'] = 2;
$where['uh.house_id'] = $house_id;
$where['uh.status'] = 2;
if(!empty($keyword)){
$where['name|remark'] = ['like','%'.$keyword.'%'];
$where['uh.name|uh.remark'] = ['like','%'.$keyword.'%'];
}
$list = UserHouse::where($where)
->field('id,name,remark')
->order('createtime desc')
$list = UserHouse::alias('uh')
->join('user u','u.id = uh.user_id')
->where($where)
->field('uh.id,u.avatar,uh.name,uh.remark')
->order('uh.createtime desc')
->page($page,$pageNum)
->select();
foreach($list as &$v){
$v['avatar'] = cdnurl($v['avatar']);
}
$this->success('success',['total_num'=>count($list),'list'=>$list]);
}
... ... @@ -585,9 +591,7 @@ class HouseAdmin extends Api
$user_house_id = $this->request->param('user_house_id');
$remark = $this->request->param('remark');
empty($user_house_id) && $this->error('缺少必要参数');
if(!$user_house_id || !$remark){
$this->error('缺少必要参数');
}
empty($remark) && $this->error('请填写备注');
$info = UserHouse::get($user_house_id);
empty($info) && $this->error('业主信息不存在');
... ... @@ -702,17 +706,17 @@ class HouseAdmin extends Api
$pageNum = $this->request->param('pageNum', 10, 'intval');
$message_id = $this->request->param('message_id');
empty($message_id) && $this->error('缺少必要参数');
$info = Message::get($message_id);
empty($info) && $this->error('消息不存在');
$info->is_read_object = 1;
$info->save();
if($info['type'] == 2) {
$msg = Message::get($message_id);
empty($msg) && $this->error('消息不存在');
$msg->is_read_object = 1;
$msg->save();
if($msg['type'] == 2) {
$model = new StoreComment();
$object_model = new \app\api\model\Store();
$object_field = 'id,store_name as nickname,store_icon as avatar';
$object_id = 'store_id';
$object_user_id = 'store_user_id';
} elseif($info['type'] == 3) {
} elseif($msg['type'] == 3) {
$model = new HouseComment();
$object_model = new \app\api\model\HouseAdmin();
$object_field = 'id,nickname,avatar';
... ... @@ -722,9 +726,9 @@ class HouseAdmin extends Api
$this->error('消息类型错误');
}
$list = $model->where([
'user_id' => $info['user_id'],
$object_id => $info['object_id'],
$object_user_id => $info['object_user_id'],
'user_id' => $msg['user_id'],
$object_id => $msg['object_id'],
$object_user_id => $msg['object_user_id'],
])->order(['createtime'=>'asc'])
->page($page,$pageNum)
->select();
... ... @@ -732,17 +736,87 @@ class HouseAdmin extends Api
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 = $object_model->field($object_field)->where(['house_id'=>$v['house_id'],'user_id'=>$v['house_user_id']])->find();
$user['avatar'] = cdnurl($user['avatar']);
if($msg['type'] == 2) {
$user = $object_model->field($object_field)->where('id',$v[$object_id])->find();
} elseif ($msg['type'] == 3) {
$user = $object_model->field($object_field)->where(['house_id'=>$v[$object_id],'user_id'=>$v[$object_user_id]])->find();
}
}
$user['avatar'] = cdnurl($user['avatar']);
$v['user'] = $user;
}
$this->success('success',['total_num'=>count($list),'list'=>$list]);
}
/**
* @ApiTitle (社区管理员-留言消息-回复)
* @ApiSummary (社区管理员-留言消息-回复)
* @ApiMethod (POST)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="message_id", type="integer", required=true, description="消息ID")
* @ApiParams (name="content", type="string", required=true, description="留言内容")
* @ApiParams (name="image", 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 messageReply()
{
$message_id = $this->request->param('message_id');
$content = $this->request->param('content');
$image = $this->request->param('image');
empty($message_id) && $this->error('缺少必要参数');
if(empty($content) && empty($image)) {
$this->error('请填写内容或上传图片');
}
$msg = Message::get($message_id);
empty($msg) && $this->error('留言消息不存在');
Db::startTrans();
try{
HouseComment::create([
'user_id' => $msg['user_id'],
'house_id' => $msg['object_id'],
'house_user_id' => $msg['object_user_id'],
'type' => 2,
'content' => $content,
'image' => $image,
]);
// 记录最新内容
$msg = Message::get([
'user_id' => $msg['user_id'],
'object_id' => $msg['object_id'],
'object_user_id' => $msg['object_user_id'],
]);
$msg->content = $content;
$msg->image = $image;
$msg->is_read_user = 2;
$msg->is_read_object = 1;
$msg->save();
// 发送模板消息
// $send_data = array(
// "first" => '',
// 'keyword1' => '',
// "keyword2" => '',
// "keyword3" => date('Y-m-s',time()),
// "remark" => '',
// );
// $this->wxsendmessage('','','');
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success('回复成功');
}
/**
* @ApiTitle (社区管理员-社区信息)
* @ApiSummary (社区管理员-社区信息)
* @ApiMethod (POST)
... ...
... ... @@ -11,7 +11,6 @@ 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;
... ... @@ -435,13 +434,13 @@ class HouseBoard extends Api
];
$msg_model->edit($edit);
// 获取记录列表
$model = new StoreComment();
$model = new HouseComment();
$where_c = [
'user_id' => $msg['user_id'],
'house_id' => $msg['object_id'],
'house_user_id' => $msg['object_user_id'],
];
$order = ['createtime'=>'DESC'];
$order = ['createtime'=>'asc'];
$comment = $model->pageSelect($page,$where_c,'*',$order,config('option.num'));
$list = $comment->items();
$user_model = new \app\api\model\User();
... ... @@ -450,8 +449,11 @@ class HouseBoard extends Api
$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']);
$user = [
'id' => $house_admin['user_id'],
'nickname' => $house_admin['nickname'],
'avatar' => cdnurl($house_admin['avatar'])
];
}
$v['user'] = $user;
}
... ...
... ... @@ -411,7 +411,7 @@ class User extends Api
$v['name'] = Db::name('store')->where('id',$v['object_id'])->value('store_name');
}
if($v['type'] == 3) {
$v['name'] = Db::name('house')->where('id',$v['house_id'])->value('name');
$v['name'] = Db::name('house')->where('id',$v['object_id'])->value('name');
}
}
$return = [
... ... @@ -484,8 +484,8 @@ class User extends Api
$object_user_id = 'store_user_id';
} elseif($msg['type'] == 3) {
$model = new HouseComment();
$object_model = new \app\api\model\User();
$object_field = 'id,admin_nickname as nickname,admin_avatar as avatar';
$object_model = new \app\api\model\HouseAdmin();
$object_field = 'id,nickname,avatar';
$object_id = 'house_id';
$object_user_id = 'house_user_id';
} else {
... ... @@ -498,19 +498,21 @@ class User extends Api
$object_user_id => $msg['object_user_id'],
]
];
$order = ['createtime'=>'DESC'];
$order = ['createtime'=>'ASC'];
$comment = $model->pageSelect($param['page'],$where_c,'*',$order,config('option.num'));
$list = $comment->items();
$list = array_multisort(array_column($list,'createtime'),SORT_ASC,$list);
$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']);
$user = $user_model->field('id,nickname,avatar')->where('id',$v['user_id'])->find();
} else {
$user = $object_model->field($object_field)->where('id',$v[$object_user_id])->find();
$user['avatar'] = cdnurl($user['avatar']);
if($msg['type'] == 2) {
$user = $object_model->field($object_field)->where('id',$v[$object_id])->find();
} elseif ($msg['type'] == 3) {
$user = $object_model->field($object_field)->where(['house_id'=>$v[$object_id],'user_id'=>$v[$object_user_id]])->find();
}
}
$user['avatar'] = cdnurl($user['avatar']);
$v['user'] = $user;
}
$return = [
... ...