Commit 263aea97 by 赵增煜

Merge branch 'bug-fix-1201' into develop

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