MedicationRecipient.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace common\models\user;
  3. use common\enums\StatusEnum;
  4. use Exception;
  5. use RuntimeException;
  6. use Yii;
  7. /**
  8. * This is the model class for table "qimall_medication_recipient".
  9. *
  10. * @property int $id
  11. * @property int $mall_id
  12. * @property int $user_id
  13. * @property string $name
  14. * @property string $mobile
  15. * @property string $id_card
  16. * @property int $sex
  17. * @property int $age
  18. * @property int $is_allergy_history 是否有过敏史(0:无 1:有)
  19. * @property string $allergy_history_details 过敏史详情
  20. * @property int $is_medical_history 是否有疾病史(0:无 1:有)
  21. * @property string $sickness_detail 疾病史详情
  22. * @property int $liver_function_status 肝功能(0:正常 1:异常)
  23. * @property int $kidney_function_status 肾功能(0:正常 1:异常)
  24. * @property int $pregnancy_breastfeeding_status 妊娠哺乳状态 (0:否 1:备孕中 2:怀孕中 3:正在哺乳 男性传0 默认0)
  25. * @property int $status 状态[-1:删除;0:禁用;1启用]
  26. * @property int $created_at
  27. * @property int $updated_at
  28. */
  29. class MedicationRecipient extends \common\models\base\BaseActiveRecord
  30. {
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public static function tableName()
  35. {
  36. return 'qimall_medication_recipient';
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function rules()
  42. {
  43. return [
  44. [['mall_id', 'user_id', 'sex', 'age', 'is_allergy_history', 'is_medical_history', 'liver_function_status', 'kidney_function_status', 'pregnancy_breastfeeding_status', 'status', 'created_at', 'updated_at'], 'integer'],
  45. [['name'], 'string', 'max' => 20],
  46. [['mobile'], 'string', 'max' => 11],
  47. [['id_card'], 'string', 'max' => 18],
  48. [['allergy_history_details', 'sickness_detail'], 'string', 'max' => 100],
  49. ];
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function attributeLabels()
  55. {
  56. return [
  57. 'id' => 'ID',
  58. 'mall_id' => 'Mall ID',
  59. 'user_id' => 'User ID',
  60. 'sex' => 'Sex',
  61. 'age' => 'Age',
  62. 'name' => 'Name',
  63. 'mobile' => 'Mobile',
  64. 'id_card' => 'Id Card',
  65. 'is_allergy_history' => 'Is Allergy History',
  66. 'allergy_history_details' => 'Allergy History Details',
  67. 'is_medical_history' => 'Is Medical History',
  68. 'sickness_detail' => 'Sickness Detail',
  69. 'liver_function_status' => 'Liver Function Status',
  70. 'kidney_function_status' => 'Kidney Function Status',
  71. 'pregnancy_breastfeeding_status' => 'Pregnancy Breastfeeding Status',
  72. 'status' => 'Status',
  73. 'created_at' => 'Created At',
  74. 'updated_at' => 'Updated At',
  75. ];
  76. }
  77. /**
  78. * @param array $params
  79. *
  80. * @return bool|self
  81. */
  82. public static function setData(array $params)
  83. {
  84. try {
  85. if (!empty($params['id'])) {
  86. $model = static::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  87. if (!$model) {
  88. throw new RuntimeException('数据不存在或已删除');
  89. }
  90. if ($model->mall_id != $params['mall_id']) {
  91. throw new RuntimeException('不允许操作此数据');
  92. }
  93. if (!empty($params['user_id']) && $model->user_id != $params['user_id']) {
  94. throw new RuntimeException('不允许操作此数据');
  95. }
  96. } else {
  97. $model = new static();
  98. $model->loadDefaultValues();
  99. }
  100. if (!$model->load($params, '')) {
  101. throw new RuntimeException($model->getErrorMessage());
  102. }
  103. if (!$model->save()) {
  104. throw new RuntimeException($model->getErrorMessage());
  105. }
  106. return $model;
  107. } catch (Exception $e) {
  108. static::$static_error = $e->getMessage();
  109. return false;
  110. }
  111. }
  112. }