diff --git a/app/controller/api/Comment.php b/app/controller/api/Comment.php index 035ef62..0b7e3a8 100644 --- a/app/controller/api/Comment.php +++ b/app/controller/api/Comment.php @@ -5,6 +5,7 @@ namespace app\controller\api; use app\exception\RepositoryException; use app\model\Comment as CommentModel; use app\repository\AccountRepository; +use app\repository\CommentRepository; use app\repository\CouponRepository; use think\Exception; use think\exception\ValidateException; @@ -24,23 +25,18 @@ class Comment extends Base /** * 群聊列表 开发中 * */ - public function commentList() + public function myCommentZone() { $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"]); + $data = CommentRepository::getInstance()->myCommentZone( $page, $size); return $this->json(0, "success", $data); } /** - * 创建一条评论 开发中 + * 创建一条文字评论 开发中 * */ - public function createComment() + public function commentText() { $accountId = $this->request->user['user_id'] ?? 0; $accountRepo = AccountRepository::getInstance(); @@ -55,24 +51,28 @@ class Comment extends Base 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"),//评论类型 + "type" => input("type/d",0),//评论类型 "lng" => input("lng/s"),//经度 "lat" => input("lat/s"),//纬度 "location" => input("location/s"), ]; CommentModel::create($param); - return $this->json(); + return $this->json(0,"评论成功,等待审核"); } catch (ValidateException $e) { return $this->json(4001, $e->getError()); } catch (RepositoryException $e) { return $this->json(4001, $e->getError()); } catch (Exception $e) { + echo $e->getMessage(); return $this->json(5001, '服务器繁忙!获取用户个人信息失败'); } } diff --git a/app/controller/api/Consumer.php b/app/controller/api/Consumer.php index 1580e9e..f13cd7f 100644 --- a/app/controller/api/Consumer.php +++ b/app/controller/api/Consumer.php @@ -164,10 +164,7 @@ class Consumer extends Base * */ public function flowBusiness() { - $accountId = $this->request->user['user_id'] ?? 0; - - $accountRepo = AccountRepository::getInstance(); try { $account = $accountRepo->findById($accountId, [], function ($q) { @@ -198,6 +195,37 @@ class Consumer extends Base } catch (Exception $e) { return $this->json(5001, '服务器繁忙!'); } + } + + + /** + * 关注商家的列表 + * */ + public function getFlowBusiness() + { + $accountId = $this->request->user['user_id'] ?? 0; + $page = $this->request->param('page/d', 1); + $size = $this->request->param('size/d', 10); + $keyword = input("keyWord/s"); + $accountRepo = AccountRepository::getInstance(); + try { + $account = $accountRepo->findById($accountId, [], function ($q) { + return $q->with(['business', 'parent']); + }); + if (empty($account)) { + throw new ValidateException('用户无效!'); + } + $data = AccountRepository::getInstance()->getBusinessFlowList($account->user_code,$page,$size,$keyword); + $data->each(function ($item){ + $item->businessCover = $this->request->domain() . $item->background; + }); + return $this->json(0,"success",$data); + }catch (ValidateException $e) { + return $this->json(4001, $e->getError()); + } catch (Exception $e) { + echo $e->getMessage(); + return $this->json(5001, '服务器繁忙!获取用户个人信息失败'); + } } } \ No newline at end of file diff --git a/app/controller/api/Coupon.php b/app/controller/api/Coupon.php index 8a6c90f..1d6b4c0 100644 --- a/app/controller/api/Coupon.php +++ b/app/controller/api/Coupon.php @@ -147,9 +147,5 @@ class Coupon extends Base return $this->json(5001,"领取失败"); } - - - - } } \ No newline at end of file diff --git a/app/controller/api/User.php b/app/controller/api/User.php index 050ce38..bf48f84 100644 --- a/app/controller/api/User.php +++ b/app/controller/api/User.php @@ -224,32 +224,4 @@ class User extends Base } } - - - /** - * 关注商家的列表 - * */ - public function businessFlowList() - { - return false; - $page = $this->request->param('page/d', 1); - $size = $this->request->param('size/d', 30); - - $accountRepo = AccountRepository::getInstance(); - try { - $account = $accountRepo->findById($accountId, [], function ($q) { - return $q->with(['business', 'parent']); - }); - if (empty($account)) { - throw new ValidateException('用户无效!'); - } - }catch (ValidateException $e) { - return $this->json(4001, $e->getError()); - } catch (Exception $e) { - return $this->json(5001, '服务器繁忙!获取用户个人信息失败'); - } - $data = AccountRepository::getInstance()->getBusinessFlowList(); - } - - } \ No newline at end of file diff --git a/app/repository/CommentRepository.php b/app/repository/CommentRepository.php new file mode 100644 index 0000000..281d47c --- /dev/null +++ b/app/repository/CommentRepository.php @@ -0,0 +1,48 @@ +join("account b" ,"a.user_code = b.user_code") + ->where($whereMap) + ->field([ + "a.comment", + "a.user_code as userCode", + "a.business_code as businessCode", + "b.nick_name as consumerName", + "a.create_time as createTime", + "a.url", + "a.type", + ]) + ->page($page,$size) + ->order("a.create_time desc") + ->select(); + } + +} \ No newline at end of file diff --git a/app/traits/account/BusinessFlowTrait.php b/app/traits/account/BusinessFlowTrait.php index 7739152..80d3426 100644 --- a/app/traits/account/BusinessFlowTrait.php +++ b/app/traits/account/BusinessFlowTrait.php @@ -11,22 +11,27 @@ trait BusinessFlowTrait * @param $accountCode * @param $page * @param $size + * @param $keyword * @return */ - public function getBusinessFlowList($accountCode, $page, $size) + public function getBusinessFlowList($accountCode, $page, $size,$keyword=null) { return BusinessFlow::alias("a") ->join("business b","a.business_code = b.code") ->where("a.user_code",$accountCode) - ->field(["b.code", - "b.business_name", - "b.business_subtitle", - "b.lat", - "b.lng", - "b.characteristic", + ->when(!empty($keyword), function ($q) use ($keyword) { + $q->where("b.business_name", "like", "%{$keyword}%"); + }) + ->field([ + "b.id", + "b.code as businessCode", + "b.business_name as businessName", "b.background", + "a.create_time as createTime", + "a.user_code as userCode", ]) ->page($page,$size) + ->order("a.id desc") ->select(); } diff --git a/public/.htaccess b/public/.htaccess index 8aa9d23..3de7df8 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -1,9 +1,9 @@ - - Options +FollowSymlinks -Multiviews - RewriteEngine On - - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{REQUEST_FILENAME} !-f - RewriteCond %{REQUEST_URI} !^(.*)\.(gif|jpg|jpeg|png|swf|mp4)$ [NC] - RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L] + + Options +FollowSymlinks -Multiviews + RewriteEngine On + + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_URI} !^(.*)\.(gif|jpg|jpeg|png|swf|mp4)$ [NC] + RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L] \ No newline at end of file