| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace api\modules\v1\controllers\user;
- use api\controllers\OnAuthController;
- use api\services\MedicationRecipientService;
- use common\enums\ApiStatusEnum;
- use Yii;
- class MedicationRecipientController extends OnAuthController
- {
- /**
- * @var string
- */
- public $modelClass = '';
- /**
- * @return void
- */
- public function actionIndex()
- {
- $service = new MedicationRecipientService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]);
- $this->success('success', $service->list(), ApiStatusEnum::CODE_SUCCESS, 0);
- }
- /**
- * @return void
- */
- public function actionEdit()
- {
- $params = $this->request->post();
- $rules = [
- [['name', 'mobile', 'id_card'], 'required'],
- [['id', 'sex', 'age', 'is_allergy_history', 'is_medical_history', 'liver_function_status', 'kidney_function_status', 'pregnancy_breastfeeding_status'], 'integer'],
- [['name', 'mobile', 'id_card', 'allergy_history_details', 'sickness_detail'], 'string'],
- [['sex'], 'in', 'range' => [1, 2]],
- [['is_allergy_history', 'is_medical_history', 'liver_function_status', 'kidney_function_status'], 'in', 'range' => [0, 1]],
- [['pregnancy_breastfeeding_status'], 'in', 'range' => [0, 1, 2, 3]],
- ];
- $res = Yii::$app->services->validate->validate($params, $rules);
- if ($res === false) {
- $this->error(Yii::$app->services->validate->getErrorMessage());
- return;
- }
- $service = new MedicationRecipientService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]);
- if (!$service->edit($params)) {
- $this->error($service->getError());
- return;
- }
- $this->success('success');
- }
- /**
- * @return void
- */
- public function actionDetail()
- {
- $id = $this->request->get('id', 0);
- if ($id <= 0) {
- $this->error('参数错误');
- return;
- }
- $service = new MedicationRecipientService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]);
- $this->success('success', $service->detail($id), ApiStatusEnum::CODE_SUCCESS, 0);
- }
- /**
- * @return void
- */
- public function actionDel()
- {
- $id = $this->request->post('id');
- if ($id <= 0) {
- $this->error('参数错误');
- return;
- }
- $service = new MedicationRecipientService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]);
- if (!$service->del($id)) {
- $this->error($service->getError() ?: '删除失败');
- return;
- }
- $this->success('success');
- }
- }
|