123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace app\api\controller;
- use think\facade\Lang;
- class Article extends MobileMall
- {
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/article.lang.php');
- }
-
- public function article_list()
- {
- $ac_id = intval(input('param.ac_id'));
- if ($ac_id > 0) {
- $articleclass_model = model('articleclass');
- $article_model = model('article');
- $condition = array();
- $child_class_list = $articleclass_model->getChildClass($ac_id);
- $ac_ids = array();
- if (!empty($child_class_list) && is_array($child_class_list)) {
- foreach ($child_class_list as $v) {
- $ac_ids[] = $v['ac_id'];
- }
- }
- $ac_ids = implode(',', $ac_ids);
- $condition[] = array('ac_id', 'in', $ac_ids);
- $condition[] = array('article_show', '=', '1');
- $result['article_list'] = $article_model->getArticleList($condition, 20);
- $result['article_type_name'] = $this->article_type_name($ac_ids);
- $result = array_merge(array('article_list' => $result['article_list'], 'article_type_name' => $result['article_type_name']), mobile_page(is_object($article_model->page_info) ? $article_model->page_info : ''));
- ds_json_encode(10000, '', $result);
- } else {
- ds_json_encode(10001, lang('param_error'));
- }
- }
-
- private function article_type_name()
- {
- $ac_id = intval(input('param.ac_id'));
- if ($ac_id > 0) {
- $articleclass_model = model('articleclass');
- $article_class = $articleclass_model->getOneArticleclass($ac_id);
- return ($article_class['ac_name']);
- } else {
- return (lang('param_error'));
- }
- }
-
- public function article_show()
- {
- $article_model = model('article');
- $article_id = intval(input('param.article_id'));
- if ($article_id > 0) {
- $prefix = 'api-article-show-';
- $article = rcache($article_id, $prefix);
- if (empty($article)) {
- $condition = array();
- $condition[] = array('article_id', '=', $article_id);
- $article = $article_model->getOneArticle($condition);
- wcache($article_id, $article, $prefix, 3600);
- }
- if (empty($article)) {
- ds_json_encode(10001, lang('article_show_not_exists'));
- } else {
- $article['article_content'] = htmlspecialchars_decode($article['article_content']);
- ds_json_encode(10000, '', $article);
- }
- } else {
- ds_json_encode(10001, lang('param_error'));
- }
- }
- }
|