作者 Cool

留言相关功能调整

... ... @@ -6,6 +6,7 @@ namespace app\api\controller;
use app\api\model\Deposit;
use app\api\model\DepositOrder;
use app\api\model\Industry;
use app\api\model\Message;
use app\api\model\StoreComment;
use app\api\model\StoreInform;
use app\api\model\StoreInformGood;
... ... @@ -351,6 +352,7 @@ class Hot extends Api
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="store_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 ({
... ... @@ -361,6 +363,9 @@ class Hot extends Api
public function comment_add()
{
$param = (new HotValidate())->goCheck('comment_add');
if(empty($param['content']) && empty($param['image'])) {
$this->error('请填写内容或上传图片');
}
$where = [
'where' => ['id' => $param['store_id']]
];
... ... @@ -372,6 +377,31 @@ class Hot extends Api
$param['store_user_id'] = $store['user_id'];
$model = new StoreComment();
$result = $model->add($param);
// 记录最新内容
$msg_model = new Message();
$where_m = [
'user_id' => $this->auth->id,
'object_id' => $store['id'],
'object_user_id' => $store['user_id'],
];
$msg = $msg_model->where($where_m)->find();
if($msg) {
$update = [
'id' => $msg['id'],
'content' => $param['content'],
'image' => $param['image'],
'is_read_user' => 1,
'is_read_object' => 2,
];
$res_msg = $msg_model->edit($update);
} else {
$insert = $where_m;
$insert['type'] = 2;
$insert['content'] = $param['content'];
$insert['image'] = $param['image'];
$insert['is_read_user'] = 1;
$res_msg = $msg_model->add($insert);
}
Db::commit();
} catch (PDOException $e) {
Db::rollback();
... ... @@ -380,7 +410,7 @@ class Hot extends Api
Db::rollback();
$this->error($e->getMessage());
}
if(!$result) {
if(!$result || !$res_msg) {
$this->error('留言失败');
}
$this->success('留言成功');
... ...
... ... @@ -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);
}
... ...
... ... @@ -8,6 +8,7 @@ use app\admin\model\UserWithdraw;
use app\api\model\Deposit;
use app\api\model\DepositOrder;
use app\api\model\Industry;
use app\api\model\Message;
use app\api\model\Report;
use app\api\model\StoreApply;
use app\api\model\StoreComment;
... ... @@ -893,11 +894,11 @@ class Store extends Api
$store = $this->get_store();
$page = $param['page'];
$where = [
'where' => ['store_id'=>$store['id'],'type'=>1],
'where' => ['object_id'=>$store['id'],'object_user_id'=>$this->auth->id],
'with' => ['user_info']
];
$order = ['createtime'=>'DESC'];
$model = new StoreComment();
$model = new Message();
$comment = $model->pageSelect($page,$where,'*',$order,config('option.num'));
$list = $comment->items();
$return = [
... ... @@ -918,7 +919,8 @@ class Store extends Api
* @ApiMethod (POST)
* @ApiRoute (/api/store/comment_detail)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="comment_id", type="integer", required=true, description="留言id")
* @ApiParams (name="msg_id", type="integer", required=true, description="留言id")
* @ApiParams (name="page", type="integer", required=true, description="页数")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
... ... @@ -941,13 +943,39 @@ class Store extends Api
$param = (new StoreValidate())->goCheck('comment_detail');
$store = $this->get_store();
$where = [
'where' => ['id'=>$param['comment_id']],
'with' => ['user_info']
'where' => ['id'=>$param['msg_id']],
];
$msg_model = new Message();
$msg = $msg_model->findOrFail($where);
$edit = [
'id' => $msg['id'],
'is_read_object' => 1,
];
$msg_model->edit($edit);
$model = new StoreComment();
$comment = $model->findOrFail($where,'*');
$where_c = [
'user_id' => $msg['user_id'],
'store_id' => $msg['object_id'],
'store_user_id' => $msg['object_user_id'],
];
$order = ['createtime'=>'DESC'];
$comment = $model->pageSelect($param['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 = $this->store_model->field('id,store_name as nickname,store_icon as avatar')->where('id',$v['house_user_id'])->find();
$user['avatar'] = cdnurl($user['avatar']);
}
$v['user'] = $user;
}
$return = [
'comment' => $comment
'list' => $list,
'this_page' => $comment->currentPage(),
'total_page' => $comment->lastPage()
];
$this->success('请求成功',$return);
}
... ... @@ -962,8 +990,9 @@ class Store extends Api
* @ApiMethod (POST)
* @ApiRoute (/api/store/comment_reply)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="comment_id", type="integer", required=true, description="留言id")
* @ApiParams (name="msg_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 ({
... ... @@ -974,12 +1003,44 @@ class Store extends Api
public function comment_reply()
{
$param = (new StoreValidate())->goCheck('comment_reply');
if(empty($param['content']) && empty($param['image'])) {
$this->error('请填写内容或上传图片');
}
$msg_model = new Message();
$model = new StoreComment();
$where = [
'where' => [
'id' => $param['msg_id']
]
];
$msg = $msg_model->findOrFail($where);
Db::startTrans();
$result = false;
try{
$param['user_id'] = $this->auth->id;
$model = new StoreComment();
$result = $model->add($param);
$add = [
'user_id' => $msg['user_id'],
'store_id' => $msg['object_id'],
'store_user_id' => $msg['object_user_id'],
'type' => 2,
'content' => $param['content'],
'image' => $param['image'],
];
$result = $model->add($add);
// 记录最新内容
$where_m = [
'user_id' => $msg['user_id'],
'object_id' => $msg['object_id'],
'object_user_id' => $msg['object_user_id'],
];
$msg = $msg_model->where($where_m)->find();
$update = [
'id' => $msg['id'],
'content' => $param['content'],
'image' => $param['image'],
'is_read_user' => 2,
'is_read_object' => 1,
];
$res_msg = $msg_model->edit($update);
Db::commit();
} catch (PDOException $e) {
Db::rollback();
... ... @@ -988,10 +1049,10 @@ class Store extends Api
Db::rollback();
$this->error($e->getMessage());
}
if(!$result) {
$this->error('提交失败');
if(!$result || !$res_msg) {
$this->error('回复失败');
}
$this->success('提交成功');
$this->success('回复成功');
}
/**
... ...
... ... @@ -3,11 +3,17 @@
namespace app\api\controller;
use app\admin\model\UserWithdraw;
use app\api\model\HouseComment;
use app\api\model\Message;
use app\api\model\StoreComment;
use app\api\validate\StoreValidate;
use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use fast\Random;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\Validate;
use think\Cache;
use app\api\model\HouseJoin;
... ... @@ -340,6 +346,221 @@ class User extends Api
}
/**
* 留言消息
* @ApiWeigh (24)
*
* @ApiTitle (留言消息)
* @ApiSummary (留言消息)
* @ApiMethod (POST)
* @ApiRoute (/api/user/comment_list)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="page", type="integer", required=true, description="页数")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"list": [
{
"id": 1,
"name": "行业名称",
"weigh": 0,
}
]
}
})
*/
public function comment_list()
{
if($this->request->isPost()){
$param = (new StoreValidate())->goCheck('common');
$page = $param['page'];
$where = [
'where' => ['user_id'=>$this->auth->id],
];
$order = ['createtime'=>'DESC'];
$model = new Message();
$comment = $model->pageSelect($page,$where,'*',$order,config('option.num'));
$list = $comment->items();
$return = [
'list' => $list,
'this_page' => $comment->currentPage(),
'total_page' => $comment->lastPage()
];
$this->success('请求成功',$return);
}
}
/**
* 留言消息详情
* @ApiWeigh (23)
*
* @ApiTitle (留言消息详情)
* @ApiSummary (留言消息详情)
* @ApiMethod (POST)
* @ApiRoute (/api/user/comment_detail)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="msg_id", type="integer", required=true, description="留言id")
* @ApiParams (name="page", type="integer", required=true, description="页数")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"comment": [
{
"id": 1,
"name": "行业名称",
"weigh": 0,
}
]
}
})
*/
public function comment_detail()
{
if($this->request->isPost()){
$param = (new StoreValidate())->goCheck('comment_detail');
$where = [
'where' => ['id'=>$param['msg_id']],
];
$msg_model = new Message();
$msg = $msg_model->findOrFail($where);
$edit = [
'id' => $msg['id'],
'is_read_user' => 1,
];
$msg_model->edit($edit);
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($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_id = 'house_id';
$object_user_id = 'house_user_id';
} else {
$this->error('消息类型错误');
}
$where_c = [
'user_id' => $msg['user_id'],
$object_id => $msg['object_id'],
$object_user_id => $msg['object_user_id'],
];
$order = ['createtime'=>'DESC'];
$comment = $model->pageSelect($param['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 = $object_model->field($object_field)->where('id',$v['house_user_id'])->find();
$user['avatar'] = cdnurl($user['avatar']);
}
$v['user'] = $user;
}
$return = [
'list' => $list,
'this_page' => $comment->currentPage(),
'total_page' => $comment->lastPage()
];
$this->success('请求成功',$return);
}
}
/**
* 留言回复
* @ApiWeigh (22)
*
* @ApiTitle (留言回复)
* @ApiSummary (留言回复)
* @ApiMethod (POST)
* @ApiRoute (/api/user/comment_reply)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="msg_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 comment_reply()
{
$param = (new StoreValidate())->goCheck('comment_reply');
if(empty($param['content']) && empty($param['image'])) {
$this->error('请填写内容或上传图片');
}
$msg_model = new Message();
$where = [
'where' => [
'id' => $param['msg_id']
]
];
$msg = $msg_model->findOrFail($where);
if($msg['type'] == 2) {
$model = new StoreComment();
$object_id = 'store_id';
$object_user_id = 'store_user_id';
} elseif($msg['type'] == 3) {
$model = new HouseComment();
$object_id = 'house_id';
$object_user_id = 'house_user_id';
} else {
$this->error('无法回复该类型消息');
}
Db::startTrans();
$result = false;
try{
$add = [
'user_id' => $msg['user_id'],
$object_id => $msg['object_id'],
$object_user_id => $msg['object_user_id'],
'type' => 2,
'content' => $param['content'],
'image' => $param['image'],
];
$result = $model->add($add);
// 记录最新内容
$where_m = [
'user_id' => $msg['user_id'],
'object_id' => $msg['object_id'],
'object_user_id' => $msg['object_user_id'],
];
$msg = $msg_model->where($where_m)->find();
$update = [
'id' => $msg['id'],
'content' => $param['content'],
'image' => $param['image'],
'is_read_user' => 1,
'is_read_object' => 2,
];
$res_msg = $msg_model->edit($update);
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)
... ...
<?php
namespace app\api\model;
class HouseComment extends Base
{
protected $updateTime = false;
public function getImageAttr($value)
{
return $value ? cdnurl($value) : '';
}
public function getCreatetimeAttr($value)
{
return date('Y-m-d H:i:s',$value);
}
}
\ No newline at end of file
... ...
... ... @@ -9,6 +9,11 @@ class StoreComment extends Base
protected $updateTime = false;
public function getImageAttr($value)
{
return $value ? cdnurl($value) : '';
}
public function getCreatetimeAttr($value)
{
return date('Y-m-d H:i:s',$value);
... ...
... ... @@ -15,6 +15,8 @@ class HotValidate extends BaseValidate
'city' => 'require',
'region' => 'require',
'images' => 'require',
'house_id' => 'require',
'house_user_id' => 'require',
'content' => 'require',
'house_ids' => 'require',
'type' => 'require|in:1,2',
... ... @@ -29,7 +31,8 @@ class HotValidate extends BaseValidate
protected $scene = [
'common' => ['page'], // 公共分页验证
'comment_add' => ['store_id','content'], // 留言提交
'comment_add' => ['store_id'], // 留言提交
'house_comment_add' => ['house_id','house_user_id'], // 社区留言提交
'store_apply' => ['store_name','province','city','region','name','mobile'], // 开通社区提交
'store_report' => ['content'], // 举报建议提交
'store_edit' => ['store_icon','store_name','mobile','province','city','region','images'], // 店铺信息修改
... ...
... ... @@ -16,9 +16,11 @@ class StoreValidate extends BaseValidate
'region' => 'require',
'images' => 'require',
'content' => 'require',
'image' => 'require',
'house_ids' => 'require',
'type' => 'require|in:1,2',
'red_package' => 'require',
'msg_id' => 'require',
'number' => 'require',
'deposit_id' => 'require'
];
... ... @@ -36,8 +38,8 @@ class StoreValidate extends BaseValidate
'store_inform_add' => ['content','images','house_ids','type'], // 发布信息
'red' => ['red_package','number'], // 发布信息红包
'house_new' => ['house_ids'], // 绑定社区
'comment_detail' => ['comment_id'], // 留言详情
'comment_reply' => ['comment_id','content'], // 留言回复
'comment_detail' => ['msg_id','page'], // 留言详情
'comment_reply' => ['msg_id'], // 留言回复
'deposit_order' => ['deposit_id'], // 板币充值提交
];
}
\ No newline at end of file
... ...