切换导航条
此项目
正在载入...
登录
景龙
/
feipin
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
景龙
6 years ago
提交
2303eab2c2df01ea76c7fcdf122209055b40a991
1 个父辈
c4399d18
1 个管道 的构建
通过
耗费 0 秒
修改浏览记录接口
变更
2
构建
1
隐藏空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
84 行增加
和
16 行删除
application/admin/model/Browse.php
application/api/controller/Goods.php
application/admin/model/Browse.php
0 → 100644
查看文件 @
2303eab
<?php
namespace
app\admin\model
;
use
think\Model
;
class
Browse
extends
Model
{
// 表名
protected
$name
=
'browse'
;
// 自动写入时间戳字段
protected
$autoWriteTimestamp
=
'int'
;
// 定义时间戳字段名
protected
$createTime
=
'createtime'
;
protected
$updateTime
=
'updatetime'
;
// 追加属性
protected
$append
=
[
'deletetime_text'
];
public
function
getDeletetimeTextAttr
(
$value
,
$data
)
{
$value
=
$value
?
$value
:
(
isset
(
$data
[
'deletetime'
])
?
$data
[
'deletetime'
]
:
''
);
return
is_numeric
(
$value
)
?
date
(
"Y-m-d H:i:s"
,
$value
)
:
$value
;
}
protected
function
setDeletetimeAttr
(
$value
)
{
return
$value
&&
!
is_numeric
(
$value
)
?
strtotime
(
$value
)
:
$value
;
}
}
...
...
application/api/controller/Goods.php
查看文件 @
2303eab
...
...
@@ -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
);
}
}
}
...
...
请
注册
或
登录
后发表评论