You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.7 KiB
89 lines
2.7 KiB
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use think\Db;
|
|
use app\api\library\buiapi\Api;
|
|
|
|
class WxArticle extends Api{
|
|
|
|
protected $model = null;
|
|
|
|
protected $noNeedRight = '*';
|
|
protected $noNeedLogin = '*';
|
|
protected $_allow_func = ['index','view'];
|
|
|
|
|
|
use \app\api\library\buiapi\traits\Api;
|
|
|
|
public function _initialize(){
|
|
parent::_initialize();
|
|
$this->model = new \app\api\model\WxArticle;
|
|
}
|
|
|
|
|
|
/**
|
|
* 公共方法-列表
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->relationSearch = true;
|
|
$this->request->filter('trim,strip_tags,xss_clean');
|
|
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
$item = $this->model->where($where)->where($this->_init_where)->where('recdata','=',1)->order($sort, $order);
|
|
if (!empty($this->_index_field)) {
|
|
$item->field($this->_index_field);
|
|
}
|
|
$list = $this->__handle_index__($item->paginate($limit));
|
|
$this->success('数据列表', $list);
|
|
}
|
|
|
|
/**
|
|
* 公共方法-详情
|
|
*/
|
|
public function view($ids = null)
|
|
{
|
|
//$this->_init_where[$this->model->getPk()] = $ids;
|
|
//$this->_init_where['wx_menu_id'] = $this->request->post('wx_menu_id') ?? 0;
|
|
$this->_init_where['wx_category_id'] = $ids;
|
|
$item = $this->model->get($this->_init_where, $this->_view_with);
|
|
if (empty($item)) {
|
|
$this->error('数据记录不存在');
|
|
}
|
|
if (!empty($this->_view_field)) {
|
|
$item->field($this->_view_field);
|
|
}
|
|
$row = !empty($item) ? $this->__handle_view__($ids, $item) : [];
|
|
|
|
$row['is_collect'] = 0;
|
|
$user = $this->auth->getUser();
|
|
if($user){
|
|
$data['user_id'] = $user->id;
|
|
$data['wx_article_id'] = $row['id'];
|
|
$data['wx_category_id'] = $row['wx_category_id'];
|
|
$data['createtime'] = time();
|
|
$info =Db::table('lx_wx_article_view')
|
|
->where('user_id','=',$data['user_id'])
|
|
->where('wx_article_id','=',$data['wx_article_id'])
|
|
->find();
|
|
if($info){
|
|
Db::table('lx_wx_article_view')->where('id','=',$info['id'])->update(['createtime'=>time()]);
|
|
}else{
|
|
Db::table('lx_wx_article_view')->insert($data);
|
|
//+1阅读量
|
|
Db::table('lx_wx_article')->where('id','=',$row['id'])->setInc('counts');
|
|
}
|
|
|
|
//是否收藏
|
|
$is_collect = Db::table("lx_wx_article_collect")->where('user_id','=',$user->id)->where('wx_article_id','=',$row['id'])->find();
|
|
if($is_collect){
|
|
$row['is_collect'] = 1;
|
|
}
|
|
|
|
}
|
|
|
|
$this->success('数据信息', $row);
|
|
}
|
|
|
|
|
|
} |