作者 sgj

complete the register page

... ... @@ -10,6 +10,7 @@ namespace app\admin\controller;
use app\admin\model\HospitalModel;
use app\admin\model\JobModel;
use app\admin\model\OfficeModel;
use cmf\controller\AdminBaseController;
use think\db;
... ... @@ -210,6 +211,48 @@ class HospitalController extends AdminBaseController
return $this->fetch();
}
}
/**
* @adminMenu(
* 'name' => '职位管理',
* 'parent' => 'default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '',
* 'param' => ''
* )
*/
public function job(){
$Job=new JobModel();
$jobs=$Job->getJOb()->toArray();
$this->assign('jobs',$jobs);
return $this->fetch();
}
/**
* @adminMenu(
* 'name' => '职位添加',
* 'parent' => 'default',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '',
* 'param' => ''
* )
*/
public function jobAdd(){
if (\request()->isAjax()){
$insert=input('name');
$Job=new JobModel();
$result=$Job->addJob($insert);
if ($result==1){
$this->success('添加成功!');
}
$this->error('添加失败!');
}
return $this->fetch();
}
... ...
... ... @@ -9,6 +9,7 @@
namespace app\admin\model;
use think\Db;
use think\Model;
use traits\model\SoftDelete;
... ... @@ -87,10 +88,9 @@ class HospitalModel extends Model
*/
public function getHospitalByPaltform($platform){
$map['platform_id']=$platform;
$info=view('platform_info')->field('hospital_name,hospital_id')->where($map)->select();
$info=db('platform_info_view')->field('hospital_name,hospital_id')->where($map)->select();
return $info;
}
/**
* 通过 平台 医院获取科室
* @param $platform 平台id
... ... @@ -100,7 +100,8 @@ class HospitalModel extends Model
public function getOfficeByHP($platform,$hospital){
$map['platform_id']=$platform;
$map['hospital_id']=$hospital;
$info=view('platform_info')->field('office_name,office_id')->where($map)->select();
$info=\db('platform_info_view')->field('office_name,office_id')->where($map)->select();
return $info;
}
... ... @@ -115,7 +116,9 @@ class HospitalModel extends Model
return $info;
}
public function getJob(){
}
... ...
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2018/12/4
* Time: 14:49
*/
namespace app\admin\model;
use think\Model;
use traits\model\SoftDelete;
class JobModel extends Model
{
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $insert =['addtime'];
public function getJob($jobId=''){
if (!empty($jobId)){
$map['id']=$jobId;
}else{
$map='';
}
$job=$this->where($map)->select();
return $job;
}
public function addJob($name){
$data['name']=$name;
$return=$this->insert($data);
return $return;
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2018/12/4
* Time: 16:21
*/
namespace app\admin\validate;
use think\Validate;
class RegisterValidate extends Validate
{
protected $rule = [
'platform' => 'require|integer',
'hospital' => 'require|integer',
'office' => 'require|integer',
'user_name' => 'require',
'tel'=>'require|/^1[34578]\d{9}$/',
'job'=>'require|integer',
'province'=>'require',
'city'=>'require',
'town'=>'require',
];
protected $message = [
'user_name.require' => '姓名不能为空',
'platform' => '平台信息错误',
'hospital' => '医院信息错误',
'office' => '科室信息错误',
'tel'=>'手机号错误',
'job'=>'职位必填',
'province'=>'省为必填项',
'city'=>'城市为必填项',
];
}
\ No newline at end of file
... ...
... ... @@ -9,10 +9,12 @@
namespace app\portal\controller;
use app\admin\model\HospitalModel;
use app\admin\model\JobModel;
use app\user\model\UserModel;
use cmf\controller\HomeBaseController;
use EasyWeChat\Foundation\Application;
use cmf\controller\WeChatBaseController;
use think\Log;
class IndexController extends WeChatBaseController
... ... @@ -30,10 +32,79 @@ class IndexController extends WeChatBaseController
public function register()
{
$Hospital=new HospitalModel();
$platform=$Hospital->getPlatment()->toArray();
$this->assign('platform',$platform);
return $this->fetch();
/*检查用户是否注册成功*/
$Hospital = new HospitalModel();
$platform = $Hospital->getPlatment()->toArray();
$Job = new JobModel();
$jobs = $Job->getJob()->toArray();
$this->assign('jobs', $jobs);
$this->assign('platform', $platform);
return $this->fetch();
}
public function registerPost(){
$info=input();
/*验证验证码*/
$check=cmf_check_verification_code($info['tel'], $info['verify_code'], $clear = false);
if (!empty($check)){
$this->error($check);
}
/*验证器检查参数*/
$result = $this->validate($info, 'admin/Register');
if ($result !== true) {
$this->error($result);
}
/*查找openid用户进行添加信息*/
$user_id=cmf_get_current_user_id();
if (empty($user_id)){
$this->error('内部错误');
}else{
/*添加相应的信息到用户表*/
$insert['paltform']=$info['platform'];
$insert['hospital']=$info['hospital'];
$insert['office']=$info['office'];
$insert['job']=$info['job'];
$insert['province']=$info['province'];
$insert['city']=$info['city'];
$insert['town']=$info['town'];
$insert['mobile']=$info['tel'];
$insert['user_login']=$info['user_name'];
$User=new UserModel();
$result=$User->register($user_id,$insert);
if ($result==1){
$this->success('注册成功!');
}else{
$this->error('注册失败!');
}
}
}
/**
* 发送短信验证码
* @param $tel
*/
public function sendVerifyCode(){
$tel=input('tel');
$code=cmf_get_verification_code($tel, $length = 6);
$text='您好,您的验证为'.$code;
$data = array(
'content' => $text,
'mobile' => $tel,
'productid' => '676767',
'xh' => ''
);
$return=send_sms($data);
$ret=explode(',',$return);
if ($ret[0]=='1'){
cmf_verification_code_log($tel,$code);
$this->success('验证码已经发送成功');
}else{
$info=date('Y-m-d H:i:s')." 短信发送失败 error:".$return;
Log::write($info,'ERROR');
$this->error('短信发送失败!');
}
}
/**
... ... @@ -52,5 +123,38 @@ class IndexController extends WeChatBaseController
return $this->fetch();
}
/**
* 获取平台下的医院
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getHospital(){
$platform=input('platform');
if(empty($platform)){
$this->error();
}
$Hospital=new HospitalModel();
$hospital=$Hospital->getHospitalByPaltform($platform);
$this->success('','',$hospital);
}
public function getOffice(){
$platform_id=input('platform_id');
$hospital_id=input('hospital_id');
if (empty($platform_id)||empty($hospital_id)){
$this->error('缺少参数');
}
$Hospital=new HospitalModel();
$office=$Hospital->getOfficeByHP($platform_id,$hospital_id);
$this->success('','',$office);
}
public function getJob(){
}
}
... ...
... ... @@ -338,6 +338,17 @@ class UserModel extends Model
return 0;
}
/**
* 注册用户
* @param $user_id
* @param $data
* @return UserModel
*/
public function register($user_id,$data){
$map['id']=$user_id;
$return=$this->where($map)->update($data);
return $return;
}
}
... ...
<include file="public@header"/>
</head>
<body>
<div class="wrap">
<ul class="nav nav-tabs">
<li class="active"><a href="">职位管理</a></li>
<li><a href="{:url('jobAdd')}">添加职位</a></li>
</ul>
<form method="post" class="js-ajax-form margin-top-20">
<div class="table-actions">
<!--<button type="submit" class="btn btn-primary btn-sm js-ajax-submit">{:lang('SORT')}</button>-->
</div>
<table class="table table-hover table-bordered table-list">
<thead>
<tr>
<th width="50">ID</th>
<th>标签名称</th>
<th>状态</th>
<th width="160">操作</th>
</tr>
</thead>
<tbody>
<foreach name="jobs" item="vo">
<tr>
<td>{$vo.id}</td>
<td>{$vo.name}</td>
<td><a href="{:url('office',['id'=>$vo.id])}"></a></td>
<td><a class="js-ajax-delete" href="{:url('jobDel',['id'=>$vo.id])}">删除</a></td>
</tr>
</foreach>
</tbody>
<tfoot>
<tr>
<th width="50">ID</th>
<th>标签名称</th>
<th>状态</th>
<th width="160">操作</th>
</tr>
</tfoot>
</table>
<div class="table-actions">
<!--<button type="submit" class="btn btn-primary btn-sm js-ajax-submit">{:lang('SORT')}</button>-->
</div>
</form>
<ul class="pagination">{$page|default=''}</ul>
</div>
<script src="__STATIC__/js/admin.js"></script>
</body>
</html>
\ No newline at end of file
... ...
<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
<ul class="nav nav-tabs">
<li ><a href="{:url('job')}">职位管理</a></li>
<li class="active"><a href="">添加职位</a></li>
</ul>
<form method="post" class="form-horizontal js-ajax-form margin-top-20" action="{:url('jobAdd')}">
<div class="form-group">
<label class="col-sm-2 control-label"><span class="form-required">*</span>职位名称:</label>
<div class="col-md-6 col-sm-10">
<input type="text" class="form-control" name="name" value="">
</div>
</div>
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary js-ajax-submit">{:lang("SAVE")}</button>
<a class="btn btn-default" href="__URL__">返回</a>
</div>
</form>
</div>
<script src="__STATIC__/js/admin.js"></script>
</body>
</html>
\ No newline at end of file
... ...
... ... @@ -121,6 +121,8 @@
</style>
<script type="application/javascript">
$(document).ready(function () {
$('.mask_box').hide()
$('.form_popup_box').hide()
... ... @@ -129,6 +131,36 @@ $(document).ready(function () {
//获取短信验证码
var validCode = true;
$(".getCode").click(function () {
/*验证信息*/
var phone_num = $('#phone_num').val();
if (phone_num == '') {
$('.form_popup_box').show()
$('.form_popup_box').text('手机号不能为空')
$('.form_popup_box').delay(1000).hide(0);
return;
}
$.ajax({
url:'{:url('sendVerifyCode')}',
type:'POST',
data:{
tel:phone_num
},
success:function(res) {
console.log(res)
if (res.code==1){
$('.form_popup_box').show()
$('.form_popup_box').text('验证码发送成功')
$('.form_popup_box').delay(1000).hide(0);
} else {
$('.form_popup_box').show()
$('.form_popup_box').text(res.msg)
$('.form_popup_box').delay(1000).hide(0);
}
}
})
var time = 60;
var $code = $(this);
if (validCode) {
... ... @@ -152,76 +184,117 @@ $(document).ready(function () {
</volist>
], {
onChange: function (res) {
console.log(res)
$('#hospital').val('')
$('#department').val('')
},
onConfirm: function (res) {
console.log('11111');
var platform=$('#platform').val(res[0].label)
console.log(platform);
console.log(res);
}
}
)
})
$('.hospital_item').click(function () {
var platform=$('#platform').val(res[0].label)
$('#platform').data('data-id',res[0].value)
var platform=res[0].value;
$.ajax({
url:'{:url('getHospital','','',true)}',
type:'POST',
data:{
'platform':platform,
},
success:function(res){
$('.hospital_item').click(function () {
console.log($('.platform_item').html())
weui.picker([
var hospital=new Array();
for(var i=0;i<res.data.length;i++){
var one=new Object();
one.value=res.data[i].hospital_id;
one.label=res.data[i].hospital_name;
hospital.push(one)
}
weui.picker(
hospital
, {
onChange: function (res) {
$('#department').val('')
},
onConfirm: function (res) {
$('#hospital').val(res[0].label)
$('#hospital').data('data-id',res[0].value)
console.log(res)
var hospital_id=res[0].value;
$.ajax({
url:'{:url('getOffice','','',true)}',
type:'POST',
data:{
'platform_id':platform,
'hospital_id':hospital_id,
},
success:function(res){
$('.department_item').click(function () {
{label: '医院1', value: 0},
{label: '医院2', value: 1},
{label: '医院3', value: 2},
var office=new Array();
for(var i=0;i<res.data.length;i++){
var one=new Object();
one.value=res.data[i].office_id;
one.label=res.data[i].office_name;
office.push(one)
}
weui.picker(office, {
onChange: function (res) {
},
onConfirm: function (res) {
$('#department').val(res[0].label)
$('#department').data('data-id',res[0].value)
}
}
)
})
}
})
}
}
)
})
}
});
], {
onChange: function (res) {
console.log(res)
},
onConfirm: function (res) {
$('#hospital').val(res[0].label)
}
}
)
})
$('.department_item').click(function () {
weui.picker([
{label: '科室1', value: 0},
{label: '科室2', value: 1},
{label: '科室3', value: 2},
], {
onChange: function (res) {
console.log(res)
},
onConfirm: function (res) {
$('#department').val(res[0].label)
}
}
)
})
$('.position_item').click(function () {
weui.picker([
{label: '职务1', value: 0},
{label: '职务2', value: 1},
{label: '职务3', value: 2},
<volist name='jobs' id='vo'>
{label: '{$vo.name}', value: {$vo.id}},
</volist>
], {
onChange: function (res) {
console.log(res)
},
onConfirm: function (res) {
$('#position').val(res[0].label)
$('#position').data('data-id',res[0].value)
}
}
)
})
$('.register_btn').click(function () {
var platform=$('#platform').data('data-id')
var hospital=$('#hospital').data('data-id')
var office=$('#department').data('data-id')
var position=$('#position').data('data-id')
var user_name = $('#user_name').val()
var phone_num = $('#phone_num').val()
var verify_code = $('#verify_code').val()
var platform = $('#platform').val()
var hospital = $('#hospital').val()
var department = $('#department').val()
var position = $('#position').val()
// var platform = $('#platform').val()
// var hospital = $('#hospital').val()
// var department = $('#department').val()
// var position = $('#position').val()
var province = $('#province').val()
var city = $('#city').val()
var town = $('#town').val()
... ... @@ -235,7 +308,7 @@ $(document).ready(function () {
$('.form_popup_box').delay(1000).hide(0);
} else if (verify_code == '') {
$('.form_popup_box').show()
$('.form_popup_box').text('码不能为空')
$('.form_popup_box').text('验证码码不能为空')
$('.form_popup_box').delay(1000).hide(0);
} else if (platform == '') {
$('.form_popup_box').show()
... ... @@ -258,7 +331,7 @@ $(document).ready(function () {
$('.form_popup_box').text('省份不能为空')
$('.form_popup_box').delay(1000).hide(0);
} else if (city == '请选择') {
$('.form_popup_box').show()
$('.form_popup_box').text('城市不能为空')
$('.form_popup_box').delay(1000).hide(0);
} else if (town == '请选择') {
... ... @@ -266,11 +339,36 @@ $(document).ready(function () {
$('.form_popup_box').text('区县不能为空')
$('.form_popup_box').delay(1000).hide(0);
} else {
$('.success').show().delay(2000).hide(2)
// $('.first').show().delay(2000).hide(2)
// setTimeout(function () {
// $('.success').show().delay(2000).hide(2)
// },2000);
$.ajax({
url:'{:url('registerPost')}',
type:'POST',
data:{
platform:platform,
hospital:hospital,
office:office,
user_name:user_name,
tel:phone_num,
verify_code:verify_code,
job:position,
province:province,
city:city,
town:town,
},
success:function(res) {
console.log(res)
if (res.code==1){
$('.success').show().delay(2000).hide(2);
window.location.href='{:url('/')}'
}else {
$('.form_popup_box').show()
$('.form_popup_box').text(res.msg)
$('.form_popup_box').delay(1000).hide(0);
}
}
})
}
}
)
... ...
... ... @@ -205,7 +205,7 @@ class WeChatBaseController extends BaseController
*/
public function checkWeChatUserLogin()
{
session('user.id',2);
session('user.id',8);
$userId = cmf_get_current_user_id();
if (empty($userId)) {
... ...