...
|
...
|
@@ -2,6 +2,7 @@ |
|
|
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
use app\admin\model\Browse;
|
|
|
use app\common\controller\Api;
|
|
|
use app\admin\model\Search;
|
|
|
use think\Db;
|
...
|
...
|
@@ -253,6 +254,7 @@ class Goods extends Api |
|
|
foreach($data as &$value){
|
|
|
$value['pre_time'] = date('Y-m-d H:i:s',$value['pre_time']);
|
|
|
}
|
|
|
$this->broGoods($goods_id);
|
|
|
$this->success('成功', ['data'=>$data,'comment_count'=>$comment_count]);
|
|
|
}else{
|
|
|
$this->error('请求方式错误');
|
...
|
...
|
@@ -294,28 +296,53 @@ class Goods extends Api |
|
|
public function guessLikes(){
|
|
|
if($this->request->isGet()){
|
|
|
//随机取出1条检索的历史
|
|
|
$keywords = Db::table('gc_search')
|
|
|
->where(['uid'=>$this->user_id,'is_search'=>$this->is_search[0]])
|
|
|
->field('keywords')
|
|
|
->orderRaw('rand()')
|
|
|
->limit(1)
|
|
|
->find();
|
|
|
$bro_num = Db::table('gc_browse')
|
|
|
->where(['uid'=>$this->user_id])
|
|
|
->order('bro_num desc')
|
|
|
->select();
|
|
|
$where['p.status'] = $this->normal;
|
|
|
$where['u.status'] = 'normal';
|
|
|
if($keywords){
|
|
|
$where['p.title'] = ['like','%'.$keywords['keywords'].'%'];
|
|
|
if($bro_num){
|
|
|
$g_Ids = array_column($bro_num,'g_id');
|
|
|
$data = Db::table('gc_product')
|
|
|
->alias('p')
|
|
|
->join('gc_user u','p.uid = u.id','LEFT')
|
|
|
->where($where)
|
|
|
->whereIn('p.id',$g_Ids)
|
|
|
->field('p.id,p.title,p.price,p.images')
|
|
|
->limit(20)
|
|
|
->order('p.id desc')
|
|
|
->select();
|
|
|
}else{
|
|
|
$data = Db::table('gc_product')
|
|
|
->alias('p')
|
|
|
->join('gc_user u','p.uid = u.id','LEFT')
|
|
|
->where($where)
|
|
|
->field('p.id,p.title,p.price,p.images')
|
|
|
->limit(20)
|
|
|
->order('p.id desc')
|
|
|
->select();
|
|
|
}
|
|
|
$data = Db::table('gc_product')
|
|
|
->alias('p')
|
|
|
->join('gc_user u','p.uid = u.id','LEFT')
|
|
|
->where($where)
|
|
|
->field('p.id,p.title,p.price,p.images')
|
|
|
->limit(20)
|
|
|
->order('p.id desc')
|
|
|
->select();
|
|
|
$this->success('成功', $data);
|
|
|
}else{
|
|
|
$this->error('请求方式错误');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//浏览记录表
|
|
|
private function broGoods($id){
|
|
|
$broModel = new Browse();
|
|
|
$bro_num = Db::table('gc_browse')
|
|
|
->where(['uid'=>$this->user_id,'g_id'=>$id])
|
|
|
->find();
|
|
|
$data['g_id'] = $id;
|
|
|
$data['uid'] = $this->user_id;
|
|
|
if($bro_num){
|
|
|
$data['bro_num'] = $bro_num['bro_num']+1;
|
|
|
$broModel->where(['g_id'=>$id,'uid'=>$this->user_id])->update($data);
|
|
|
}else{
|
|
|
$data['bro_num'] = 1;
|
|
|
$broModel::create($data);
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|