OrderModifyShippingAddressLog.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_modify_shipping_address_log".
  9. *
  10. * @property int $id
  11. * @property int $mall_id
  12. * @property int $order_id
  13. * @property int $status -1删除 1禁用 2正常
  14. * @property int $created_at
  15. * @property int $updated_at
  16. */
  17. class OrderModifyShippingAddressLog extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return 'qimall_order_modify_shipping_address_log';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'order_id', 'status', 'created_at', 'updated_at'], 'integer']
  33. ];
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'id' => 'ID',
  42. 'mall_id' => 'Mall ID',
  43. 'order_id' => 'Order ID',
  44. 'status' => 'Status',
  45. 'created_at' => 'Created At',
  46. 'updated_at' => 'Updated At',
  47. ];
  48. }
  49. /**
  50. * @param array $params
  51. *
  52. * @return bool|self
  53. */
  54. public static function setData(array $params)
  55. {
  56. try {
  57. if (!empty($params['id'])) {
  58. $model = self::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  59. if (!$model) {
  60. throw new RuntimeException('数据不存在');
  61. }
  62. if ($model->mall_id != $params['mall_id']) {
  63. throw new RuntimeException('不允许操作此数据');
  64. }
  65. } else {
  66. $model = new self();
  67. $model->loadDefaultValues();
  68. }
  69. if (!$model->load($params, '')) {
  70. throw new RuntimeException($model->getErrorMessage());
  71. }
  72. if (!$model->save()) {
  73. throw new RuntimeException($model->getErrorMessage());
  74. }
  75. return $model;
  76. } catch (Exception $e) {
  77. self::$static_error = $e->getMessage();
  78. return false;
  79. }
  80. }
  81. }