Parcourir la source

提交列表页详情页

huanglei il y a 3 mois
Parent
commit
08168034e6

+ 216 - 0
app/Http/Controllers/Api/Article/Comment.php

@@ -0,0 +1,216 @@
+<?php namespace App\Http\Controllers\Api\Article;
+
+use App\Http\Controllers\Api\Api;
+use App\Models\Article as Model;
+use App\Models\ArticleComment as ArticleCommentModel;
+
+
+
+/**
+ * 分享设置
+ *
+ * @author    huanglei
+ *
+ */
+class Comment extends Api{
+	const EVENT_TYPE = [
+		'1' => '阅读',
+		'2' => '点赞',
+		'3' => '分享',
+		'4' => '推荐',
+		'5' => '取消推荐',
+		'6' => '取消点赞'	
+	];
+	public function list(Model $Model, ArticleCommentModel $ArticleCommentModel){
+		
+		// 接受参数
+		$code					= request('article_code','');
+
+		$status					= request('status');
+		$startTime				= request('start_time','');
+		$endTime				= request('end_time','');
+		// 编码转ID
+		$id						= $code ? $Model->codeToId($code) : 0;
+		// 查询条件
+		$map 					= [];
+		// 编码ID
+		if( $id )				$map[] = ['id','=',$id];
+		if( $startTime )		$map[] = ['start_time','>=',strtotime($startTime)];
+		if( $endTime )			$map[] = ['end_time','<=',strtotime($endTime)];
+		if( !is_null($status) )	$map[] = ['status','=',$status];
+		// 查询文章数据
+		$list					= $Model->query()->where($map);
+        $list                   =  $list->orderByDesc('id')->paginate(request('limit',config('page_num',10)))->appends(request()->all());
+		
+
+		// 循环处理数据
+		foreach ($list as $key => $value) {
+			// id转编号
+			$value['article_id']		= $value['id'];
+			// 重组
+			$value['poster']			= $value['poster']? path_compat($value['poster']):'';
+			
+			$value['read_count']        = $ArticleCommentModel->query()
+											->where(['article_id'=>$value['id'],'event_type'=>1])
+											->count();
+
+			$value['like_count']       = $ArticleCommentModel->query()
+											->where(['article_id'=>$value['id'],'event_type'=>2])
+											->count();
+		
+		    $value['update_time']      = date('Y-m-d H:i:s',$value['update_time']);	
+			$list[$key]					= $value;
+		}
+		
+		// 分配数据
+		return			json_send(['code'=>'success','msg'=>'列表数据','data'=>$list]);
+
+		
+		
+		
+    }
+	/**
+	 * 数据详情
+	 * 
+	 * */
+    public function detail(Model $Model, ArticleCommentModel $ArticleCommentModel){
+
+		// 接受参数
+		$tid					= request('article_id',0);
+
+		$uid 					= $this->checkLogin(); // custom_uid
+		
+		// 查询条件
+		$map 					= [];
+		// 编码ID
+		if( $tid )				$map[] = ['id','=',$tid];
+		
+		
+		
+
+        $data                   = $Model->query()->where($map)->find($tid,['id','title','poster','content']);
+		$data['like_count']     = $ArticleCommentModel->query()
+											->where(['article_id'=>$tid,'event_type'=>2])
+											->count();
+
+		$data['read_count']     = $ArticleCommentModel->query()
+											->where(['article_id'=>$tid,'event_type'=>1])
+											->count();
+
+		$data['share_count']    = $ArticleCommentModel->query()
+											->where(['article_id'=>$tid,'event_type'=>3])
+											->count();
+
+		$data['recommend_count'] = $ArticleCommentModel->query()
+											->where(['article_id'=>$tid,'event_type'=>4])
+											->count();
+		
+	
+		//用户是否点赞和推荐
+		if ($uid){
+			$user_envent              = $ArticleCommentModel->query()->where(['uid'=>$uid,'article_id'=>$tid])
+										->get();
+			foreach ($user_envent as $value){
+			
+				if ($value['event_type'] == 2){
+					$data['like_type'] = 2;
+				}else{	
+					$data['like_type'] = 6;
+				}
+				if ($value['event_type'] == 4){
+					$data['recommend_type'] = 4;	
+				}else{
+					$data['recommend_type'] = 5;
+				}
+			}
+
+
+			//写入浏览记录
+			$read = [
+				'article_id'	  	=> $tid,
+				'event_type'		=> 1,
+				'uid'				=> $uid,
+				'insert_time'		=> time()
+			];
+			//查询用户是否浏览过
+			$read_type       		=   $ArticleCommentModel->query()->where(['uid'=>$uid,'article_id'=>$tid])->value('event_type');
+			
+			if (!$read_type){
+				$comment_id			= $ArticleCommentModel->add($read);	
+			}
+			
+			
+		}else{
+			
+			$read['event_type'] = 0;//禁止分享、推荐和点赞
+		}
+
+		// 加载模板
+		
+		if ($data){
+			return			json_send(['code'=>'success','msg'=>'数据','data'=>$data]);
+		}
+		return			json_send(['code'=>'success','msg'=>'暂无','data'=>[]]);
+		
+	}
+
+	/**
+	 * 数据详情
+	 * 
+	 * */
+    public function update_event(Model $Model, ArticleCommentModel $ArticleCommentModel){
+		// '1' => '阅读',
+		// '2' => '点赞',
+		// '3' => '分享',
+		// '4' => '推荐',
+		// '5' => '取消推荐',
+		// '6' => '取消点赞'
+		$event 					= request('event_type',0);
+		$tid					= request('article_id',0);
+		$uid 					= $this->checkLogin(); // custom_uid
+
+		// 查询条件
+		$map 					= [];
+		$map[] 					= ['uid','=',$uid];
+		$map[] 					= ['article_id','=',$tid];
+		$map[] 					= ['event_type','=',$event];
+		$user_envent            = $ArticleCommentModel->query()->where($map)->get();
+		switch ($event){
+			case 2:
+				
+				if ($user_envent){
+					$Res       	=   $ArticleCommentModel::query()
+									->where(['uid'=>$uid,'article_id'=>$tid])
+									->update(['event_type'=>'6']);
+					return			json_send(['code'=>'error','msg'=>'取消点赞','data'=>[]]);	
+				}
+				break;
+			case 4:
+				if ($user_envent){
+					$Res       	=   $ArticleCommentModel::query()
+									->where(['uid'=>$uid,'article_id'=>$tid])
+									->update(['event_type'=>'4']);
+					return			json_send(['code'=>'error','msg'=>'取消推荐','data'=>[]]);	
+				}
+				break;
+			case 6:
+				$map[] = ['uid','=',$uid];
+				$map[] = ['article_id','=',$tid];
+				$map[] = ['event_type','=',$event];	
+		}
+
+		$user_envent            = $ArticleCommentModel->query()->where($map)->get();
+		if( $tid )				$map[] = ['id','=',$tid];
+		// $orderRes       	=   $Model::query()->where('article_id','=',$tid)->update(['status'=>'1']);
+		//用户是否点赞和推荐
+
+		
+		return			json_send(['code'=>'success','msg'=>'成功',
+							'data'=>[
+								'event_type'=>$event,'article_id'=>$tid,'uid'=>$uid]
+							]);
+	
+
+	}
+    
+}

+ 1 - 1
app/Http/Controllers/Api/Score/Orders.php

@@ -88,7 +88,7 @@ class Orders extends Api{
 				// 回退数据
 				DB::rollBack();
 				// 提示信息
-				return					json_send(['code'=>'error','msg'=>'兑换失败','data'=>['error'=>result['error']]]);
+				return					json_send(['code'=>'error','msg'=>'兑换失败','data'=>['error'=>$result['error']]]);
 			}
 			// 订单ID
 			$addr['order_id']			= $orderId;

+ 7 - 0
routes/api.php

@@ -269,3 +269,10 @@ Route::any('riddle_question/get_question',[\App\Http\Controllers\Api\Riddle\Ques
 Route::any('riddle_active_share/add',[\App\Http\Controllers\Api\Riddle\ActiveShare::class,'add']);
 // 判断回答是否正确
 Route::any('riddle_answer/check_answer',[\App\Http\Controllers\Api\Riddle\Answer::class,'check_answer']);
+
+/**
+ * 文章详情
+ */
+Route::any('article/list',[App\Http\Controllers\Api\Article\Comment::class,'list']);
+Route::any('article/detail',[App\Http\Controllers\Api\Article\Comment::class,'detail']);
+Route::any('article/update_event',[App\Http\Controllers\Api\Article\Comment::class,'update_event']);