add:增加影圈功能,优化部分接口
This commit is contained in:
@@ -48,7 +48,7 @@ class Base extends Common
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result === false) {
|
||||
$this->error(__('No rows were inserted'));
|
||||
$this->error('操作失败');
|
||||
}
|
||||
$this->success('Success');
|
||||
}
|
||||
@@ -70,7 +70,7 @@ class Base extends Common
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result === false) {
|
||||
$this->error(__('No rows were inserted'));
|
||||
$this->error('操作失败');
|
||||
}
|
||||
$this->success('Success');
|
||||
}
|
||||
|
||||
177
addons/shopro/controller/zy/Circle.php
Normal file
177
addons/shopro/controller/zy/Circle.php
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\controller\zy;
|
||||
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use app\admin\model\zy\Club;
|
||||
use app\admin\model\zy\Menber;
|
||||
use think\exception\PDOException;
|
||||
use app\admin\model\zy\circle\Likes;
|
||||
use think\exception\ValidateException;
|
||||
use app\admin\model\zy\circle\Circle as CircleModel;
|
||||
use app\admin\model\zy\circle\Comment;
|
||||
use app\admin\model\zy\link\Relation;
|
||||
|
||||
class Circle extends Base
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
|
||||
$sub = CircleModel::alias('c')
|
||||
->join([Likes::$tableName => 'l'], 'c.id = l.circle_id', 'LEFT')
|
||||
->field("c.*,JSON_ARRAYAGG(JSON_OBJECT(
|
||||
'id', l.id,
|
||||
'user_id', l.user_id,
|
||||
'nickname', l.nickname,
|
||||
'avatar', l.avatar,
|
||||
'gender', l.gender
|
||||
)) AS likes")->group('c.id')->buildSql();
|
||||
$query = Comment::alias('m')
|
||||
->join([$sub => 'c'], 'c.id = m.circle_id', 'RIGHT')
|
||||
->field("c.*,
|
||||
JSON_ARRAYAGG(JSON_OBJECT(
|
||||
'id', m.id,
|
||||
'pid', m.pid,
|
||||
'puser_id', m.puser_id,
|
||||
'pnickname', m.pnickname,
|
||||
'user_id', m.user_id,
|
||||
'nickname', m.nickname,
|
||||
'avatar', m.avatar,
|
||||
'gender', m.gender,
|
||||
'content', m.content,
|
||||
'create_time', m.create_time
|
||||
)) AS comment")->group('c.id');
|
||||
if (isset($params['club_id'])) {
|
||||
$query->where('c.club_id', $params['club_id']);
|
||||
}
|
||||
if (isset($params['user_id'])) {
|
||||
$query->where('c.user_id', $params['user_id']);
|
||||
}
|
||||
if (isset($params['friend'])) {
|
||||
$friend = Relation::where('user_id', $this->auth->id)->where('status', 'IN', explode(',', $params['friend']))->column('target_id');
|
||||
$query->where('c.user_id', 'IN', $friend);
|
||||
}
|
||||
$res = $query->select();
|
||||
foreach ($res as &$r) {
|
||||
$r['likes'] = json_decode($r['likes'], true);
|
||||
if (count($r['likes']) == 1 && empty($r['likes'][0]['id'])) $r['likes'] = [];
|
||||
$r['comment'] = buildTree(json_decode($r['comment'], true));
|
||||
}
|
||||
|
||||
$this->success('Success', $res);
|
||||
}
|
||||
|
||||
public function view()
|
||||
{
|
||||
$model = CircleModel::get($this->request->param('id'));
|
||||
if (empty($model)) {
|
||||
$this->error(__('No rows were found'));
|
||||
}
|
||||
$this->success('Success', $model);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
if (empty($params['content'])) {
|
||||
$this->error('内容不能为空');
|
||||
}
|
||||
$user = auth_user();
|
||||
$club = Menber::alias('m')->join([Club::$tableName => 'c'], 'm.club_id=c.id')
|
||||
->field('c.name')
|
||||
->where(['m.club_id' => $params['club_id'], 'm.user_id' => $user['id']])
|
||||
->where('m.role', '>', 0)->find();
|
||||
if (empty($club)) {
|
||||
$this->error('你无权在此俱乐部发布');
|
||||
}
|
||||
$params['user_id'] = $user['id'];
|
||||
$params['nickname'] = $user['nickname'];
|
||||
$params['avatar'] = $user['avatar'];
|
||||
$params['gender'] = $user['gender'];
|
||||
$params['club_name'] = $club['name'];
|
||||
$params['status'] = 1;
|
||||
Db::startTrans();
|
||||
try {
|
||||
$result = (new CircleModel)->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 like()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$club = CircleModel::get($params['circle_id']);
|
||||
if (empty($club)) {
|
||||
$this->error('数据不存在');
|
||||
}
|
||||
$user = auth_user();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$like = Likes::get(['circle_id' => $params['circle_id'], 'user_id' => $user['id']]);
|
||||
if (empty($like)) { // 点赞
|
||||
(new Likes)->allowField(true)->save([
|
||||
'circle_id' => $params['circle_id'],
|
||||
'user_id' => $user['id'],
|
||||
'nickname' => $user['nickname'],
|
||||
'avatar' => $user['avatar'],
|
||||
'gender' => $user['gender'],
|
||||
]);
|
||||
} else { // 取消点赞
|
||||
$like->delete();
|
||||
}
|
||||
Db::commit();
|
||||
} catch (ValidateException | PDOException | Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success('Success');
|
||||
}
|
||||
|
||||
// 评论
|
||||
public function comment()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$club = CircleModel::get($params['circle_id']);
|
||||
if (empty($club)) {
|
||||
$this->error('数据不存在');
|
||||
}
|
||||
if (empty($params['content'])) {
|
||||
$this->error('内容不能为空');
|
||||
}
|
||||
$pcomment = Comment::get($params['pid']);
|
||||
if (!empty($params['pid']) && empty($pcomment)) {
|
||||
$this->error('回复的评论不存在');
|
||||
}
|
||||
$user = auth_user();
|
||||
Db::startTrans();
|
||||
try {
|
||||
(new Comment)->allowField(true)->save([
|
||||
'circle_id' => $params['circle_id'],
|
||||
'pid' => $params['pid'],
|
||||
'puser_id' => $pcomment['user_id'] ?? 0,
|
||||
'pnickname' => $pcomment['nickname'] ?? '',
|
||||
'user_id' => $user['id'],
|
||||
'nickname' => $user['nickname'],
|
||||
'avatar' => $user['avatar'],
|
||||
'gender' => $user['gender'],
|
||||
'content' => $params['content'],
|
||||
]);
|
||||
Db::commit();
|
||||
} catch (ValidateException | PDOException | Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success('Success');
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,11 @@ namespace addons\shopro\controller\zy;
|
||||
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use app\admin\model\User;
|
||||
use app\admin\model\zy\Menber;
|
||||
use think\exception\PDOException;
|
||||
use app\admin\model\zy\link\Apply;
|
||||
use app\admin\model\zy\link\Message;
|
||||
use app\admin\model\shopro\user\User;
|
||||
use app\admin\model\zy\game\Activity;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
@@ -27,6 +27,9 @@ class Club extends Base
|
||||
if (isset($params['name'])) {
|
||||
$model->where('name', 'like', '%' . $params['name'] . '%');
|
||||
}
|
||||
if (isset($params['gym_id'])) {
|
||||
$model->where('gym_id', $params['gym_id']);
|
||||
}
|
||||
$res = $model->select();
|
||||
|
||||
$this->success('Success', $res);
|
||||
@@ -52,7 +55,7 @@ class Club extends Base
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result === false) {
|
||||
$this->error(__('No rows were inserted'));
|
||||
$this->error('操作失败');
|
||||
}
|
||||
$this->success('Success', $result);
|
||||
}
|
||||
|
||||
73
addons/shopro/controller/zy/Sys.php
Normal file
73
addons/shopro/controller/zy/Sys.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?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');
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace addons\shopro\controller\zy;
|
||||
|
||||
use app\admin\model\zy\Tags as TagsModel;
|
||||
use addons\shopro\controller\Common;
|
||||
|
||||
class Tags extends Common
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$params = $this->request->param();
|
||||
$model = new TagsModel();
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user