Problems.php 2.7 KB
<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
use think\Validate;
/**
 * 常见问题接口**
 */
class Problems extends Api
{
    protected  $noNeedLogin = [];
    protected $noNeedRight = '*';
    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * @ApiTitle    (常见问题列表)
     * @ApiSummary  (常见问题列表)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/problems/getProblemList)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiReturn ({
            "code": 1,
            "msg": "成功",
            "time": "1553777266",
            "data":[
                {
                    "id": 1,
                    "title": "如何回收?"//标题
                },
                {
                    "id": 3,
                    "title": "如何购买废品?"
                }
            ]
            })
    */
    public function getProblemList(){
        if($this->request->isGet()){
            $data = Db::table('gc_problem')
                ->field('id,title')
                ->select();
            $this->success('成功',$data);
        }else{
            $this->error('请求方式错误');
        }
    }

    /**
     * @ApiTitle    (常见问题详情)
     * @ApiSummary  (常见问题列表)
     * @ApiMethod   (GET)
     * @ApiRoute    (/api/problems/problemDetail)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="integer", required=true, description="常见问题id")
     * @ApiReturn ({
            "code": 1,
            "msg": "成功",
            "time": "1553777266",
            "data":[
                {
                    "id": 1,
                    "title": "如何回收?",//标题
                    "description": "废杂铜的种类繁多,回收利用技术和工艺也有所不同",//详情
                    "image": "/uploads/20190320/4d82786ab0f7866110519f221cbf29a6.jpg"
                }
            ]
            })
     */
    public function problemDetail(){
        if($this->request->isGet()){
            $problem_id = $this->request->get('id');//商品id
            $rule = config('site.goods');
            $validate = new Validate($rule['rule'],$rule['msg']);
            if (!$validate->check(['id'=>$problem_id])) {
                $this->error($validate->getError());
            }
            $data = Db::table('gc_problem')
                ->where(['id'=>$problem_id])
                ->field('id,title,description,image')
                ->select();
            $this->success('成功',$data);
        }else{
            $this->error('请求方式错误');
        }
    }
}