Commit 3825a4af by 赵增煜

药店

parent 883ee984
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
use App\Http\Controllers\BaseApiController; use App\Http\Controllers\BaseApiController;
use App\Models\DrugModel; use App\Models\DrugModel;
use App\Models\PharmacyDrugModel;
use App\Models\PharmacyModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
// 药品控制器 // 药品控制器
...@@ -11,22 +13,33 @@ class DrugController extends BaseApiController ...@@ -11,22 +13,33 @@ class DrugController extends BaseApiController
{ {
public function test() public function test()
{ {
return $this->success(['a' => 1, 'b' => 2, 'c' => 3]); $search_input = "测试";
$data = PharmacyDrugModel::where("pharmacy_id", 1)
->whereHas('drug', function ($query) use ($search_input) {
$query->where('name', 'LIKE', "%{$search_input}%")
->orWhere('code','LIKE',"%{$search_input}%"); // 这里的'%筛选条件%'是你想要匹配的药品名称
})
->paginate(10);
// $drugs = $data->map(function ($row) {
// return $row->drug;
// });
return $this->success($data);
} }
// 药品列表 // 药品列表
public function drugList(Request $request) public function drugList(Request $request)
{ {
// $code = $request->input('code'); $authInfo = auth('api')->user();
// TODO 通过药店编号筛选药品列表 $pharmacy = PharmacyModel::where('user_id', $authInfo->id)->first();
// pharmacy_id = $request->input('code'); $search_input = $request->input('search_input');
$data = DrugModel::query()->paginate(10); $data = PharmacyDrugModel::where("pharmacy_id", $pharmacy->id)
->whereHas('drug', function ($query) use ($search_input) {
// $total = DrugModel::query()->count(); if ($search_input) {
// $data = [ $query->where('name', 'LIKE', "%{$search_input}%")
// 'data'=>$drugList, ->orWhere('code','LIKE',"%{$search_input}%"); // 这里的'%筛选条件%'是你想要匹配的药品名称
// 'total'=>$total }
// ]; })
->paginate(10);
return $this->success($data); return $this->success($data);
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
use App\Common\Util; use App\Common\Util;
use App\Http\Controllers\BaseApiController; use App\Http\Controllers\BaseApiController;
use App\Models\PatientModel; use App\Models\PatientModel;
use App\Models\PharmacyModel;
use App\Models\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
// 问诊人控制器 // 问诊人控制器
...@@ -18,20 +20,23 @@ public function test() ...@@ -18,20 +20,23 @@ public function test()
// 获取问诊人列表 // 获取问诊人列表
public function patientList(Request $request) public function patientList(Request $request)
{ {
$login_type = $request->input('login_type'); $authInfo = auth('api')->user();
$id = $request->input('id');
$query = PatientModel::query(); $query = PatientModel::query();
if ($login_type == 0) { // 用户 if ($authInfo->last_login_type == User::LOGIN_TYPE_USER) { // 用户
$query = $query->where('user_id', $id); $query = $query->where('user_id', $authInfo->id);
} elseif ($login_type == 2) { // 药店 } elseif ($authInfo->last_login_type == User::LOGIN_TYPE_PHARMACY) { // 药店
$query = $query->where('pharmacy_id', $id); $pharmacy = PharmacyModel::query()->where('user_id', $authInfo->id)->first();
$query = $query->where('pharmacy_id', $pharmacy->id);
} }
$search_input = $request->input('search_input'); $search_input = $request->input('search_input');
if ($search_input) { if ($search_input) {
$query->where('mobile', 'like', "%{$search_input}%"); $query->where('mobile', 'like', "%{$search_input}%");
// ->orWhere('mobile', 'like', "%{$search_input}%"); // ->orWhere('mobile', 'like', "%{$search_input}%");
} }
$data = $query->paginate(10); // 分页
$page = $request->input('page', 1);
$perPage = $request->input('per_page', 10);
$data = $query->orderBy('id', 'desc')->paginate($perPage, ['*'], 'page', $page);
return $this->success($data); return $this->success($data);
} }
...@@ -40,13 +45,16 @@ public function patientList(Request $request) ...@@ -40,13 +45,16 @@ public function patientList(Request $request)
public function add(Request $request) public function add(Request $request)
{ {
$data = $request->all(); $data = $request->all();
// TODO 表中缺少关联 $authInfo = auth('api')->user();
if ($authInfo->last_login_type == User::LOGIN_TYPE_USER) { // 用户
// TODO 验证身份证号码是否正确 $data['user_id'] = $authInfo->id;
} elseif ($authInfo->last_login_type == User::LOGIN_TYPE_PHARMACY) { // 药店
$pharmacy = PharmacyModel::query()->where('user_id', $authInfo->id)->first();
$data['pharmacy_id'] = $pharmacy->id;
}
$idCardInfo = Util::getIdCardInfo($data['id_card']); $idCardInfo = Util::getIdCardInfo($data['id_card']);
$data['gender'] = $idCardInfo['gender']; $data['gender'] = $idCardInfo['gender'];
// $data['age'] = $idCardInfo['age']; $data['is_default'] = 0;
$res = PatientModel::create($data); $res = PatientModel::create($data);
if ($res) { if ($res) {
return $this->success($res); return $this->success($res);
...@@ -92,19 +100,19 @@ public function setDefault(Request $request) ...@@ -92,19 +100,19 @@ public function setDefault(Request $request)
{ {
// 通过id找到是否存在默认问诊人,如果存在比对id是否相同,如果不同则修改默认问诊人状态 // 通过id找到是否存在默认问诊人,如果存在比对id是否相同,如果不同则修改默认问诊人状态
// TODO 验证条件待调整 // TODO 验证条件待调整
$login_type = $request->input('login_type'); $authInfo = auth('api')->user();
$uid = $request->input('uid');
// 把该账号下的默认问诊人状态改为0 // 把该账号下的默认问诊人状态改为0
$query = PatientModel::where('id', $uid)->where('is_default', 1); $query = PatientModel::where('is_default', 1);
if ($login_type == 0) { if ($authInfo->last_login_type == User::LOGIN_TYPE_USER) {
$query = $query->where('user_id', $uid); $query = $query->where('user_id', $authInfo->id);
} elseif ($login_type == 2) { } elseif ($authInfo->last_login_type == User::LOGIN_TYPE_PHARMACY) {
$query = $query->where('pharmacy_id', $uid); $pharmacy = PharmacyModel::query()->where('user_id', $authInfo->id)->first();
$query = $query->where('pharmacy_id', $pharmacy->id);
} }
$data = $query->first(); $defaultPatient = $query->first();
if ($data) { if ($defaultPatient) {
$data->is_default = 0; $defaultPatient->is_default = 0;
$data->save(); $defaultPatient->save();
} }
// 把当前问诊人设为默认 // 把当前问诊人设为默认
$id = $request->input('id'); $id = $request->input('id');
...@@ -114,20 +122,21 @@ public function setDefault(Request $request) ...@@ -114,20 +122,21 @@ public function setDefault(Request $request)
} }
$data->is_default = 1; $data->is_default = 1;
$data->save(); $data->save();
return $this->success($data); return $this->success($data);
} }
// 获取默认问诊人 // 获取默认问诊人
public function getDefault(Request $request) public function getDefault(Request $request)
{ {
$login_type = $request->input('login_type'); $authInfo = auth('api')->user();
$id = $request->input('id');
$query = PatientModel::where('is_default', 1); $query = PatientModel::where('is_default', 1);
if ($login_type == 0) { $last_login_type = $authInfo->last_login_type;
$query = $query->where('user_id', $id); $user_id = $authInfo->id;
} elseif ($login_type == 2) { if ($last_login_type == User::LOGIN_TYPE_USER) {
$query = $query->where('pharmacy_id', $id); $query = $query->where('user_id', $user_id);
} elseif ($last_login_type == User::LOGIN_TYPE_PHARMACY) {
$pharmacy = PharmacyModel::query()->where('user_id', $user_id)->first();
$query = $query->where('pharmacy_id', $pharmacy->id);
} }
$data = $query->first(); $data = $query->first();
if ($data) { if ($data) {
......
...@@ -36,40 +36,40 @@ public function prescriptionList(Request $request) ...@@ -36,40 +36,40 @@ public function prescriptionList(Request $request)
$authInfo = auth('api')->user(); $authInfo = auth('api')->user();
$query = PrescriptionModel::query(); $query = PrescriptionModel::query();
// TODO 判断当前登录的用户角色 // TODO 判断当前登录的用户角色
# $userInfo = User::with(['doctor', 'pharmacist'])->find($authInfo->id); // $userInfo = User::with(['doctor', 'pharmacist'])->find($authInfo->id);
if( $authInfo->last_login_type == User::LOGIN_TYPE_USER ){ if ($authInfo->last_login_type == User::LOGIN_TYPE_USER) {
$query->where('user_id', $authInfo->id); $query->where('user_id', $authInfo->id);
}else if( $authInfo->last_login_type == User::LOGIN_TYPE_DOCTOR ){ // 医师 } elseif ($authInfo->last_login_type == User::LOGIN_TYPE_DOCTOR) { // 医师
$doctor = DoctorModel::query()->where('user_id', $authInfo->id)->first(); $doctor = DoctorModel::query()->where('user_id', $authInfo->id)->first();
$query->where('doctor_id', $doctor->id); $query->where('doctor_id', $doctor->id);
}else if( $authInfo->last_login_type == User::LOGIN_TYPE_PHARMACY ){ // 药店 } elseif ($authInfo->last_login_type == User::LOGIN_TYPE_PHARMACY) { // 药店
$pharmacy = PharmacyModel::query()->where('user_id', $authInfo->id)->first(); $pharmacy = PharmacyModel::query()->where('user_id', $authInfo->id)->first();
$query->where('pharmacy_id', $pharmacy->id); $query->where('pharmacy_id', $pharmacy->id);
} }
# 时间段 // 时间段
$start_time = $request->input('start_time'); $start_time = $request->input('start_time');
$end_time = $request->input('end_time'); $end_time = $request->input('end_time');
if ($start_time && $end_time) { if ($start_time && $end_time) {
$query->whereBetween('created_at', [$start_time, $end_time]); $query->whereBetween('created_at', [$start_time, $end_time]);
} else if ($start_time) { } elseif ($start_time) {
$query->where('created_at', '>=', $start_time); $query->where('created_at', '>=', $start_time);
} else if ($end_time) { } elseif ($end_time) {
$query->where('created_at', '<=', $end_time); $query->where('created_at', '<=', $end_time);
} }
# 状态 // 状态
$status = $request->input('status'); $status = $request->input('status');
if ($status) { if ($status) {
$query->where('status', $status); $query->where('status', $status);
} }
# 分页 // 分页
$page = $request->input('page', 1); $page = $request->input('page', 1);
$perPage = $request->input('per_page', 10); $perPage = $request->input('per_page', 10);
$prescription = $query->orderBy('id','desc')->paginate($perPage, ['*'], 'page', $page); $prescription = $query->orderBy('id', 'desc')->paginate($perPage, ['*'], 'page', $page);
# $prescription = $query->paginate(10); // $prescription = $query->paginate(10);
return $this->success($prescription); return $this->success($prescription);
} }
......
...@@ -23,8 +23,9 @@ ...@@ -23,8 +23,9 @@
Route::post('login', 'App\Api\Controllers\UserController@login'); Route::post('login', 'App\Api\Controllers\UserController@login');
// Route::get('test', 'App\Api\Controllers\DrugController@test'); // Route::get('test', 'App\Api\Controllers\DrugController@test');
# 获取药品列表 // # 获取药品列表
Route::get('/drugs', 'App\Api\Controllers\DrugController@drugList'); // Route::get('/drugs', 'App\Api\Controllers\DrugController@drugList');
# Route::get('/test', 'App\Api\Controllers\DrugController@test');
# 获取药店列表 # 获取药店列表
Route::get('/pharmacys', 'App\Api\Controllers\PharmacyController@PharmacyList'); Route::get('/pharmacys', 'App\Api\Controllers\PharmacyController@PharmacyList');
# 获取诊断列表 # 获取诊断列表
...@@ -53,5 +54,27 @@ ...@@ -53,5 +54,27 @@
// 获取用户信息 // 获取用户信息
Route::get('/users', 'App\Api\Controllers\UserController@userInfo'); Route::get('/users', 'App\Api\Controllers\UserController@userInfo');
# 获取药品列表
Route::get('/drugs', 'App\Api\Controllers\DrugController@drugList');
// # Route::get('/test', 'App\Api\Controllers\DrugController@test');
// # 获取药店列表
// Route::get('/pharmacys', 'App\Api\Controllers\PharmacyController@PharmacyList');
// # 获取诊断列表
// Route::get('/diagnosis', 'App\Api\Controllers\DiagnosisController@diagnosisList');
// # 获取问诊人列表
// Route::get('/patients', 'App\Api\Controllers\PatientController@patientList');
// # 问诊人新增
// Route::post('/patients-add', 'App\Api\Controllers\PatientController@add');
// # 问诊人编辑
// Route::post('/patients-update', 'App\Api\Controllers\PatientController@update');
// # 问诊人删除
// Route::post('/patients-delete', 'App\Api\Controllers\PatientController@delete');
// # 设置默认问诊人
// Route::post('/patients-setDefault', 'App\Api\Controllers\PatientController@setDefault');
// # 获取默认问诊人
// Route::post('/patients-getDefault', 'App\Api\Controllers\PatientController@getDefault');
// # 获取问诊问题列表
// Route::get('/inquirys', 'App\Api\Controllers\InquiryController@InquirytList');
// # 开方
// Route::post('/prescription-create', 'App\Api\Controllers\PrescriptionController@create');
}); });
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment