Files
addons
app_download_files
extend
hyhproject
admin
app
common
home
home2
mobile2
wechat2
behavior
common
conf
controller
model
Articles.php
Base.php
Goods.php
GoodsAppraises.php
GoodsCats.php
Index.php
Orders.php
Payments.php
Shops.php
Users.php
validate
view
.htaccess
command.php
mobile
oss
static
thinkphp
upload
vendor
wxtmp
.gitignore
.htaccess
.user.ini
404.html
H5B854518.wgt
admin.php
app-release.apk
app_download.html
cash.lock
demo.php
get_startup.php
get_version.php
get_version_new.php
hyhproject.tar.gz
index.html
index.php
reg.lock
robots.txt
qlg.tsgz.moe/hyhproject/wechat2/model/Articles.php
2019-09-06 23:53:10 +08:00

101 lines
2.8 KiB
PHP
Executable File

<?php
namespace wstmart\wechat\model;
use think\Db;
/**
* ============================================================================
* 文章类
*/
class Articles extends Base{
/**
* 获取咨询中中心所有文章
*/
public function getArticles(){
// 获取咨询中心下的所有分类id
$catId = input('catId');
$rs = $this->alias('a')
->field('a.*')
->join('__ARTICLE_CATS__ ac','a.catId=ac.catId','inner')
->where(['a.catId'=>$catId,
'a.isShow'=>1,
'a.dataFlag'=>1,
'ac.dataFlag'=>1,
'ac.isShow'=>1,
'ac.catType'=>0,
])
->order('createTime desc')
->paginate((int)input('pagesize'));
return $rs;
}
/**
* 根据id获取资讯文章
*/
public function getNewsById(){
$id = (int)input('id');
WSTArticleVisitorNum($id);// 统计文章访问量
$article = $this->alias('a')
->field('a.*')
->join('__ARTICLE_CATS__ ac','a.catId=ac.catId','inner')
->where('ac.catType=0 and a.dataFlag=1 and a.isShow=1')
->cache(true)
->find($id);
// 图片延迟加载
$article['articleContent']=htmlspecialchars_decode($article['articleContent']);
$rule = '/<img src="\/(wstmartp.*?)"/';
preg_match_all($rule, $article['articleContent'],$images);
foreach($images[0] as $k=>$v){
$article['articleContent'] = str_replace($v, "<img src='/".WSTImg($images[1][$k],3)."'", $article['articleContent']);
}
$articleId = cookie("wechat_like_articleId");
$articleId = is_array($articleId)?$articleId:[];
$rc = !empty($articleId)?in_array($id,$articleId):'';
if($rc){
$article['likeState'] = 1;
}else{
$article['likeState'] = 0;
}
return $article;
}
/**
* 点赞
*/
public function like(){
$id = input("param.id/d");
//判断记录是否存在
$articleId = cookie("wechat_like_articleId");
$articleId = is_array($articleId)?$articleId:[];
$rc = !empty($articleId)?in_array($id,$articleId):'';
if($rc)return WSTReturn("已点赞成功", -1);
$rs = $this->where(['isShow'=>1,'dataFlag'=>1,'articleId'=>$id])->setInc('likeNum',1);
//判断是否点赞成功
if(false !== $rs){
array_push($articleId,$id);
cookie("wechat_like_articleId",$articleId,25920000);
return WSTReturn("点赞成功", 1);
}else{
return WSTReturn($this->getError(),-1);
}
}
/**
* 获取资讯中心的子集分类
*/
public function getChildInfos(){
$infos = cache('NEW_INFOS');
$i = 0;
if(!$infos){
$data = Db::name('article_cats')->cache(true)->select();
foreach($data as $k=>$v){
if($v['parentId']== 8){
$infos[$i]['catId'] = $v['catId'];
$infos[$i]['catName'] = $v['catName'];
$i++;
}
}
cache('NEW_INFOS',$infos);
}
return $infos;
}
}