...
|
...
|
@@ -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)
|
...
|
...
|
|