Information.php 2.2 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/12/16
 * Time: 15:30
 */

namespace app\api\controller;


use app\common\controller\Api;
use think\Db;

/**
 * 农场资讯模块
 */
class Information extends Api
{
    /**
     * @ApiTitle    (农场资讯列表)
     * @ApiSummary  (农场资讯列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/information/index)
     * @ApiReturn({
        "code": 1,
        "msg": "SUCCESS",
        "time": "1553839125",
        "data": {
          'title'://标题,
          'url': //跳转链接地址,
          'form'://来源,
          'look_num'://浏览量,
          'thumbnail'://图片
          'content'://内容,
          'createtime'://创建时间
        }
        })
     */
    public function index()
    {
        $data = Db::name('information')
            ->field('updatetime',true)
            ->order('id desc')
            ->select();
        foreach ($data as $k=>$v){
            $data[$k]['thumbnail'] = 'http://q2ugvq3qf.bkt.clouddn.com'.$v['thumbnail'];
            $data[$k]['content'] = strip_tags($v['content']);
            $data[$k]['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
        }
        $this->success('success',$data);

    }

    /**
     * @ApiTitle    (资讯新闻增加浏览量)
     * @ApiSummary  (资讯新闻增加浏览量)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/information/add_num)
     *
     * @ApiParams   (name="id", type="int", required=false, description="农业资讯ID")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "SUCCESS",
        "time": "1553839125",
        "data": {

        }
        })
     */
    public function add_num()
    {
        $id = $this->request->param('id');
        if(empty($id)){
            $this->error('缺少必要参数');
        }
        $data = Db::name('information')
            ->where('id',$id)
            ->find();
        $look_num = $data['look_num'] + 1;
        $res = Db::name('information')->where('id',$id)->update(['look_num'=>$look_num]);
        if(!empty($res)){
            $this->success('成功');
        }else{
            $this->error('失败');
        }

    }
}