| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace api\services;
- use addons\RealAuth\common\logic\AuthLogic;
- use addons\RealAuth\common\models\RealAuthUser;
- use common\enums\AddonsEnum;
- use common\enums\StatusEnum;
- use common\models\mall\MallAddons;
- use common\models\user\MedicationRecipient;
- use Exception;
- use Yii;
- class MedicationRecipientService extends BaseService
- {
- public $user_id;
- /**
- * 用药人列表
- *
- * @return array
- */
- public function list(): array
- {
- return MedicationRecipient::listPage([
- 'where' => [
- [
- 'mall_id' => $this->mall_id,
- 'status' => StatusEnum::ENABLED,
- 'user_id' => $this->user_id
- ]
- ],
- 'select' => 'id, name, mobile, id_card, sex, age',
- 'order' => 'id desc'
- ]);
- }
- /**
- * 用药人详情
- *
- * @param int $id
- *
- * @return array
- */
- public function detail(int $id): array
- {
- $find = MedicationRecipient::find();
- $select = 'id, name, mobile, id_card, sex, age, is_allergy_history, allergy_history_details, is_medical_history, ' .
- 'sickness_detail, liver_function_status, kidney_function_status, pregnancy_breastfeeding_status';
- MedicationRecipient::paramPack([
- 'where' => [
- [
- 'mall_id' => $this->mall_id,
- 'status' => StatusEnum::ENABLED,
- 'user_id' => $this->user_id,
- 'id' => $id
- ]
- ],
- 'select' => $select,
- ], $find);
- return $find->asArray()->one() ?: [];
- }
- /**
- * 编辑/保存 用药人
- *
- * @param array $data
- *
- * @return bool
- */
- public function edit(array $data): bool
- {
- if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_REAL_AUTH)) {
- $config = Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_REAL_AUTH, 'basic');
- if (!empty($config['status'])) {
- try {
- if (!(new AuthLogic)->auth([
- 'user_id' => $this->user_id,
- 'mall_id' => $this->mall_id,
- 'real_name' => $data['name'],
- 'id_no' => $data['id_card'],
- 'auth_type' => RealAuthUser::USER,
- 'check_pass_mode' => 1
- ])) {
- $this->error = '实名验证失败';
- return false;
- }
- }catch (Exception $e) {
- if ($e->getMessage() !== '您已通过实名认证') {
- $this->error = $e->getMessage();
- return false;
- }
- }
- }
- }
- $data['user_id'] = $this->user_id;
- $data['mall_id'] = $this->mall_id;
- if (MedicationRecipient::setData($data) === false) {
- $this->error = MedicationRecipient::getStaticError();
- return false;
- }
- return true;
- }
- /**
- * 删除用药人
- *
- * @param int $id
- *
- * @return void
- */
- public function del(int $id): bool
- {
- return (bool)MedicationRecipient::updateAll(
- [
- 'updated_at' => time(),
- 'status' => StatusEnum::DELETE
- ],
- [
- 'id' => $id,
- 'mall_id' => $this->mall_id,
- 'status' => StatusEnum::ENABLED,
- 'user_id' => $this->user_id
- ]
- );
- }
- }
|