<?php
/**
 * Created by PhpStorm.
 * User: 86132
 * Date: 2020/7/6
 * Time: 10:13
 */

namespace app\api\controller;

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


/**
 * 团队接口
 */
class Team extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }


    /**
     * @ApiTitle    (团队接口-类型,行业展示)
     * @ApiSummary  (类型,行业展示)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Team/TypeIndustryList)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功'
    "data": [
    {
    "type2": [
    {
    "type": "类型",
    "type_id": "id"
    ]
    },
    {
    "industrys": [
    {
    "industry": "行业",
    "industry_id": "id"
    }
    ]
    }
    ]
    })
     */
    public function TypeIndustryList()
    {
        $type = Db::name('type')->select();
        $industry = Db::name('industry')->select();
        foreach ($type as $k => $v) {
            $type1[$k]['type'] = $v['type'];
            $type1[$k]['type_id'] = $v['id'];
        }
        foreach ($industry as $k => $v) {
            $industry1[$k]['industry'] = $v['industry'];
            $industry1[$k]['industry_id'] = $v['id'];
        }
        $return[]['types'] = $type1;
        $return[]['industrys'] = $industry1;
        $this->success('成功', $return);
    }


    /**
     * @ApiTitle    (团队接口-申请公司团队)
     * @ApiSummary  (申请公司团队)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Team/ApplicationCompanyTeam)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="company_name", type="integer", required=true, description="公司名")
     * @ApiParams   (name="credit", type="integer", required=true, description="公司信用代码")
     * @ApiParams   (name="company_address", type="string", required=true, description="公司地址")
     * @ApiParams   (name="address_con", type="string", required=true, description="公司详细地址")
     * @ApiParams   (name="invoice_address", type="string", required=true, description="开票地址")
     * @ApiParams   (name="bank_name", type="string", required=true, description="银行名称")
     * @ApiParams   (name="bank_num", type="string", required=true, description="银行账号")
     * @ApiParams   (name="company_tel", type="string", required=true, description="公司电话")
     * @ApiParams   (name="type_id", type="int", required=true, description="类型")
     * @ApiParams   (name="industry_id", type="int", required=true, description="行业")
     * @ApiParams   (name="business_avatar", type="string", required=true, description="营业执照")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功'
    "data": "1"
    })
     */
    public function ApplicationCompanyTeam()
    {
        $user_id = $this->is_token($this->request->header());
        $param = $this->request->param();
        $data = [
            'company_name' => $param['company_name'],
            'credit' => $param['credit'],
            'company_address' => $param['company_address'],
            'address_con' => $param['address_con'],
            'invoice_address' => $param['invoice_address'],
            'bank_name' => $param['bank_name'],
            'bank_num' => $param['bank_num'],
            'company_tel' => $param['company_tel'],
            'type_id' => $param['type_id'],
            'industry_id' => $param['industry_id'],
            'business_avatar' => $param['business_avatar'],
            'status' => 2,
            'company_holder' => $user_id
        ];
        $model = new Company();
        $res = $model->save($data);
        if ($res) {
            $this->success('成功', 1);
        } else {
            $this->error('失败', 0);
        }
    }
}