74 lines
2.2 KiB
PHP
74 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace addons\shopro\controller\zy;
|
|
|
|
use think\Db;
|
|
use think\Exception;
|
|
use app\admin\model\zy\Tags;
|
|
use think\exception\PDOException;
|
|
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');
|
|
}
|
|
}
|