|
@@ -4,6 +4,10 @@
|
|
namespace App\Http\Controllers\Api;
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
|
|
|
|
|
|
+use App\Http\Params\DynamicParam;
|
|
|
|
+use App\Http\Params\DynamicZanParam;
|
|
|
|
+use App\Http\Params\UserReportParam;
|
|
|
|
+use App\Models\Banner;
|
|
use App\Services\DynamicService;
|
|
use App\Services\DynamicService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
@@ -22,10 +26,12 @@ class DynamicController extends Controller
|
|
* 获取话题列表
|
|
* 获取话题列表
|
|
*/
|
|
*/
|
|
public function get_tag_list(Request $request){
|
|
public function get_tag_list(Request $request){
|
|
-
|
|
|
|
-
|
|
|
|
- $data = DB::table("dynamic_tag")->where("title","like","%{$request->keyword}%")->orderBy("hot","desc")->limit(20)->get();
|
|
|
|
- return response()->json($data)->setStatusCode(201);
|
|
|
|
|
|
+ try {
|
|
|
|
+ $data = $this->dynamicService->tag_list($request->keyword);
|
|
|
|
+ }catch (\Exception $exception){
|
|
|
|
+ return $this->response->errorForbidden($exception->getMessage());
|
|
|
|
+ }
|
|
|
|
+ return response()->json($data);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -33,7 +39,6 @@ class DynamicController extends Controller
|
|
* 发布动态
|
|
* 发布动态
|
|
*/
|
|
*/
|
|
public function release(Request $request){
|
|
public function release(Request $request){
|
|
- $user = auth('api')->user();
|
|
|
|
$validator = Validator::make($request->all(), [
|
|
$validator = Validator::make($request->all(), [
|
|
'content' => 'required',
|
|
'content' => 'required',
|
|
], [
|
|
], [
|
|
@@ -42,60 +47,136 @@ class DynamicController extends Controller
|
|
if ($validator->fails()) {
|
|
if ($validator->fails()) {
|
|
return $this->response()->errorForbidden($validator->messages()->first());
|
|
return $this->response()->errorForbidden($validator->messages()->first());
|
|
}
|
|
}
|
|
-
|
|
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
-
|
|
|
|
try {
|
|
try {
|
|
- //如果设置了话题
|
|
|
|
- if(isset($request->tag) && !empty($request->tag)){
|
|
|
|
-
|
|
|
|
|
|
+ $user = auth('api')->user();
|
|
|
|
+ $dynamicParam = new DynamicParam();
|
|
|
|
+ $dynamicParam->user_id = $user->id;
|
|
|
|
+ $dynamicParam->content = htmlspecialchars($request->post('content'));
|
|
|
|
+ $dynamicParam->img_url = $request->post('img_url');
|
|
|
|
+ $dynamicParam->type = $request->post('type');
|
|
|
|
+ $dynamicParam->status = 1;
|
|
|
|
+ $dynamicParam->zan_num = 0;
|
|
|
|
+ $dynamicParam->site = $request->post('site');
|
|
|
|
+ $dynamicParam->tag = $request->post('tag');
|
|
|
|
+ $this->dynamicService->release($dynamicParam);
|
|
|
|
+ DB::commit();
|
|
|
|
+ }catch (\Exception $exception){
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ return $this->response->errorForbidden($exception->getMessage());
|
|
|
|
+ }
|
|
|
|
+ return $this->response->noContent();
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 动态banner,话题,风险提示
|
|
|
|
+ */
|
|
|
|
+ public function dynamic_info(){
|
|
|
|
+ try {
|
|
|
|
+ $oss_config = config("filesystems.disks.oss");
|
|
|
|
+ $banner = Banner::where(["site"=>1,"status"=>1])->orderBy("sort",'asc')->limit(3)->get(['id','img_url']);
|
|
|
|
+ foreach ($banner as $k=>$v){
|
|
|
|
+ $banner[$k]['img_url'] = "https://".$oss_config['bucket'].'.'.$oss_config['endpoint'].'/'.$v['img_url'];
|
|
}
|
|
}
|
|
-
|
|
|
|
- }catch (\Exception $e){
|
|
|
|
-
|
|
|
|
|
|
+ $res['banner'] = $banner;
|
|
|
|
+ $res['tag'] = DB::table("dynamic_tag")->orderBy('hot','desc')->limit(10)->get();
|
|
|
|
+ }catch (\Exception $exception){
|
|
|
|
+ return $this->response->errorForbidden($exception->getMessage());
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ return response()->json($res);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 动态列表
|
|
* 动态列表
|
|
*/
|
|
*/
|
|
public function get_list(Request $request){
|
|
public function get_list(Request $request){
|
|
|
|
|
|
|
|
+ $where = array();
|
|
|
|
+ $where['type'] = $request->post('type',1); //类型 type 1全部 2关注 3附近
|
|
|
|
+ $where['look_type'] =$request->post('look_type',3);//查看类型 type 1只看男士 2只看女士 3全部
|
|
|
|
+ $where['tag_id'] =$request->post('tag_id',0); //话题标签
|
|
|
|
+ $where['user_id'] =0;
|
|
|
|
+ try {
|
|
|
|
+ $list = $this->dynamicService->dynamic_list($where);
|
|
|
|
+ }catch (\Exception $exception){
|
|
|
|
+ return $this->response->errorForbidden($exception->getMessage());
|
|
|
|
+ }
|
|
|
|
+ return response()->json($list);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 我的动态
|
|
* 我的动态
|
|
*/
|
|
*/
|
|
public function my_list(Request $request){
|
|
public function my_list(Request $request){
|
|
|
|
+ $user = auth('api')->user();
|
|
|
|
+ $where = array();
|
|
|
|
+ $where['type'] = $request->post('type',1); //类型 type 1全部 2关注 3附近
|
|
|
|
+ $where['look_type'] =$request->post('look_type',3);//查看类型 type 1只看男士 2只看女士 3全部
|
|
|
|
+ $where['tag_id'] =$request->post('tag_id',0); //话题标签
|
|
|
|
|
|
|
|
+ $where['user_id'] =$user->id;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ $list = $this->dynamicService->dynamic_list($where);
|
|
|
|
+ }catch (\Exception $exception){
|
|
|
|
+ return $this->response->errorForbidden($exception->getMessage());
|
|
|
|
+ }
|
|
|
|
+ return response()->json($list);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 动态点赞
|
|
* 动态点赞
|
|
*/
|
|
*/
|
|
public function zan(Request $request){
|
|
public function zan(Request $request){
|
|
-
|
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+ try {
|
|
|
|
+ $user = auth('api')->user();
|
|
|
|
+ $dynamic_zan_param = new DynamicZanParam();
|
|
|
|
+ $dynamic_zan_param->user_id = $user->id;
|
|
|
|
+ $dynamic_zan_param->dynamic_id = $request->id;
|
|
|
|
+ $this->dynamicService->zan($dynamic_zan_param);
|
|
|
|
+ DB::commit();
|
|
|
|
+ }catch (\Exception $exception){
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ return $this->response->errorForbidden($exception->getMessage());
|
|
|
|
+ }
|
|
|
|
+ return $this->response->noContent();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 删除动态
|
|
* 删除动态
|
|
*/
|
|
*/
|
|
public function del(Request $request){
|
|
public function del(Request $request){
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ try {
|
|
|
|
+ $DynamicParam = new DynamicParam();
|
|
|
|
+ $DynamicParam->id = $request->id;
|
|
|
|
+ $this->dynamicService->del($DynamicParam);
|
|
|
|
+ }catch (\Exception $exception){
|
|
|
|
+ return $this->response->errorForbidden($exception->getMessage());
|
|
|
|
+ }
|
|
|
|
+ return $this->response->noContent();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 举报动态
|
|
* 举报动态
|
|
*/
|
|
*/
|
|
public function report(Request $request){
|
|
public function report(Request $request){
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+ try {
|
|
|
|
+ $user = auth('api')->user();
|
|
|
|
+ $UserReportParam = new UserReportParam();
|
|
|
|
+ $UserReportParam->type = 2;
|
|
|
|
+ $UserReportParam->user_id = $user->id;
|
|
|
|
+ $UserReportParam->content = $request->post('content');
|
|
|
|
+ $UserReportParam->report_id = $request->post('id');
|
|
|
|
+ $UserReportParam->status = 0;
|
|
|
|
+ $UserReportParam->img_url = $request->post('img_url');
|
|
|
|
+ $UserReportParam->info = $request->post('info',"");
|
|
|
|
+ $this->dynamicService->report($UserReportParam);
|
|
|
|
+ }catch (\Exception $exception){
|
|
|
|
+ return $this->response->errorForbidden($exception->getMessage());
|
|
|
|
+ }
|
|
|
|
+ return $this->response->noContent();
|
|
}
|
|
}
|
|
}
|
|
}
|