IndexController.php 5.8 KB
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\HomeBaseController;
use think\Db;
use think\Request;
use think\Validate;

class IndexController extends HomeBaseController
{
    public function index()
    {
        echo '<h1>==403Forbidden==</h1>';
    }

    //step1 在线报名
    public function online_baoming()
    {
        $re = Db::name('user')->where(['openid'=>session('openid')])->find();

        if($re && $re['student_type'] == '1'){
            $this->success('您已成功报名,无需再次报名',url('user/login/index'));
        }elseif ($re['user_type'] == '3'){
            $this->success('教练无需报名',url('user/login/index'));
        }
        $res = Db::name('goods')->where(['delete_time' => '0', 'status' => '1'])->select()->toArray();
        $this->assign('data', $res);

        return $this->fetch();
    }

    //step2 在线报名详情
    public function baoming_detail(Request $req)
    {
        $id = $req->param('id');
        if (!$id) {
            return $this->error('参数错误');
        }
        $res = Db::name('goods')->where(['id' => $id])->find();
        $this->assign('data', $res);
        return $this->fetch();
    }

    //step3 报名信息填写
    public function write_info(Request $req)
    {
        $id = $req->param('gid');
        $this->assign('gid', $id);
        $resp = Db::name('goods')->where(['id' => $id])->value('hetong');
        $this->assign('page', htmlspecialchars_decode($resp));
        return $this->fetch();
    }

    //step4 提交报名信息ajax
    public function baoming_do()
    {
        $rules    = [
            'name'     => 'require',
            'sex'      => 'require',
            'birthday' => 'require',
            'idnumber' => 'require',
            'mobile'   => 'require',
            'sms_code' => 'require',
        ];
        $validate = new Validate($rules);
        $validate->message([
            'name.require'     => '姓名不能为空',
            'sex.require'      => '性别不能为空',
            'birthday.require' => '生日不能为空',
            'idnumber.require' => '身份证号不能为空',
            'mobile.require'   => '手机号不能为空',
            'sms_code.require' => '验证码不能为空',
        ]);

        //验证参数
        $data = $this->request->post();
        if (!$validate->check($data)) {
            return json(['code' => '0', 'msg' => $validate->getError()]);
        }
        //验证验证码
        $sres = cmf_check_verification_code($data['mobile'], $data['sms_code']);
        if ($sres != '') {
            return json(['code' => '0', 'msg' => $sres]);
        }

        $dataup['user_nickname'] = $data['name'];
        $dataup['sex']           = $data['sex'];
        $dataup['birthday']      = $data['birthday'];
        $dataup['mobile']        = $data['mobile'];
        $dataup['idnumber']      = $data['idnumber'];
        $dataup['add_type']      = '1';
        $w['openid']             = session('openid');
        $re = Db::name("user")
            ->where($w)
            ->find();
        if ($re) {
            $dataup['id'] = $re['id'];
            session('user.id', $dataup['id']);
            $res = Db::name('user')->update($dataup);
            if ($res) {
                return json(['code' => '1', 'msg' => '保存成功']);
            } else {
                return json(['code' => '0', 'msg' => '保存失败']);
            }
        } else {
            return json(['code' => '0', 'msg' => '保存失败']);
        }


    }


    public function confirm_order(Request $req)
    {

        $gid = $req->param('gid');
        $id  = session('user.id');
        $re  = Db::name('user')->where(['id' => $id])->find();
        $res = Db::name('goods')->where(['id' => $gid])->find();

        $this->assign('data', $re);
        $this->assign('gdata', $res);
        $this->assign('gid', $gid);

        return $this->fetch();
    }

    //订单入库 ajax
    public function baoming_dodata(Request $req)
    {

        $gid                  = $req->param('gid');
        $res                  = Db::name('goods')->where(['id' => $gid])->find();
        $id                   = session('user.id');
        $data['gid']          = $gid;
        $data['uid']          = $id;
        $data['create_time']  = time();
        $data['price']        = $res['price'];
        $data['out_trade_no'] = date('YmdHis') . rand(111,999);
        $rr                   = Db::name('order')->insert($data);
        if ($rr) {
            return json(['code' => '1', 'msg' => '保存成功', 'data' => $data['out_trade_no']]);
        } else {
            return json(['code' => '0', 'msg' => '保存失败']);
        }
    }


    //学员手册
    public function student_shouce()
    {
        $data = Db::name('portal_post')->select()->toArray();
        $this->assign('data', $data);
        return $this->fetch();
    }

    //手册详情
    public function shouce_details(Request $req)
    {
        $id   = $req->param('id');
        $data = Db::name('portal_post')->where(['id' => $id])->find();
        $this->assign('data', $data);
        return $this->fetch();
    }

    //关于我们
    public function about()
    {
        return $this->fetch();
    }


}