777 lines
32 KiB
PHP
777 lines
32 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Jobs\SendNotice;
|
|
use App\Jobs\SendNoticeMessage;
|
|
use App\Models\App\UserVote;
|
|
use App\Models\App\Vote;
|
|
use App\Models\Configs;
|
|
use App\Models\RestrictMomentUser;
|
|
use App\Models\User;
|
|
use App\Models\App\VoteOption;
|
|
use App\Models\MomentTopic;
|
|
use App\Services\UserService;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Moment;
|
|
use App\Contracts\MomentContract;
|
|
use App\Http\Response\ResponseJson;
|
|
use Illuminate\Support\Facades\DB;
|
|
use App\Models\MomentTopicsActivities;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class MomentController extends Controller
|
|
{
|
|
use ResponseJson;
|
|
protected $moment_service;
|
|
public function __construct(MomentContract $moment_service)
|
|
{
|
|
$this->moment_service = $moment_service;
|
|
}
|
|
public function moments(Request $request)
|
|
{
|
|
try {
|
|
$result = $this->moment_service->moments();
|
|
if (empty($result)) throw new \Exception("获取动态列表失败", 1);
|
|
return $this->success('ok', $result);
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('获取动态列表失败,联系技术人员');
|
|
}
|
|
}
|
|
|
|
public function momentsV3(Request $request)
|
|
{
|
|
try {
|
|
$count = Moment::where('is_audited',1)->count('id');
|
|
$result = $this->moment_service->momentsV3();
|
|
if (empty($result)) throw new \Exception("获取动态列表失败", 1);
|
|
return $this->success($count, $result);
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('获取动态列表失败,联系技术人员');
|
|
}
|
|
}
|
|
|
|
public function momentsV4(Request $request)
|
|
{
|
|
try {
|
|
$count = Moment::where('is_audited',1)->count('id');
|
|
$result = $this->moment_service->momentsV4();
|
|
if (empty($result)) throw new \Exception("获取动态列表失败", 1);
|
|
return $this->success($count, $result);
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('获取动态列表失败,联系技术人员');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 修改动态
|
|
* @param Request $request
|
|
* @param Moment $moment
|
|
*/
|
|
public function updateComment(Request $request, Moment $moment)
|
|
{
|
|
$is_change_topic = false;
|
|
$topic_id = $request->input("topic_id");
|
|
if ($topic_id && $moment->topic_id != $topic_id) {
|
|
$moment->old_topic_id = $moment->topic_id;
|
|
$moment->topic_id = $topic_id;
|
|
$is_change_topic = true;
|
|
}
|
|
$moment->save();
|
|
if ($is_change_topic) {
|
|
//系统通知
|
|
$user_service = new UserService();
|
|
$message = '您的动态话题与动态内容不符,系统已修改为对应话题,是否同意?';
|
|
$user_service->sendNotice($moment->user_id, 1, 'change_moment_topic', $message,$message, $moment->id, 'pages/dynamic/feedDetail?id='.$moment->id, 1);
|
|
}
|
|
return $this->success('ok');
|
|
}
|
|
|
|
//置顶动态
|
|
public function topMoment(Request $request ,$moment_id){
|
|
try {
|
|
$tops = Moment::where('is_top','<>',0)->pluck('is_top')->toArray();//拿到所有置顶动态的is_top值
|
|
if (empty($tops)) {//为空 就说明没有置顶动态
|
|
Moment::where('id',$moment_id)->update(['is_top'=>1]);
|
|
}else{ //有置顶动态 就拿到其中的最大值
|
|
$max = array_search(max($tops), $tops);
|
|
$max_top = $tops[$max];
|
|
Moment::where('id',$moment_id)->update(['is_top'=>$max_top+1]);
|
|
}
|
|
return $this->success('ok');
|
|
} catch (Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('置顶动态失败,联系技术人员');
|
|
}
|
|
|
|
}
|
|
|
|
//取消置顶动态
|
|
public function removeTopMoment(Request $request,$moment_id){
|
|
try {
|
|
Moment::where('id',$moment_id)->update(['is_top'=>0]);
|
|
return $this->success('ok');
|
|
} catch (Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('取消置顶动态失败,联系技术人员');
|
|
}
|
|
|
|
}
|
|
|
|
public function moment(Request $request, $moment_id)
|
|
{
|
|
try {
|
|
$result = $this->moment_service->moment($moment_id);
|
|
if (empty($result)) throw new \Exception("获取动态详情失败", 1);
|
|
return $this->success('ok', $result);
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('获取动态详情失败,联系技术人员');
|
|
}
|
|
}
|
|
|
|
public function auditedMoment(Request $request, $moment_id)
|
|
{
|
|
try {
|
|
$result = $this->moment_service->auditedMoment($moment_id);
|
|
if (empty($result)) throw new \Exception("审核动态失败", 1);
|
|
return $this->success('ok', $result);
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('审核动态失败,联系技术人员');
|
|
}
|
|
}
|
|
|
|
//把动态设置为推荐
|
|
public function setHotMoments(Request $request, $moment_id=0){
|
|
Moment::where('id', $request->moment_id)->update(['is_hot'=>$request->is_hot]);
|
|
return $this->success('ok');
|
|
}
|
|
|
|
//删除动态
|
|
public function delMoment(Request $request, $moment_id){
|
|
Moment::where('id', $moment_id)->delete();
|
|
return $this->success('ok');
|
|
}
|
|
|
|
//隐藏动态
|
|
public function hideMoment(Request $request, $moment_id){
|
|
$is_show = $request->is_show ? $request->is_show : 0;
|
|
Moment::where('id', $moment_id)->update(['is_show'=>$is_show]);
|
|
return $this->success('ok');
|
|
}
|
|
|
|
//动态标题
|
|
public function addTopic(Request $request){
|
|
$is_forever = $request->is_forever;//话题时间是否设置为永久
|
|
|
|
$is_set = MomentTopic::where('name', $request->name)->count();
|
|
if($is_set){
|
|
return $this->failure('不能创建重复的话题');
|
|
}
|
|
$topic = New MomentTopic();
|
|
$topic->name = $request->name;
|
|
$topic->back_image = $request->back_image;
|
|
$topic->info = $request->info;
|
|
$topic->color = $request->color;
|
|
$topic->back_color = $request->back_color;
|
|
$topic->is_hot = $request->is_hot?:0;
|
|
$topic->sort = $request->sort?:0;
|
|
$topic->is_show = is_numeric($request->is_show)?$request->is_show:1;
|
|
|
|
$start_time = $request->start_time;
|
|
$end_time = $request->end_time;
|
|
|
|
if ($is_forever){
|
|
$topic->start_time = date('Y-m-d H:i:s');
|
|
$topic->end_time = date('Y-m-d H:i:s',strtotime('+100 years'));
|
|
}else{
|
|
$topic->start_time = $start_time ? $topic->start_time = $start_time : date('Y-m-d H:i:s');
|
|
$topic->end_time = $end_time ? $topic->end_time = $end_time : date('Y-m-d H:i:s',strtotime('+10 days'));
|
|
}
|
|
|
|
$topic->save();
|
|
return $this->success('ok',$topic);
|
|
}
|
|
|
|
public function topics(Request $request){
|
|
$topics = MomentTopic::withCount('moment')->with('momentTopicsActivities')->orderBy('sort','desc')->orderBy('id','asc');
|
|
if($request->keyword){
|
|
$topics = $topics->where('name', 'like', '%'.$request->keyword.'%');
|
|
}
|
|
// if(is_numeric($request->is_hot)){
|
|
// $topics = $topics->where('is_hot', $request->is_hot);
|
|
// }
|
|
// if(is_numeric($request->is_show)){
|
|
// $topics = $topics->where('is_hot', $request->is_hot);
|
|
// }
|
|
$nopage = $request->input('nopage');
|
|
if ($nopage) {
|
|
$topics = $topics->get();
|
|
}else {
|
|
$topics = $topics->paginate();
|
|
}
|
|
foreach ($topics as $topic){
|
|
$topic->quote_num = $topic->moment_count;
|
|
}
|
|
return $this->success('ok', $topics);
|
|
}
|
|
|
|
|
|
public function topic(Request $request, $topic_id){
|
|
$page = $request->input('page',1);//第几页
|
|
$size = $request->input('size',15);//每页数量
|
|
$count = $count = Moment::where('topic_id',$topic_id)->count();
|
|
|
|
//每一条动态评论总数
|
|
$sql = "SELECT * from ufutx_moments as m LEFT JOIN (SELECT commentable_id as moment_id, COUNT(*) as comment_count FROM `ufutx_comments` WHERE commentable_type = 'App\\\\Models\\\\Moment' GROUP BY commentable_id ) as `c` on c.moment_id = m.id
|
|
where topic_id = ".$topic_id." and deleted_at IS NULL ORDER BY m.created_at DESC limit ".($page-1)*$size.',15';
|
|
$results = DB::select($sql);
|
|
|
|
//每一条动态点赞总数
|
|
$q = "SELECT * from ufutx_moments as m LEFT JOIN (SELECT followable_id as moment_id, COUNT(*) as like_count FROM `ufutx_followables` WHERE followable_type = 'App\\\\Models\\\\Moment' GROUP BY followable_id ) as `f` on f.moment_id = m.id
|
|
where topic_id = ".$topic_id." and deleted_at IS NULL";
|
|
$querys = DB::select($q);
|
|
|
|
foreach ($results as $result) {
|
|
$user = User::where('id',$result->user_id)->select('id','nickname','app_avatar','circle_avatar','mobile')->first();
|
|
$result->user = $user;
|
|
$result->photos = json_decode($result->photos,true);
|
|
|
|
$result->like_count = 0;
|
|
foreach ($querys as $query) {
|
|
if ($result->moment_id == $query->moment_id) {
|
|
$result->like_count = $query->like_count;
|
|
}
|
|
}
|
|
if ($result->like_count == null) {
|
|
$result->like_count = 0;
|
|
}
|
|
if ($result->comment_count == null) {
|
|
$result->comment_count = 0;
|
|
}
|
|
}
|
|
return $this->success($count, $results);
|
|
}
|
|
|
|
//话题动态按评论排序
|
|
public function topicByComment(Request $request, $topic_id){
|
|
$page = $request->input('page',1);//第几页
|
|
$size = $request->input('size',15);//每页数量
|
|
$count = Moment::where('topic_id',$topic_id)->count();
|
|
|
|
//每一条动态评论总数
|
|
$sql = "SELECT * from ufutx_moments as m LEFT JOIN (SELECT commentable_id as moment_id, COUNT(*) as comment_count FROM `ufutx_comments` WHERE commentable_type = 'App\\\\Models\\\\Moment' GROUP BY commentable_id ) as `c` on c.moment_id = m.id
|
|
where topic_id = ".$topic_id." and deleted_at IS NULL ORDER BY c.comment_count DESC limit ".($page-1)*$size.',15';
|
|
$results = DB::select($sql);
|
|
|
|
$q = "SELECT * from ufutx_moments as m LEFT JOIN (SELECT followable_id as moment_id, COUNT(*) as like_count FROM `ufutx_followables` WHERE followable_type = 'App\\\\Models\\\\Moment' GROUP BY followable_id ) as `f` on f.moment_id = m.id where topic_id = ".$topic_id." and deleted_at IS NULL";
|
|
$querys = DB::select($q);
|
|
|
|
//每一条动态点赞总数
|
|
foreach ($results as $result) {
|
|
$user = User::where('id',$result->user_id)->select('id','nickname','app_avatar','circle_avatar','mobile')->first();
|
|
$result->user = $user;
|
|
$result->photos = json_decode($result->photos,true);
|
|
|
|
$result->like_count = 0;
|
|
foreach ($querys as $query) {
|
|
if ($result->moment_id == $query->moment_id) {
|
|
$result->like_count = $query->like_count;
|
|
}
|
|
}
|
|
if ($result->like_count == null) {
|
|
$result->like_count = 0;
|
|
}
|
|
if ($result->comment_count == null) {
|
|
$result->comment_count = 0;
|
|
}
|
|
}
|
|
return $this->success($count, $results);
|
|
}
|
|
|
|
//话题动态按点赞排序
|
|
public function topicByLike(Request $request, $topic_id){
|
|
$page = $request->input('page',1);//第几页
|
|
$size = $request->input('size',15);//每页数量
|
|
$count = Moment::where('topic_id',$topic_id)->count();
|
|
//每一条动态评论总数
|
|
$sql = "SELECT * from ufutx_moments as m LEFT JOIN (SELECT commentable_id as moment_id, COUNT(*) as comment_count FROM `ufutx_comments` WHERE commentable_type = 'App\\\\Models\\\\Moment' GROUP BY commentable_id ) as `c` on c.moment_id = m.id
|
|
where topic_id = ".$topic_id." and deleted_at IS NULL";
|
|
$results = DB::select($sql);
|
|
|
|
//每一条动态点赞总数
|
|
$q = "SELECT * from ufutx_moments as m LEFT JOIN (SELECT followable_id as moment_id, COUNT(*) as like_count FROM `ufutx_followables` WHERE followable_type = 'App\\\\Models\\\\Moment' GROUP BY followable_id ) as `f` on f.moment_id = m.id
|
|
where topic_id = ".$topic_id." and deleted_at IS NULL ORDER BY f.like_count DESC limit ".($page-1)*$size.',15';
|
|
$querys = DB::select($q);
|
|
|
|
foreach ($querys as $query) {
|
|
$user = User::where('id',$query->user_id)->select('id','nickname','app_avatar','circle_avatar','mobile')->first();
|
|
$query->user = $user;
|
|
$query->photos = json_decode($query->photos,true);
|
|
$query->comment_count = 0;
|
|
foreach ($results as $result) {
|
|
if ($query->moment_id == $result->moment_id) {
|
|
$query->comment_count = $result->comment_count;
|
|
}
|
|
}
|
|
if ($query->like_count == null) {
|
|
$query->like_count = 0;
|
|
}
|
|
if ($query->comment_count == null) {
|
|
$query->comment_count = 0;
|
|
}
|
|
}
|
|
return $this->success($count, $querys);
|
|
}
|
|
|
|
public function updateTopic(Request $request, $topic_id){
|
|
$topic = MomentTopic::find($topic_id);
|
|
if($request->name && $request->name != $topic->name){
|
|
$is_set = MomentTopic::where('name', $request->name)->count();
|
|
if($is_set){
|
|
return $this->failure('不能使用重复的话题名');
|
|
}
|
|
$topic->name = $request->name;
|
|
}
|
|
if($request->back_image && $request->back_image != $topic->back_image){
|
|
$topic->back_image = $request->back_image;
|
|
}
|
|
if($request->info && $request->info != $topic->info){
|
|
$topic->info = $request->info;
|
|
}
|
|
if($request->color && $request->color != $topic->color){
|
|
$topic->color = $request->color;
|
|
}
|
|
if($request->back_color && $request->back_color != $topic->back_color){
|
|
$topic->back_color = $request->back_color;
|
|
}
|
|
if(is_numeric($request->is_hot) && $request->is_hot != $topic->is_hot){
|
|
$topic->is_hot = $request->is_hot;
|
|
}
|
|
if(is_numeric($request->is_show) && $request->is_show != $topic->is_show){
|
|
$topic->is_show = $request->is_show;
|
|
}
|
|
if(is_numeric($request->sort) && $request->sort != $topic->sort){
|
|
$topic->sort = $request->sort;
|
|
}
|
|
if ($request->is_forever) {
|
|
$topic->start_time = date('Y-m-d H:i:s');
|
|
$topic->end_time = date('Y-m-d H:i:s',strtotime('+100 years'));
|
|
}else{
|
|
$topic->start_time = $request->start_time ? $request->start_time : date('Y-m-d H:i:s');
|
|
$topic->end_time = $request->end_time ? $request->end_time : date('Y-m-d H:i:s',strtotime('+10 days'));
|
|
}
|
|
$topic->save();
|
|
return $this->success('ok',$topic);
|
|
}
|
|
|
|
//动态投票
|
|
public function addVote(Request $request){
|
|
try {
|
|
DB::beginTransaction();
|
|
$vote = new Vote();
|
|
$vote->parent_id = is_numeric($request->parent_id) ? $request->parent_id : 0;
|
|
$vote->title = $request->title;
|
|
$vote->content = $request->input('content')?:'如题';
|
|
$vote->is_show = is_numeric($request->is_show) ? $request->is_show : 1;
|
|
$vote->is_hot = is_numeric($request->is_hot) ? $request->is_hot : 0;
|
|
$vote->sort = is_numeric($request->sort) ? $request->sort : 0;
|
|
$vote->save();
|
|
$options = $request->options;
|
|
foreach ($options as $key => $value) {
|
|
VoteOption::create([
|
|
'vote_id'=>$vote->id,
|
|
'title'=>$value
|
|
]);
|
|
}
|
|
DB::commit();
|
|
return $this->success('添加成功');
|
|
} catch (\Exception $e) {
|
|
DB::rollBack();
|
|
$this->getError($e);
|
|
return $this->failure('添加失败, 联系开发人员');
|
|
}
|
|
}
|
|
|
|
//投票列表
|
|
public function votes(Request $request){
|
|
$votes = Vote::withCount('userVote')->with('option:vote_id,title')->where('parent_id', 0)->orderBy('id', 'desc');
|
|
if($request->keyword){
|
|
$votes = $votes->where('title', 'like', '%'.$request->keyword.'%');
|
|
}
|
|
if(is_numeric($request->is_show)){
|
|
$votes = $votes->where('is_show', $request->is_show);
|
|
}
|
|
if(is_numeric($request->parent_id)){
|
|
$votes = $votes->where('parent_id', $request->parent_id);
|
|
}
|
|
$votes = $votes->paginate();
|
|
return $this->success('ok', $votes);
|
|
}
|
|
|
|
//投票详情
|
|
public function vote(Request $request, $vote_id){
|
|
$vote = Vote::with(['option'=>function($query) {
|
|
$query->withCount('voteUser');
|
|
}])->where('id', $vote_id)->first();
|
|
return $this->success('ok', $vote);
|
|
}
|
|
|
|
//已投选项用户列表
|
|
public function voteInfo(Request $request ,$vote_id ,$option_id){
|
|
$keyword = $request->keyword;
|
|
$users = UserVote::with('user')->where('vote_id',$vote_id)->where('option_id',$option_id)->whereHas('user');
|
|
if ($keyword) {
|
|
$keyword = trim($keyword);
|
|
$users = $users->whereHas('user',function($sql) use($keyword){
|
|
$sql->where('nickname','like','%'.$keyword.'%')
|
|
->orWhere('id',$keyword)
|
|
->orWhere('mobile','like','%'.$keyword.'%');
|
|
});
|
|
}
|
|
$users = $users->orderBy('id','desc')->paginate();
|
|
return $this->success('ok',$users);
|
|
}
|
|
|
|
//修改投票
|
|
public function updateVote(Request $request, $vote_id){
|
|
try {
|
|
$vote = Vote::find($vote_id);
|
|
if(!empty($request->title) && $request->title != $vote->title){
|
|
$vote->title = $request->title;
|
|
}
|
|
if(!empty($request->input('content')) && $request->input('content') != $vote->content){
|
|
$vote->content = $request->input('content');
|
|
}
|
|
if(is_numeric($request->is_show) && $request->is_show != $vote->is_show){
|
|
$vote->is_show = $request->is_show;
|
|
}
|
|
if(is_numeric($request->is_hot) && $request->is_hot != $vote->is_hot){
|
|
$vote->is_hot = $request->is_hot;
|
|
}
|
|
if(is_numeric($request->sort) && $request->sort != $vote->sort){
|
|
$vote->sort = $request->sort;
|
|
}
|
|
$vote->save();
|
|
return $this->success('ok');
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('修改失败,联系开发人员');
|
|
}
|
|
|
|
}
|
|
|
|
//删除投票
|
|
public function delVote(Request $request, $vote_id){
|
|
try {
|
|
\DB::beginTransaction();
|
|
Vote::where('id', $vote_id)->delete();
|
|
UserVote::where('vote_id', $vote_id)->delete();
|
|
VoteOption::where('vote_id', $vote_id)->delete();
|
|
\DB::commit();
|
|
return $this->success('删除成功');
|
|
} catch (\Exception $e) {
|
|
\DB::rollback();
|
|
$this->getError($e);
|
|
return $this->failure('添加失败, 联系开发人员');
|
|
}
|
|
}
|
|
|
|
//投票选项
|
|
public function addOption(Request $request){
|
|
$is_set = VoteOption::where('title', $request->title)->where('vote_id', $request->vote_id)->count();
|
|
if($is_set){
|
|
return $this->failure('不能添加相同的选项');
|
|
}
|
|
$option = New VoteOption();
|
|
$option->vote_id = $request->vote_id ?: 0;
|
|
$option->title = $request->title ?: '说说你的想法';
|
|
$option->save();
|
|
return $this->success('添加成功');
|
|
}
|
|
|
|
public function options(Request $request){
|
|
$options = VoteOption::where('vote_id', $request->vote_id)->get();
|
|
return $this->success('ok', $options);
|
|
}
|
|
|
|
public function updateOption(Request $request, $option_id){
|
|
$is_set = VoteOption::where('title', $request->title)->where('vote_id', $request->vote_id)->count();
|
|
if($is_set){
|
|
return $this->success('不能添加相同的选项');
|
|
}
|
|
$option = VoteOption::find($option_id);
|
|
if($request->title != $option->title){
|
|
$option->title = $request->title;
|
|
}
|
|
$option->save();
|
|
return $this->success('ok', $option);
|
|
}
|
|
|
|
public function delOption(Request $request, $option_id){
|
|
VoteOption::where('id', $option_id)->delete();
|
|
UserVote::where('option_id', $option_id)->delete();
|
|
return $this->success('ok');
|
|
}
|
|
|
|
/**
|
|
* 发布动态
|
|
* @return [type] [description]
|
|
*/
|
|
public function storeMoment(Request $request)
|
|
{
|
|
try {
|
|
//检查参数
|
|
$result = $this->checkStoreMoment();
|
|
if (empty($result)) throw new \Exception("发送动态参数错误", 1);
|
|
if (is_array($result) && $result['code']) return $this->failure($result['msg']);
|
|
|
|
$moment = $this->moment_service->addMoment(auth()->id(), 'ADMIN');
|
|
if (empty($moment)) throw new \Exception("发布动态失败", 1);
|
|
if (is_array($moment) && $moment['code']) return $this->failure($moment['msg']);
|
|
return $this->success('ok', $moment);
|
|
|
|
// //发布动态
|
|
// $moment = new Moment;
|
|
// $moment->user_id = $request->user_id;
|
|
// $moment->topic_id = $request->input('topic_id')?:0;
|
|
// $moment->content = $request->content;
|
|
// $moment->photos = json_encode($request->input('photos')?:[]);
|
|
// $moment->aliyun_video_id = $request->input('video_id');
|
|
// //获取视频信息
|
|
// $video_height = 0;
|
|
// $video_width = 0;
|
|
// if(!empty($moment->aliyun_video_id)){
|
|
// $result = $this->getVodInfo($moment->aliyun_video_id);
|
|
// if(is_array($result)){
|
|
// $video_height = $result['Mezzanine']['Height'];
|
|
// $video_width = $result['Mezzanine']['Width'];
|
|
// }
|
|
// }
|
|
// $moment->video_height = $video_height;
|
|
// $moment->video_width = $video_width;
|
|
// $moment->location_latitude = $request->input('location_latitude');
|
|
// $moment->location_longitude = $request->input('location_longitude');
|
|
// $moment->address = $request->input('address');
|
|
// $moment->is_audited = 1;
|
|
// $moment->is_hot = $request->input('is_hot')?:0;
|
|
// $moment->save();
|
|
// return $this->success('ok', $moment);
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return $this->failure('发布动态失败,请联系开发人员');
|
|
}
|
|
}
|
|
|
|
public function checkStoreMoment()
|
|
{
|
|
try {
|
|
//内容
|
|
$content = request()->input('content');
|
|
if (empty($content)) return ['code'=>1, 'msg'=>'请输入动态内容'];
|
|
//用户
|
|
$user_id = request()->input('user_id');
|
|
if (empty($user_id)) return ['code'=>1, 'msg'=>'请输入指定发布用户'];
|
|
//凭证
|
|
// $token = request()->input('token');
|
|
// if (empty($token)) return ['code'=>1, 'msg'=>'请输入上传视频凭证'];
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
$this->getError($e);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
//创建話題配置
|
|
public function createConfigureTopic(Request $request,$topic_id){
|
|
$topic = MomentTopic::find($topic_id);
|
|
if (empty($topic)) return $this->failure('話題不存在');
|
|
|
|
$activity_topic = MomentTopicsActivities::where('topic_id',$topic_id)->first();
|
|
if (!empty($activity_topic)) return $this->failure('一个话题只能有一个活动');
|
|
|
|
//配置話题
|
|
$topic_activity = new MomentTopicsActivities();
|
|
//字数限制 0为无限制
|
|
$topic_activity->tc_moment_content_count = $request->tc_moment_content_count?$request->tc_moment_content_count:0;
|
|
//图片限制 0为无限制
|
|
$topic_activity->tc_moment_photos_count = $request->tc_moment_photos_count?$request->tc_moment_photos_count:0;
|
|
$topic_activity->award_member_days = $request->award_member_days?$request->award_member_days:0;
|
|
|
|
if (empty($request->succeed_picture)) return $this->failure('请选择领取成功图片');
|
|
$topic_activity->succeed_picture = $request->succeed_picture;
|
|
|
|
if (empty($request->failure_picture)) return $this->failure('请选择失败提醒图片');
|
|
$topic_activity->failure_picture = $request->failure_picture;
|
|
|
|
if (empty($request->failure_picture_app)) return $this->failure('请选择失败提醒app图片');
|
|
$topic_activity->failure_picture_app = $request->failure_picture_app;
|
|
|
|
if (empty($request->entrance_picture)) return $this->failure('请选择入口小图标');
|
|
$topic_activity->entrance_picture = $request->entrance_picture;
|
|
|
|
if (empty($request->goto_url)) return $this->failure('请输入前往的url');
|
|
$topic_activity->goto_url = $request->goto_url;
|
|
|
|
|
|
$topic_activity->topic_id = $topic_id;
|
|
|
|
$topic_activity->start_time = $request->start_time;
|
|
$topic_activity->end_time = $request->end_time;
|
|
|
|
$topic_activity->save();
|
|
|
|
return $this->success('ok',$topic_activity);
|
|
}
|
|
|
|
//修改話題配置
|
|
public function updateConfigureTopic(Request $request,$topic_id){
|
|
$topic_activity = MomentTopicsActivities::where('topic_id',$topic_id)->first();
|
|
if (empty($topic_activity)) return $this->failure('话题活动不存在');
|
|
|
|
if (is_numeric($request->tc_moment_content_count) && $request->tc_moment_content_count!= $topic_activity->tc_moment_content_count) {
|
|
$topic_activity->tc_moment_content_count = $request->tc_moment_content_count;
|
|
}
|
|
if (is_numeric($request->tc_moment_photos_count) && $request->tc_moment_photos_count!= $topic_activity->tc_moment_photos_count) {
|
|
$topic_activity->tc_moment_photos_count = $request->tc_moment_photos_count;
|
|
}
|
|
if (is_numeric($request->award_member_days) && $request->award_member_days!= $topic_activity->award_member_days) {
|
|
$topic_activity->award_member_days = $request->award_member_days;
|
|
}
|
|
if ($request->succeed_picture && $request->succeed_picture!= $topic_activity->succeed_picture) {
|
|
$topic_activity->succeed_picture = $request->succeed_picture;
|
|
}
|
|
if ($request->failure_picture_app && $request->failure_picture_app!= $topic_activity->failure_picture_app) {
|
|
$topic_activity->failure_picture_app = $request->failure_picture_app;
|
|
}
|
|
if ($request->entrance_picture && $request->entrance_picture!= $topic_activity->entrance_picture) {
|
|
$topic_activity->entrance_picture = $request->entrance_picture;
|
|
}
|
|
if ($request->goto_url && $request->goto_url!= $topic_activity->goto_url) {
|
|
$topic_activity->goto_url = $request->goto_url;
|
|
}
|
|
if ($request->failure_picture && $request->failure_picture!= $topic_activity->failure_picture) {
|
|
$topic_activity->failure_picture = $request->failure_picture;
|
|
}
|
|
if ($request->start_time && $request->start_time!= $topic_activity->start_time) {
|
|
$topic_activity->start_time = $request->start_time;
|
|
}
|
|
if ($request->end_time && $request->end_time!= $topic_activity->end_time) {
|
|
$topic_activity->end_time = $request->end_time;
|
|
}
|
|
|
|
$topic_activity->save();
|
|
return $this->success('ok',$topic_activity);
|
|
}
|
|
|
|
//话题配置详情
|
|
public function topicActivityDetail(Request $request,$topic_id){
|
|
$topic_activity = MomentTopicsActivities::where('topic_id',$topic_id)->first();
|
|
return $this->success('ok',$topic_activity);
|
|
}
|
|
|
|
//刪除活动奖励
|
|
public function delTopicActivity(Request $request,$id){
|
|
MomentTopicsActivities::where('id',$id)->delete();
|
|
return $this->success('ok');
|
|
}
|
|
|
|
/**
|
|
* 限制发动态用户列表
|
|
* @param Request $request
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\Http\JsonResponse|\Illuminate\View\View
|
|
*/
|
|
public function restrictMomentUsers(Request $request)
|
|
{
|
|
try {
|
|
$keyword = $request->input('keyword');
|
|
$list = RestrictMomentUser::query()
|
|
->with('user:id,nickname,photo,app_avatar,circle_avatar,type,sex,is_photo_audited')
|
|
->whereHas('user', function ($query) use ($keyword) {
|
|
$query->where('name', 'like', "%{$keyword}%");
|
|
})
|
|
->orderBy('id', 'desc')
|
|
->paginate();
|
|
$config_value = Configs::query()->where('key','restrict_moment_num')->value('value') ?: 1;
|
|
return $this->success('ok', compact('list','config_value'));
|
|
} catch (\Exception $e) {
|
|
return $this->failure($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 修改配置次数
|
|
* @param Request $request
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\Http\JsonResponse|\Illuminate\View\View
|
|
*/
|
|
public function updateRestrictMomentNum(Request $request)
|
|
{
|
|
try {
|
|
$num = $request->input('num');
|
|
if (!is_numeric($num)) {
|
|
return $this->failure('参数错误');
|
|
}
|
|
$config = Configs::query()->where('key', 'restrict_moment_num')->first();
|
|
if ($num != $config->value) {
|
|
$config->value = $num;
|
|
$config->save();
|
|
}
|
|
return $this->success('ok');
|
|
} catch (\Exception $e) {
|
|
return $this->failure($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 添加限制发动态用户
|
|
* @param Request $request
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\Http\JsonResponse|\Illuminate\View\View
|
|
*/
|
|
public function restrictMomentUserAdd(Request $request)
|
|
{
|
|
try {
|
|
$user_id = $request->input('user_id');
|
|
$user = User::find($user_id);
|
|
if (!$user) {
|
|
return $this->failure('用户不存在');
|
|
}
|
|
$restrict_moment_user = RestrictMomentUser::query()->where('user_id', $user_id)->first();
|
|
if ($restrict_moment_user) {
|
|
return $this->failure('该用户添加过了');
|
|
}
|
|
$data = new RestrictMomentUser;
|
|
$data->user_id = $user_id;
|
|
$data->save();
|
|
return $this->success('ok');
|
|
} catch (\Exception $e) {
|
|
return $this->failure($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除限制发动态用户
|
|
* @param Request $request
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\Http\JsonResponse|\Illuminate\View\View
|
|
*/
|
|
public function restrictMomentUserDel(Request $request)
|
|
{
|
|
try {
|
|
$user_id = $request->input('user_id');
|
|
$restrict_moment_user = RestrictMomentUser::query()->where('user_id', $user_id)->first();
|
|
if (!$restrict_moment_user) {
|
|
return $this->failure('数据不存在');
|
|
}
|
|
$restrict_moment_user->delete();
|
|
return $this->success('ok');
|
|
} catch (\Exception $e) {
|
|
return $this->failure($e->getMessage());
|
|
}
|
|
}
|
|
|
|
}
|