where('uid', $conditions['uid']); } })->orderByRaw($sort)->paginate($limit, $fields); return $this->response($result); } public function findBy(array $conditions, array $fields){ $result = BaseTable::where(function($query) use($conditions){ if (isset($conditions['id'])){ $query->where('id', $conditions['id']); } if (isset($conditions['uid'])){ $query->where('uid', $conditions['uid']); } })->first($fields); return $result ? $this->response($result) : $this->error()->dataDoesNotExist(); } public function create(array $data) { //此用户和身份证号是否存在绑定关系 $hisData = BaseTable::where('uid', $data['uid'])->where('id_number', $data['id_number'])->first(['id']); if ($hisData) { $this->error()->dataDoesExist('已存在绑定关系'); } //微信帐号信息 $wxInfo = User::where('id', $data['uid'])->first(['id','weichat_uid','wx_headimgurl']); if (!$wxInfo) { $this->error()->userDoesNotExist(); } //身份证信息 $idCardInfo = idCardInfo($data['id_number']); try { $dbData = DB::transaction(function () use ($data, $wxInfo, $idCardInfo) { if ($data['is_chat'] == BaseTable::IS_CHAT_1) { BaseTable::where('uid', $data['uid'])->update(['is_chat'=>BaseTable::IS_CHAT_0]); } //在线咨询接口交互 $ThirdConsult = ThirdConsultFacade::customerCreate('', $data['id_number'], $data['name'], $idCardInfo['sex'], 90, $idCardInfo['age'], $data['phone'], $wxInfo->weichat_uid, $wxInfo->wx_headimgurl); $data['third_customer_openid'] = $ThirdConsult->getData()->data->open_id; return BaseTable::create($data); //还未知HIS结构,停止向下 //HIS接口交互 $address = $data['city'].$data['addiress']; $hisData = HisApiFacade::patientRegister($data['name'], $data['sex']=='男'?1:2, $data['phone'], $address, $data['id_number']); if ($hisData->getData()->code == self::SUCCESS_CODE && $ThirdConsult->getData()->code == self::SUCCESS_CODE) { $data['third_customer_openid'] = $ThirdConsult->getData()->data->open_id; $data['yktid'] = isset($hisData->getData()->data->yktid)?$hisData->getData()->data->yktid:$hisData->getData()->data->ykt_id; $data['card'] = $hisData->getData()->data->yktbh; return BaseTable::create($data); } }); return $this->response($dbData); } catch (\Exception $e) { $this->setLog(self::TYPENAME.'失败', $this->startTime(), [$e->getMessage()]); $this->error()->fail(); } } public function updateBy(array $conditions, array $data) { //此用户和身份证号是否存在绑定关系 $hisData = BaseTable::where('id', $conditions['id'])->first(); if (!$hisData) { $this->error()->dataDoesNotExist('此就诊人不存在'); } //微信帐号信息 $wxInfo = User::where('id', $conditions['uid'])->first(['id','weichat_uid','wx_headimgurl']); if (!$wxInfo) { $this->error()->userDoesNotExist(); } //身份证信息 $idCardInfo = idCardInfo($data['id_number']); try { DB::transaction(function () use ($hisData, $wxInfo, $idCardInfo, $data, $conditions) { //在线咨询接口交互 更新患者信息 ThirdConsultFacade::customerCreate($hisData->third_customer_openid, $data['id_number'], $data['name'], $idCardInfo['sex'], 90, $idCardInfo['age'], $data['phone'], $wxInfo->wechat_uid, $wxInfo->wx_headimgurl); if ($data['is_chat'] == BaseTable::IS_CHAT_1) { BaseTable::where('uid', $conditions['uid'])->update(['is_chat'=>BaseTable::IS_CHAT_0]); } BaseTable::where(function($query) use($conditions){ if (isset($conditions['id'])){ $query->where('id', $conditions['id']); } if (isset($conditions['uid'])){ $query->where('uid', $conditions['uid']); } })->update($data); }); return $this->response(); } catch (\Exception $e) { $this->setLog(self::TYPENAME.'更新 失败', $this->startTime(), [$e->getMessage()]); $this->error()->fail(); } } public function deleteBy(array $conditions) { $result = BaseTable::where(function($query) use($conditions){ if (isset($conditions['id'])){ $query->where('id', $conditions['id']); } if (isset($conditions['uid'])){ $query->where('uid', $conditions['uid']); } })->delete(); return $result ? $this->response($result) : $this->error()->fail(); } }