Government.php 4.3 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/12/26
 * Time: 17:37
 */

namespace app\api\controller;


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

/**
 * 农户认证
 */
class Government extends Api
{
    /**
     * @ApiTitle    (农场列表)
     * @ApiSummary  (农场列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/government/index)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiParams   (name="type", type="inter", required=false, description="状态(不传或者1为待认证,2为已通过,3为已拒绝)")
     * @ApiParams   (name="page", type="inter", required=false, description="当前页(默认1)")
     * @ApiParams   (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
     *
     * @ApiReturn({
        "code": 1,
        "msg": "SUCCESS",
        "time": "1553839125",
        "data": {
            "id"://认证ID
            "farm_id"://农场id
            "createtime"://申请日期
            "name"://农场名称
            "avatar"://用户头像
            "content"://农场简介
            "address"://农场地址
            }
        })
     */
    public function index(){
        $user_id = $this->getUserId();
        //首先查出政府入驻信息
        $government = Db::name('government')
            ->where('user_id',$user_id)
            ->find();
        $type = $this->request->param('type');
        if(empty($type) || $type == 1){
            //待认证

            //查出是属于该政府审核的农场信息
            $data = Db::name('attestation')
                ->where('institution_id',$government['id'])
                ->field('id,farm_id,createtime,user_id')
                ->where('status',0)
                ->select();
            foreach ($data as &$v){
                $v['createtime'] = date('Y-m-d',$v['createtime']);
                $farm = Db::name('farm')
                    ->alias('a')
                    ->join('user b','a.user_id = b.id')
                    ->where('a.id',$v['farm_id'])
                    ->field('a.name,a.content,a.address,b.avatar')
                    ->find();
                $v['name'] = $farm['name'];
                $v['content'] = $farm['content'];
                $v['address'] = $farm['address'];
                $v['avatar'] = $farm['avatar'];
            }
            $this->success('success',$data);
        }elseif($type == 2){
            //已通过

            //查出是属于该政府审核的农场信息
            $data = Db::name('attestation')
                ->where('institution_id',$government['id'])
                ->field('id,farm_id,createtime,user_id')
                ->where('status',1)
                ->select();
            foreach ($data as &$v){
                $v['createtime'] = date('Y-m-d',$v['createtime']);
                $farm = Db::name('farm')
                    ->alias('a')
                    ->join('user b','a.user_id = b.id')
                    ->where('a.id',$v['farm_id'])
                    ->field('a.name,a.content,a.address,b.avatar')
                    ->find();
                $v['name'] = $farm['name'];
                $v['content'] = $farm['content'];
                $v['address'] = $farm['address'];
                $v['avatar'] = $farm['avatar'];
            }
            $this->success('success',$data);
        }elseif ($type == 3){
            //已拒绝

            //查出是属于该政府审核的农场信息
            $data = Db::name('attestation')
                ->where('institution_id',$government['id'])
                ->field('id,farm_id,createtime,user_id')
                ->where('status',2)
                ->select();
            foreach ($data as &$v){
                $v['createtime'] = date('Y-m-d',$v['createtime']);
                $farm = Db::name('farm')
                    ->alias('a')
                    ->join('user b','a.user_id = b.id')
                    ->where('a.id',$v['farm_id'])
                    ->field('a.name,a.content,a.address,b.avatar')
                    ->find();
                $v['name'] = $farm['name'];
                $v['content'] = $farm['content'];
                $v['address'] = $farm['address'];
                $v['avatar'] = $farm['avatar'];
            }
            $this->success('success',$data);
        }
    }


}