sku as $sku) { $this->prescriptionCheck($form, $sku, $symptom, $checkedGoodsIds, $oneExecFlag); } } /** * 处方药类型验证 * * @param $sku * @param $symptom * @param $checkedGoodsIds * @param $oneExecFlag * * @return void */ private function prescriptionCheck($form, $sku, $symptom, &$checkedGoodsIds, &$oneExecFlag) { // 如果是处方药需要验证必填参数 if ($sku['goods']['goods_subtype'] == GoodsTypeEnum::GOODS_SUBTYPE_PRESCRIPTION) { if (isset($checkedGoodsIds[$sku['goods_id']])) { return; } if (!$oneExecFlag) { $cloudPrescriptionSettingService = new \addons\CloudPrescription\common\services\SettingService(['mall_id' => $form->mall_id]); if ( !MallAddons::isInstall($form->mall_id, AddonsEnum::ADDONS_NAME_CLOUD_PRESCRIPTION) || !$cloudPrescriptionSettingService->isEnable() ) { throw new RuntimeException('暂不支持购买处方药'); } if (empty($form['data']['medication_recipient_id'])) { throw new RuntimeException('用药人必选'); } // 查询用药人信息 $medicationRecipientService = new MedicationRecipientService(['mall_id' => $form->mall_id, 'user_id' => $form->user_id]); $medicationRecipient = $medicationRecipientService->detail($form['data']['medication_recipient_id']); if (empty($medicationRecipient)) { throw new RuntimeException('用药人信息不存在'); } // 记录用药人信息 $form->process_extra_data['medication_recipient'] = $medicationRecipient; $oneExecFlag = true; } if (empty($symptom[$sku['goods_id']])) { throw new RuntimeException('疾病必选'); } if (array_diff($symptom[$sku['goods_id']], json_decode($sku['goods']['extra']['symptom_list'], true))) { throw new RuntimeException('疾病选择有误'); } $checkedGoodsIds[$sku['goods_id']] = true; } } }