ProjectController.php 3.1 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/12
 * Time: 16:25
 */

namespace api\index\controller;

use cmf\controller\RestBaseController;
use think\Db;
use think\Validate;

/**
 * @title 关于我们
 * @description
 */
class ProjectController extends RestBaseController
{
    /**
     * @title 公司介绍
     * @description
     * @author GuoSheng
     * @url /index/Project/index
     * @method GET
     *
     * @return id:ID
     * @return content:公司介绍
     * @return create_time:创建时间
     *
     */
    public function index(){
        $data = Db::name('about')
            ->where('id',1)
            ->field('id,content,create_time')
            ->find();
        $data['content'] = cmf_replace_content_file_url(htmlspecialchars_decode($data['content']));
        $data['create_time'] = date('Y-m-d H:i:s',$data['create_time']);
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 产品方案
     * @description
     * @author GuoSheng
     * @url /index/Project/project
     * @method GET
     *
     * @return id:ID
     * @return content:产品方案
     *
     */
    public function project(){
        $data = Db::name('project')
            ->where('id',1)
            ->field('id,content')
            ->find();
        $data['content'] = cmf_replace_content_file_url(htmlspecialchars_decode($data['content']));
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 加入我们
     * @description
     * @author GuoSheng
     * @url /index/Project/joinUs
     * @method GET
     *
     * @return id:ID
     * @return content:内容
     *
     */
    public function joinUs(){
        $data = Db::name('joinus')
            ->where('id',1)
            ->field('id,content')
            ->find();
        $data['content'] = cmf_replace_content_file_url(htmlspecialchars_decode($data['content']));
        $this->success('SUCCESS',$data);
    }

    /**
     * @title 加入我们信息填写
     * @description
     * @author GuoSheng
     * @url /index/Project/join
     * @method GET
     *
     * @header name:XX-Token require:1 default: desc:token
     *
     * @param name:name type:string require:1 other: desc:姓名
     * @param name:phone type:int require:1 other: desc:电话
     * @param name:email type:string require:1 other: desc:邮箱
     * @param name:content type:string require:1 other: desc:加盟信息
     *
     */
    public function join()
    {
        $user_id = $this->getUserId();
        $param = $this->request->param();
        $param['user_id'] = $user_id;
        $param['create_time'] = time();
        $validate = new Validate([
            'name' => 'require',
            'phone' => 'require|max:11',
            'email'=>'require',
            'content'=>'require',
        ]);
        if (!$validate->check($param)) {
            $this->error(['code'=>40005,'msg'=>$validate->getError()]);
        }
        $data = Db::name('join')
            ->insert($param);
        if(empty($data)){
            $this->error(['code'=>40006,'msg'=>'sql执行失败']);
        }
        $this->success('SUCCESS');
    }

}