master
wangxinglong 2021-12-07 18:14:38 +08:00
parent 8a3deee5f0
commit 13dd86109c
7 changed files with 110 additions and 61 deletions

View File

@ -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, '服务器繁忙!获取用户个人信息失败');
}
}

View File

@ -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, '服务器繁忙!获取用户个人信息失败');
}
}
}

View File

@ -147,9 +147,5 @@ class Coupon extends Base
return $this->json(5001,"领取失败");
}
}
}

View File

@ -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();
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace app\repository;
use app\model\Comment as CommentModel;
use app\service\Repository;
use think\Model;
/**
* 评论相关
*
* Class CommentRepository
* @package app\repository
* @method self getInstance(Model $model = null) static
*/
class CommentRepository extends Repository
{
/**
* 评论列表
* @param array $whereMap
* @param array $field
* @param int $page
* @param int $size
* @param array $order
*/
public function myCommentZone($page = 1, $size = 10)
{
$whereMap = [
["a.is_delete", "=", CommentModel::COMMON_OFF],//未删除
["a.state", "=", CommentModel::COMMON_ON],//审核通过
];
return CommentModel::alias("a")
->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();
}
}

View File

@ -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();
}