| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace common\models\user;
- use common\enums\StatusEnum;
- use Exception;
- use RuntimeException;
- use Yii;
- /**
- * This is the model class for table "qimall_medication_recipient".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id
- * @property string $name
- * @property string $mobile
- * @property string $id_card
- * @property int $sex
- * @property int $age
- * @property int $is_allergy_history 是否有过敏史(0:无 1:有)
- * @property string $allergy_history_details 过敏史详情
- * @property int $is_medical_history 是否有疾病史(0:无 1:有)
- * @property string $sickness_detail 疾病史详情
- * @property int $liver_function_status 肝功能(0:正常 1:异常)
- * @property int $kidney_function_status 肾功能(0:正常 1:异常)
- * @property int $pregnancy_breastfeeding_status 妊娠哺乳状态 (0:否 1:备孕中 2:怀孕中 3:正在哺乳 男性传0 默认0)
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class MedicationRecipient extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_medication_recipient';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['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'],
- [['name'], 'string', 'max' => 20],
- [['mobile'], 'string', 'max' => 11],
- [['id_card'], 'string', 'max' => 18],
- [['allergy_history_details', 'sickness_detail'], 'string', 'max' => 100],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'sex' => 'Sex',
- 'age' => 'Age',
- 'name' => 'Name',
- 'mobile' => 'Mobile',
- 'id_card' => 'Id Card',
- 'is_allergy_history' => 'Is Allergy History',
- 'allergy_history_details' => 'Allergy History Details',
- 'is_medical_history' => 'Is Medical History',
- 'sickness_detail' => 'Sickness Detail',
- 'liver_function_status' => 'Liver Function Status',
- 'kidney_function_status' => 'Kidney Function Status',
- 'pregnancy_breastfeeding_status' => 'Pregnancy Breastfeeding Status',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * @param array $params
- *
- * @return bool|self
- */
- public static function setData(array $params)
- {
- try {
- if (!empty($params['id'])) {
- $model = static::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (!$model) {
- throw new RuntimeException('数据不存在或已删除');
- }
- if ($model->mall_id != $params['mall_id']) {
- throw new RuntimeException('不允许操作此数据');
- }
- if (!empty($params['user_id']) && $model->user_id != $params['user_id']) {
- throw new RuntimeException('不允许操作此数据');
- }
- } else {
- $model = new static();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '')) {
- throw new RuntimeException($model->getErrorMessage());
- }
- if (!$model->save()) {
- throw new RuntimeException($model->getErrorMessage());
- }
- return $model;
- } catch (Exception $e) {
- static::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|