| 
									
										
										
										
											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-02 10:41:02 +08:00
										 |  |  | use app\repository\CouponRepository; | 
					
						
							| 
									
										
										
										
											2021-12-02 18:34:44 +08:00
										 |  |  | use think\Exception; | 
					
						
							|  |  |  | use think\exception\ValidateException; | 
					
						
							| 
									
										
										
										
											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
										 |  |  |     /** | 
					
						
							|  |  |  |      * 群聊列表 开发中 | 
					
						
							|  |  |  |      * */ | 
					
						
							|  |  |  |     public function commentList() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $page = $this->request->param('page/d', 1); | 
					
						
							|  |  |  |         $size = $this->request->param('size/d', 30); | 
					
						
							|  |  |  |         $whereMap = [ | 
					
						
							|  |  |  |             ["is_delete",    "=", CommentModel::COMMON_OFF],//未删除
 | 
					
						
							|  |  |  |             ["state",        "=", CommentModel::COMMON_ON],//审核通过
 | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $data = CommentModel::findList($whereMap, [], $page, $size, null, ["id" => "desc"]); | 
					
						
							|  |  |  |         return $this->json(0, "success", $data); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * 创建一条评论 开发中 | 
					
						
							|  |  |  |      * */ | 
					
						
							|  |  |  |     public function createComment() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $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)) { | 
					
						
							|  |  |  |                 throw new ValidateException('用户无效!'); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $param = [ | 
					
						
							|  |  |  |                 "comment"            => input("comment/s", ""),//评论内容   图片类型放入地址  语音类型放置语音文件地址
 | 
					
						
							|  |  |  |                 "user_code"          => $account['user_code'], | 
					
						
							|  |  |  |                 "create_time"        => date("Y-m-d H:i:s"), | 
					
						
							|  |  |  |                 "url"                => input("url/s", ""),//图片地址   仅图片评论才有
 | 
					
						
							|  |  |  |                 "state"              => CommentModel::state_default, | 
					
						
							|  |  |  |                 "type"               => input("type/s"),//评论类型
 | 
					
						
							|  |  |  |                 "lng"                => input("lng/s"),//经度
 | 
					
						
							|  |  |  |                 "lat"                => input("lat/s"),//纬度
 | 
					
						
							|  |  |  |                 "location"           => input("location/s"), | 
					
						
							|  |  |  |             ]; | 
					
						
							|  |  |  |             CommentModel::create($param); | 
					
						
							|  |  |  |             return $this->json(); | 
					
						
							|  |  |  |         } catch (ValidateException $e) { | 
					
						
							|  |  |  |             return $this->json(4001, $e->getError()); | 
					
						
							|  |  |  |         } catch (RepositoryException $e) { | 
					
						
							|  |  |  |             return $this->json(4001, $e->getError()); | 
					
						
							|  |  |  |         } catch (Exception $e) { | 
					
						
							|  |  |  |             return $this->json(5001, '服务器繁忙!获取用户个人信息失败'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-12-02 10:41:02 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |