68 lines
2.0 KiB
PHP
68 lines
2.0 KiB
PHP
<?php
|
||
/**
|
||
* @copyright Copyright (c) 2021 勾股工作室
|
||
* @license https://opensource.org/licenses/Apache-2.0
|
||
* @link https://www.gougucms.com
|
||
*/
|
||
declare (strict_types = 1);
|
||
namespace app\api\controller;
|
||
|
||
use app\api\BaseController;
|
||
use app\api\middleware\Auth;
|
||
use Firebase\JWT\JWT;
|
||
use Firebase\JWT\Key;
|
||
use think\facade\Db;
|
||
use think\facade\Request;
|
||
|
||
class Index extends BaseController
|
||
{
|
||
/**
|
||
* 控制器中间件 [登录、注册 不需要鉴权]
|
||
* @var array
|
||
*/
|
||
protected $middleware = [
|
||
Auth::class => ['except' => ['index','reg','login'] ]
|
||
];
|
||
|
||
/**
|
||
* 文章投诉接口.
|
||
*/
|
||
public function complaint(){
|
||
$param = get_params();
|
||
$id = $param['id']; //文章id
|
||
$content = $param['content']; //投诉内容
|
||
$type = $param['type']??1; //标识(1文章/2朋友圈)
|
||
$user_id = $this->request->uid;//用户的id
|
||
$where['article_id'] = $id;
|
||
$where['user_id'] = $user_id;
|
||
$where['type'] = $type;
|
||
$is_complaint = Db::table('fa_article_complaint')->where($where)->find();
|
||
if($is_complaint){
|
||
$this->apiError('您已投诉!');
|
||
}else{
|
||
|
||
$useraddress = Db::table('fa_szxc_information_useraddress')->where('user_id', $this->request->uid)->where('status', 1)->find();
|
||
$data = [];
|
||
if ($useraddress) {
|
||
$data['county'] = $useraddress['area_id'];
|
||
$data['township'] = $useraddress['street_id'];
|
||
$data['village'] = $useraddress['village_id'];
|
||
}
|
||
|
||
$data['article_id'] = $id;
|
||
$data['user_id'] = $user_id;
|
||
$data['type'] = $type;
|
||
$data['content'] = $content;
|
||
$data['createtime'] = time();
|
||
$res = Db::table('fa_article_complaint')->strict(false)->insert($data);
|
||
if($res){
|
||
$this->apiSuccess('投诉成功');
|
||
}else{
|
||
$this->apiError('投诉失败');
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
}
|