Enter.php 5.3 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/4/29
 * Time: 15:08
 */

namespace app\index\controller;


use app\common\controller\Frontend;
use app\index\model\Firmstores;
use app\index\model\Minestore;

class Enter extends Frontend
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize(); // TODO: Change the autogenerated stub
        $this->view->assign('is_search', 0);
        $this->view->assign('is_active', 0);
    }

    /**
     * 申请入驻页面
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index(){
        $user_id = $this->auth->id;
        $userModel = new \app\index\model\User();
        $user = $userModel->findData(['id'=>$user_id]);
        if(empty($user)){
            $this->error('查无此人','','','');
        }
        if($user['identity'] != '0'){
            $this->redirect('index/index');
        }
        $this->assign('title', '入驻申请');
        return $this->fetch();
    }

    /**
     * 申请个人店铺
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function apply_personage(){
        $user_id = $this->auth->id;
        $userModel = new \app\index\model\User();
        $user = $userModel->findData(['id'=>$user_id]);
        if(empty($user)){
            $this->error('查无此人','','','');
        }
        if($user['identity'] != '0'){
            $this->redirect('index/index');
        }
        $this->assign('title',"申请个人店铺");
        return $this->fetch();
    }

    /**
     * 申请企业店铺
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function apply_company(){
        $user_id = $this->auth->id;
        $userModel = new \app\index\model\User();
        $user = $userModel->findData(['id'=>$user_id]);
        if(empty($user)){
            $this->error('查无此人','','','');
        }
        if($user['identity'] != '0'){
            $this->redirect('index/index');
        }
        $this->assign('title',"申请企业店铺");
        return $this->fetch();
    }

    public function submit_personage(){
        $user_id = $this->auth->id;
        $userModel = new \app\index\model\User();
        $user = $userModel->findData(['id'=>$user_id]);
        if(empty($user)){
            $this->error('查无此人','','','');
        }
        if($user['identity'] != '0'){
            $this->error('您已成为个人店铺或企业店铺');
        }
        $param = $this->request->param();
        $validate = new \think\Validate([
            'linkname' => 'require',
            'idcard' => 'require',
            'card_images' => 'require',
            'phone' => 'require',
            'address' => 'require',
            'lng' => 'require',
            'lat' => 'require',
            'thumbnail' => 'require',
        ]);
        if (!$validate->check($param)) {
            $this->error($validate->getError());
        }
        $minestoreModel = new Minestore();
        $data = $minestoreModel->findData(['user_id'=>$user_id]);
        $param['user_id'] = $user_id;
        $param['updatetime'] = time();
        if(empty($data)){
            $param['createtime'] = time();
            $result = $minestoreModel->insertData($param);
        }else{
            $result = $minestoreModel->updateData(['id'=>$data['id']],$param);
        }
        if(empty($result)){
            $this->error('sql执行失败');
        }
        $this->success('SUCCESS');
    }

    public function submit_company(){
        $user_id = $this->auth->id;
        $userModel = new \app\index\model\User();
        $user = $userModel->findData(['id'=>$user_id]);
        if(empty($user)){
            $this->error('查无此人','','','');
        }
        if($user['identity'] != '0'){
            $this->error('您已成为个人店铺或企业店铺');
        }
        $param = $this->request->param();
        $validate = new \think\Validate([
            'name' => 'require',
            'companyname' => 'require',
            'business' => 'require',
            'companytype' => 'require',
            'companyscale' => 'require',
            'linkname' => 'require',
            'phone' => 'require',
            'address' => 'require',
            'lng' => 'require',
            'lat' => 'require',
        ]);
        if (!$validate->check($param)) {
            $this->error($validate->getError());
        }
        $firmstoresModel = new Firmstores();
        $data = $firmstoresModel->findData(['user_id'=>$user_id]);
        $param['user_id'] = $user_id;
        $param['updatetime'] = time();
        if(empty($data)){
            $param['createtime'] = time();
            $result = $firmstoresModel->insertData($param);
        }else{
            $result = $firmstoresModel->updateData(['id'=>$data['id']],$param);
        }
        if(empty($result)){
            $this->error('sql执行失败');
        }
        $this->success('SUCCESS');
    }
}