OrderPrescriptionDetails.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace common\models\order;
  3. use common\enums\StatusEnum;
  4. use Exception;
  5. use RuntimeException;
  6. use Yii;
  7. /**
  8. * This is the model class for table "qimall_order_prescription_details".
  9. *
  10. * @property int $id
  11. * @property int $mall_id
  12. * @property int $user_id
  13. * @property int $order_id 订单id
  14. * @property string|null $symptom 下单选择的症状
  15. * @property int $prescription_status 开方状态 (-1 开方失败 0: 未开方 1: 已开方)
  16. * @property string $prescription_err_msg 开方失败消息
  17. * @property string $img_url 处方图片url
  18. * @property string|null $medication_recipient 处方图片url
  19. * @property int $audit_status 审核状态 -1审核不通过 0待审核 1待复核 2已核发
  20. * @property int $status 状态[-1:删除;0:禁用;1启用]
  21. * @property int $created_at
  22. * @property int $updated_at
  23. */
  24. class OrderPrescriptionDetails extends \common\models\base\BaseActiveRecord
  25. {
  26. const PRESCRIPTION_STATUS_FAIL = -1; // 开方失败
  27. const PRESCRIPTION_STATUS_UNOPEN = 0; // 未开方
  28. const PRESCRIPTION_STATUS_OPENED = 1; // 已开方
  29. const PRESCRIPTION_STATUS_MAP = [
  30. self::PRESCRIPTION_STATUS_UNOPEN => '待开方',
  31. self::PRESCRIPTION_STATUS_OPENED => '成功',
  32. self::PRESCRIPTION_STATUS_FAIL => '失败',
  33. ];
  34. const AUDIT_STATUS_REJECTED = -1; // 审核不通过
  35. const AUDIT_STATUS_PENDING = 0; // 待审核
  36. const AUDIT_STATUS_TO_BE_REVIEWED = 1; // 待复核
  37. const AUDIT_STATUS_ISSUED = 2; // 已核发
  38. const AUDIT_STATUS_MAP = [
  39. self::AUDIT_STATUS_REJECTED => '审核不通过',
  40. self::AUDIT_STATUS_PENDING => '待审核',
  41. self::AUDIT_STATUS_TO_BE_REVIEWED => '待复核',
  42. self::AUDIT_STATUS_ISSUED => '已核发',
  43. ];
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public static function tableName()
  48. {
  49. return 'qimall_order_prescription_details';
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function rules()
  55. {
  56. return [
  57. [['mall_id', 'user_id', 'order_id', 'prescription_status', 'audit_status', 'status', 'created_at', 'updated_at'], 'integer'],
  58. [['symptom', 'medication_recipient'], 'safe'],
  59. [['prescription_err_msg'], 'string', 'max' => 100],
  60. [['img_url'], 'string', 'max' => 255],
  61. ];
  62. }
  63. /**
  64. * {@inheritdoc}
  65. */
  66. public function attributeLabels()
  67. {
  68. return [
  69. 'id' => 'ID',
  70. 'mall_id' => 'Mall ID',
  71. 'user_id' => 'User ID',
  72. 'order_id' => 'Order ID',
  73. 'symptom' => 'Symptom',
  74. 'prescription_status' => 'Prescription Status',
  75. 'prescription_err_msg' => 'Prescription Err Msg',
  76. 'img_url' => 'Img Url',
  77. 'medication_recipient' => 'Medication Recipient',
  78. 'audit_status' => 'Audit Status',
  79. 'status' => 'Status',
  80. 'created_at' => 'Created At',
  81. 'updated_at' => 'Updated At',
  82. ];
  83. }
  84. /**
  85. * @param array $params
  86. *
  87. * @return bool|self
  88. */
  89. public static function setData(array $params)
  90. {
  91. try {
  92. if (!empty($params['id'])) {
  93. $model = static::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  94. if (!$model) {
  95. throw new RuntimeException('数据不存在或已删除');
  96. }
  97. if ($model->mall_id != $params['mall_id']) {
  98. throw new RuntimeException('不允许操作此数据');
  99. }
  100. } else {
  101. $model = new static();
  102. $model->loadDefaultValues();
  103. }
  104. if (!$model->load($params, '')) {
  105. throw new RuntimeException($model->getErrorMessage());
  106. }
  107. if (!$model->save()) {
  108. throw new RuntimeException($model->getErrorMessage());
  109. }
  110. return $model;
  111. } catch (Exception $e) {
  112. static::$static_error = $e->getMessage();
  113. return false;
  114. }
  115. }
  116. }