This commit is contained in:
Your Name
2026-03-11 09:49:47 +08:00
parent 02ae537b4c
commit 38ad60f4bb
290 changed files with 36917 additions and 123 deletions
@@ -0,0 +1,149 @@
<?php
declare(strict_types=1);
namespace app\adminapi\controller\order;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\order\OrderLists;
use app\adminapi\logic\order\OrderLogic;
use app\adminapi\validate\order\OrderValidate;
/**
* 订单管理控制器
* Class OrderController
* @package app\adminapi\controller\order
*/
class OrderController extends BaseAdminController
{
/**
* @notes 订单列表
* @return \think\response\Json
*/
public function lists()
{
return $this->dataLists(new OrderLists());
}
/**
* @notes 订单详情
* @return \think\response\Json
*/
public function detail()
{
$params = (new OrderValidate())->post()->goCheck('detail');
$detail = OrderLogic::detail($params['id']);
if (!$detail) {
return $this->fail('订单不存在');
}
return $this->data($detail);
}
/**
* @notes 创建订单
* @return \think\response\Json
*/
public function create()
{
$params = (new OrderValidate())->post()->goCheck('create');
$params['creator_id'] = $this->adminId;
$result = OrderLogic::create($params);
if (!$result) {
return $this->fail(OrderLogic::getError());
}
return $this->success('创建成功', $result->toArray());
}
/**
* @notes 编辑订单
* @return \think\response\Json
*/
public function edit()
{
$params = (new OrderValidate())->post()->goCheck('edit');
$result = OrderLogic::edit($params['id'], $params);
if (!$result) {
return $this->fail(OrderLogic::getError());
}
return $this->success('编辑成功');
}
/**
* @notes 支付订单
* @return \think\response\Json
*/
public function pay()
{
$params = (new OrderValidate())->post()->goCheck('pay');
$result = OrderLogic::pay($params['id'], $params['payment_method']);
if (!$result) {
return $this->fail(OrderLogic::getError());
}
return $this->success('支付成功');
}
/**
* @notes 取消订单
* @return \think\response\Json
*/
public function cancel()
{
$params = (new OrderValidate())->post()->goCheck('cancel');
$result = OrderLogic::cancel($params['id']);
if (!$result) {
return $this->fail(OrderLogic::getError());
}
return $this->success('取消成功');
}
/**
* @notes 退款订单
* @return \think\response\Json
*/
public function refund()
{
$params = (new OrderValidate())->post()->goCheck('refund');
$result = OrderLogic::refund($params['id']);
if (!$result) {
return $this->fail(OrderLogic::getError());
}
return $this->success('退款成功');
}
/**
* @notes 删除订单
* @return \think\response\Json
*/
public function delete()
{
$params = (new OrderValidate())->post()->goCheck('delete');
$result = OrderLogic::delete($params['id']);
if (!$result) {
return $this->fail(OrderLogic::getError());
}
return $this->success('删除成功');
}
/**
* @notes 导出订单
* @return \think\response\Json
*/
public function export()
{
return $this->dataLists(new OrderLists());
}
}
@@ -283,4 +283,38 @@ class DiagnosisController extends BaseAdminController
$result = DiagnosisLogic::generateMiniProgramQrcode($params);
return $this->data($result);
}
/**
* @notes 搜索患者(用于创建订单等场景)
* @return \think\response\Json
*/
public function searchPatient()
{
$keyword = $this->request->get('keyword', '');
$page_no = $this->request->get('page_no', 1);
$page_size = $this->request->get('page_size', 10);
if (empty($keyword)) {
return $this->success('', ['lists' => [], 'count' => 0]);
}
$offset = ($page_no - 1) * $page_size;
$lists = \app\common\model\tcm\Diagnosis::where('patient_name|patient_phone|patient_id_card', 'like', '%' . $keyword . '%')
->field(['id', 'patient_name', 'patient_phone', 'patient_id_card', 'gender', 'age'])
->limit($offset, $page_size)
->order('id desc')
->select()
->toArray();
$count = \app\common\model\tcm\Diagnosis::where('patient_name|patient_phone|patient_id_card', 'like', '%' . $keyword . '%')
->count();
return $this->success('', [
'lists' => $lists,
'count' => $count,
'page_no' => $page_no,
'page_size' => $page_size
]);
}
}
@@ -83,4 +83,38 @@ class UserController extends BaseAdminController
return $this->fail($res);
}
/**
* @notes 搜索用户(用于创建订单等场景)
* @return \think\response\Json
*/
public function search()
{
$keyword = $this->request->get('keyword', '');
$page_no = $this->request->get('page_no', 1);
$page_size = $this->request->get('page_size', 10);
if (empty($keyword)) {
return $this->success('', ['lists' => [], 'count' => 0]);
}
$offset = ($page_no - 1) * $page_size;
$lists = \app\common\model\user\User::where('nickname|mobile|account', 'like', '%' . $keyword . '%')
->field(['id', 'nickname', 'mobile', 'account', 'avatar'])
->limit($offset, $page_size)
->order('id desc')
->select()
->toArray();
$count = \app\common\model\user\User::where('nickname|mobile|account', 'like', '%' . $keyword . '%')
->count();
return $this->success('', [
'lists' => $lists,
'count' => $count,
'page_no' => $page_no,
'page_size' => $page_size
]);
}
}
@@ -0,0 +1,95 @@
<?php
declare(strict_types=1);
namespace app\adminapi\lists\order;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\Order;
/**
* 订单列表
* Class OrderLists
* @package app\adminapi\lists\order
*/
class OrderLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return array
*/
public function setSearch(): array
{
return [
'=' => ['order_type', 'status'],
'like' => ['order_no'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function lists(): array
{
$where = $this->searchWhere;
// 处理患者关键词搜索
if (!empty($this->params['patient_keyword'])) {
$where[] = ['patient_id', 'in', function ($query) {
$query->table('user')
->where('nickname|mobile', 'like', '%' . $this->params['patient_keyword'] . '%')
->field('id');
}];
}
// 处理创建时间范围
if (!empty($this->params['create_time_start'])) {
$where[] = ['create_time', '>=', $this->params['create_time_start'] . ' 00:00:00'];
}
if (!empty($this->params['create_time_end'])) {
$where[] = ['create_time', '<=', $this->params['create_time_end'] . ' 23:59:59'];
}
return Order::where($where)
->with(['patient', 'creator', 'details'])
->order(['create_time' => 'desc'])
->limit($this->limitOffset, $this->pageSize)
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
*/
public function count(): int
{
$where = $this->searchWhere;
// 处理患者关键词搜索
if (!empty($this->params['patient_keyword'])) {
$where[] = ['patient_id', 'in', function ($query) {
$query->table('user')
->where('nickname|mobile', 'like', '%' . $this->params['patient_keyword'] . '%')
->field('id');
}];
}
// 处理创建时间范围
if (!empty($this->params['create_time_start'])) {
$where[] = ['create_time', '>=', $this->params['create_time_start'] . ' 00:00:00'];
}
if (!empty($this->params['create_time_end'])) {
$where[] = ['create_time', '<=', $this->params['create_time_end'] . ' 23:59:59'];
}
return Order::where($where)->count();
}
}
@@ -0,0 +1,242 @@
<?php
declare(strict_types=1);
namespace app\adminapi\logic\order;
use app\common\model\Order;
use app\common\model\OrderDetail;
use think\facade\Db;
/**
* 订单业务逻辑
* Class OrderLogic
* @package app\adminapi\logic\order
*/
class OrderLogic
{
/**
* @notes 生成订单号
* @return string
*/
public static function generateOrderNo(): string
{
return 'ORD' . date('YmdHis') . mt_rand(100000, 999999);
}
/**
* @notes 创建订单
* @param array $params
* @return Order|false
*/
public static function create(array $params)
{
try {
Db::startTrans();
$order = new Order();
$order->order_no = self::generateOrderNo();
$order->patient_id = $params['patient_id'];
$order->creator_id = $params['creator_id'];
$order->order_type = $params['order_type'];
$order->amount = $params['amount'];
$order->status = 1; // 待支付
$order->remark = $params['remark'] ?? '';
$order->save();
// 创建订单详情
if (!empty($params['details'])) {
foreach ($params['details'] as $detail) {
$orderDetail = new OrderDetail();
$orderDetail->order_id = $order->id;
$orderDetail->related_type = $detail['related_type'];
$orderDetail->related_id = $detail['related_id'];
$orderDetail->quantity = $detail['quantity'] ?? 1;
$orderDetail->unit_price = $detail['unit_price'];
$orderDetail->total_price = $detail['total_price'];
$orderDetail->save();
}
}
Db::commit();
return $order;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑订单
* @param int $id
* @param array $params
* @return bool
*/
public static function edit(int $id, array $params): bool
{
try {
$order = Order::find($id);
if (!$order) {
self::setError('订单不存在');
return false;
}
if (isset($params['remark'])) {
$order->remark = $params['remark'];
}
$order->save();
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 支付订单
* @param int $id
* @param string $paymentMethod
* @return bool
*/
public static function pay(int $id, string $paymentMethod): bool
{
try {
$order = Order::find($id);
if (!$order) {
self::setError('订单不存在');
return false;
}
if ($order->status != 1) {
self::setError('订单状态不允许支付');
return false;
}
$order->status = 2; // 已支付
$order->payment_method = $paymentMethod;
$order->payment_time = date('Y-m-d H:i:s');
$order->save();
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 取消订单
* @param int $id
* @return bool
*/
public static function cancel(int $id): bool
{
try {
$order = Order::find($id);
if (!$order) {
self::setError('订单不存在');
return false;
}
if ($order->status != 1) {
self::setError('只有待支付的订单才能取消');
return false;
}
$order->status = 3; // 已取消
$order->save();
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 退款订单
* @param int $id
* @return bool
*/
public static function refund(int $id): bool
{
try {
$order = Order::find($id);
if (!$order) {
self::setError('订单不存在');
return false;
}
if ($order->status != 2) {
self::setError('只有已支付的订单才能退款');
return false;
}
$order->status = 4; // 已退款
$order->save();
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除订单
* @param int $id
* @return bool
*/
public static function delete(int $id): bool
{
try {
$order = Order::find($id);
if (!$order) {
self::setError('订单不存在');
return false;
}
// 删除订单详情
OrderDetail::where('order_id', $id)->delete();
// 删除订单
$order->delete();
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 获取订单详情
* @param int $id
* @return array|null
*/
public static function detail(int $id): ?array
{
$order = Order::with(['patient', 'creator', 'details'])
->find($id);
if (!$order) {
return null;
}
return $order->toArray();
}
private static $error = '';
public static function setError(string $error): void
{
self::$error = $error;
}
public static function getError(): string
{
return self::$error;
}
}
@@ -338,7 +338,7 @@ class DiagnosisLogic extends BaseLogic
try {
// 获取配置
$config = self::getTrtcConfig();
if (!$config) {
self::setError('请先配置腾讯云TRTC参数');
return false;
@@ -1197,4 +1197,158 @@ class DiagnosisLogic extends BaseLogic
return false;
}
}
/**
* @notes 获取就诊卡列表(供小程序调用)
* @param int $patientId
* @return array|false
*/
public static function getCardList(int $patientId)
{
try {
if (!$patientId) {
self::setError('患者ID不能为空');
return false;
}
// 查询该患者的所有诊单
$cardList = Diagnosis::where('patient_id', $patientId)
->where('delete_time', null)
->field([
'id', 'patient_id', 'patient_name', 'gender', 'age',
'diagnosis_date', 'diagnosis_type', 'syndrome_type',
'status', 'create_time', 'update_time'
])
->order('create_time', 'desc')
->select()
->toArray();
// 处理数据格式
foreach ($cardList as &$card) {
// 转换诊断日期为时间戳和格式化文本
if ($card['diagnosis_date']) {
$card['diagnosis_date_text'] = date('Y-m-d', $card['diagnosis_date']);
} else {
$card['diagnosis_date_text'] = '-';
}
// 添加性别描述
$card['gender_desc'] = $card['gender'] == 1 ? '男' : '女';
// 添加状态描述
$card['status_desc'] = $card['status'] == 1 ? '启用' : '禁用';
// 格式化创建时间
if ($card['create_time']) {
$card['create_time'] = date('Y-m-d H:i:s', $card['create_time']);
}
// 格式化更新时间
if ($card['update_time']) {
$card['update_time'] = date('Y-m-d H:i:s', $card['update_time']);
}
}
return $cardList;
} catch (\Exception $e) {
\think\facade\Log::error('获取就诊卡列表失败 - patient_id: ' . $patientId . ', error: ' . $e->getMessage());
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 更新就诊卡(供小程序调用)
* @param array $params
* @return bool
*/
public static function updateCard(array $params)
{
try {
$diagnosisId = $params['id'] ?? 0;
$patientId = $params['patient_id'] ?? 0;
if (!$diagnosisId) {
self::setError('诊单ID不能为空');
return false;
}
if (!$patientId) {
self::setError('患者ID不能为空');
return false;
}
// 获取诊单信息
$diagnosis = Diagnosis::find($diagnosisId);
if (!$diagnosis) {
self::setError('诊单不存在');
return false;
}
// 权限验证:只能修改自己的诊单
if ($diagnosis->patient_id != $patientId) {
\think\facade\Log::warning('非法修改诊单 - diagnosis_id: ' . $diagnosisId . ', patient_id: ' . $patientId . ', actual_patient_id: ' . $diagnosis->patient_id);
self::setError('无权限修改此诊单');
return false;
}
// 准备更新数据
$updateData = [
'patient_name' => $params['patient_name'] ?? '',
'gender' => $params['gender'] ?? 1,
'age' => $params['age'] ?? 0,
'diagnosis_type' => $params['diagnosis_type'] ?? '',
'syndrome_type' => $params['syndrome_type'] ?? '',
'diabetes_type' => $params['diabetes_type'] ?? '',
// 现病史字段
'appetite' => $params['appetite'] ?? '',
'water_intake' => $params['water_intake'] ?? '',
'diet_condition' => $params['diet_condition'] ?? '',
'weight_change' => $params['weight_change'] ?? '',
'body_feeling' => $params['body_feeling'] ?? '',
'sleep_condition' => $params['sleep_condition'] ?? '',
'eye_condition' => $params['eye_condition'] ?? '',
'head_feeling' => $params['head_feeling'] ?? '',
'sweat_condition' => $params['sweat_condition'] ?? '',
'skin_condition' => $params['skin_condition'] ?? '',
'urine_condition' => $params['urine_condition'] ?? '',
'stool_condition' => $params['stool_condition'] ?? '',
'kidney_condition' => $params['kidney_condition'] ?? '',
'fatty_liver_degree' => $params['fatty_liver_degree'] ?? '',
// 既往史字段
'past_history' => $params['past_history'] ?? '',
'trauma_history' => $params['trauma_history'] ?? 0,
'surgery_history' => $params['surgery_history'] ?? 0,
'allergy_history' => $params['allergy_history'] ?? 0,
'family_history' => $params['family_history'] ?? 0,
'pregnancy_history' => $params['pregnancy_history'] ?? 0,
// 临床信息
'symptoms' => $params['symptoms'] ?? '',
'tongue_coating' => $params['tongue_coating'] ?? '',
'pulse' => $params['pulse'] ?? '',
'treatment_principle' => $params['treatment_principle'] ?? '',
'prescription' => $params['prescription'] ?? '',
'doctor_advice' => $params['doctor_advice'] ?? '',
'remark' => $params['remark'] ?? '',
'update_time' => time()
];
// 处理诊断日期
if (!empty($params['diagnosis_date'])) {
$updateData['diagnosis_date'] = strtotime($params['diagnosis_date']);
}
// 执行更新
$diagnosis->save($updateData);
\think\facade\Log::info('诊单更新成功 - diagnosis_id: ' . $diagnosisId . ', patient_id: ' . $patientId);
return true;
} catch (\Exception $e) {
\think\facade\Log::error('更新诊单失败 - error: ' . $e->getMessage());
self::setError($e->getMessage());
return false;
}
}
}
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace app\adminapi\validate\order;
use app\common\validate\BaseValidate;
/**
* 订单验证
* Class OrderValidate
* @package app\adminapi\validate\order
*/
class OrderValidate extends BaseValidate
{
protected $rule = [
'id' => 'require|integer',
'patient_id' => 'require|integer',
'creator_id' => 'require|integer',
'order_type' => 'require|in:1,2,3',
'amount' => 'require|float',
'status' => 'require|in:1,2,3,4',
'payment_method' => 'in:alipay,wechat,bank',
'remark' => 'string|max:500',
];
protected $message = [
'patient_id.require' => '患者ID必填',
'creator_id.require' => '创建人ID必填',
'order_type.require' => '订单类型必填',
'order_type.in' => '订单类型不正确',
'amount.require' => '订单金额必填',
'status.require' => '订单状态必填',
'status.in' => '订单状态不正确',
'payment_method.in' => '支付方式不正确',
];
protected $scene = [
'create' => ['patient_id', 'creator_id', 'order_type', 'amount'],
'edit' => ['id', 'remark'],
'detail' => ['id'],
'pay' => ['id', 'payment_method'],
'cancel' => ['id'],
'refund' => ['id'],
'delete' => ['id'],
];
}
+95 -1
View File
@@ -28,7 +28,7 @@ class TcmController extends BaseApiController
* @notes 不需要登录的方法
* @var array
*/
public array $notNeedLogin = ['getPatientSignature', 'diagnosisDetail', 'getDict', 'confirmDiagnosis'];
public array $notNeedLogin = ['getPatientSignature', 'diagnosisDetail', 'getDict', 'confirmDiagnosis', 'getCardList'];
/**
* @notes 获取患者签名(供小程序调用)
@@ -129,4 +129,98 @@ class TcmController extends BaseApiController
return $this->fail($e->getMessage());
}
}
/**
* @notes 获取就诊卡列表(供小程序调用)
* @return \think\response\Json
*/
public function getCardList()
{
$patientId = $this->request->get('patient_id');
if (!$patientId) {
return $this->fail('患者ID不能为空');
}
try {
$result = DiagnosisLogic::getCardList($patientId);
if ($result === false) {
return $this->fail(DiagnosisLogic::getError());
}
return $this->data($result);
} catch (\Exception $e) {
return $this->fail($e->getMessage());
}
}
/**
* @notes 更新就诊卡(供小程序调用)
* @return \think\response\Json
*/
public function updateCard()
{
$params = [
'id' => $this->request->post('id'),
'patient_id' => $this->request->post('patient_id'),
'patient_name' => $this->request->post('patient_name'),
'gender' => $this->request->post('gender'),
'age' => $this->request->post('age'),
'diagnosis_date' => $this->request->post('diagnosis_date'),
'diagnosis_type' => $this->request->post('diagnosis_type'),
'syndrome_type' => $this->request->post('syndrome_type'),
'diabetes_type' => $this->request->post('diabetes_type'),
// 现病史字段
'appetite' => $this->request->post('appetite'),
'water_intake' => $this->request->post('water_intake'),
'diet_condition' => $this->request->post('diet_condition'),
'weight_change' => $this->request->post('weight_change'),
'body_feeling' => $this->request->post('body_feeling'),
'sleep_condition' => $this->request->post('sleep_condition'),
'eye_condition' => $this->request->post('eye_condition'),
'head_feeling' => $this->request->post('head_feeling'),
'sweat_condition' => $this->request->post('sweat_condition'),
'skin_condition' => $this->request->post('skin_condition'),
'urine_condition' => $this->request->post('urine_condition'),
'stool_condition' => $this->request->post('stool_condition'),
'kidney_condition' => $this->request->post('kidney_condition'),
'fatty_liver_degree' => $this->request->post('fatty_liver_degree'),
// 既往史字段
'past_history' => $this->request->post('past_history'),
'trauma_history' => $this->request->post('trauma_history'),
'surgery_history' => $this->request->post('surgery_history'),
'allergy_history' => $this->request->post('allergy_history'),
'family_history' => $this->request->post('family_history'),
'pregnancy_history' => $this->request->post('pregnancy_history'),
// 临床信息
'symptoms' => $this->request->post('symptoms'),
'tongue_coating' => $this->request->post('tongue_coating'),
'pulse' => $this->request->post('pulse'),
'treatment_principle' => $this->request->post('treatment_principle'),
'prescription' => $this->request->post('prescription'),
'doctor_advice' => $this->request->post('doctor_advice'),
'remark' => $this->request->post('remark')
];
if (!$params['id']) {
return $this->fail('诊单ID不能为空');
}
if (!$params['patient_id']) {
return $this->fail('患者ID不能为空');
}
try {
$result = DiagnosisLogic::updateCard($params);
if ($result === false) {
return $this->fail(DiagnosisLogic::getError());
}
return $this->success('更新成功');
} catch (\Exception $e) {
return $this->fail($e->getMessage());
}
}
}
+1 -1
View File
@@ -119,7 +119,7 @@ class UserController extends BaseApiController
*/
public function setInfo()
{
$params = (new SetUserInfoValidate())->post()->goCheck(null, ['id' => $this->userId]);
$params = (new SetUserInfoValidate())->post()->goCheck();
$result = UserLogic::setInfo($this->userId, $params);
if (false === $result) {
return $this->fail(UserLogic::getError());
+36 -10
View File
@@ -72,13 +72,20 @@ class UserLogic extends BaseLogic
{
$user = User::where(['id' => $userId])
->with('diagnosis')
->field('id,sn,sex,account,password,nickname,real_name,avatar,mobile,create_time,user_money')
->field('id,sn,sex,account,password,nickname,real_name,avatar,mobile,age,create_time,user_money')
->findOrEmpty();
$user['has_password'] = !empty($user['password']);
$user['has_auth'] = self::hasWechatAuth($userId);
$user['version'] = config('project.version');
$user->hidden(['password']);
return $user->toArray();
// 字段映射,便于前端使用
$result = $user->toArray();
$result['phone'] = $result['mobile'] ?? '';
$result['gender'] = $result['sex'] ?? 1;
$result['patient_name'] = $result['real_name'] ?? '';
return $result;
}
@@ -86,21 +93,40 @@ class UserLogic extends BaseLogic
* @notes 设置用户信息
* @param int $userId
* @param array $params
* @return User|false
* @return bool
* @author 段誉
* @date 2022/9/21 16:53
*/
public static function setInfo(int $userId, array $params)
{
try {
if ($params['field'] == "avatar") {
$params['value'] = FileService::setFileUrl($params['value']);
// 支持批量更新多个字段
$updateData = ['id' => $userId];
// 字段映射
$fieldMap = [
'avatar' => 'avatar',
'phone' => 'mobile',
'nickname' => 'nickname',
'sex' => 'sex',
'age' => 'age',
'patient_name' => 'real_name'
];
// 处理头像
if (isset($params['avatar']) && !empty($params['avatar'])) {
$updateData['avatar'] = FileService::setFileUrl($params['avatar']);
}
return User::update([
'id' => $userId,
$params['field'] => $params['value']]
);
// 处理其他字段
foreach ($fieldMap as $key => $field) {
if ($key !== 'avatar' && isset($params[$key])) {
$updateData[$field] = $params[$key];
}
}
User::update($updateData);
return true;
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
+11 -38
View File
@@ -27,47 +27,20 @@ use app\common\validate\BaseValidate;
class SetUserInfoValidate extends BaseValidate
{
protected $rule = [
'field' => 'require|checkField',
'value' => 'require',
'avatar' => 'string',
'phone' => 'regex:/^1[3-9]\d{9}$/|',
'nickname' => 'string|max:50',
'gender' => 'in:0,1',
'age' => 'integer|between:0,150',
'patient_name' => 'string|max:50'
];
protected $message = [
'field.require' => '参数缺失',
'value.require' => '值不存在',
'phone.regex' => '手机号格式不正确',
'nickname.max' => '昵称不能超过50个字符',
'gender.in' => '性别参数错误',
'age.between' => '年龄必须在0-150之间',
'patient_name.max' => '姓名不能超过50个字符'
];
/**
* @notes 校验字段内容
* @param $value
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/9/21 17:01
*/
protected function checkField($value, $rule, $data)
{
$allowField = [
'nickname', 'account', 'sex', 'avatar', 'real_name',
];
if (!in_array($value, $allowField)) {
return '参数错误';
}
if ($value == 'account') {
$user = User::where([
['account', '=', $data['value']],
['id', '<>', $data['id']]
])->findOrEmpty();
if (!$user->isEmpty()) {
return '账号已被使用!';
}
}
return true;
}
}
+163
View File
@@ -0,0 +1,163 @@
<?php
declare(strict_types=1);
namespace app\common\model;
use think\model\concern\SoftDelete;
/**
* 订单模型
* Class Order
* @package app\common\model
*/
class Order extends BaseModel
{
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $name = 'order';
/**
* @notes 关联订单详情
* @return \think\model\relation\HasMany
*/
public function details()
{
return $this->hasMany(OrderDetail::class, 'order_id', 'id');
}
/**
* @notes 关联患者
* @return \think\model\relation\BelongsTo
*/
public function patient()
{
return $this->belongsTo('app\common\model\user\User', 'patient_id', 'id');
}
/**
* @notes 关联创建人
* @return \think\model\relation\BelongsTo
*/
public function creator()
{
return $this->belongsTo('app\common\model\admin\Admin', 'creator_id', 'id');
}
/**
* @notes 搜索器-订单号
*/
public function searchOrderNoAttr($query, $value, $data)
{
if ($value) {
$query->where('order_no', 'like', '%' . $value . '%');
}
}
/**
* @notes 搜索器-患者关键词
*/
public function searchPatientKeywordAttr($query, $value, $data)
{
if ($value) {
$query->whereHas('patient', function ($q) use ($value) {
$q->where('nickname|mobile', 'like', '%' . $value . '%');
});
}
}
/**
* @notes 搜索器-订单类型
*/
public function searchOrderTypeAttr($query, $value, $data)
{
if ($value) {
$query->where('order_type', '=', $value);
}
}
/**
* @notes 搜索器-订单状态
*/
public function searchStatusAttr($query, $value, $data)
{
if ($value) {
$query->where('status', '=', $value);
}
}
/**
* @notes 搜索器-创建时间开始
*/
public function searchCreateTimeStartAttr($query, $value, $data)
{
if ($value) {
$query->where('create_time', '>=', $value . ' 00:00:00');
}
}
/**
* @notes 搜索器-创建时间结束
*/
public function searchCreateTimeEndAttr($query, $value, $data)
{
if ($value) {
$query->where('create_time', '<=', $value . ' 23:59:59');
}
}
/**
* @notes 获取器-订单类型描述
*/
public function getOrderTypeDescAttr($value, $data)
{
$typeMap = [1 => '挂号费', 2 => '问诊费', 3 => '药品费用'];
return $typeMap[$data['order_type']] ?? '未知';
}
/**
* @notes 获取器-订单状态描述
*/
public function getStatusDescAttr($value, $data)
{
$statusMap = [1 => '待支付', 2 => '已支付', 3 => '已取消', 4 => '已退款'];
return $statusMap[$data['status']] ?? '未知';
}
/**
* @notes 获取器-患者名称
*/
public function getPatientNameAttr($value, $data)
{
if ($value) {
return $value;
}
$patient = $this->patient()->find();
return $patient ? $patient->nickname : '';
}
/**
* @notes 获取器-患者电话
*/
public function getPatientPhoneAttr($value, $data)
{
if ($value) {
return $value;
}
$patient = $this->patient()->find();
return $patient ? $patient->mobile : '';
}
/**
* @notes 获取器-创建人名称
*/
public function getCreatorNameAttr($value, $data)
{
if ($value) {
return $value;
}
$creator = $this->creator()->find();
return $creator ? $creator->name : '';
}
}
+33
View File
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace app\common\model;
/**
* 订单详情模型
* Class OrderDetail
* @package app\common\model
*/
class OrderDetail extends BaseModel
{
protected $table = 'la_order_detail';
/**
* @notes 关联订单
* @return \think\model\relation\BelongsTo
*/
public function order()
{
return $this->belongsTo(Order::class, 'order_id', 'id');
}
/**
* @notes 获取器-关联类型描述
*/
public function getRelatedTypeDescAttr($value, $data)
{
$typeMap = ['appointment' => '挂号', 'diagnosis' => '问诊', 'medicine' => '药品'];
return $typeMap[$data['related_type']] ?? '未知';
}
}