| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace common\models\order;
- use common\enums\StatusEnum;
- use Exception;
- use RuntimeException;
- use Yii;
- /**
- * This is the model class for table "qimall_order_prescription_details".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id
- * @property int $order_id 订单id
- * @property string|null $symptom 下单选择的症状
- * @property int $prescription_status 开方状态 (-1 开方失败 0: 未开方 1: 已开方)
- * @property string $prescription_err_msg 开方失败消息
- * @property string $img_url 处方图片url
- * @property string|null $medication_recipient 处方图片url
- * @property int $audit_status 审核状态 -1审核不通过 0待审核 1待复核 2已核发
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class OrderPrescriptionDetails extends \common\models\base\BaseActiveRecord
- {
- const PRESCRIPTION_STATUS_FAIL = -1; // 开方失败
- const PRESCRIPTION_STATUS_UNOPEN = 0; // 未开方
- const PRESCRIPTION_STATUS_OPENED = 1; // 已开方
- const PRESCRIPTION_STATUS_MAP = [
- self::PRESCRIPTION_STATUS_UNOPEN => '待开方',
- self::PRESCRIPTION_STATUS_OPENED => '成功',
- self::PRESCRIPTION_STATUS_FAIL => '失败',
- ];
- const AUDIT_STATUS_REJECTED = -1; // 审核不通过
- const AUDIT_STATUS_PENDING = 0; // 待审核
- const AUDIT_STATUS_TO_BE_REVIEWED = 1; // 待复核
- const AUDIT_STATUS_ISSUED = 2; // 已核发
- const AUDIT_STATUS_MAP = [
- self::AUDIT_STATUS_REJECTED => '审核不通过',
- self::AUDIT_STATUS_PENDING => '待审核',
- self::AUDIT_STATUS_TO_BE_REVIEWED => '待复核',
- self::AUDIT_STATUS_ISSUED => '已核发',
- ];
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_order_prescription_details';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'order_id', 'prescription_status', 'audit_status', 'status', 'created_at', 'updated_at'], 'integer'],
- [['symptom', 'medication_recipient'], 'safe'],
- [['prescription_err_msg'], 'string', 'max' => 100],
- [['img_url'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'order_id' => 'Order ID',
- 'symptom' => 'Symptom',
- 'prescription_status' => 'Prescription Status',
- 'prescription_err_msg' => 'Prescription Err Msg',
- 'img_url' => 'Img Url',
- 'medication_recipient' => 'Medication Recipient',
- 'audit_status' => 'Audit 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('不允许操作此数据');
- }
- } 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;
- }
- }
- }
|