Files
fast/addons/shopro/controller/zy/Sys.php
xiadc 9223c1b127 feat(shopro): 添加俱乐部、球馆的访客记录功能
- 在 Club 控制器中添加访客记录逻辑
- 在 Gym 控制器中添加访客记录逻辑
- 在 Sys 控制器中添加获取访客记录的功能
2025-06-05 14:55:16 +08:00

122 lines
3.8 KiB
PHP

<?php
namespace addons\shopro\controller\zy;
use app\admin\model\zy\link\Visitor;
use think\Db;
use think\Exception;
use app\admin\model\zy\Tags;
use think\exception\PDOException;
use app\admin\model\zy\link\Message;
use app\admin\model\shopro\user\User;
use app\admin\model\zy\circle\Circle;
use app\admin\model\zy\link\Complaint;
use think\exception\ValidateException;
class Sys extends Base
{
public function index()
{
$params = $this->request->param();
$model = new Tags();
if (isset($params['type'])) {
$model->where('type', $params['type']);
}
if (isset($params['group'])) {
$model->where('group', $params['group']);
}
$res = $model->select();
$this->success('Success', $res);
}
// 举报投诉
public function complain()
{
$params = $this->request->param();
if ($params['type'] == 3) { //用户举报
$target = User::get($params['target_id']);
} elseif ($params['type'] == 2) { //影圈举报
$target = Circle::get($params['target_id']);
} elseif ($params['type'] == 1) {
$target = ['id' => 0];
$params['target_id'] = 0;
} else {
$this->error('type 类型错误');
}
if (empty($target)) {
$this->error('举报对象不存在');
}
if (empty($params['content'])) {
$this->error('举报内容不能为空');
}
$user = auth_user();
$res = Complaint::get(['user_id' => $user['id'], 'target_id' => $params['target_id'], 'type' => $params['type'], 'status' => 0]);
if ($res) {
$this->error('您已举报过该对象');
}
$params['status'] = 0;
$params['user_id'] = $user['id'];
$params['username'] = $params['username'] ?? $user['username'];
Db::startTrans();
try {
$result = (new Complaint)->allowField(true)->save($params);
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result === false) {
$this->error('操作失败');
}
$this->success('Success');
}
// 发送用户消息
public function sendMsg()
{
$params = $this->request->param();
if ($params['user_id'] == $this->auth->id) {
$this->error('不能发送给自己');
}
$user = auth_user();
$target = User::get($params['user_id']);
if (empty($target)) {
$this->error('用户不存在');
}
Db::startTrans();
try {
$result = (new Message())->allowField(true)->save([
'type' => 2,
'name' => $user['nickname'],
'avatar' => $user['avatar'],
'from_id' => $user['id'],
'target_id' => $params['user_id'],
'content' => json_encode([
'topic' => '好友消息',
'time' => date('Y-m-d H:i:s'),
'content' => $params['content']
]),
'status' => 0
]);
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result === false) {
$this->error('操作失败');
}
$this->success('Success');
}
public function visitor()
{
$params = $this->request->param();
$res = Visitor::where('type', $params['type'])->where('obj_id', $params['obj_id'])->paginate($params['pageSize'] ?? 10);
$this->success('Success', ['list' => $res->items(), 'count' => $res->total()]);
}
}