| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 | <?phpnamespace app\mobile\controller;use app\common\model\HumanEnterpriseApplyModel;use app\common\model\HumanEnterpriseModel;use app\common\model\HumanInstitutionApplyModel;use app\common\model\HumanInstitutionModel;use app\common\validate\HumanEnterpriseApplyValidate;use app\common\validate\HumanInstitutionApplyValidate;use app\mobile\MobileBaseController;use think\exception\ValidateException;class Human extends MobileBaseController{    protected function initialize()    {        $open_id = session('mobile.human.open_id');        if (empty($open_id)) {            return redirect('https://www.jucai.gov.cn/api/auth/wechat_auth?url=' . urlencode(url('/mobile/login/humanLogin')));        }    }    /**     * 表单     */    public function index()    {        $this->_formValidate();        return view();    }    public function institutionForm()    {        $this->_formValidate();        return view();    }    public function institutionFormPost()    {        $data = input('post.');        try {            validate(HumanInstitutionApplyValidate::class)->check($data);        } catch (ValidateException $e) {            ajax_return(1, $e->getError());        }        $data['open_id'] = session('mobile.human.open_id');        HumanInstitutionApplyModel::create($data);        ajax_return();    }    public function enterpriseForm()    {        return view('', [            'cooperate_list' => json_encode(HumanInstitutionModel::COOPERATE),        ]);    }    public function enterpriseFormPost()    {        $data = input('post.');        try {            validate(HumanEnterpriseApplyValidate::class)->check($data);        } catch (ValidateException $e) {            ajax_return(1, $e->getError());        }        $data['open_id'] = session('mobile.human.open_id');        HumanEnterpriseApplyModel::create($data);        ajax_return();    }    public function tips()    {        $open_id = session('mobile.human.open_id');        $msg     = '';        $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();        $enterprise  = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();        if (empty($institution) && empty($enterprise)) {            return redirect(url('human/index'));        }        if (!empty($institution)) {            if ($institution['status'] != HumanInstitutionApplyModel::STATUS_PASS) {                $msg = HumanInstitutionApplyModel::STATUS[$institution['status']];            } else {                return redirect(url('human/enterpriseList'));            }        }        if (!empty($enterprise)) {            if ($enterprise['status'] != HumanEnterpriseApplyModel::STATUS_PASS) {                $msg = HumanEnterpriseApplyModel::STATUS[$institution['status']];            } else {                return redirect(url('human/institutionList'));            }        }        return view('', ['msg' => $msg]);    }    /**     * 列表     */    public function institutionList()    {        $this->_listValidate();        $cooperate_list = [['text' => '业务范围', 'value' => '']];        foreach (HumanInstitutionModel::COOPERATE as $cooperate) {            $cooperate_list[] = ['text' => $cooperate, 'value' => $cooperate];        }        return view('', [            'cooperate_list' => json_encode($cooperate_list),        ]);    }    public function listInstitution()    {        $where   = $this->dealLikeInput(['name', 'cooperate']);        $where[] = ['status', '=', HumanInstitutionModel::STATUS_SHOW];        $list = HumanInstitutionModel::where($where)            ->order(['priority' => 'desc'])            ->limit(input('limit', 10))            ->page(input('page', 1))            ->select();        ajax_success($list);    }    public function institutionDetail()    {        $this->_listValidate();        $id = input('id');        empty($id) && jump('该机构不存在或已删除');        $info = HumanInstitutionModel::find($id);        empty($info) && jump('该机构不存在或已删除');        return view('', ['info' => $info]);    }    public function enterpriseList()    {        $this->_listValidate();        return view();    }    public function listEnterprise()    {        $where   = $this->dealLikeInput(['name']);        $where[] = ['status', '=', HumanEnterpriseModel::STATUS_SHOW];        $list = HumanEnterpriseModel::where($where)            ->order(['priority' => 'desc'])            ->limit(input('limit', 10))            ->page(input('page', 1))            ->select();        ajax_success($list);    }    public function enterpriseDetail()    {        $this->_listValidate();        $id = input('id');        empty($id) && jump('该企业不存在或已删除');        $info = HumanEnterpriseModel::find($id);        empty($info) && jump('该企业不存在或已删除');        return view('', ['info' => $info]);    }    private function _formValidate()    {        $open_id = session('mobile.human.open_id');        $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();        $enterprise  = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();        if (!empty($institution)) {            if ($institution['status'] != HumanInstitutionApplyModel::STATUS_PASS) {                return redirect(url('human/tips'));            } else {                return redirect(url('human/enterpriseList'));            }        }        if (!empty($enterprise)) {            if ($enterprise['status'] != HumanEnterpriseApplyModel::STATUS_PASS) {                return redirect(url('human/tips'));            } else {                return redirect(url('human/institutionList'));            }        }    }    private function _listValidate()    {        $open_id = session('mobile.human.open_id');        $institution = HumanInstitutionApplyModel::where('open_id', $open_id)->find();        $enterprise  = HumanEnterpriseApplyModel::where('open_id', $open_id)->find();        if (empty($institution) && empty($enterprise)) {            return redirect(url('human/index'));        }        if (!empty($institution)) {            if ($institution['status'] != HumanInstitutionApplyModel::STATUS_PASS) {                return redirect(url('human/tips'));            }        }        if (!empty($enterprise)) {            if ($enterprise['status'] != HumanEnterpriseApplyModel::STATUS_PASS) {                return redirect(url('human/tips'));            }        }    }}
 |