123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace app\manage\controller;
- use think\Controller;
- use think\Db;
- use think\Session;
- use think\Config;
- use think\Cookie;
- use think\Request;
- use app\common\library\SysLogs;
- use app\common\library\UUIDs;
- class DoctorClass extends Base {
- public function index() {
- return $this->fetch();
- }
- public function datas() {
- $page = empty($_GET["page"]) ? 1 : $_GET["page"];
- $pagesize = empty($_GET["rows"]) ? 1 : $_GET["rows"];
- if (empty($page) || $page < 1) {
- $page = 1;
- }
- if (empty($pagesize) || $pagesize < 1) {
- $pagesize = 30;
- }
- $info = DB::table('doctor_class')->page($page, $pagesize)->select();
- foreach ($info as $k => $v) {
- $doctorname = DB::table('doctors')->where('id', $v['doctor_id'])->field('realname')->find();
- $info[$k]['doctor_name'] = $doctorname['realname'];
- $departmentname = DB::table('department')->where('id', $v['department_id'])->field('department_name')->find();
- $info[$k]['department_name'] = $departmentname['department_name'];
- }
- $num = DB::table('doctor_class')->count();
- $data = array();
- $data['total'] = $num;
- $data['rows'] = $info;
- echo json_encode($data);
- }
- public function edit() {
- if (isset($_GET["id"])) {
- $id = $_GET["id"];
- if ($id != null) {
- $doctorclass = Db::table("doctor_class")->where("id", $id)->find();
- if (count($doctorclass) > 0) {
- if (empty($doctorclass['doctor_class'])) {
- $doctorclass['doctor_class'] = array();
- } else {
- $doctorclass['doctor_class'] = explode(',', $doctorclass['doctor_class']);
- }
- $this->assign("doctorclass", $doctorclass);
- }
- }
- }
- $doctors = DB::table('doctors')->select();
- $this->assign('doctors', $doctors);
- $department = DB::table('department')->select();
- $this->assign('department', $department);
- return $this->fetch('edit');
- }
- public function save() {
- $info = $_GET;
- $info['doctor_class'] = implode(',', $_GET['doctor_class']);
- if (empty($_GET['id'])) {
- unset($_GET['id']);
- $id = UUIDs::uuid16();
- $info['id'] = $id;
- $a = DB::table('doctor_class')->insert($info);
- SysLogs::log("doctorclass", "C", json_encode($info));
- return 'insert_ok;' . $id;
- } else {
- $a = DB::table('doctor_class')->where('id', $_GET['id'])->update($info);
- SysLogs::log("doctorclass", "U", $_GET['id'] . " --> " . $info);
- return 'update_ok';
- }
- }
- /**
- * 软删除记录
- */
- public function delete() {
- if (isset($_GET["ids"])) {
- $ids = $_GET["ids"];
- if (!empty($ids)) {
- $idArr = explode(",", $ids);
- if (count($idArr) > 0) {
- Db::table("doctor_class")->where("id", "in", $idArr)->delete();
- }
- SysLogs::log("doctorclass", "D", $ids );
- echo "delete_ok";
- return;
- }
- }
- echo "fail";
- }
- }
|