作者 何书鹏
1 个管道 的构建 通过 耗费 5 秒

后台添加医生

... ... @@ -61,7 +61,7 @@ class Doctor extends Backend
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->with(['doctorlevel'])
->with(['doctorlevel','user'])
->where($where)
->order($sort, $order)
->paginate($limit);
... ... @@ -70,6 +70,8 @@ class Doctor extends Backend
$row->visible(['id','nickname','mobile','avatar','city','idcard_front','idcard_back','certificates','images','status','star','month_receive_num','total_receive_num','text_price','audio_price','createtime']);
$row->visible(['doctorlevel']);
$row->getRelation('doctorlevel')->visible(['level']);
$row->visible(['user']);
$row->getRelation('user')->visible(['nickname']);
}
$result = array("total" => $list->total(), "rows" => $list->items());
... ... @@ -80,6 +82,65 @@ class Doctor extends Backend
}
/**
* 添加
*/
public function add()
{
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$has = $this->model->where('user_id',$params['user_id'])->find();
!empty($has) && $this->error('申请入驻已存在,请勿重复操作');
// 格式化城市
$params['city'] = str_replace('/',',',$params['city']);
// 一级分类ID也存下来
$pids = Dept::where('id','in',$params['dept_ids'])->where('pid','>',0)->column('pid');
$params['dept_ids'] = implode(',',array_unique(array_merge($pids,explode(',',$params['dept_ids']))));
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException(true)->validate($validate);
}
// 修改用户身份
$identity = $params['status'] == '1' ? '2' : '1';
User::where('id',$params['user_id'])->update(['identity'=>$identity]);
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result !== false) {
$this->success();
} else {
$this->error(__('No rows were inserted'));
}
}
$this->error(__('Parameter %s can not be empty', ''));
}
return $this->view->fetch();
}
/**
* 编辑
*/
public function edit($ids = null)
... ... @@ -98,11 +159,13 @@ class Doctor extends Backend
$params = $this->request->post("row/a");
if ($params) {
$params = $this->preExcludeFields($params);
// 格式化城市
$params['city'] = str_replace('/',',',$params['city']);
// 一级分类ID也存下来
$pids = Dept::where('id','in',$params['dept_ids'])->where('pid','>',0)->column('pid');
$params['dept_ids'] = implode(',',array_unique(array_merge($pids,explode(',',$params['dept_ids']))));
$result = false;
Db::startTrans();
try {
... ... @@ -144,6 +207,48 @@ class Doctor extends Backend
}
/**
* 删除
*/
public function del($ids = "")
{
if (!$this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$ids = $ids ? $ids : $this->request->post("ids");
if ($ids) {
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$list = $this->model->where($pk, 'in', $ids)->select();
$count = 0;
Db::startTrans();
try {
foreach ($list as $k => $v) {
// 修改用户身份
User::where('id',$v['user_id'])->update(['identity'=>'1']);
$count += $v->delete();
}
Db::commit();
} catch (PDOException $e) {
Db::rollback();
$this->error($e->getMessage());
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success();
} else {
$this->error(__('No rows were deleted'));
}
}
$this->error(__('Parameter %s can not be empty', 'ids'));
}
/**
* 审核
*/
public function examine($ids = null)
... ...
... ... @@ -27,5 +27,6 @@ return [
'Audio_price' => '音频沟通费用',
'Createtime' => '申请时间',
'Updatetime' => '更新时间',
'Doctorlevel.level' => '等级'
'Doctorlevel.level' => '等级',
'User.nickname' => '申请人'
];
... ...
... ... @@ -50,4 +50,9 @@ class Doctor extends Model
{
return $this->belongsTo('DoctorLevel', 'level_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function user()
{
return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}
... ...
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<!--<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('User_id')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-user_id" data-rule="required" data-source="user/user/index" data-field="nickname" class="form-control selectpage" name="row[user_id]" type="text" value="{$row.user_id|htmlentities}">
</div>
</div>
</div>-->
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Nickname')}:</label>
<div class="col-xs-12 col-sm-8">
... ...
... ... @@ -17,7 +17,7 @@
<div class="widget-body no-padding">
<div id="toolbar" class="toolbar">
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<!--<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('doctor/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>-->
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('doctor/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('doctor/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
<a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('doctor/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
<!--<a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('doctor/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
... ...
... ... @@ -35,6 +35,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
{field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
{field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
{field: 'avatar', title: __('Avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
... ...
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
\ No newline at end of file
... ...