MedicationRecipientController.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace api\modules\v1\controllers\user;
  3. use api\controllers\OnAuthController;
  4. use api\services\MedicationRecipientService;
  5. use common\enums\ApiStatusEnum;
  6. use Yii;
  7. class MedicationRecipientController extends OnAuthController
  8. {
  9. /**
  10. * @var string
  11. */
  12. public $modelClass = '';
  13. /**
  14. * @return void
  15. */
  16. public function actionIndex()
  17. {
  18. $service = new MedicationRecipientService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]);
  19. $this->success('success', $service->list(), ApiStatusEnum::CODE_SUCCESS, 0);
  20. }
  21. /**
  22. * @return void
  23. */
  24. public function actionEdit()
  25. {
  26. $params = $this->request->post();
  27. $rules = [
  28. [['name', 'mobile', 'id_card'], 'required'],
  29. [['id', 'sex', 'age', 'is_allergy_history', 'is_medical_history', 'liver_function_status', 'kidney_function_status', 'pregnancy_breastfeeding_status'], 'integer'],
  30. [['name', 'mobile', 'id_card', 'allergy_history_details', 'sickness_detail'], 'string'],
  31. [['sex'], 'in', 'range' => [1, 2]],
  32. [['is_allergy_history', 'is_medical_history', 'liver_function_status', 'kidney_function_status'], 'in', 'range' => [0, 1]],
  33. [['pregnancy_breastfeeding_status'], 'in', 'range' => [0, 1, 2, 3]],
  34. ];
  35. $res = Yii::$app->services->validate->validate($params, $rules);
  36. if ($res === false) {
  37. $this->error(Yii::$app->services->validate->getErrorMessage());
  38. return;
  39. }
  40. $service = new MedicationRecipientService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]);
  41. if (!$service->edit($params)) {
  42. $this->error($service->getError());
  43. return;
  44. }
  45. $this->success('success');
  46. }
  47. /**
  48. * @return void
  49. */
  50. public function actionDetail()
  51. {
  52. $id = $this->request->get('id', 0);
  53. if ($id <= 0) {
  54. $this->error('参数错误');
  55. return;
  56. }
  57. $service = new MedicationRecipientService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]);
  58. $this->success('success', $service->detail($id), ApiStatusEnum::CODE_SUCCESS, 0);
  59. }
  60. /**
  61. * @return void
  62. */
  63. public function actionDel()
  64. {
  65. $id = $this->request->post('id');
  66. if ($id <= 0) {
  67. $this->error('参数错误');
  68. return;
  69. }
  70. $service = new MedicationRecipientService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]);
  71. if (!$service->del($id)) {
  72. $this->error($service->getError() ?: '删除失败');
  73. return;
  74. }
  75. $this->success('success');
  76. }
  77. }