TeamController.php 3.1 KB
<?php
namespace app\team\controller;
use cmf\controller\HomeBaseController;
use Think\Db;

/**
 * @title 团队定制模块
 */
class TeamController extends HomeBaseController
{

    /**
     * @title 提交表单
     * @description 默认访问接口
     * @author sᴏᴜʟ ᴏғ ᴄɪɴᴅᴇʀ
     * @url /team/Team/teamCustomization
     * @method POST
     *
     * @param name:team_name type:char require:1 default:法兰不死队 other: desc:团队名称
     * @param name:team_num type:int require:1 default:999 other: desc:团队人员数量
     * @param name:start_time type:date require:1 default:2018-09-01 other: desc:出发日期
     * @param name:end_time type:date require:1 default:2018-10-01 other: desc:结束日期
     * @param name:city type:char require:1 default:天津市 other: desc:市
     * @param name:county type:char require:1 default:南开区 other: desc:区
     * @param name:street type:char require:1 default:华苑 other: desc:街道
     * @param name:contact type:char require:1 default:李大师 other: desc:联系人
     * @param name:tel type:char require:1 default:15122554643 other: desc:电话
     * @param name:wechat type:char require:1 default:xxx other: desc:微信号
     * @param name:desc type:text require:1 default:欢迎来到德莱联盟 other: desc:需求描述
     */
    public function teamCustomization()
    {
        $request = request();
        if ($request->isPost()) {
            $post = $request->param();
            $result = $this->validate(
                [
                    'team_name' => $post['team_name'],
                    'team_num' => $post['team_num'],
                    'start_time' => $post['start_time'],
                    'end_time' => $post['end_time'],
                    'contact' => $post['contact'],
                    'tel' => $post['tel'],
                    'wechat' => $post['wechat'],
                    'desc' => $post['desc']
                ],
                [
                    'team_name' => 'require',
                    'team_num' => 'require',
                    'start_time' => 'require',
                    'end_time' => 'require',
                    'contact' => 'require',
                    'tel' => 'require',
                    'wechat' => 'require',
                    'desc' => 'require'
                ]);
            if (true !== $result) {
                echo json_encode(['msg' => $result, 'code' => 40000]);
                exit();
            } else {
                $post['address'] = $post['city'] . $post['county'] . $post['street'];
                unset($post['city']);
                unset($post['county']);
                unset($post['street']);
                if (Db::name('team_customization')->insert($post)) {
                    echo json_encode(['msg' => '提交成功', 'code' => 20000]);
                    exit();
                } else {
                    echo json_encode(['msg' => '提交失败', 'code' => 40000]);
                    exit();
                }
            }
        } else {
            return $this->fetch();
        }
    }

}