80 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			80 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			PHP
		
	
	
| <?php
 | |
| 
 | |
| namespace app\controller\api;
 | |
| 
 | |
| use app\exception\RepositoryException;
 | |
| use app\model\Comment as CommentModel;
 | |
| use app\repository\AccountRepository;
 | |
| use app\repository\CouponRepository;
 | |
| use think\Exception;
 | |
| use think\exception\ValidateException;
 | |
| 
 | |
| /**
 | |
|  * 评论相关
 | |
|  *
 | |
|  * Class Comment
 | |
|  * @package app\controller\api
 | |
|  */
 | |
| class Comment extends Base
 | |
| {
 | |
|     protected $noNeedLogin = [
 | |
|         'commentList',
 | |
|     ];
 | |
| 
 | |
|     /**
 | |
|      * 群聊列表 开发中
 | |
|      * */
 | |
|     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, '服务器繁忙!获取用户个人信息失败');
 | |
|         }
 | |
|     }
 | |
| 
 | |
| } |