Commit 216d1b53 by 赵增煜

bug修复

parent e0705467
...@@ -205,6 +205,11 @@ public function delete(Request $request) ...@@ -205,6 +205,11 @@ public function delete(Request $request)
if (! $pharmacy) { if (! $pharmacy) {
return $this->failed('该药店不存在'); return $this->failed('该药店不存在');
} }
# 判断该药店下是否有几个开启的药师
$pharmacist = PharmacistModel::where('pharmacy_id', $pharmacy->id)->where('status', 1)->count();
if( $pharmacist <= 1 ){
return $this->failed('无法删除,至少需要一个开启的药师!');
}
$id = $request->input('id'); $id = $request->input('id');
$data = PharmacistModel::where('id', $id)->where('pharmacy_id', $pharmacy->id)->first(); $data = PharmacistModel::where('id', $id)->where('pharmacy_id', $pharmacy->id)->first();
if (! $data) { if (! $data) {
......
...@@ -259,17 +259,26 @@ public function create(Request $request) ...@@ -259,17 +259,26 @@ public function create(Request $request)
$prescription->pharmacy_id = $pharmacy->id; $prescription->pharmacy_id = $pharmacy->id;
$prescription->pharmacy_name = $pharmacy->name; $prescription->pharmacy_name = $pharmacy->name;
// 分派药师,先搜索是否存在默认药师,如果不存在则随机抽取一个 // 分派药师,先搜索是否存在默认药师,如果不存在则随机抽取一个
$pharmacist = PharmacistModel::where('status', 1) $pharmacist = PharmacistModel::where('status', PharmacistModel::IS_STATUS_TRUE)
->where('pharmacy_id', $pharmacy_id) ->where('is_default', PharmacistModel::IS_DEFAULT_TRUE)
->where(function ($query) { ->first();
$query->where('is_default', 1) if (! $pharmacist) {
->orWhere('is_default', 0); $pharmacist = PharmacistModel::where('status', PharmacistModel::IS_STATUS_TRUE)
})
->inRandomOrder() ->inRandomOrder()
->first(); ->first();
}
// $pharmacist = PharmacistModel::where('status', 1)
// ->where('pharmacy_id', $pharmacy_id)
// ->where(function ($query) {
// $query->where('is_default', 1)
// ->orWhere('is_default', 0);
// })
// ->inRandomOrder()
// ->first();
if (! $pharmacist) { if (! $pharmacist) {
return $this->failed('药师信息不存在'); return $this->failed('该药店暂无可审方药师,请联系管理员!');
} }
Log::info('药师:'.json_encode($pharmacist)); Log::info('药师:'.json_encode($pharmacist));
$prescription->pharmacist_id = $pharmacist->id; $prescription->pharmacist_id = $pharmacist->id;
......
...@@ -32,6 +32,15 @@ class PharmacistModel extends Model ...@@ -32,6 +32,15 @@ class PharmacistModel extends Model
self::IS_DEFAULT_TRUE => 'success', self::IS_DEFAULT_TRUE => 'success',
]; ];
// 是否启用[0=否,1=是]
const IS_STATUS_FALSE = 0;
const IS_STATUS_TRUE = 1;
const IS_STATUS_MAP = [
self::IS_STATUS_FALSE => '否',
self::IS_STATUS_TRUE => '是',
];
// 药师关联的药店,多对一 // 药师关联的药店,多对一
public function pharmacy() public function pharmacy()
{ {
......
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