DoctorMVC系统

0 22
自行配置ThinkPHP环境,如果弹出class不存在错误请把app/view/Index文件夹名的大写I改为小写i再试试演示链接:点我查看演示效果contro...

自行配置ThinkPHP环境,如果弹出class不存在错误请把app/view/Index文件夹名的大写I改为小写i再试试

演示链接:点我查看演示效果


controller/Index.php:

<?php
namespace app\controller;

use app\BaseController;

use think\facade\Db;

use app\model\MdehDepartment;

use think\facade\View;

use app\model\MdehDoctor;

class Index extends BaseController
{
    public function index(){
        $dataSet = Db::table('mdeh_department')->limit(10)->select();
        dump($dataSet);
    }
    
    public function department(){
        $department = new MdehDepartment();
        $list = $department->getDepartments();
        View::assign("departments", $list);
        return View::fetch();
    }
    
    public function doctor(){
        $depIds = ['HC001', 'HC002', 'HC003'];
        $depNames = [
            'HC001' => '儿科',
            'HC002' => '神经科',
            'HC003' => '妇科'
        ];
        $depNameList = array_values($depNames);
        $dlist = MdehDoctor::getDoctorsByDepIds($depIds);
        View::assign('doctors', $dlist);
        View::assign('departments', implode('、', $depNameList));
        return View::fetch();
    }
    public function hello($name = 'ThinkPHP6')
    {
        return 'hello,' . $name;
    }
}

app/model/MdehDoctor:

<?php
namespace app\model;

use think\Model;

class MdehDoctor extends Model
{
    protected $name = 'mdeh_doctor';

    public static function getDoctorsByDepIds($depIds)
    {
        return self::whereIn('dep_id', $depIds)
                   ->field('d_id, d_name, d_sex, d_title1')
                   ->select();
    }
}

app/view/Index/doctor.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>医生列表 - {$departments}</title>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 40px 20px;
        }
        .container { max-width: 1000px; margin: 0 auto; }
        .header { text-align: center; margin-bottom: 30px; color: #fff; }
        .header h1 { font-size: 2.2rem; font-weight: 300; text-shadow: 2px 2px 4px rgba(0,0,0,0.2); }
        .doctor-table {
            width: 100%; background: #fff; border-radius: 16px;
            overflow: hidden; box-shadow: 0 20px 40px rgba(0,0,0,0.15);
            border-collapse: collapse;
        }
        .doctor-table thead { background: linear-gradient(90deg, #4facfe 0%, #00f2fe 100%); }
        .doctor-table th {
            padding: 18px 20px; text-align: left; font-weight: 600;
            color: #fff; letter-spacing: 1px; text-transform: uppercase;
        }
        .doctor-table td { padding: 16px 20px; border-bottom: 1px solid #f0f0f0; color: #333; }
        .doctor-table tbody tr:hover { background: #f8f9ff; }
        .gender-badge {
            display: inline-block; padding: 4px 12px; border-radius: 20px;
            font-size: 0.85rem; font-weight: 500;
        }
        .gender-male { background: #e3f2fd; color: #1565c0; }
        .gender-female { background: #fce4ec; color: #c2185b; }
        .title-badge {
            display: inline-block; padding: 4px 10px; border-radius: 20px;
            font-size: 0.85rem; background: #e8f5e9; color: #2e7d32;
        }
        .footer { margin-top: 20px; text-align: center; color: rgba(255,255,255,0.8); }
    </style>
</head>
<body>
    <div>
        <div>
            <h1>医生信息列表</h1>
            <div>查询科室:{$departments}</div>
        </div>
        
        <table>
            <thead>
                <tr>
                    <th>工号</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>职称</th>
                </tr>
            </thead>
            <tbody>
                {if condition="$doctors->isEmpty()"}
                <tr><td colspan="4" style="text-align:center; padding:40px;">暂无医生数据</td></tr>
                {else /}
                {volist name="doctors" id="doctor"}
                <tr>
                    <td><strong>{$doctor.d_id}</strong></td>
                    <td>{$doctor.d_name}</td>
                    <td>
                        {if $doctor.d_sex == '男'}
                        <span class="gender-badge gender-male">{$doctor.d_sex}</span>
                        {elseif $doctor.d_sex == '女' /}
                        <span class="gender-badge gender-female">{$doctor.d_sex}</span>
                        {else /}
                        <span>{$doctor.d_sex}</span>
                        {/if}
                    </td>
                    <td><span>{$doctor.d_title1}</span></td>
                </tr>
                {/volist}
                {/if}
            </tbody>
        </table>
        <div><p>共 {$doctors->count()} 位医生</p></div>
    </div>
</body>
</html>


最后修改时间:
欧机邦货
上一篇 2026年03月18日 17:01
随机下篇 2026年03月03日 21:10

评论已关闭