作者 王智

daima

... ... @@ -309,213 +309,206 @@ class Index extends Api
}
$rult = Db::name('seller')->where($map3)->where($map)->where($map2)->order('weight asc')->page($param['pages'], $param['rows'])->select();
$count = Db::name('seller')->where($map3)->where($map)->where($map2)->order('weight asc')->select();
//asc
$list = [
'count' => 0,
'list' => []
];
} else
{
//计算距离 KM
foreach ($rult as $k => $v)
{
$ruestul[$k]['id'] = $v['id'];
$ruestul[$k]['title'] = $v['title'];
$ruestul[$k]['address'] = $v['address'];
$ruestul[$k]['avatar'] = cdnurl($v['avatar']);
$ruestul[$k]['order'] = $v['order'];
if (empty($param['lng']) || $param['lng'] == null || $param['lng'] == '' || $param['lng'] == "")
{
$ruestul[$k]['from'] = '暂无距离信息';
}
else {
$ruestul[$k]['from'] = $this->getDistance($param['lng'], $param['lat'], $v['lng'], $v['lat']) . 'km';
}
$ruestul[$k]['talk_num'] = $v['talk_num'];
}
$newarr = array_column($ruestul, 'from');
array_multisort($newarr, SORT_ASC, $ruestul);
$list = [
'count' => count($count),
'list' => $ruestul
];
}
$this->success('成功', $list);
}
if (empty($rult)) {
//如果为空
$list = [
'count' => 0,
'list' => []
];
} else {
//计算距离 KM
foreach ($rult as $k => $v) {
$ruestul[$k]['id'] = $v['id'];
$ruestul[$k]['title'] = $v['title'];
$ruestul[$k]['address'] = $v['address'];
$ruestul[$k]['avatar'] = cdnurl($v['avatar']);
$ruestul[$k]['order'] = $v['order'];
if (empty($param['lng']) || $param['lng'] == null || $param['lng'] == '' || $param['lng'] == "") {
$ruestul[$k]['from'] = '暂无距离信息';
} else {
$ruestul[$k]['from'] = $this->getDistance($param['lng'], $param['lat'], $v['lng'], $v['lat']) . 'km';
}
$ruestul[$k]['talk_num'] = $v['talk_num'];
}
$newarr = array_column($ruestul, 'from');
array_multisort($newarr, SORT_ASC, $ruestul);
$list = [
'count' => count($count),
'list' => $ruestul
];
}
$this->success('成功', $list);
}
/**
* 首页接口
* @ApiTitle (首页接口-店铺详情)
* @ApiSummary (店铺详情)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/SellerCon)
* @ApiParams (name="id", type="int", required=true, description="店铺ID")
* @ApiParams (name="pages", type="int", required=true, description="pages")
* @ApiParams (name="rows", type="int", required=true, description="rows")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"id": 3,
"avatar": "http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png",
"title": "这是第三个店铺",
"opentime": "8:00-9:00",
"address": "北京市北京市海淀区吴玉章路",
"mobile": "1391929399",
"content": "<p>这是第三个商家的详情</p>",
"num": 3, //平均评分
"talkList": {
"count": 1,//评论总数
"talk": [
{
"id": 1, //评论id
"num": 3, //评分
"createtime": "1970-05-09", //评论时间
"avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/0wpUDw5m0LRvdDueia3uMWmrYb53GXRaTnYwMWC18kRmX6P6PIaPDgQqarEIfwroicx1z51D6bjQicOV0PibBx2PqQ/132",
"nickname": "Gody",
"images": [ //评论图
"http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png",
"http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png"
]
}
]
}
}
})
*/
public
function SellerCon()
{
$param = $this->request->param();
$seller_arr = Db::name('seller')->where('id', $param['id'])->find();
if (empty($seller_arr)) {
$this->error('参数错误', 0);
die;
/**
* 首页接口
* @ApiTitle (首页接口-店铺详情)
* @ApiSummary (店铺详情)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/SellerCon)
* @ApiParams (name="id", type="int", required=true, description="店铺ID")
* @ApiParams (name="pages", type="int", required=true, description="pages")
* @ApiParams (name="rows", type="int", required=true, description="rows")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
"data": {
"id": 3,
"avatar": "http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png",
"title": "这是第三个店铺",
"opentime": "8:00-9:00",
"address": "北京市北京市海淀区吴玉章路",
"mobile": "1391929399",
"content": "<p>这是第三个商家的详情</p>",
"num": 3, //平均评分
"talkList": {
"count": 1,//评论总数
"talk": [
{
"id": 1, //评论id
"num": 3, //评分
"createtime": "1970-05-09", //评论时间
"avatar": "https://thirdwx.qlogo.cn/mmopen/vi_32/0wpUDw5m0LRvdDueia3uMWmrYb53GXRaTnYwMWC18kRmX6P6PIaPDgQqarEIfwroicx1z51D6bjQicOV0PibBx2PqQ/132",
"nickname": "Gody",
"images": [ //评论图
"http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png",
"http://xiche.qiniu.bronet.cn/uploads/20200831/FsGkAQhqnwBodzLvJyn1rtbZIFUd.png"
]
}
$list = [
'id' => $seller_arr['id'],
'avatar' => cdnurl($seller_arr['avatar']),
'title' => $seller_arr['title'],
'opentime' => $seller_arr['opentime'],
'address' => $seller_arr['address'],
'lng' => $seller_arr['lng'],
'lat' => $seller_arr['lat'],
'mobile' => $seller_arr['mobile'],
'content' => $seller_arr['content']
];
$talk_arr = Db::name('seller_talk')
->alias('s')
->join('user u', 'u.id=s.user_id')
->where('seller_id', $param['id'])
->order('id desc')
->page($param['pages'], $param['rows'])
->field('s.id,s.num,s.title,s.images,s.createtime,u.avatar,u.nickname')
->select();
$count = Db::name('seller_talk')
->alias('s')
->join('user u', 'u.id=s.user_id')
->where('seller_id', $param['id'])
->order('id desc')
->field('s.id,s.num,s.title,s.images,s.createtime,u.avatar,u.nickname')
->select();
if (empty($talk_arr)) {
$list['num'] = 5;
$list['talkList'] = [
'count' => 0,
'talk' => []
]
}
}
})
*/
public function SellerCon()
{
$param = $this->request->param();
$seller_arr = Db::name('seller')->where('id', $param['id'])->find();
if (empty($seller_arr)) {
$this->error('参数错误', 0);
die;
}
$list = [
'id' => $seller_arr['id'],
'avatar' => cdnurl($seller_arr['avatar']),
'title' => $seller_arr['title'],
'opentime' => $seller_arr['opentime'],
'address' => $seller_arr['address'],
'lng' => $seller_arr['lng'],
'lat' => $seller_arr['lat'],
'mobile' => $seller_arr['mobile'],
'content' => $seller_arr['content']
];
} else {
$sum = array_sum(array_column($count, 'num'));
$list['num'] = ($sum + 5) / (count($count) + 1);
foreach ($talk_arr as $k => $v) {
$talkList[$k]['id'] = $v['id'];
$talkList[$k]['num'] = $v['num'];
$talkList[$k]['createtime'] = date('Y-m-d', $v['createtime']);
$talkList[$k]['avatar'] = $v['avatar'];
$talkList[$k]['nickname'] = $v['nickname'];
$talkList[$k]['title'] = $v['title'];
if (empty($v['images'])) {
$talkList[$k]['images'] = [];
} else {
if (strstr($v['images'], ',')) {
$image = explode(',', $v['images']);
$talk_arr = Db::name('seller_talk')
->alias('s')
->join('user u', 'u.id=s.user_id')
->where('seller_id', $param['id'])
->order('id desc')
->page($param['pages'], $param['rows'])
->field('s.id,s.num,s.title,s.images,s.createtime,u.avatar,u.nickname')
->select();
$count = Db::name('seller_talk')
->alias('s')
->join('user u', 'u.id=s.user_id')
->where('seller_id', $param['id'])
->order('id desc')
->field('s.id,s.num,s.title,s.images,s.createtime,u.avatar,u.nickname')
->select();
if (empty($talk_arr)) {
$list['num'] = 5;
$list['talkList'] = [
'count' => 0,
'talk' => []
];
} else {
$sum = array_sum(array_column($count, 'num'));
$list['num'] = ($sum + 5) / (count($count) + 1);
foreach ($talk_arr as $k => $v) {
$talkList[$k]['id'] = $v['id'];
$talkList[$k]['num'] = $v['num'];
$talkList[$k]['createtime'] = date('Y-m-d', $v['createtime']);
$talkList[$k]['avatar'] = $v['avatar'];
$talkList[$k]['nickname'] = $v['nickname'];
$talkList[$k]['title'] = $v['title'];
if (empty($v['images'])) {
$talkList[$k]['images'] = [];
} else {
$image = explode(' ', $v['images']);
if (strstr($v['images'], ',')) {
$image = explode(',', $v['images']);
} else {
$image = explode(' ', $v['images']);
}
foreach ($image as $k1 => $v1) {
$image[$k1] = cdnurl($v1);
}
$talkList[$k]['images'] = $image;
}
foreach ($image as $k1 => $v1) {
$image[$k1] = cdnurl($v1);
}
$talkList[$k]['images'] = $image;
}
$list['talkList'] = [
'count' => count($count),
'talk' => $talkList
];
}
$list['talkList'] = [
'count' => count($count),
'talk' => $talkList
];
$this->success('成功', $list);
}
$this->success('成功', $list);
}
/**
* 首页接口
* @ApiTitle (首页接口-添加评论)
* @ApiSummary (添加评论)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/TalkSave)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="seller_id", type="int", required=true, description="商家ID")
* @ApiParams (name="title", type="int", required=true, description="评论内容")
* @ApiParams (name="images", type="int", required=true, description="评论图")
* @ApiParams (name="num", type="int", required=true, description="评分")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
})
*/
public
function TalkSave()
{
$param = $this->request->param();
$user_id = $this->is_token($this->request->header());
$data = [
'seller_id' => $param['seller_id'],
'user_id' => $user_id,
'title' => $param['title'],
'num' => $param['num'],
'images' => $param['images'],
'createtime' => time(),
];
$res = Db::name('seller_talk')->insert($data);
$talk_num = Db::name('seller')->where('id', $param['seller_id'])->value('talk_num');
Db::name('seller')->where('id', $param['seller_id'])->update(['talk_num' => $talk_num + 1]);
$this->res($res);
}
/**
* 首页接口
* @ApiTitle (首页接口-添加评论)
* @ApiSummary (添加评论)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/TalkSave)
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="seller_id", type="int", required=true, description="商家ID")
* @ApiParams (name="title", type="int", required=true, description="评论内容")
* @ApiParams (name="images", type="int", required=true, description="评论图")
* @ApiParams (name="num", type="int", required=true, description="评分")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
})
*/
public function TalkSave()
{
$param = $this->request->param();
$user_id = $this->is_token($this->request->header());
$data = [
'seller_id' => $param['seller_id'],
'user_id' => $user_id,
'title' => $param['title'],
'num' => $param['num'],
'images' => $param['images'],
'createtime' => time(),
];
$res = Db::name('seller_talk')->insert($data);
$talk_num = Db::name('seller')->where('id', $param['seller_id'])->value('talk_num');
Db::name('seller')->where('id', $param['seller_id'])->update(['talk_num' => $talk_num + 1]);
$this->res($res);
}
/**
* 首页接口
* @ApiTitle (首页接口-联系客服文字)
* @ApiSummary (联系客服文字)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/Lianxi)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
})
*/
public
function Lianxi()
{
$title = Db::name('lianxi')->where('id', 1)->value('title');
$this->success('成功', $title);
}
/**
* 首页接口
* @ApiTitle (首页接口-联系客服文字)
* @ApiSummary (联系客服文字)
* @ApiMethod (POST)
* @ApiRoute (/api/Index/Lianxi)
* @ApiReturnParams (name="code", type="integer", required=true, sample="0")
* @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
* @ApiReturn ({
'code':'1',
'msg':'返回成功',
})
*/
public function Lianxi()
{
$title = Db::name('lianxi')->where('id', 1)->value('title');
$this->success('成功', $title);
}
}
... ...