| 
									
										
										
										
											2021-12-02 10:41:02 +08:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-02 10:41:02 +08:00
										 |  |  | namespace app\controller\api; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  | use app\exception\RepositoryException; | 
					
						
							|  |  |  | use app\model\Comment as CommentModel; | 
					
						
							|  |  |  | use app\repository\AccountRepository; | 
					
						
							| 
									
										
										
										
											2021-12-07 18:14:38 +08:00
										 |  |  | use app\repository\CommentRepository; | 
					
						
							| 
									
										
										
										
											2021-12-08 10:25:31 +08:00
										 |  |  | use app\validate\Comment as VComment; | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  | use think\Exception; | 
					
						
							|  |  |  | use think\exception\ValidateException; | 
					
						
							| 
									
										
										
										
											2021-12-08 11:48:22 +08:00
										 |  |  | use think\facade\Config; | 
					
						
							| 
									
										
										
										
											2021-12-22 11:15:17 +08:00
										 |  |  | use think\facade\Log; | 
					
						
							| 
									
										
										
										
											2021-12-02 10:41:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * 评论相关 | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |  * Class Comment | 
					
						
							| 
									
										
										
										
											2021-12-02 10:41:02 +08:00
										 |  |  |  * @package app\controller\api | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | class Comment extends Base | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     protected $noNeedLogin = [ | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |         'commentList', | 
					
						
							| 
									
										
										
										
											2021-12-02 10:41:02 +08:00
										 |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-12-08 10:25:31 +08:00
										 |  |  |      * 群聊列表 | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |      * */ | 
					
						
							| 
									
										
										
										
											2021-12-07 18:14:38 +08:00
										 |  |  |     public function myCommentZone() | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |     { | 
					
						
							|  |  |  |         $page = $this->request->param('page/d', 1); | 
					
						
							| 
									
										
										
										
											2021-12-08 11:48:22 +08:00
										 |  |  |         //$size = $this->request->param('size/d', 30);
 | 
					
						
							|  |  |  |         Config::load("extra/wechat","wechat"); | 
					
						
							|  |  |  |         $systemSize = config("wechat.commentNum") ?? 30; | 
					
						
							|  |  |  |         $data = CommentRepository::getInstance()->myCommentZone( $page, $systemSize); | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |         return $this->json(0, "success", $data); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							| 
									
										
										
										
											2021-12-07 18:14:38 +08:00
										 |  |  |      * 创建一条文字评论 开发中 | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |      * */ | 
					
						
							| 
									
										
										
										
											2021-12-07 18:14:38 +08:00
										 |  |  |     public function commentText() | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |     { | 
					
						
							|  |  |  |         $accountId = $this->request->user['user_id'] ?? 0; | 
					
						
							|  |  |  |         $accountRepo = AccountRepository::getInstance(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         try { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $account = $accountRepo->findById($accountId, [], function ($q) { | 
					
						
							|  |  |  |                 return $q->with(['business', 'parent']); | 
					
						
							|  |  |  |             }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (empty($account)) { | 
					
						
							| 
									
										
										
										
											2021-12-22 10:45:44 +08:00
										 |  |  |                 throw new RepositoryException('用户无效!'); | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-12-22 09:32:41 +08:00
										 |  |  |             if(strtotime($account->blank_time) >time()){ | 
					
						
							| 
									
										
										
										
											2021-12-22 10:45:44 +08:00
										 |  |  |                 throw new RepositoryException('用户被加入黑名单,暂时不能评论,请在'  .$account->blank_time . "后评论"); | 
					
						
							| 
									
										
										
										
											2021-12-22 09:32:41 +08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-12-22 11:15:17 +08:00
										 |  |  |             $comment = input("comment/a", [],null); | 
					
						
							|  |  |  |             $comment = urldecode(json_encode($comment)); | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |             $param = [ | 
					
						
							| 
									
										
										
										
											2021-12-22 11:15:17 +08:00
										 |  |  |                 "comment"            => $comment,//评论内容   图片类型放入地址  语音类型放置语音文件地址
 | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |                 "user_code"          => $account['user_code'], | 
					
						
							|  |  |  |                 "create_time"        => date("Y-m-d H:i:s"), | 
					
						
							| 
									
										
										
										
											2021-12-08 10:25:31 +08:00
										 |  |  |                 //"url"                => input("url/s", ""),//图片地址   仅图片评论才有
 | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |                 "state"              => CommentModel::state_default, | 
					
						
							| 
									
										
										
										
											2021-12-07 18:14:38 +08:00
										 |  |  |                 "type"               => input("type/d",0),//评论类型
 | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |                 "lng"                => input("lng/s"),//经度
 | 
					
						
							|  |  |  |                 "lat"                => input("lat/s"),//纬度
 | 
					
						
							|  |  |  |                 "location"           => input("location/s"), | 
					
						
							|  |  |  |             ]; | 
					
						
							| 
									
										
										
										
											2021-12-08 11:48:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-08 10:25:31 +08:00
										 |  |  |             //如果是图片或者语音  加上域名信息
 | 
					
						
							|  |  |  |             if(in_array($param['type'],[CommentModel::type_img,CommentModel::type_voice])){ | 
					
						
							| 
									
										
										
										
											2021-12-22 12:01:10 +08:00
										 |  |  |                 $comment            =  input("comment/s", '',null); | 
					
						
							| 
									
										
										
										
											2021-12-08 10:25:31 +08:00
										 |  |  |                 $param['url']       = $this->request->domain() . $comment; | 
					
						
							|  |  |  |                 $param['comment']   = $this->request->domain() . $comment; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             //检测评论规则
 | 
					
						
							|  |  |  |             validate(VComment::class)->check($param); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |             CommentModel::create($param); | 
					
						
							| 
									
										
										
										
											2021-12-07 18:14:38 +08:00
										 |  |  |             return $this->json(0,"评论成功,等待审核"); | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |         } catch (ValidateException $e) { | 
					
						
							|  |  |  |             return $this->json(4001, $e->getError()); | 
					
						
							|  |  |  |         } catch (RepositoryException $e) { | 
					
						
							| 
									
										
										
										
											2021-12-22 10:45:44 +08:00
										 |  |  |             return $this->json(4001, $e->getError()); | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |         } catch (Exception $e) { | 
					
						
							| 
									
										
										
										
											2021-12-07 18:14:38 +08:00
										 |  |  |             echo $e->getMessage(); | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  |             return $this->json(5001, '服务器繁忙!获取用户个人信息失败'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-12-02 10:41:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |